mirror of
https://github.com/EchoVault/SugarDB.git
synced 2025-10-17 13:31:55 +08:00
Added configuration options for snapshot threshold and snapshot interval
This commit is contained in:
@@ -20,10 +20,12 @@ CMD "./server" \
|
|||||||
"--cert" "${CERT}" \
|
"--cert" "${CERT}" \
|
||||||
"--pluginDir" "${PLUGIN_DIR}" \
|
"--pluginDir" "${PLUGIN_DIR}" \
|
||||||
"--dataDir" "${DATA_DIR}" \
|
"--dataDir" "${DATA_DIR}" \
|
||||||
|
"--snapshotThreshold" "${SNAPSHOT_THRESHOLD}" \
|
||||||
|
"--snapshotInterval" "${SNAPSHOT_INTERVAL}" \
|
||||||
"--tls=${TLS}" \
|
"--tls=${TLS}" \
|
||||||
"--inMemory=${IN_MEMORY}" \
|
"--inMemory=${IN_MEMORY}" \
|
||||||
"--bootstrapCluster=${BOOTSTRAP_CLUSTER}" \
|
"--bootstrapCluster=${BOOTSTRAP_CLUSTER}" \
|
||||||
"--aclConfig=${ACL_CONFIG}" \
|
"--aclConfig=${ACL_CONFIG}" \
|
||||||
"--requirePass=${REQUIRE_PASS}" \
|
"--requirePass=${REQUIRE_PASS}" \
|
||||||
"--password=${PASSWORD}" \
|
"--password=${PASSWORD}" \
|
||||||
"--forwardCommand=${FORWARD_COMMAND}" \
|
"--forwardCommand=${FORWARD_COMMAND}" \
|
||||||
|
@@ -39,8 +39,8 @@ func (r *Raft) RaftInit(ctx context.Context) {
|
|||||||
|
|
||||||
raftConfig := raft.DefaultConfig()
|
raftConfig := raft.DefaultConfig()
|
||||||
raftConfig.LocalID = raft.ServerID(conf.ServerID)
|
raftConfig.LocalID = raft.ServerID(conf.ServerID)
|
||||||
raftConfig.SnapshotThreshold = 5
|
raftConfig.SnapshotThreshold = conf.SnapShotThreshold
|
||||||
raftConfig.SnapshotInterval = 5 * time.Second
|
raftConfig.SnapshotInterval = time.Duration(conf.SnapshotInterval) * time.Second
|
||||||
|
|
||||||
var logStore raft.LogStore
|
var logStore raft.LogStore
|
||||||
var stableStore raft.StableStore
|
var stableStore raft.StableStore
|
||||||
|
@@ -28,6 +28,8 @@ type Config struct {
|
|||||||
ForwardCommand bool `json:"forwardCommand" yaml:"forwardCommand"`
|
ForwardCommand bool `json:"forwardCommand" yaml:"forwardCommand"`
|
||||||
RequirePass bool `json:"requirePass" yaml:"requirePass"`
|
RequirePass bool `json:"requirePass" yaml:"requirePass"`
|
||||||
Password string `json:"password" yaml:"password"`
|
Password string `json:"password" yaml:"password"`
|
||||||
|
SnapShotThreshold uint64 `json:"snapshotThreshold" yaml:"snapshotThreshold"`
|
||||||
|
SnapshotInterval uint `json:"snapshotInterval" yaml:"snapshotInterval"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetConfig() (Config, error) {
|
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.")
|
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.")
|
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.")
|
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.")
|
raftBindPort := flag.Uint("raftPort", 7481, "Port to use for intra-cluster communication. Leave on the client.")
|
||||||
mlBindPort := flag.Int("mlPort", 7946, "Port to use for memberlist communication.")
|
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.")
|
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.")
|
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.")
|
bootstrapCluster := flag.Bool("bootstrapCluster", false, "Whether this instance should bootstrap a new cluster.")
|
||||||
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.")
|
||||||
|
snapshotInterval := flag.Uint("snapshotInterval", 60*5, "The time interval between snapshots (in seconds). Default is 5 minutes.")
|
||||||
forwardCommand := flag.Bool(
|
forwardCommand := flag.Bool(
|
||||||
"forwardCommand",
|
"forwardCommand",
|
||||||
false,
|
false,
|
||||||
@@ -87,6 +91,8 @@ It is a plain text value by default but you can provide a SHA256 hash by adding
|
|||||||
ForwardCommand: *forwardCommand,
|
ForwardCommand: *forwardCommand,
|
||||||
RequirePass: *requirePass,
|
RequirePass: *requirePass,
|
||||||
Password: *password,
|
Password: *password,
|
||||||
|
SnapShotThreshold: *snapshotThreshold,
|
||||||
|
SnapshotInterval: *snapshotInterval,
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(*config) > 0 {
|
if len(*config) > 0 {
|
||||||
|
Reference in New Issue
Block a user