Skip to content

Commit cf7ceb7

Browse files
committed
Add stoping balancer logic for restore
1 parent 2aa63f1 commit cf7ceb7

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

cmd/pbm-agent/restore.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,26 @@ func (a *Agent) Restore(ctx context.Context, r *ctrl.RestoreCmd, opid ctrl.OPID,
8787
a.removePitr()
8888
}
8989

90+
// stop balancer during the restore
91+
if a.brief.Sharded && nodeInfo.IsClusterLeader() {
92+
bs, err := topo.GetBalancerStatus(ctx, a.leadConn)
93+
if err != nil {
94+
l.Error("get balancer status: %v", err)
95+
return
96+
}
97+
98+
if bs.IsOn() {
99+
err := topo.SetBalancerStatus(ctx, a.leadConn, topo.BalancerModeOff)
100+
if err != nil {
101+
l.Error("set balancer off: %v", err)
102+
}
103+
104+
l.Debug("waiting for balancer off")
105+
bs := topo.WaitForBalancerOff(ctx, a.leadConn, time.Second*30, l)
106+
l.Debug("balancer status: %s", bs)
107+
}
108+
}
109+
90110
var bcpType defs.BackupType
91111
var bcp *backup.BackupMeta
92112

0 commit comments

Comments
 (0)