From 97f0f142a6496a813c0568b67c12c890ed35f36d Mon Sep 17 00:00:00 2001 From: Kelvin Clement Mwinuka Date: Thu, 25 Jan 2024 18:59:04 +0800 Subject: [PATCH] Added configuration options for snapshot threshold and snapshot interval --- Dockerfile | 4 +++- src/raft/raft.go | 4 ++-- src/utils/config.go | 10 ++++++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 48cd2a9..a32c613 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,10 +20,12 @@ CMD "./server" \ "--cert" "${CERT}" \ "--pluginDir" "${PLUGIN_DIR}" \ "--dataDir" "${DATA_DIR}" \ + "--snapshotThreshold" "${SNAPSHOT_THRESHOLD}" \ + "--snapshotInterval" "${SNAPSHOT_INTERVAL}" \ "--tls=${TLS}" \ "--inMemory=${IN_MEMORY}" \ "--bootstrapCluster=${BOOTSTRAP_CLUSTER}" \ "--aclConfig=${ACL_CONFIG}" \ "--requirePass=${REQUIRE_PASS}" \ "--password=${PASSWORD}" \ - "--forwardCommand=${FORWARD_COMMAND}" \ \ No newline at end of file + "--forwardCommand=${FORWARD_COMMAND}" \ diff --git a/src/raft/raft.go b/src/raft/raft.go index b33029e..6bc61f4 100644 --- a/src/raft/raft.go +++ b/src/raft/raft.go @@ -39,8 +39,8 @@ func (r *Raft) RaftInit(ctx context.Context) { raftConfig := raft.DefaultConfig() raftConfig.LocalID = raft.ServerID(conf.ServerID) - raftConfig.SnapshotThreshold = 5 - raftConfig.SnapshotInterval = 5 * time.Second + raftConfig.SnapshotThreshold = conf.SnapShotThreshold + raftConfig.SnapshotInterval = time.Duration(conf.SnapshotInterval) * time.Second var logStore raft.LogStore var stableStore raft.StableStore diff --git a/src/utils/config.go b/src/utils/config.go index c1fd4a9..b20e3a2 100644 --- a/src/utils/config.go +++ b/src/utils/config.go @@ -28,6 +28,8 @@ type Config struct { ForwardCommand bool `json:"forwardCommand" yaml:"forwardCommand"` RequirePass bool `json:"requirePass" yaml:"requirePass"` Password string `json:"password" yaml:"password"` + SnapShotThreshold uint64 `json:"snapshotThreshold" yaml:"snapshotThreshold"` + SnapshotInterval uint `json:"snapshotInterval" yaml:"snapshotInterval"` } func GetConfig() (Config, error) { @@ -39,12 +41,14 @@ func GetConfig() (Config, error) { serverId := flag.String("serverId", "1", "Server ID in raft cluster. Leave empty for client.") joinAddr := flag.String("joinAddr", "", "Address of cluster member in a cluster to you want to join.") bindAddr := flag.String("bindAddr", "", "Address to bind the server to.") - raftBindPort := flag.Int("raftPort", 7481, "Port to use for intra-cluster communication. Leave on the client.") - mlBindPort := flag.Int("mlPort", 7946, "Port to use for memberlist communication.") + raftBindPort := flag.Uint("raftPort", 7481, "Port to use for intra-cluster communication. Leave on the client.") + mlBindPort := flag.Uint("mlPort", 7946, "Port to use for memberlist communication.") inMemory := flag.Bool("inMemory", false, "Whether to use memory or persistent storage for raft logs and snapshots.") dataDir := flag.String("dataDir", "/var/lib/memstore", "Directory to store raft snapshots and logs.") bootstrapCluster := flag.Bool("bootstrapCluster", false, "Whether this instance should bootstrap a new cluster.") aclConfig := flag.String("aclConfig", "", "ACL config file path.") + 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.") forwardCommand := flag.Bool( "forwardCommand", false, @@ -87,6 +91,8 @@ It is a plain text value by default but you can provide a SHA256 hash by adding ForwardCommand: *forwardCommand, RequirePass: *requirePass, Password: *password, + SnapShotThreshold: *snapshotThreshold, + SnapshotInterval: *snapshotInterval, } if len(*config) > 0 {