diff --git a/snapshot.go b/snapshot.go new file mode 100644 index 000000000..16a3d8d19 --- /dev/null +++ b/snapshot.go @@ -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) + } + } +} \ No newline at end of file