Skip to content

Commit

Permalink
Set initial HB for PITR
Browse files Browse the repository at this point in the history
  • Loading branch information
boris-ilijic committed Aug 12, 2024
1 parent de75e6e commit d9c30b4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion cmd/pbm-agent/pitr.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (a *Agent) getPitr() *currentPitr {
return a.pitrjob
}

// startMon starts monitor (watcher) jobs only on cluster leader.
// startMon starts monitor (watcher) and heartbeat jobs only on cluster leader.
func (a *Agent) startMon(ctx context.Context, cfg *config.Config) {
a.monMx.Lock()
defer a.monMx.Unlock()
Expand Down Expand Up @@ -409,6 +409,7 @@ func (a *Agent) leadNomination(
err = oplog.InitMeta(ctx, a.leadConn)
if err != nil {
l.Error("init meta: %v", err)
return
}

agents, err := topo.ListAgentStatuses(ctx, a.leadConn)
Expand Down Expand Up @@ -890,6 +891,7 @@ func (a *Agent) pitrErrorMonitor(ctx context.Context) {
}
}

// pitrHB job sets PITR heartbeat.
func (a *Agent) pitrHb(ctx context.Context) {
l := log.LogEventFromContext(ctx)
l.Debug("start pitr hb")
Expand Down
8 changes: 7 additions & 1 deletion pbm/oplog/nomination.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,18 @@ const (

// Init add initial PITR document.
func InitMeta(ctx context.Context, conn connect.Client) error {
ts, err := topo.GetClusterTime(ctx, conn)
if err != nil {
return errors.Wrap(err, "init pitr meta, read cluster time")
}

pitrMeta := PITRMeta{
StartTS: time.Now().Unix(),
Nomination: []PITRNomination{},
Replsets: []PITRReplset{},
Hb: ts,
}
_, err := conn.PITRCollection().ReplaceOne(
_, err = conn.PITRCollection().ReplaceOne(
ctx,
bson.D{},
pitrMeta,
Expand Down

0 comments on commit d9c30b4

Please sign in to comment.