mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
test(storage): distinguish upload retry from abandoned cut points
This commit is contained in:
1 parent
df5d3a6d7d
commit
fc06e7f6c4
3 files changed
+64
-40
No files matched your search
@@ -127,6 +127,8 @@ func TestCutCOWV3_PutRetryUsesFrozenSlot(t *testing.T) {
|
||||
gate.unblock()
|
||||
r := &retrySlotRemote{fakeChunkRemote: f, first: make(chan struct{}), release: make(chan struct{})}
|
||||
l.remote = r
|
||||
var fixed uint64
|
||||
l.testAfterBarrierSyncHook = func(h uint64) { fixed = h }
|
||||
var reads atomic.Int32
|
||||
l.testCOWRead = func(idx uint64, _ bool) {
|
||||
if idx == 0 {
|
||||
@@ -154,6 +156,9 @@ func TestCutCOWV3_PutRetryUsesFrozenSlot(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
result := <-results
|
||||
if result.H != fixed || result.Head.RemoteLSN != fixed {
|
||||
t.Fatalf("PUT retry replaced the point: fixed=%d result=%d remote=%d", fixed, result.H, result.Head.RemoteLSN)
|
||||
}
|
||||
r.mu.Lock()
|
||||
attempts := r.attempts
|
||||
r.mu.Unlock()
|
||||
|
||||
@@ -225,46 +225,63 @@ func TestCutCOWV3_ChangedImageExceedsSpillCap(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCutCOWV3_OverwriteStormAbortsAndRetries(t *testing.T) {
|
||||
s, l, f, gate := cowFixture(t)
|
||||
// Keep chunk 0 hottest, with two other candidates still waiting behind it.
|
||||
for _, lba := range []uint32{9, 1} {
|
||||
if _, err := s.Write(lba, makeBlock(ctBlockSize, byte(lba))); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
before := f.stats().head.Gen
|
||||
done, errs := cowStartCut(t, l, gate)
|
||||
w := l.cowActive.Load()
|
||||
w.mu.Lock()
|
||||
w.memory = w.memoryLimit
|
||||
w.spillLimit = w.chunkBytes
|
||||
w.mu.Unlock()
|
||||
for _, lba := range []uint32{5, 9} {
|
||||
start := time.Now()
|
||||
if _, err := s.Write(lba, makeBlock(ctBlockSize, 0xd0+byte(lba))); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if time.Since(start) >= ctLocalBound {
|
||||
t.Fatal("overwrite exceeded guest budget")
|
||||
}
|
||||
}
|
||||
gate.unblock()
|
||||
cowWaitSignal(t, done, "spill-refused update")
|
||||
if err := <-errs; !errors.Is(err, errCutCOWAborted) || !strings.Contains(err.Error(), "spill would exceed its cap") {
|
||||
t.Fatalf("cut: %v", err)
|
||||
}
|
||||
if f.stats().head.Gen != before {
|
||||
t.Fatal("refused cut published")
|
||||
}
|
||||
result, err := l.Cut(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal("retry:", err)
|
||||
}
|
||||
img := f.imageOf(t, result.Head)
|
||||
for _, lba := range []uint32{5, 9} {
|
||||
if !bytes.Equal(blockOf(img, lba), makeBlock(ctBlockSize, 0xd0+byte(lba))) {
|
||||
t.Fatal("retry lost overwrite", lba)
|
||||
}
|
||||
// Every invocation reports its own failure. Rolling and periodic callers
|
||||
// may issue a new invocation; a named caller must retain the failure.
|
||||
for _, request := range []string{"rolling", "periodic", "named"} {
|
||||
t.Run(request, func(t *testing.T) {
|
||||
s, l, f, gate := cowFixture(t)
|
||||
// Keep chunk 0 hottest, with two other candidates still waiting behind it.
|
||||
for _, lba := range []uint32{9, 1} {
|
||||
if _, err := s.Write(lba, makeBlock(ctBlockSize, byte(lba))); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
before := f.stats().head.Gen
|
||||
var fixed uint64
|
||||
l.testAfterBarrierSyncHook = func(h uint64) { fixed = h }
|
||||
done, errs := cowStartCut(t, l, gate)
|
||||
w := l.cowActive.Load()
|
||||
w.mu.Lock()
|
||||
w.memory = w.memoryLimit
|
||||
w.spillLimit = w.chunkBytes
|
||||
w.mu.Unlock()
|
||||
for _, lba := range []uint32{5, 9} {
|
||||
start := time.Now()
|
||||
if _, err := s.Write(lba, makeBlock(ctBlockSize, 0xd0+byte(lba))); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if time.Since(start) >= ctLocalBound {
|
||||
t.Fatal("overwrite exceeded guest budget")
|
||||
}
|
||||
}
|
||||
gate.unblock()
|
||||
cowWaitSignal(t, done, "spill-refused update")
|
||||
if err := <-errs; !errors.Is(err, errCutCOWAborted) || !strings.Contains(err.Error(), "spill would exceed its cap") {
|
||||
t.Fatalf("cut: %v", err)
|
||||
}
|
||||
if f.stats().head.Gen != before {
|
||||
t.Fatal("refused cut published")
|
||||
}
|
||||
if request == "named" {
|
||||
// The failed named invocation ends here: only a new request may
|
||||
// select another point, never an implicit replacement success.
|
||||
return
|
||||
}
|
||||
oldPoint := fixed
|
||||
result, err := l.Cut(context.Background())
|
||||
if err != nil {
|
||||
t.Fatal("retry:", err)
|
||||
}
|
||||
if result.H <= oldPoint || result.Head.RemoteLSN != result.H {
|
||||
t.Fatalf("new invocation reused aborted point: old=%d new=%d remote=%d", oldPoint, result.H, result.Head.RemoteLSN)
|
||||
}
|
||||
img := f.imageOf(t, result.Head)
|
||||
for _, lba := range []uint32{5, 9} {
|
||||
if !bytes.Equal(blockOf(img, lba), makeBlock(ctBlockSize, 0xd0+byte(lba))) {
|
||||
t.Fatal("retry lost overwrite", lba)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -122,6 +122,8 @@ func (l *chunkLayerImpl) stagePayloadRound(ctx context.Context, batch []uint64,
|
||||
|
||||
// Only immutable metadata survives an attempt. The intent remains a GC root
|
||||
// until this version is superseded or a confirmed HEAD makes it reachable.
|
||||
// This cache belongs to one layer/owner lifetime. Generation equality is not
|
||||
// a reuse proof across reopen or takeover; those require content-hash matching.
|
||||
func (l *chunkLayerImpl) rememberPayload(c capturedChunk, gen uint64) {
|
||||
if !l.usesOwnedMapV3() {
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user