mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
test: cover real-store WAL dispatch after a held read miss
This commit is contained in:
1 parent
90bd02b37d
commit
3cf779490e
2 files changed
+86
-1
No files matched your search
@@ -0,0 +1,85 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// This sink controls only the read-miss seam; both reads and writes use the
|
||||
// actual WALStore. No remote fill or manifest behavior is simulated here.
|
||||
type heldWALReadMiss struct{ entered, release chan struct{} }
|
||||
|
||||
func (h *heldWALReadMiss) OnReadMiss(uint64) ([]byte, error) {
|
||||
close(h.entered)
|
||||
<-h.release
|
||||
return nil, nil
|
||||
}
|
||||
func (*heldWALReadMiss) OnExtentWrite(uint64, uint64) {}
|
||||
func (*heldWALReadMiss) BeforeCheckpointAdvance(uint64) error { return nil }
|
||||
func (*heldWALReadMiss) BeginBaseInstall() error { return nil }
|
||||
func (*heldWALReadMiss) EndBaseInstall(uint64) error { return nil }
|
||||
|
||||
func TestWALStore_PostReadMissRechecksWALFormat(t *testing.T) {
|
||||
for _, version := range []string{"v2", "v3"} {
|
||||
t.Run(version, func(t *testing.T) {
|
||||
var s *WALStore
|
||||
if version == "v3" {
|
||||
s, _ = newStoreV3(t, WModeLagged)
|
||||
} else {
|
||||
var err error
|
||||
s, err = CreateWALStore(filepath.Join(t.TempDir(), "store"), 16, v3TestBlock)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s.DisableAutoFlushForRecoveryTest()
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
if err := s.Close(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
})
|
||||
h := &heldWALReadMiss{entered: make(chan struct{}), release: make(chan struct{})}
|
||||
s.chunk.Store(&chunkHooks{sink: h, closer: func() error { return nil }})
|
||||
var once sync.Once
|
||||
release := func() { once.Do(func() { close(h.release) }) }
|
||||
type result struct {
|
||||
data []byte
|
||||
err error
|
||||
}
|
||||
done := make(chan result, 1)
|
||||
joined := make(chan struct{})
|
||||
// Release and join before the store closes, including on an assertion failure.
|
||||
t.Cleanup(func() {
|
||||
release()
|
||||
select {
|
||||
case <-joined:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Error("read-miss worker failed to join")
|
||||
}
|
||||
})
|
||||
go func() { defer close(joined); data, err := s.Read(3); done <- result{data, err} }()
|
||||
select {
|
||||
case <-h.entered:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("read never reached OnReadMiss")
|
||||
}
|
||||
want := bytes.Repeat([]byte{0xB7}, v3TestBlock)
|
||||
// The read has already missed the dirty map. Write while OnReadMiss is held.
|
||||
if _, err := s.Write(3, want); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
release()
|
||||
select {
|
||||
case got := <-done:
|
||||
if got.err != nil || !bytes.Equal(got.data, want) {
|
||||
t.Fatalf("post-OnReadMiss WAL recheck returned stale or misdecoded bytes: len=%d err=%v", len(got.data), got.err)
|
||||
}
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("read did not finish after OnReadMiss release")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -369,7 +369,7 @@ Notes:
|
||||
| `INV-CUT-RECOVER-BARRIER-001` | `Recover` holds the capture barrier, so no record above H can enter a HEAD labelled H. | M5 Quiesce; M1 Recovering | `core/storage/walstore.go` `WALStore.Recover` | `TestChunkCut_RecoverWaitsForTheCaptureBarrier` (`core/storage/chunk_layer_precopy_test.go`) | — | ACTIVE |
|
||||
| `INV-CUT-INTENT-FIRST-001` | Before the first upload of a cut, an intent naming every new key is durable, and it is removed only after the CAS outcome is known. | M5 Intent → Upload → CAS | `core/storage/chunk_layer.go` `captureLocked`, `stage`; `core/frontend/chunkstore/manifest.go` `PrepareManifest` | `TestChunkIntent_WrittenBeforeFirstUploadAndDeletedAfterCAS` (`core/storage/chunk_layer_intent_test.go`); `TestChunkPrecopy_StagedUploadsAreCoveredByIntents` (`core/storage/chunk_layer_precopy_test.go`) | `ChunkLifecycleFixed` `GCSafe`; `WorkspaceTakeover` `NoLiveIntentExpired` | ACTIVE |
|
||||
| `INV-CUT-SEGMENT-REUSE-001` | A cut rewrites only manifest segments whose chunk references changed, and an uploaded but unpublished segment leaves the published root unchanged. | M5 Manifest | `core/frontend/chunkstore/manifest.go` `PrepareManifest` | `TestManifest_ReusesUnchangedRangeAndCrashKeepsOldRoot` (`core/frontend/chunkstore/manifest_test.go`) | `CutPipeline` `SegConsistent` | ACTIVE |
|
||||
| `INV-CUT-READMISS-001` | A block fetched from HEAD after a move is installed only if it does not overwrite a newer local extent version; a newer WAL-only write still wins on reads, and HEAD's value may be installed beneath it as the backing value, which is correct if a crash loses that unsynced write. | M4 Holder (lazy restore) | `core/storage/chunk_layer.go` `OnReadMiss`, `installFetchedBlock` | `TestChunkLayer_WALOnlyOverlapReadNeverReturnsUntouchedZero` (`core/storage/chunk_layer_races_test.go`) | — | ACTIVE |
|
||||
| `INV-CUT-READMISS-001` | A block fetched from HEAD after a move is installed only if it does not overwrite a newer local extent version; a newer WAL-only write still wins on reads, and HEAD's value may be installed beneath it as the backing value, which is correct if a crash loses that unsynced write. | M4 Holder (lazy restore) | `core/storage/chunk_layer.go` `OnReadMiss`, `installFetchedBlock`; `core/storage/walstore.go` `readFromExtent` | `TestChunkLayer_WALOnlyOverlapReadNeverReturnsUntouchedZero` (`core/storage/chunk_layer_races_test.go`); `TestWALStore_PostReadMissRechecksWALFormat` (`core/storage/walstore_read_miss_v3_test.go`; real-store v2/v3 dispatch, v3 remains dark) | — | ACTIVE |
|
||||
|
||||
Notes:
|
||||
|
||||
|
||||
Reference in new issue
Block a user