From 443d1bce08777aaf503e4f4a818e93efd49e4b72 Mon Sep 17 00:00:00 2001 From: secwall Date: Mon, 9 Sep 2024 17:50:09 +0200 Subject: [PATCH] Let primary to be available for write earlier if data loss is allowed --- internal/app/switchover.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/internal/app/switchover.go b/internal/app/switchover.go index 3138427..81ac35a 100644 --- a/internal/app/switchover.go +++ b/internal/app/switchover.go @@ -354,6 +354,17 @@ func (app *App) performSwitchover(shardState map[string]*HostState, activeNodes app.waitPoisonPill(app.config.Redis.WaitPoisonPillTimeout) } + if len(aliveActiveNodes) == 1 || app.config.Redis.AllowDataLoss || app.config.Redis.MaxReplicasToWrite == 0 { + node := app.shard.Get(newMaster) + err, errConf := node.SetMinReplicas(app.ctx, 0) + if err != nil { + return fmt.Errorf("unable to set %s available for write before promote: %s", newMaster, err.Error()) + } + if errConf != nil { + return fmt.Errorf("unable to rewrite config on %s before promote: %s", newMaster, errConf.Error()) + } + } + if app.config.Redis.TurnBeforeSwitchover { var psyncNodes []string for _, host := range aliveActiveNodes {