api.go
func HasExistingState(logs LogStore, stable StableStore, snaps SnapshotStore) (bool, error) {
	// Make sure we don't have a current term.
	currentTerm, err := stable.GetUint64(keyCurrentTerm)
	if err == nil {
		if currentTerm > 0 {
			return true, nil
		}
	} else {
		if err.Error() != "not found" {
			return false, fmt.Errorf("failed to read current term: %v", err)
		}
	}

	// Make sure we have an empty log.
	lastIndex, err := logs.LastIndex()
	if err != nil {
		return false, fmt.Errorf("failed to get last log index: %v", err)
	}
	if lastIndex > 0 {
		return true, nil
	}

	// Make sure we have no snapshots
	snapshots, err := snaps.List()
	if err != nil {
		return false, fmt.Errorf("failed to list snapshots: %v", err)
	}
	if len(snapshots) > 0 {
		return true, nil
	}

	return false, nil
}
func HasExistingState(logs LogStore, stable StableStore, snaps SnapshotStore) (bool, error) {
	// Make sure we don't have a current term.
	currentTerm, err := stable.GetUint64(keyCurrentTerm)
	if err == nil {
		if currentTerm > 0 {
			return true, nil
		}
	} else {
		if err.Error() != "not found" {
			return false, fmt.Errorf("failed to read current term: %v", err)
		}
	}

	// Make sure we have an empty log.
	lastIndex, err := logs.LastIndex()
	if err != nil {
		return false, fmt.Errorf("failed to get last log index: %v", err)
	}
	if lastIndex > 0 {
		return true, nil
	}

	// Make sure we have no snapshots
	snapshots, err := snaps.List()
	if err != nil {
		return false, fmt.Errorf("failed to list snapshots: %v", err)
	}
	if len(snapshots) > 0 {
		return true, nil
	}

	return false, nil
}
func HasExistingState ( logs LogStore , stable StableStore , snaps SnapshotStore ) ( bool , error ) { // Make sure we don't have a current term. currentTerm , err := stable . GetUint64 ( keyCurrentTerm ) if err == nil { if currentTerm > 0 { return true , nil } } else { if err . Error ( ) != " " { return false , fmt . Errorf ( " " , err ) } } // Make sure we have an empty log. lastIndex , err := logs . LastIndex ( ) if err != nil { return false , fmt . Errorf ( " " , err ) } if lastIndex > 0 { return true , nil } // Make sure we have no snapshots snapshots , err := snaps . List ( ) if err != nil { return false , fmt . Errorf ( " " , err ) } if len ( snapshots ) > 0 { return true , nil } return false , nil }
// HasExistingState returns true if the server has any existing state (logs,
// knowledge of a current term, or any snapshots).
HasExistingState returns true if the server has any existing state ( logs knowledge of a current term or any snapshots ) .