Skip to content

Commit

Permalink
Merge pull request #61 from replicase/feature/add-server-time-to-pg-s…
Browse files Browse the repository at this point in the history
…ource-checkpoint

feat: add server time info to the pg source checkpoints
  • Loading branch information
rueian authored Jul 24, 2024
2 parents 34cec4b + e4b118d commit ec7ea6d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
8 changes: 5 additions & 3 deletions pkg/cursor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import (
"errors"
"strconv"
"strings"
"time"

"github.com/apache/pulsar-client-go/pulsar"
"github.com/jackc/pglogrepl"
)

type Checkpoint struct {
LSN uint64
Seq uint32
Data []byte
LSN uint64
Seq uint32
Data []byte
ServerTime time.Time
}

func (cp *Checkpoint) Equal(cp2 Checkpoint) bool {
Expand Down
13 changes: 10 additions & 3 deletions pkg/source/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,15 @@ func (p *PGXSource) fetching(ctx context.Context) (change Change, err error) {
p.nextReportTime = time.Time{}
}
change = Change{
Checkpoint: cursor.Checkpoint{LSN: uint64(pkm.ServerWALEnd)},
Message: &pb.Message{Type: &pb.Message_KeepAlive{KeepAlive: &pb.KeepAlive{}}},
Checkpoint: cursor.Checkpoint{
LSN: uint64(pkm.ServerWALEnd),
ServerTime: pkm.ServerTime,
},
Message: &pb.Message{
Type: &pb.Message_KeepAlive{
KeepAlive: &pb.KeepAlive{},
},
},
}
case pglogrepl.XLogDataByteID:
xld, err := pglogrepl.ParseXLogData(msg.Data[1:])
Expand Down Expand Up @@ -221,7 +228,7 @@ func (p *PGXSource) fetching(ctx context.Context) (change Change, err error) {
p.currentSeq++
}
change = Change{
Checkpoint: cursor.Checkpoint{LSN: p.currentLsn, Seq: p.currentSeq},
Checkpoint: cursor.Checkpoint{LSN: p.currentLsn, Seq: p.currentSeq, ServerTime: xld.ServerTime},
Message: m,
}
if !p.first {
Expand Down

0 comments on commit ec7ea6d

Please sign in to comment.