snapshot.go 617 B

12345678910111213141516171819202122232425262728293031323334
  1. package main
  2. import (
  3. "fmt"
  4. "time"
  5. )
  6. type snapshotConf struct {
  7. // basic
  8. checkingInterval time.Duration
  9. lastWrites uint64
  10. writesThr uint64
  11. }
  12. var snapConf *snapshotConf
  13. func newSnapshotConf() *snapshotConf {
  14. return &snapshotConf{time.Second * 3, etcdStore.TotalWrites(), 20 * 1000}
  15. }
  16. func monitorSnapshot() {
  17. for {
  18. time.Sleep(snapConf.checkingInterval)
  19. currentWrites := etcdStore.TotalWrites() - snapConf.lastWrites
  20. if currentWrites > snapConf.writesThr {
  21. raftServer.TakeSnapshot()
  22. snapConf.lastWrites = etcdStore.TotalWrites()
  23. } else {
  24. fmt.Println(currentWrites)
  25. }
  26. }
  27. }