From d721da7b677d46ea3ff803319a7e6bf9984dad05 Mon Sep 17 00:00:00 2001 From: Preetha Appan Date: Thu, 10 May 2018 17:06:47 -0500 Subject: [PATCH] Also make snapshot interval configurable --- agent/agent.go | 3 +++ agent/config/builder.go | 1 + agent/config/config.go | 1 + agent/config/runtime.go | 5 +++++ agent/config/runtime_test.go | 4 ++++ agent/consul/config.go | 2 +- website/source/docs/agent/options.html.md | 10 ++++++++-- 7 files changed, 23 insertions(+), 3 deletions(-) diff --git a/agent/agent.go b/agent/agent.go index 3b77878b1b..20f5a1ca66 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -766,6 +766,9 @@ func (a *Agent) consulConfig() (*consul.Config, error) { if a.config.RaftSnapshotThreshold != 0 { base.RaftConfig.SnapshotThreshold = uint64(a.config.RaftSnapshotThreshold) } + if a.config.RaftSnapshotInterval != 0 { + base.RaftConfig.SnapshotInterval = a.config.RaftSnapshotInterval + } if a.config.ACLMasterToken != "" { base.ACLMasterToken = a.config.ACLMasterToken } diff --git a/agent/config/builder.go b/agent/config/builder.go index 9a2bdc1d40..6048dab929 100644 --- a/agent/config/builder.go +++ b/agent/config/builder.go @@ -674,6 +674,7 @@ func (b *Builder) Build() (rt RuntimeConfig, err error) { RPCRateLimit: rate.Limit(b.float64Val(c.Limits.RPCRate)), RaftProtocol: b.intVal(c.RaftProtocol), RaftSnapshotThreshold: b.intVal(c.RaftSnapshotThreshold), + RaftSnapshotInterval: b.durationVal("raft_snapshot_interval", c.RaftSnapshotInterval), ReconnectTimeoutLAN: b.durationVal("reconnect_timeout", c.ReconnectTimeoutLAN), ReconnectTimeoutWAN: b.durationVal("reconnect_timeout_wan", c.ReconnectTimeoutWAN), RejoinAfterLeave: b.boolVal(c.RejoinAfterLeave), diff --git a/agent/config/config.go b/agent/config/config.go index 58d585acee..f3345c8b14 100644 --- a/agent/config/config.go +++ b/agent/config/config.go @@ -195,6 +195,7 @@ type Config struct { RPCProtocol *int `json:"protocol,omitempty" hcl:"protocol" mapstructure:"protocol"` RaftProtocol *int `json:"raft_protocol,omitempty" hcl:"raft_protocol" mapstructure:"raft_protocol"` RaftSnapshotThreshold *int `json:"raft_snapshot_threshold,omitempty" hcl:"raft_snapshot_threshold" mapstructure:"raft_snapshot_threshold"` + RaftSnapshotInterval *string `json:"raft_snapshot_interval,omitempty" hcl:"raft_snapshot_interval" mapstructure:"raft_snapshot_interval"` ReconnectTimeoutLAN *string `json:"reconnect_timeout,omitempty" hcl:"reconnect_timeout" mapstructure:"reconnect_timeout"` ReconnectTimeoutWAN *string `json:"reconnect_timeout_wan,omitempty" hcl:"reconnect_timeout_wan" mapstructure:"reconnect_timeout_wan"` RejoinAfterLeave *bool `json:"rejoin_after_leave,omitempty" hcl:"rejoin_after_leave" mapstructure:"rejoin_after_leave"` diff --git a/agent/config/runtime.go b/agent/config/runtime.go index fe1e315f20..66e7e79e7b 100644 --- a/agent/config/runtime.go +++ b/agent/config/runtime.go @@ -905,6 +905,11 @@ type RuntimeConfig struct { // hcl: raft_snapshot_threshold = int RaftSnapshotThreshold int + // RaftSnapshotInterval sets the interval to use when checking whether to create + // a new snapshot. Defaults to 5 seconds. + // hcl: raft_snapshot_threshold = int + RaftSnapshotInterval time.Duration + // ReconnectTimeoutLAN specifies the amount of time to wait to reconnect with // another agent before deciding it's permanently gone. This can be used to // control the time it takes to reap failed nodes from the cluster. diff --git a/agent/config/runtime_test.go b/agent/config/runtime_test.go index 7c1d0ad611..060215c355 100644 --- a/agent/config/runtime_test.go +++ b/agent/config/runtime_test.go @@ -2422,6 +2422,7 @@ func TestFullConfig(t *testing.T) { "protocol": 30793, "raft_protocol": 19016, "raft_snapshot_threshold": 16384, + "raft_snapshot_interval": "30s", "reconnect_timeout": "23739s", "reconnect_timeout_wan": "26694s", "recursors": [ "63.38.39.58", "92.49.18.18" ], @@ -2854,6 +2855,7 @@ func TestFullConfig(t *testing.T) { protocol = 30793 raft_protocol = 19016 raft_snapshot_threshold = 16384 + raft_snapshot_interval = "30s" reconnect_timeout = "23739s" reconnect_timeout_wan = "26694s" recursors = [ "63.38.39.58", "92.49.18.18" ] @@ -3412,6 +3414,7 @@ func TestFullConfig(t *testing.T) { RPCMaxBurst: 44848, RaftProtocol: 19016, RaftSnapshotThreshold: 16384, + RaftSnapshotInterval: 30 * time.Second, ReconnectTimeoutLAN: 23739 * time.Second, ReconnectTimeoutWAN: 26694 * time.Second, RejoinAfterLeave: true, @@ -4092,6 +4095,7 @@ func TestSanitize(t *testing.T) { "RPCProtocol": 0, "RPCRateLimit": 0, "RaftProtocol": 0, + "RaftSnapshotInterval": "0s", "RaftSnapshotThreshold": 0, "ReconnectTimeoutLAN": "0s", "ReconnectTimeoutWAN": "0s", diff --git a/agent/consul/config.go b/agent/consul/config.go index ef7b153438..976f16bdba 100644 --- a/agent/consul/config.go +++ b/agent/consul/config.go @@ -448,7 +448,7 @@ func DefaultConfig() *Config { // Disable shutdown on removal conf.RaftConfig.ShutdownOnRemove = false - // Check every 5 seconds to see if there are enough new entries for a snapshot + // Check every 5 seconds to see if there are enough new entries for a snapshot, can be overridden conf.RaftConfig.SnapshotInterval = 5 * time.Second // Snapshots are created every 8192 entries by default, can be overridden diff --git a/website/source/docs/agent/options.html.md b/website/source/docs/agent/options.html.md index 1d99892389..e1869075d1 100644 --- a/website/source/docs/agent/options.html.md +++ b/website/source/docs/agent/options.html.md @@ -360,7 +360,10 @@ will exit with an error at startup. for more details. * `-raft-snapshot-threshold` - This - control the minimum number of raft commit entries between snapshots that are saved to disk. + controls the minimum number of raft commit entries between snapshots that are saved to disk. + +* `-raft-snapshot-interval` - This + controls how often servers check if they need to save a snapshot to disk. * `-recursor` - Specifies the address of an upstream DNS server. This option may be provided multiple times, and is functionally @@ -939,7 +942,10 @@ Consul will not enable TLS for the HTTP API unless the `https` port has been ass [`-raft-protocol` command-line flag](#_raft_protocol). * `raft_snapshot_threshold` Equivalent to the - [`-raft-snapshot-threshold` command-line flag](#_raft_snapshot_threshold). + [`-raft-snapshot-threshold` command-line flag](#_raft_snapshot_threshold). + +* `raft_snapshot_interval` Equivalent to the + [`-raft-snapshot-interval` command-line flag](#_raft_snapshot_interval). * `reap` This controls Consul's automatic reaping of child processes, which is useful if Consul is running as PID 1 in a Docker container. If this isn't specified, then Consul will