Xiang Li vor 12 Jahren
Ursprung
Commit
107762e82a
3 geänderte Dateien mit 9 neuen und 4 gelöschten Zeilen
  1. 3 3
      server/peer_server.go
  2. 1 1
      store/stats.go
  3. 5 0
      store/store.go

+ 3 - 3
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()
 		}
 	}
 }

+ 1 - 1
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 +

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