From 9053071135348bf81df86128428bafea158bc1d3 Mon Sep 17 00:00:00 2001 From: secwall Date: Sun, 7 Jan 2024 12:44:31 +0100 Subject: [PATCH] Use fresh shard state in offline node repair --- internal/app/candidate.go | 2 +- internal/app/manager.go | 2 +- internal/app/repair.go | 7 ++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/app/candidate.go b/internal/app/candidate.go index 964128d..6f0dda6 100644 --- a/internal/app/candidate.go +++ b/internal/app/candidate.go @@ -52,7 +52,7 @@ func (app *App) stateCandidate() appState { app.logger.Error("Candidate: failed to get current master from DCS", "error", err) return stateCandidate } - app.repairLocalNode(shardState, master) + app.repairLocalNode(master) if app.dcs.AcquireLock(pathManagerLock) { return stateManager diff --git a/internal/app/manager.go b/internal/app/manager.go index d895eaf..a21deb0 100644 --- a/internal/app/manager.go +++ b/internal/app/manager.go @@ -65,7 +65,7 @@ func (app *App) stateManager() appState { return stateMaintenance } - app.repairLocalNode(shardState, master) + app.repairLocalNode(master) var switchover Switchover if err := app.dcs.Get(pathCurrentSwitch, &switchover); err == nil { diff --git a/internal/app/repair.go b/internal/app/repair.go index 6bffd3a..08f136a 100644 --- a/internal/app/repair.go +++ b/internal/app/repair.go @@ -107,7 +107,7 @@ func (app *App) repairReplica(node *redis.Node, masterState, state *HostState, m } } -func (app *App) repairLocalNode(shardState map[string]*HostState, master string) { +func (app *App) repairLocalNode(master string) { local := app.shard.Local() offline, err := local.IsOffline(app.ctx) @@ -132,6 +132,11 @@ func (app *App) repairLocalNode(shardState map[string]*HostState, master string) return } + shardState, err := app.getShardStateFromDB() + if err != nil { + app.logger.Error("Local repair: unable to get actual shard state", "error", err) + return + } state, ok := shardState[local.FQDN()] if !ok { app.logger.Error("Local repair: unable to find local node in shard state")