test(durable): retain real batch caller and reopen completed local BASE

This commit is contained in:
pingqiu committed 2026-11-17 18:06:42 -08:00
1 parent 4a9d33f6f1
commit 12e9536674
3 files changed
+65 -6

No files matched your search

@@ -114,7 +114,8 @@ func TestDurableProviderV3_CompletedBASEDoesNotRestoreOlderHEAD(t *testing.T) {
if e := source.Close(); e != nil {
t.Fatal(e)
}
target := mappedProviderV3(t, t.TempDir(), remote)
root := t.TempDir()
target := mappedProviderV3(t, root, remote)
st, e := target.EnsureStorage("v1")
if e != nil {
t.Fatal(e)
@@ -141,10 +142,26 @@ func TestDurableProviderV3_CompletedBASEDoesNotRestoreOlderHEAD(t *testing.T) {
if _, e = target.RecoverVolume(ctx, "v1"); e != nil {
t.Fatalf("completed local BASE was treated as empty remote restore: %v", e)
}
for lba, expected := range map[int64][]byte{5: want, 9: make([]byte, 4096)} {
got := make([]byte, 4096)
if n, e := target.Backend("v1").Read(ctx, lba*4096, got); e != nil || n != 4096 || !bytes.Equal(got, expected) {
t.Fatalf("local BASE lba%d bytes lost: n%d err%v", lba, n, e)
check := func() {
t.Helper()
for lba, expected := range map[int64][]byte{5: want, 9: make([]byte, 4096)} {
got := make([]byte, 4096)
if n, e := target.Backend("v1").Read(ctx, lba*4096, got); e != nil || n != 4096 || !bytes.Equal(got, expected) {
t.Fatalf("local BASE lba%d bytes lost: n%d err%v", lba, n, e)
}
}
}
check()
if e = target.Close(); e != nil {
t.Fatal(e)
}
target = mappedProviderV3(t, root, remote)
if _, e = target.EnsureStorage("v1"); e != nil {
t.Fatal(e)
}
if _, e = target.RecoverVolume(ctx, "v1"); e != nil {
t.Fatal(e)
}
check()
}
@@ -420,3 +420,45 @@ func TestDurableProviderV3_StatusTracksRecoverSyncAndCapture(t *testing.T) {
t.Fatalf("after capture=%+v", v)
}
}
func TestDurableProviderV3_ContiguousWriteSurvivesCheckpointAndReopen(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
root := t.TempDir()
remote := storage.NewMemChunkRemote()
p := mappedProviderV3(t, root, remote)
st, e := p.EnsureStorage("v1")
if e != nil {
t.Fatal(e)
}
if _, e = p.RecoverVolume(ctx, "v1"); e != nil {
t.Fatal(e)
}
want := append(bytes.Repeat([]byte{0x31}, 4096), bytes.Repeat([]byte{0x72}, 4096)...)
if n, e := p.Backend("v1").Write(ctx, 4*4096, want); e != nil || n != len(want) {
t.Fatalf("actual provider contiguous Write: n=%d err=%v", n, e)
}
if e = p.Backend("v1").Sync(ctx); e != nil {
t.Fatal(e)
}
if e = storage.FlushMappedWALStoreV3Test(st.(*storage.WALStore)); e != nil {
t.Fatal(e)
}
if _, e = p.CaptureVolume(ctx, "v1"); e != nil {
t.Fatal(e)
}
if e = p.Close(); e != nil {
t.Fatal(e)
}
q := mappedProviderV3(t, root, remote)
if _, e = q.EnsureStorage("v1"); e != nil {
t.Fatal(e)
}
if _, e = q.RecoverVolume(ctx, "v1"); e != nil {
t.Fatal(e)
}
got := make([]byte, len(want))
if n, e := q.Backend("v1").Read(ctx, 4*4096, got); e != nil || n != len(want) || !bytes.Equal(got, want) {
t.Fatalf("reopen n=%d err=%v equal=%v", n, e, bytes.Equal(got, want))
}
}
@@ -15,7 +15,7 @@ import (
// exclusive, which drains every already-admitted mutation of the old ID; a
// handle mutation takes it shared and checks, under it, that the volume is
// still installing under the handle's ID. Below it the order is the store's
// usual captureMu -> lifecycleMu -> syncMu -> s.mu -> descMu -> fileSyncMu,
// optional chunk capMu -> captureMu -> lifecycleMu -> syncMu -> s.mu -> descMu -> fileSyncMu,
// and nothing below ever waits for installMu.
var (