Merge pull request #507 from philips/turn-snapshots-on-by-default

feat(*): enable snapshots by default
This commit is contained in:
Brandon Philips
2014-02-05 09:08:43 -08:00
5 changed files with 41 additions and 28 deletions

View File

@@ -89,6 +89,7 @@ func NewConfig() *Config {
c.MaxClusterSize = 9
c.MaxResultBuffer = 1024
c.MaxRetryAttempts = 3
c.Snapshot = true
c.SnapshotCount = 10000
c.Peer.Addr = "127.0.0.1:7001"
c.Peer.HeartbeatTimeout = defaultHeartbeatTimeout

View File

@@ -412,14 +412,25 @@ func (s *PeerServer) recordMetricEvent(event raft.Event) {
(*s.metrics).Timer(name).Update(value)
}
// logSnapshot logs about the snapshot that was taken.
func (s *PeerServer) logSnapshot(err error, currentIndex, count uint64) {
info := fmt.Sprintf("%s: snapshot of %d events at index %d", s.Config.Name, count, currentIndex)
if err != nil {
log.Infof("%s attempted and failed: %v", info, err)
} else {
log.Infof("%s completed", info)
}
}
func (s *PeerServer) monitorSnapshot() {
for {
time.Sleep(s.snapConf.checkingInterval)
currentIndex := s.RaftServer().CommitIndex()
count := currentIndex - s.snapConf.lastIndex
if uint64(count) > s.snapConf.snapshotThr {
s.raftServer.TakeSnapshot()
err := s.raftServer.TakeSnapshot()
s.logSnapshot(err, currentIndex, count)
s.snapConf.lastIndex = currentIndex
}
}

View File

@@ -52,7 +52,7 @@ Other Options:
-max-result-buffer Max size of the result buffer.
-max-retry-attempts Number of times a node will try to join a cluster.
-max-cluster-size Maximum number of nodes in the cluster.
-snapshot Open or close the snapshot.
-snapshot=false Disable log snapshots
-snapshot-count Number of transactions before issuing a snapshot.
`