From 091c078b02bb9c32e8d05f01d2301e731ae3f369 Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Tue, 13 Feb 2024 08:29:13 -0500 Subject: [PATCH] Make a init case cleare for IsStaleRead --- store/state.go | 5 +++++ store/state_test.go | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/store/state.go b/store/state.go index 74191a9f..87094022 100644 --- a/store/state.go +++ b/store/state.go @@ -39,6 +39,11 @@ func IsStaleRead( // Strict mode is not enabled, so no further checks are needed. return false } + if lastAppendedAtTime.IsZero() { + // We've yet to be told about any appended log entries, so we + // assume we're caught up. + return false + } if fsmIndex == commitIndex { // FSM index is the same as the commit index, so we're caught up. return false diff --git a/store/state_test.go b/store/state_test.go index 98f6ffca..c7dd99ad 100644 --- a/store/state_test.go +++ b/store/state_test.go @@ -44,6 +44,13 @@ func Test_IsStaleRead(t *testing.T) { Freshness: time.Second, Exp: true, }, + { + Name: "freshness set and ok, strict is set, but no appended time", + LeaderLastContact: time.Now(), + Freshness: 10 * time.Second, + Strict: true, + Exp: false, + }, { Name: "freshness set, is ok, strict is set, appended time exceeds, but applied index is up-to-date", LeaderLastContact: time.Now(),