mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
test(storage): a write between a cut's barrier and its recording leaves no mark
A test hook runs after the cut's compare and before it records its marks; a write there, on a chunk the cut compared equal, must reach HEAD in the next cut. Recording the current version instead of the captured one (without the version check) hides the write: the next cut compares nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f7313f5f2d
commit
49772850c0
2 files changed
+38
No files matched your search
@@ -328,3 +328,37 @@ func TestWithoutAFailedCutEveryUnknownChunkIsCompared(t *testing.T) {
|
||||
t.Errorf("compared %d chunks, want %d", r.Stats.CandidateChunks, want)
|
||||
}
|
||||
}
|
||||
|
||||
// A write that lands after a cut's barrier, on a chunk the cut compared
|
||||
// equal, leaves no trusted mark: the mark is recorded with the version the
|
||||
// barrier captured and only while the chunk still has it, so the next cut
|
||||
// compares the chunk and publishes the write. Recording the current version
|
||||
// instead would hide the write from every later cut.
|
||||
func TestAWriteBetweenTheBarrierAndTheRecordingLeavesNoMark(t *testing.T) {
|
||||
s, l, f := unknownFilledVolume(t)
|
||||
local := makeBlock(ctBlockSize, 0xD7)
|
||||
var wrote bool
|
||||
l.testBeforeRecordMarksHook = func() {
|
||||
if wrote {
|
||||
return
|
||||
}
|
||||
wrote = true
|
||||
if _, err := s.Write(ctChunkBlocks+1, local); err != nil { // chunk 1, compared equal by this cut
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
if _, err := l.Cut(ctTimeout(t)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
l.testBeforeRecordMarksHook = nil
|
||||
if !wrote {
|
||||
t.Fatal("setup: the cut recorded no marks (the hook never ran)")
|
||||
}
|
||||
r, err := l.Cut(ctTimeout(t))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !bytes.Equal(blockOf(f.imageOf(t, r.Head), ctChunkBlocks+1), local) {
|
||||
t.Fatalf("the write made between the barrier and the recording is not in HEAD (the next cut compared %d chunks): a mark hid it", r.Stats.CandidateChunks)
|
||||
}
|
||||
}
|
||||
@@ -147,6 +147,7 @@ type chunkLayerImpl struct {
|
||||
testAfterStageReadHook func(idx uint64) // after a staging read, before its result is kept
|
||||
testAfterBarrierSyncHook func(h uint64) // under the capture barrier, right after Sync fixed H
|
||||
testBeforeBarrierLockHook func() // right before the capture barrier's Lock request
|
||||
testBeforeRecordMarksHook func() // after a cut's compare, before it records its marks
|
||||
syncDirFn func(dir string) error // directory fsync after a rename; syncDir in production
|
||||
|
||||
// Absence: chunks whose local bytes are not authoritative (fresh host,
|
||||
@@ -1045,6 +1046,9 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch
|
||||
}
|
||||
uploads = append(uploads, upload{c: c, key: l.keyFor(c.idx, c.sum, l.newKey(c.idx))})
|
||||
}
|
||||
if hook := l.testBeforeRecordMarksHook; hook != nil {
|
||||
hook()
|
||||
}
|
||||
if len(equal) > 0 {
|
||||
l.stMu.Lock()
|
||||
for _, idx := range equal {
|
||||
|
||||
Reference in new issue
Block a user