fix: retain inherited BASE birth frontiers including zero

This commit is contained in:
pingqiu committed 2026-11-19 01:26:52 -08:00
1 parent e5391bea54
commit ac02bbc2ac
3 files changed
+104 -3

No files matched your search

@@ -633,7 +633,15 @@ func (s *WALStore) markMapUnknownV3(lba uint64) {
if v.ownedMap == nil {
return
}
v.mapEntries[lba/v.ownedMap.chunkBlocks].Unknown = true
e := &v.mapEntries[lba/v.ownedMap.chunkBlocks]
e.Unknown = true
// A BASE byte has no WAL record: inherit its image frontier, not an
// unrelated later write. Keep UNKNOWN conservative as before.
birth := s.nextLSN - 1
if d := v.pub.current(); d.BaseState == BaseInstalling {
birth = d.BaseLSN
}
e.LSN = max(e.LSN, birth)
}
// InstalledBaseLSN reports a completed local BASE obligation, not a normal
+1 -1
View File
@@ -9,7 +9,7 @@ func (l *chunkLayerImpl) captureBirths(candidates map[uint64]bool, frontier uint
defer l.s.mu.RUnlock()
for idx := range candidates {
birth := frontier
if l.usesOwnedMapV3() && l.s.v3.mapEntries[idx].LSN != 0 {
if l.usesOwnedMapV3() {
birth = l.s.v3.mapEntries[idx].LSN
}
out[idx] = birth
+94 -1
View File
@@ -1,6 +1,99 @@
package storage
import "testing"
import (
"bytes"
"context"
"sync"
"testing"
"time"
)
func TestChunkBirthBASEUsesInheritedFrontierIncludingZero(t *testing.T) {
for _, frontier := range []uint64{0, 7} {
t.Run(string(rune('0'+frontier)), func(t *testing.T) {
s, _, l := mappedBASELayerV3(t)
h, err := s.BeginBaseInstall(frontier, idA)
if err != nil {
t.Fatal(err)
}
if err := h.WriteBase(5, blk(0x55)); err != nil {
t.Fatal(err)
}
if err := h.MarkBaseComplete(); err != nil {
t.Fatal(err)
}
newest, err := s.Write(0, blk(0x41))
if err != nil {
t.Fatal(err)
}
cut, err := l.Cut(ctTimeout(t))
if err != nil {
t.Fatal(err)
}
if cut.Head.Chunks[1].BirthLSN != frontier || cut.Head.Chunks[0].BirthLSN != newest {
t.Fatalf("BASE birth drifted with unrelated WAL writes: %+v, inherited %d", cut.Head, frontier)
}
})
}
}
func TestChunkBirthCOWDoesNotObservePostBarrierWrite(t *testing.T) {
s, _ := newChunkTestStore(t)
f := newFakeChunkRemote()
cfg := ctConfig(1)
cfg.FreshFromHead = true
cfg.BarrierBound = 0
cfg.UploadConcurrency = 1
l := mustAttach(t, s, f, cfg).(*chunkLayerImpl)
if _, err := s.Write(0, makeBlock(ctBlockSize, 0x41)); err != nil {
t.Fatal(err)
}
before, err := s.Write(ctChunkBlocks, makeBlock(ctBlockSize, 0x42))
if err != nil {
t.Fatal(err)
}
entered, release := make(chan struct{}), make(chan struct{})
var once, releaseOnce sync.Once
unblock := func() { releaseOnce.Do(func() { close(release) }) }
l.testCOWRead = func(idx uint64, _ bool) {
if idx == 0 {
once.Do(func() { close(entered) })
<-release
}
}
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
done := make(chan error, 1)
joined := make(chan struct{})
t.Cleanup(func() {
cancel()
unblock()
select {
case <-joined:
case <-time.After(ctLocalBound):
t.Error("birth COW worker not joined")
}
})
go func() { defer close(joined); _, err := l.Cut(ctx); done <- err }()
cowWaitSignal(t, entered, "copy after the birth barrier")
after, err := s.Write(ctChunkBlocks, makeBlock(ctBlockSize, 0x43))
if err != nil {
t.Fatal(err)
}
unblock()
if err := waitErr(t, done, "birth COW cut"); err != nil {
t.Fatal(err)
}
cowWaitSignal(t, joined, "birth COW join")
first := f.installedHeads()[0]
if first.Chunks[1].BirthLSN != before || !bytes.Equal(f.imageOf(t, first)[ctChunkBlocks*ctBlockSize:(ctChunkBlocks+1)*ctBlockSize], makeBlock(ctBlockSize, 0x42)) {
t.Fatal("post-barrier write changed the saved image or its birth")
}
l.testCOWRead = nil
second, err := l.Cut(ctTimeout(t))
if err != nil || second.Head.Chunks[1].BirthLSN != after {
t.Fatalf("next version lost post-barrier birth: %+v %v", second, err)
}
}
func TestChunkBirthTracksNewestLocalWriteAtCut(t *testing.T) {
for _, bound := range []int{0, 1} {