From 0dbe9b919147c45903fe36adf0c52eca9b54f40e Mon Sep 17 00:00:00 2001 From: pingqiu Date: Wed, 2 Dec 2026 06:39:03 -0800 Subject: [PATCH] storage: test: three tests read a locked store file through the store Three tests read or damaged the store file through a second handle while the store held its byte-range lock: mandatory on Windows, so they failed there only. They now go through the open store's own file: the slots by slotsV3Of, a record by damageOpenRecord. What they assert is unchanged. Fixes #953. Co-Authored-By: Claude Opus 5.5 --- .../core/storage/base_install_v3_test.go | 6 ++--- .../core/storage/reset_store_v3_test.go | 26 +++++++++++++++++-- .../core/storage/walstore_v3_test.go | 4 +-- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/seaweed-block/core/storage/base_install_v3_test.go b/seaweed-block/core/storage/base_install_v3_test.go index 89ccb1ebcf..85d7120db1 100644 --- a/seaweed-block/core/storage/base_install_v3_test.go +++ b/seaweed-block/core/storage/base_install_v3_test.go @@ -455,7 +455,7 @@ func TestBaseInstallV3CompletePersistsTheMapUnknownOfBaseWrites(t *testing.T) { // An attached layer without the transition protocol still refuses, writing // nothing. Actual supported layers are covered by the chunk/provider controls. func TestBaseInstallV3BeginRefusesWithAnUnsupportedAttachedChunkLayer(t *testing.T) { - s, path := newMappedCheckpointStoreV3(t) + s, _ := newMappedCheckpointStoreV3(t) cfg := ctConfig(1) cfg.Bitmap = nil cfg.BarrierBound = 1 @@ -463,11 +463,11 @@ func TestBaseInstallV3BeginRefusesWithAnUnsupportedAttachedChunkLayer(t *testing hooks := *s.chunk.Load() hooks.baseTransitionV3 = nil s.chunk.Store(&hooks) - a0, b0 := slotsV3(t, path) + a0, b0 := slotsV3Of(t, s) // the store holds the file's lock: read through it if _, err := s.beginBaseInstallV3(0, idA); !errors.Is(err, errV3NotYet) { t.Fatalf("begin with a chunk layer attached: err = %v, want errV3NotYet", err) } - if a, b := slotsV3(t, path); a != a0 || b != b0 { + if a, b := slotsV3Of(t, s); a != a0 || b != b0 { t.Fatal("a refused begin wrote a descriptor slot") } } diff --git a/seaweed-block/core/storage/reset_store_v3_test.go b/seaweed-block/core/storage/reset_store_v3_test.go index 92df3a99ae..34b37aaa2f 100644 --- a/seaweed-block/core/storage/reset_store_v3_test.go +++ b/seaweed-block/core/storage/reset_store_v3_test.go @@ -14,6 +14,28 @@ import ( // dark: only these tests call it. // slotsV3 decodes both descriptor slots of the file at path. +// slotsV3Of reads both descriptor slots through the open store's own file: +// a second handle cannot read a range the store holds locked (Windows). +func slotsV3Of(t *testing.T, s *WALStore) (a, b descriptorV3) { + t.Helper() + for i, off := range []int64{slotAOffsetV3, slotBOffsetV3} { + buf := make([]byte, slotSizeV3) + if _, err := s.fd.ReadAt(buf, off); err != nil { + t.Fatal(err) + } + d, err := decodeSlotV3(buf, nil) + if err != nil { + t.Fatalf("slot %d: %v", i, err) + } + if i == 0 { + a = d + } else { + b = d + } + } + return a, b +} + func slotsV3(t *testing.T, path string) (a, b descriptorV3) { t.Helper() f, err := os.Open(path) @@ -383,7 +405,7 @@ func TestWALStoreV3ReadOfADamagedLiveRecordIsAnIntegrityFault(t *testing.T) { // unchanged (same position and LSN), but it is a new write: the read must // retry and return it, not report WAL damage. func TestWALStoreV3ReadAcrossARecoveryThatReusesTheSamePositionAndLSNIsNotDamage(t *testing.T) { - s, path := newStoreV3(t, WModeStrict) + s, _ := newStoreV3(t, WModeStrict) t.Cleanup(func() { crashRecoveryHardeningStore(t, s) }) resolved, invalid := newHeldV3(t), newHeldV3(t) writeSynced(t, s, 1, 1) // LSN 1 @@ -403,7 +425,7 @@ func TestWALStoreV3ReadAcrossARecoveryThatReusesTheSamePositionAndLSNIsNotDamage }) waitV3(t, resolved.parked, "Read after resolving LSN 2") s.v3.testReadResolved = nil - damageRecord(t, path, 2) + damageOpenRecord(t, s, 2) // through the store's file: it holds the range locked if _, err := s.Recover(); err != nil { // drops LSN 2 and fences its bytes t.Fatalf("Recover: %v", err) } diff --git a/seaweed-block/core/storage/walstore_v3_test.go b/seaweed-block/core/storage/walstore_v3_test.go index f28637d12e..4e643a9440 100644 --- a/seaweed-block/core/storage/walstore_v3_test.go +++ b/seaweed-block/core/storage/walstore_v3_test.go @@ -869,7 +869,7 @@ func TestWALStoreV3RecoverWaitsForABatchAckAndNothingRevivesTheCut(t *testing.T) // recovery drops its cut, must not acknowledge it; a fresh Sync after the // recovery acknowledges normally. func TestWALStoreV3OuterSyncCompletionIsRefusedAcrossARecovery(t *testing.T) { - s, path := newStoreV3(t, WModeLagged) + s, _ := newStoreV3(t, WModeLagged) t.Cleanup(func() { crashRecoveryHardeningStore(t, s) }) h := newHeldV3(t) writeSynced(t, s, 1, 1) @@ -880,7 +880,7 @@ func TestWALStoreV3OuterSyncCompletionIsRefusedAcrossARecovery(t *testing.T) { syn := h.start(func() error { _, err := s.Sync(); return err }) waitV3(t, h.parked, "the outer Sync before its completion") s.v3.testSyncBeforeCompletion = nil - damageRecord(t, path, 2) + damageOpenRecord(t, s, 2) // through the store's file: it holds the range locked if _, err := s.Recover(); err != nil { t.Fatalf("Recover: %v", err) }