From 107762e82aaaeb7211900224698c23cefc32c8d7 Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Wed, 30 Oct 2013 15:14:34 -0700 Subject: [PATCH] fix snapshot --- server/peer_server.go | 6 +++--- store/stats.go | 2 +- store/store.go | 5 +++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/server/peer_server.go b/server/peer_server.go index 2f53d7863..538d3ac70 100644 --- a/server/peer_server.go +++ b/server/peer_server.go @@ -60,7 +60,7 @@ func NewPeerServer(name string, path string, url string, listenHost string, tlsC tlsInfo: tlsInfo, registry: registry, store: store, - snapConf: &snapshotConf{time.Second * 3, 0, 20 * 1000}, + snapConf: &snapshotConf{time.Second * 3, 0, 2}, followersStats: &raftFollowersStats{ Leader: name, Followers: make(map[string]*raftFollowerStats), @@ -391,10 +391,10 @@ func (s *PeerServer) PeerStats() []byte { func (s *PeerServer) monitorSnapshot() { for { time.Sleep(s.snapConf.checkingInterval) - currentWrites := 0 + currentWrites := s.store.TotalTransactions() - s.snapConf.lastWrites if uint64(currentWrites) > s.snapConf.writesThr { s.raftServer.TakeSnapshot() - s.snapConf.lastWrites = 0 + s.snapConf.lastWrites = s.store.TotalTransactions() } } } diff --git a/store/stats.go b/store/stats.go index c18f5cbf0..40dff1175 100644 --- a/store/stats.go +++ b/store/stats.go @@ -73,7 +73,7 @@ func (s *Stats) TotalReads() uint64 { return s.GetSuccess + s.GetFail } -func (s *Stats) TotalWrites() uint64 { +func (s *Stats) TotalTranscations() uint64 { return s.SetSuccess + s.SetFail + s.DeleteSuccess + s.DeleteFail + s.CompareAndSwapSuccess + s.CompareAndSwapFail + diff --git a/store/store.go b/store/store.go index 20cfe0c87..7fa21a638 100644 --- a/store/store.go +++ b/store/store.go @@ -25,6 +25,7 @@ type Store interface { Watch(prefix string, recursive bool, sinceIndex uint64, index uint64, term uint64) (<-chan *Event, error) Save() ([]byte, error) Recovery(state []byte) error + TotalTransactions() uint64 JsonStats() []byte } @@ -482,3 +483,7 @@ func (s *store) JsonStats() []byte { s.Stats.Watchers = uint64(s.WatcherHub.count) return s.Stats.toJson() } + +func (s *store) TotalTransactions() uint64 { + return s.Stats.TotalTranscations() +}