Skip to content

Commit 9c23431

Browse files
[FIXED] Filestore cache is expired too early with recent write
Signed-off-by: Maurice van Veen <github@mauricevanveen.com>
1 parent 74cbb96 commit 9c23431

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

server/filestore.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6576,10 +6576,10 @@ func (mb *msgBlock) tryForceExpireCache() {
65766576

65776577
// We will attempt to force expire this by temporarily clearing the last load time.
65786578
func (mb *msgBlock) tryForceExpireCacheLocked() {
6579-
llts, lwts := mb.llts, mb.lwts
6580-
mb.llts, mb.lwts = 0, 0
6579+
llts := mb.llts
6580+
mb.llts = 0
65816581
mb.expireCacheLocked()
6582-
mb.llts, mb.lwts = llts, lwts
6582+
mb.llts = llts
65836583
}
65846584

65856585
// This is for expiration of the write cache, which will be partial with fip.

server/filestore_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13538,6 +13538,44 @@ func TestFileStoreSyncBlocksNoErrorOnConcurrentRemovedBlock(t *testing.T) {
1353813538
require_True(t, fs.werr == nil)
1353913539
}
1354013540

13541+
func TestFileStoreDontExpireCacheWithRecentWrite(t *testing.T) {
13542+
fcfg := FileStoreConfig{StoreDir: t.TempDir()}
13543+
cfg := StreamConfig{Name: "zzz", Storage: FileStorage, Subjects: []string{">"}}
13544+
fs, err := newFileStore(fcfg, cfg)
13545+
require_NoError(t, err)
13546+
defer fs.Stop()
13547+
13548+
_, _, err = fs.StoreMsg("foo", nil, nil, 0)
13549+
require_NoError(t, err)
13550+
13551+
// Cache should still exist after above write.
13552+
fmb := fs.getFirstBlock()
13553+
fmb.mu.Lock()
13554+
cacheLoaded := fmb.cacheAlreadyLoaded()
13555+
fmb.llseq = 0
13556+
fmb.mu.Unlock()
13557+
require_True(t, cacheLoaded)
13558+
13559+
// The load will try to expire the cache, but shouldn't due to the recent write.
13560+
_, _, err = fs.LoadNextMsg(fwcs, true, 0, nil)
13561+
require_NoError(t, err)
13562+
13563+
fmb.mu.Lock()
13564+
fmb.llseq = 0
13565+
cacheLoaded = fmb.cacheAlreadyLoaded()
13566+
// We update the last write timestamp to be very old, so the next load can expire the cache.
13567+
fmb.lwts = 0
13568+
fmb.mu.Unlock()
13569+
require_True(t, cacheLoaded)
13570+
_, _, err = fs.LoadNextMsg(fwcs, true, 0, nil)
13571+
require_NoError(t, err)
13572+
13573+
fmb.mu.Lock()
13574+
cacheLoaded = fmb.cacheAlreadyLoaded()
13575+
fmb.mu.Unlock()
13576+
require_False(t, cacheLoaded)
13577+
}
13578+
1354113579
func TestFileStoreNoDirectoryNotEmptyError(t *testing.T) {
1354213580
fcfg := FileStoreConfig{StoreDir: t.TempDir()}
1354313581
mconfig := StreamConfig{Name: "TEST_DELETE", Storage: FileStorage, Subjects: []string{"foo"}, Replicas: 1}

0 commit comments

Comments
 (0)