Browse Source

add snpshot

Xiang Li 12 years ago
parent
commit
64eeca3941
1 changed files with 34 additions and 0 deletions
  1. 34 0
      snapshot.go

+ 34 - 0
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)
+		}
+	}
+}