Added config flags to choose between aof restore and snapshot restore in standalone mode.

This commit is contained in:
Kelvin Clement Mwinuka
2024-02-01 04:42:44 +08:00
parent 04ddd46d2b
commit 15d289c33d
2 changed files with 16 additions and 4 deletions

View File

@@ -256,8 +256,11 @@ func (server *Server) Start(ctx context.Context) {
StartRewriteAOF: server.StartRewriteAOF, StartRewriteAOF: server.StartRewriteAOF,
FinishRewriteAOF: server.FinishRewriteAOF, FinishRewriteAOF: server.FinishRewriteAOF,
}) })
if err := server.AOFEngine.Restore(ctx); err != nil { if conf.RestoreAOF && !conf.RestoreSnapshot {
log.Println(err) err := server.AOFEngine.Restore(ctx)
if err != nil {
log.Println(err)
}
} }
server.AOFEngine.Start(ctx) server.AOFEngine.Start(ctx)
// Initialize and start standalone snapshot engine // Initialize and start standalone snapshot engine
@@ -272,8 +275,11 @@ func (server *Server) Start(ctx context.Context) {
KeyUnlock: server.KeyUnlock, KeyUnlock: server.KeyUnlock,
SetValue: server.SetValue, SetValue: server.SetValue,
}) })
if err := server.SnapshotEngine.Restore(ctx); err != nil { if conf.RestoreSnapshot {
log.Println(err) err := server.SnapshotEngine.Restore(ctx)
if err != nil {
log.Println(err)
}
} }
server.SnapshotEngine.Start(ctx) server.SnapshotEngine.Start(ctx)
} }

View File

@@ -30,6 +30,8 @@ type Config struct {
Password string `json:"password" yaml:"password"` Password string `json:"password" yaml:"password"`
SnapShotThreshold uint64 `json:"snapshotThreshold" yaml:"snapshotThreshold"` SnapShotThreshold uint64 `json:"snapshotThreshold" yaml:"snapshotThreshold"`
SnapshotInterval uint `json:"snapshotInterval" yaml:"snapshotInterval"` SnapshotInterval uint `json:"snapshotInterval" yaml:"snapshotInterval"`
RestoreSnapshot bool `json:"restoreSnapshot" yaml:"restoreSnapshot"`
RestoreAOF bool `json:"restoreAOF" yaml:"restoreAOF"`
} }
func GetConfig() (Config, error) { func GetConfig() (Config, error) {
@@ -49,6 +51,8 @@ func GetConfig() (Config, error) {
aclConfig := flag.String("aclConfig", "", "ACL config file path.") aclConfig := flag.String("aclConfig", "", "ACL config file path.")
snapshotThreshold := flag.Uint64("snapshotThreshold", 1000, "The number of entries that trigger a snapshot. Default is 1000.") snapshotThreshold := flag.Uint64("snapshotThreshold", 1000, "The number of entries that trigger a snapshot. Default is 1000.")
snapshotInterval := flag.Uint("snapshotInterval", 60*5, "The time interval between snapshots (in seconds). Default is 5 minutes.") snapshotInterval := flag.Uint("snapshotInterval", 60*5, "The time interval between snapshots (in seconds). Default is 5 minutes.")
restoreSnapshot := flag.Bool("restoreSnapshot", false, "This flag prompts the server to restore state from snapshot when set to true. Only works in standalone mode. Higher priority than restoreAOF.")
restoreAOF := flag.Bool("restoreAOF", false, "This flag prompts the server to restore state from append-only logs. Only works in standalone mode. Lower priority than restoreSnapshot.")
forwardCommand := flag.Bool( forwardCommand := flag.Bool(
"forwardCommand", "forwardCommand",
false, false,
@@ -93,6 +97,8 @@ It is a plain text value by default but you can provide a SHA256 hash by adding
Password: *password, Password: *password,
SnapShotThreshold: *snapshotThreshold, SnapShotThreshold: *snapshotThreshold,
SnapshotInterval: *snapshotInterval, SnapshotInterval: *snapshotInterval,
RestoreSnapshot: *restoreSnapshot,
RestoreAOF: *restoreAOF,
} }
if len(*config) > 0 { if len(*config) > 0 {