snapshot.go
func (r *Raft) shouldSnapshot() bool {
	// Check the last snapshot index
	lastSnap, _ := r.getLastSnapshot()

	// Check the last log index
	lastIdx, err := r.logs.LastIndex()
	if err != nil {
		r.logger.Error(fmt.Sprintf("Failed to get last log index: %v", err))
		return false
	}

	// Compare the delta to the threshold
	delta := lastIdx - lastSnap
	return delta >= r.conf.SnapshotThreshold
}
func (r *Raft) shouldSnapshot() bool {
	// Check the last snapshot index
	lastSnap, _ := r.getLastSnapshot()

	// Check the last log index
	lastIdx, err := r.logs.LastIndex()
	if err != nil {
		r.logger.Error(fmt.Sprintf("Failed to get last log index: %v", err))
		return false
	}

	// Compare the delta to the threshold
	delta := lastIdx - lastSnap
	return delta >= r.conf.SnapshotThreshold
}
func ( r * Raft ) shouldSnapshot ( ) bool { // Check the last snapshot index lastSnap , _ := r . getLastSnapshot ( ) // Check the last log index lastIdx , err := r . logs . LastIndex ( ) if err != nil { r . logger . Error ( fmt . Sprintf ( " " , err ) ) return false } // Compare the delta to the threshold delta := lastIdx - lastSnap return delta >= r . conf . SnapshotThreshold }
// shouldSnapshot checks if we meet the conditions to take
// a new snapshot.
shouldSnapshot checks if we meet the conditions to take a new snapshot .