Skip to content

Commit

Permalink
Optionally allow turning psync-able replicas to new master before pro…
Browse files Browse the repository at this point in the history
…mote
  • Loading branch information
secwall committed May 13, 2024
1 parent bf4b3be commit 66ab325
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.55
version: v1.58
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ format:
goimports -w `find . -name '*.go'`

lint:
docker run --rm -v ${CURDIR}:/app -w /app golangci/golangci-lint:v1.55-alpine golangci-lint run -v
docker run --rm -v ${CURDIR}:/app -w /app golangci/golangci-lint:v1.58-alpine golangci-lint run -v

unittests:
go test ./cmd/... ./internal/...
Expand Down
27 changes: 27 additions & 0 deletions internal/app/switchover.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,33 @@ func (app *App) performSwitchover(shardState map[string]*HostState, activeNodes
app.waitPoisonPill(app.config.Redis.WaitPoisonPillTimeout)
}

if app.config.Redis.TurnBeforeSwitchover {
var psyncNodes []string
for _, host := range aliveActiveNodes {
if host == newMaster {
continue
}
if isPartialSyncPossible(shardState[host], shardState[newMaster]) {
psyncNodes = append(psyncNodes, host)
}
}

errs := runParallel(func(host string) error {
if !shardState[host].PingOk {
return nil
}
err := app.changeMaster(host, newMaster)
if err != nil {
return err
}
return nil
}, psyncNodes)

err := combineErrors(errs)
if err != nil {
app.logger.Warn("Unable to psync some replicas before promote", "error", err)
}
}
deadline := time.Now().Add(app.config.Redis.WaitPromoteTimeout)
forceDeadline := time.Now().Add(app.config.Redis.WaitPromoteForceTimeout)
promoted := false
Expand Down
2 changes: 2 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type RedisConfig struct {
MaxParallelSyncs int `yaml:"max_parallel_syncs"`
MaxReplicasToWrite int `yaml:"max_replicas_to_write"`
AllowDataLoss bool `yaml:"allow_data_loss"`
TurnBeforeSwitchover bool `yaml:"turn_before_switchover"`
RestartCommand string `yaml:"restart_command"`
}

Expand Down Expand Up @@ -108,6 +109,7 @@ func DefaultRedisConfig() RedisConfig {
MaxParallelSyncs: 1,
MaxReplicasToWrite: -1,
AllowDataLoss: false,
TurnBeforeSwitchover: false,
RestartCommand: "systemctl restart redis-server",
}
}
Expand Down

0 comments on commit 66ab325

Please sign in to comment.