|
@@ -0,0 +1,34 @@
|
|
|
|
|
+package main
|
|
|
|
|
+
|
|
|
|
|
+import (
|
|
|
|
|
+ "time"
|
|
|
|
|
+ "fmt"
|
|
|
|
|
+)
|
|
|
|
|
+
|
|
|
|
|
+type snapshotConf struct {
|
|
|
|
|
+ // basic
|
|
|
|
|
+ checkingInterval time.Duration
|
|
|
|
|
+ lastWrites uint64
|
|
|
|
|
+ writesThr uint64
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+var snapConf *snapshotConf
|
|
|
|
|
+
|
|
|
|
|
+func newSnapshotConf() *snapshotConf {
|
|
|
|
|
+ return &snapshotConf {time.Second*3, etcdStore.TotalWrites(), 20*1000}
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+func monitorSnapshot() {
|
|
|
|
|
+ for {
|
|
|
|
|
+ time.Sleep(snapConf.checkingInterval)
|
|
|
|
|
+ currentWrites := etcdStore.TotalWrites() - snapConf.lastWrites
|
|
|
|
|
+
|
|
|
|
|
+ if currentWrites > snapConf.writesThr {
|
|
|
|
|
+ raftServer.TakeSnapshot()
|
|
|
|
|
+ snapConf.lastWrites = etcdStore.TotalWrites()
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+ fmt.Println(currentWrites)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|