From 8a052367681d4cf410756b304ccbba9f42479944 Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Sat, 28 May 2016 22:56:53 -0700 Subject: [PATCH] Support configurable snapshot thresholds --- CHANGELOG.md | 1 + cmd/rqlited/main.go | 3 +++ doc/DESIGN.md | 2 +- store/store.go | 5 +++++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80283d09..9b6bccc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ ## 3.3.0 (unreleased) +- [PR #149](https://github.com/rqlite/rqlite/pull/149): Support configurable Raft snapshot thresholds. - [PR #148](https://github.com/rqlite/rqlite/pull/148): Support pprof information over HTTP. ## 3.2.1 (May 22nd 2016) diff --git a/cmd/rqlited/main.go b/cmd/rqlited/main.go index 976214eb..9fae7da8 100644 --- a/cmd/rqlited/main.go +++ b/cmd/rqlited/main.go @@ -77,6 +77,7 @@ var pprofEnabled bool var dsn string var onDisk bool var noVerifySelect bool +var raftSnapThreshold uint64 var showVersion bool var cpuprofile string @@ -98,6 +99,7 @@ func init() { flag.BoolVar(&onDisk, "ondisk", false, "Use an on-disk SQLite database") flag.BoolVar(&noVerifySelect, "nosel", false, "Don't verify that all queries begin with SELECT") flag.BoolVar(&showVersion, "version", false, "Show version information and exit") + flag.Uint64Var(&raftSnapThreshold, "raftsnap", 8192, "Number of outstanding log entries to trigger snapshot") flag.StringVar(&cpuprofile, "cpuprofile", "", "Write CPU profile to file") flag.Usage = func() { fmt.Fprintf(os.Stderr, "\n%s\n\n", desc) @@ -186,6 +188,7 @@ func main() { if err := store.Open(joinAddr == ""); err != nil { log.Fatalf("failed to open store: %s", err.Error()) } + store.SnapshotThreshold = raftSnapThreshold // Create and configure cluster service. tn := mux.Listen(muxMetaHeader) diff --git a/doc/DESIGN.md b/doc/DESIGN.md index 55c05c20..052bff66 100644 --- a/doc/DESIGN.md +++ b/doc/DESIGN.md @@ -28,4 +28,4 @@ The diagram below shows a high-level view of a rqlite node. └───────────────────────────────────────────────┘ ## Log Compaction -rqlite automatically performs log compaction. After a fixed number of changes rqlite snapshots the SQLite database, and truncates the Raft log. This is a technical feature of the Raft consensus system, and most users of rqlite need not be concerned with this. +rqlite automatically performs log compaction. After a configurable number of changes rqlite snapshots the SQLite database, and truncates the Raft log. This is a technical feature of the Raft consensus system, and most users of rqlite need not be concerned with this. diff --git a/store/store.go b/store/store.go index c5aa18d8..c266d429 100644 --- a/store/store.go +++ b/store/store.go @@ -163,6 +163,8 @@ type Store struct { meta *clusterMeta logger *log.Logger + + SnapshotThreshold uint64 } // New returns a new Store. @@ -208,6 +210,9 @@ func (s *Store) Open(enableSingle bool) error { // Setup Raft configuration. config := raft.DefaultConfig() + if s.SnapshotThreshold != 0 { + config.SnapshotThreshold = s.SnapshotThreshold + } // Check for any existing peers. peers, err := readPeersJSON(filepath.Join(s.raftDir, "peers.json"))