mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
Merge pull request #954 from seaweedfs/test/windows-locked-reads
storage: test: three tests read a locked store file through the store
This commit is contained in:
commit
24fa0b776b
3 files changed
+29
-7
No files matched your search
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user