Preserve native cut guards while removing retired branches

This commit is contained in:
pingqiu committed 2026-11-20 00:26:14 -08:00
1 parent 0454c6927b
commit 558ddefffd
7 files changed
+28 -37

No files matched your search

@@ -39,13 +39,6 @@ func (l *chunkLayerImpl) holdBaseTransitionV3() (func(), error) {
d := l.s.v3.pub.current()
l.noteAllMutated()
l.stMu.Lock()
l.reconcileGen++
if l.reconciled != nil {
close(l.reconciled)
l.reconciled = nil
}
l.reconcile = map[uint64]bool{}
l.hashMode = false
l.allDirty = true
l.dirtyVer++
switch d.BaseState {
+1 -6
View File
@@ -417,12 +417,7 @@ func (l *chunkLayerImpl) readCOWChunk(w *cutCOWWindow, idx uint64) ([]byte, []ui
// write of the block waits for the caller's COW entry.
func (l *chunkLayerImpl) readLocalBlock(lba uint64, w *cutCOWWindow, dst []byte) ([]byte, bool, error) {
s := l.s
if s.v3 != nil {
if data, handled, err := s.readDirtyV3Into(uint32(lba), dst, func() { w.walReads.Add(1) }); handled {
return data, err == nil, err
}
} else if walRelOff, dataOffset, _, _, ok := s.dm.get(lba); ok {
data, err := s.readFromWAL(walRelOff, dataOffset)
if data, handled, err := s.readDirtyV3Into(uint32(lba), dst, func() { w.walReads.Add(1) }); handled {
return data, err == nil, err
}
idx := l.chunkOf(lba)
@@ -95,6 +95,5 @@ func (s *WALStore) seedChunkFrontierV3Locked(lsn uint64, t *seedTimes) (err erro
s.mu.Lock()
defer s.mu.Unlock()
s.checkpointLSN, s.syncedLSN, s.walHead, s.nextLSN = lsn, lsn, lsn, lsn+1
s.pendingDirectFrontierLSN = 0
return nil
}
+7 -7
View File
@@ -71,7 +71,8 @@ type chunkLayerImpl struct {
cowTransitions int
cowClosed bool
capMu sync.Mutex // serializes Capture, Evict, Begin/EndBaseInstall
capMu sync.Mutex // serializes Capture, Evict, Begin/EndBaseInstall
presMu sync.Mutex // serializes a whole presence save: snapshot, fsync, replace, version
hydration map[uint64]*chunkHydrationFlight // under stMu
@@ -109,7 +110,8 @@ type chunkLayerImpl struct {
dirty map[uint64]bool // chunks dirtied since the cut in progress or the last HEAD
inflight map[uint64]bool // chunks captured by a cut whose HEAD is not yet installed
allDirty bool // a BASE block landed: every chunk is dirty
cutLSN uint64 // H of the latest cut taken (in flight or installed)
cutLSN uint64 // H of the latest cut taken (in flight or installed)
// chunkMut counts the mutations of each chunk: every dirty-map insert
// (any LSN, a replica apply's lower LSN included) and every BASE
// block. Flushing moves bytes without changing them and never counts.
@@ -147,7 +149,7 @@ func attachChunkLayerImpl(s *WALStore, remote chunkRemote, cfg chunkLayerConfig)
return nil, fmt.Errorf("%w: chunk layer requires the native owned map", ErrMapInvalid)
}
if remote == nil || cfg.ChunkBlocks == 0 {
return nil, errors.New("storage: chunk layer needs a remote and ChunkBlocks > 0")
return nil, errors.New("storage: chunk layer needs a remote, ChunkBlocks > 0 and a legacy bitmap unless the store owns an impl3 map")
}
var localBase bool
s.captureMu.Lock()
@@ -261,7 +263,6 @@ func attachChunkLayerImpl(s *WALStore, remote chunkRemote, cfg chunkLayerConfig)
// preserve ALL chunks as candidates for the first hash-comparing cut.
// Persist that obligation before publishing hooks/readiness.
l.hdr = chunkBitmapHeader{BaseLSN: head.RemoteLSN, HeadGen: head.Gen, Epoch: cfg.Epoch}
var initialDirty []uint64
l.dirty = map[uint64]bool{}
for idx := range head.Chunks {
@@ -524,7 +525,6 @@ func (l *chunkLayerImpl) BeginBaseInstall() error {
defer l.capMu.Unlock()
return fmt.Errorf("%w: BASE state must be published by the descriptor install protocol", errV3NotYet)
}
func (l *chunkLayerImpl) EndBaseInstall(frontier uint64) error {
l.capMu.Lock()
defer l.capMu.Unlock()
@@ -938,7 +938,7 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch
}
}
st.UploadNs += time.Since(uploadStart).Nanoseconds()
if !detach && len(changed) == 0 && h == baseHead.RemoteLSN && baseHead.Gen != 0 && !chunkHeadIsDetached(baseHead) {
if !upgrade && !detach && len(changed) == 0 && h == baseHead.RemoteLSN && baseHead.Gen != 0 && !chunkHeadIsDetached(baseHead) {
// A no-op cut still observes authority: a fresh host may have
// claimed HEAD without uploading a single chunk since our last cut.
cur, err := l.remote.GetHead(ctx)
@@ -1404,7 +1404,6 @@ func (l *chunkLayerImpl) dropIntents(ctx context.Context, ids []string) {
// Legacy fixtures retain their bounded-count rounds.
func (l *chunkLayerImpl) stage(ctx context.Context, st *chunkCutStats) (map[uint64]stagedChunk, []string, error) {
bound := l.cfg.BarrierBound
native := true
// Leave at most half the side budget exposed at the barrier. Streaming
// staging uses no local payload file, even for a much larger image.
@@ -1522,6 +1521,7 @@ func (l *chunkLayerImpl) finishCut(head chunkHead, h uint64, changed []uint64, n
l.hdr = chunkBitmapHeader{BaseLSN: h, HeadGen: head.Gen, Epoch: head.Epoch, Base: chunkBaseNone}
l.dirtyVer++
}
func (l *chunkLayerImpl) newKey(idx uint64) string {
l.stMu.Lock()
l.keySeq++
+2 -2
View File
@@ -186,7 +186,7 @@ func (f *flusher) flushOnceInternal(allowClosed bool) (err error) {
store.mu.RUnlock()
if len(entries) == 0 {
return store.refreshW()
return store.refreshW() // the mode-C idle refresh (DESIGN 6.2)
}
if f.afterSnapshotForTest != nil {
@@ -308,7 +308,7 @@ func (f *flusher) flushOnceInternal(allowClosed bool) (err error) {
f.flushes.Add(1)
return store.refreshW()
return store.refreshW() // the mode-C idle refresh (DESIGN 6.2)
}
+17 -13
View File
@@ -203,10 +203,10 @@ func OpenWALStoreWithOptions(path string, opts WALStoreOptions) (*WALStore, erro
return openWALStoreV3WithOptions(path, true, opts)
}
// openInitializedInternal is openInitializedWithMetadata with an optional
// openInitializedV3 is openInitializedWithMetadata with an optional
// init hook that runs before the committer and flusher goroutines start
// (the v3 store attaches its state there).
func openInitializedInternal(path string, f *os.File, sb *superblock, metadata BlockMetadata, init func(*WALStore) error) (*WALStore, error) {
func openInitializedV3(path string, f *os.File, sb *superblock, metadata BlockMetadata, init func(*WALStore) error) (*WALStore, error) {
dm := newDirtyMap(64) // 64 shards is plenty for Phase 07 demo workloads
s := &WALStore{
@@ -233,10 +233,8 @@ func openInitializedInternal(path string, f *os.File, sb *superblock, metadata B
return f.Sync()
}
s.syncExtentFile = f.Sync
if init != nil {
if err := init(s); err != nil {
return nil, err
}
if err := init(s); err != nil {
return nil, err
}
committer := NewGroupCommitter(GroupCommitterConfig{
SyncFunc: s.syncWALBatch,
@@ -262,7 +260,6 @@ func openInitializedInternal(path string, f *os.File, sb *superblock, metadata B
// (WALSoftWatermark, WALHardWatermark). Admission wakes the
// flusher via NotifyUrgent — same seam V2 wires for pressure-
// driven flushes.
s.admissionTimeout = 30 * time.Second
// WAL pressure gets a budget below the host's I/O timeout. This bounds
// cooperative admission waits, not a blocking callback or physical I/O.
@@ -289,8 +286,7 @@ func openInitializedInternal(path string, f *os.File, sb *superblock, metadata B
return s, nil
}
// walUsedFraction samples the active format's writer. The legacy writer is
// still present on a v3 store but receives no appends, so its occupancy is zero.
// walUsedFraction samples the native writer and both-slot reuse floor.
// Store admission is held only for this snapshot, never across a pressure wait.
func (s *WALStore) walUsedFraction() float64 {
s.mu.RLock()
@@ -668,7 +664,9 @@ func (s *WALStore) ReadContext(ctx context.Context, lba uint32) (data []byte, er
}
// SetMultiBlockRecords is retained for callers; native batching is always enabled.
func (s *WALStore) SetMultiBlockRecords(enabled bool) {}
func (s *WALStore) SetMultiBlockRecords(enabled bool) {
}
func (s *WALStore) enableMultiBlockRecordsForTest(enabled bool) {
s.SetMultiBlockRecords(enabled)
@@ -771,7 +769,7 @@ func (s *WALStore) Sync() (uint64, error) {
s.mu.RUnlock()
return 0, ErrBaseInstalling
}
targetGen = s.v3.recoverGen.Load()
targetGen = s.v3.recoverGen.Load() // captured with targetHead (Recover holds s.mu)
s.mu.RUnlock()
@@ -883,7 +881,11 @@ func (s *WALStore) RecoveryRetentionLSNs() uint64 {
}
// AdvanceFrontier is a compatibility no-op; BASE uses its install handle.
func (s *WALStore) AdvanceFrontier(lsn uint64) {}
func (s *WALStore) AdvanceFrontier(lsn uint64) {
return // v3 frontier jumps happen only inside MarkBaseComplete (rows 9 to 11)
}
// AdvanceWALTail moves the retained-window tail forward. After this,
// recovery cases where the requested LSN is below newTail must
@@ -903,7 +905,9 @@ func (s *WALStore) AdvanceWALTail(newTail uint64) {
// WriteExtentDirect refuses unguarded BASE writes; use an install handle.
func (s *WALStore) WriteExtentDirect(lba uint32, data []byte) error {
return errV3NotYet
return errV3NotYet // v3 BASE writes go through an install handle (rows 9 to 11)
}
// ApplyEntry writes a replicated block with the source's LSN rather
+1 -1
View File
@@ -401,7 +401,7 @@ func openWALStoreV3File(path string, f *os.File, requireMap bool, opts WALStoreO
return nil, err
}
}
s, err := openInitializedInternal(path, f, &sb, metadata, func(s *WALStore) error {
s, err := openInitializedV3(path, f, &sb, metadata, func(s *WALStore) error {
v := &walStoreV3State{}
v.pub = newDescriptorPublisherV3(d, id, other, descriptorIOV3{
writeSlot: func(off int64, buf []byte) error {