fix snapshot

This commit is contained in:
Xiang Li 2013-10-30 15:14:34 -07:00
parent ec175d4c47
commit 107762e82a
3 changed files with 9 additions and 4 deletions

View File

@ -60,7 +60,7 @@ func NewPeerServer(name string, path string, url string, listenHost string, tlsC
tlsInfo: tlsInfo, tlsInfo: tlsInfo,
registry: registry, registry: registry,
store: store, store: store,
snapConf: &snapshotConf{time.Second * 3, 0, 20 * 1000}, snapConf: &snapshotConf{time.Second * 3, 0, 2},
followersStats: &raftFollowersStats{ followersStats: &raftFollowersStats{
Leader: name, Leader: name,
Followers: make(map[string]*raftFollowerStats), Followers: make(map[string]*raftFollowerStats),
@ -391,10 +391,10 @@ func (s *PeerServer) PeerStats() []byte {
func (s *PeerServer) monitorSnapshot() { func (s *PeerServer) monitorSnapshot() {
for { for {
time.Sleep(s.snapConf.checkingInterval) time.Sleep(s.snapConf.checkingInterval)
currentWrites := 0 currentWrites := s.store.TotalTransactions() - s.snapConf.lastWrites
if uint64(currentWrites) > s.snapConf.writesThr { if uint64(currentWrites) > s.snapConf.writesThr {
s.raftServer.TakeSnapshot() s.raftServer.TakeSnapshot()
s.snapConf.lastWrites = 0 s.snapConf.lastWrites = s.store.TotalTransactions()
} }
} }
} }

View File

@ -73,7 +73,7 @@ func (s *Stats) TotalReads() uint64 {
return s.GetSuccess + s.GetFail return s.GetSuccess + s.GetFail
} }
func (s *Stats) TotalWrites() uint64 { func (s *Stats) TotalTranscations() uint64 {
return s.SetSuccess + s.SetFail + return s.SetSuccess + s.SetFail +
s.DeleteSuccess + s.DeleteFail + s.DeleteSuccess + s.DeleteFail +
s.CompareAndSwapSuccess + s.CompareAndSwapFail + s.CompareAndSwapSuccess + s.CompareAndSwapFail +

View File

@ -25,6 +25,7 @@ type Store interface {
Watch(prefix string, recursive bool, sinceIndex uint64, index uint64, term uint64) (<-chan *Event, error) Watch(prefix string, recursive bool, sinceIndex uint64, index uint64, term uint64) (<-chan *Event, error)
Save() ([]byte, error) Save() ([]byte, error)
Recovery(state []byte) error Recovery(state []byte) error
TotalTransactions() uint64
JsonStats() []byte JsonStats() []byte
} }
@ -482,3 +483,7 @@ func (s *store) JsonStats() []byte {
s.Stats.Watchers = uint64(s.WatcherHub.count) s.Stats.Watchers = uint64(s.WatcherHub.count)
return s.Stats.toJson() return s.Stats.toJson()
} }
func (s *store) TotalTransactions() uint64 {
return s.Stats.TotalTranscations()
}