|
|
@ -18,27 +18,27 @@ import (
|
|
|
|
|
|
|
|
|
|
|
|
// IsStaleRead returns whether a read is stale.
|
|
|
|
// IsStaleRead returns whether a read is stale.
|
|
|
|
func IsStaleRead(
|
|
|
|
func IsStaleRead(
|
|
|
|
LeaderLastContact time.Time,
|
|
|
|
leaderlastContact time.Time,
|
|
|
|
LastFSMUpdateTime time.Time,
|
|
|
|
lastFSMUpdateTime time.Time,
|
|
|
|
LastAppendedAtTime time.Time,
|
|
|
|
lastAppendedAtTime time.Time,
|
|
|
|
FSMIndex uint64,
|
|
|
|
fsmIndex uint64,
|
|
|
|
CommitIndex uint64,
|
|
|
|
commitIndex uint64,
|
|
|
|
Freshness int64,
|
|
|
|
freshness int64,
|
|
|
|
MaxStale int64,
|
|
|
|
maxStale int64,
|
|
|
|
) bool {
|
|
|
|
) bool {
|
|
|
|
if Freshness == 0 {
|
|
|
|
if freshness == 0 {
|
|
|
|
return false
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if time.Since(LeaderLastContact).Nanoseconds() > Freshness {
|
|
|
|
if time.Since(leaderlastContact).Nanoseconds() > freshness {
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if MaxStale == 0 {
|
|
|
|
if maxStale == 0 {
|
|
|
|
return false
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if FSMIndex == CommitIndex {
|
|
|
|
if fsmIndex == commitIndex {
|
|
|
|
return false
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return LastFSMUpdateTime.Sub(LastAppendedAtTime).Nanoseconds() > MaxStale
|
|
|
|
return lastFSMUpdateTime.Sub(lastAppendedAtTime).Nanoseconds() > maxStale
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// IsNewNode returns whether a node using raftDir would be a brand-new node.
|
|
|
|
// IsNewNode returns whether a node using raftDir would be a brand-new node.
|
|
|
|