keep recent log entries after snapshot
parent
10f8b9f836
commit
5c9cec3f74
19
log.go
19
log.go
|
@ -107,6 +107,25 @@ func (l *Log) lastCommandName() string {
|
|||
return ""
|
||||
}
|
||||
|
||||
// Get the log entry by index
|
||||
func (l *Log) getLogEntry(index uint64) *LogEntry {
|
||||
l.mutex.RLock()
|
||||
defer l.mutex.RUnlock()
|
||||
|
||||
if index <= l.startIndex {
|
||||
return nil
|
||||
}
|
||||
|
||||
index = index - l.startIndex - 1
|
||||
|
||||
// copy the useful information of the log entry
|
||||
return &LogEntry{
|
||||
Index: l.entries[index].Index,
|
||||
Term: l.entries[index].Term,
|
||||
Command: l.entries[index].Command,
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------
|
||||
// Log Terms
|
||||
//--------------------------------------
|
||||
|
|
12
server.go
12
server.go
|
@ -28,7 +28,8 @@ const (
|
|||
)
|
||||
|
||||
const (
|
||||
MaxLogEntriesPerRequest = 200
|
||||
MaxLogEntriesPerRequest = 200
|
||||
NumberOfLogEntreisAfterSnapshot = 200
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -922,7 +923,14 @@ func (s *Server) takeSnapshot() error {
|
|||
|
||||
s.saveSnapshot()
|
||||
|
||||
s.log.compact(lastIndex, lastTerm)
|
||||
// We keep some log entries after the snapshot
|
||||
// We do not want to send the whole snapshot
|
||||
// to the slightly slow machines
|
||||
if lastIndex > NumberOfLogEntreisAfterSnapshot {
|
||||
compactIndex := lastIndex - NumberOfLogEntreisAfterSnapshot
|
||||
compactTerm := s.log.getLogEntry(compactIndex).Term
|
||||
s.log.compact(compactIndex, compactTerm)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue