mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 11:07:31 +01:00
storage: v1.1 format build guard; the mutation hook carries the write's LSN
The draft v1.1 store format runs only in lab builds and in this package's tests (chunkV11Format). The mutation hook passes the write's store position, so the chunk record knows the position through which it has applied every write. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d8bfc6f958
commit
fc222d2386
10 files changed
+68
-22
No files matched your search
@@ -443,7 +443,7 @@ func (s *WALStore) applyEntryV3(lba uint32, data []byte, lsn uint64, installLane
|
||||
return err
|
||||
}
|
||||
s.dm.put(uint64(lba), phys, lsn, uint32(len(dataCopy)))
|
||||
s.noteChunkMutation(uint64(lba))
|
||||
s.noteChunkMutation(uint64(lba), lsn)
|
||||
if lsn >= s.nextLSN {
|
||||
s.nextLSN = lsn + 1
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ type chunkHooks struct {
|
||||
closer func() error
|
||||
// mutated runs after every dirty-map insert (a write, a batch write,
|
||||
// a replica apply) with the LBA: O(1), lock-free, on the write path.
|
||||
mutated func(lba uint64)
|
||||
mutated func(lba, lsn uint64)
|
||||
// recovered runs when Recover republished the dirty map (any chunk
|
||||
// may have changed), before reads resume.
|
||||
recovered func()
|
||||
@@ -453,7 +453,7 @@ func (l *chunkLayerImpl) OnExtentWrite(lba uint64, lsn uint64) {
|
||||
}
|
||||
}
|
||||
if lsn == 0 { // a BASE block lands in the extent directly
|
||||
l.noteMutation(lba)
|
||||
l.noteMutation(lba, 0)
|
||||
}
|
||||
l.dirtyVer++
|
||||
}
|
||||
@@ -461,10 +461,10 @@ func (l *chunkLayerImpl) OnExtentWrite(lba uint64, lsn uint64) {
|
||||
// noteMutation counts a mutation of lba's chunk. It runs after the
|
||||
// mutation is visible to reads, so a staging read that sampled the count
|
||||
// first either sees the new bytes or a stale count (never reused).
|
||||
func (l *chunkLayerImpl) noteMutation(lba uint64) {
|
||||
func (l *chunkLayerImpl) noteMutation(lba, lsn uint64) {
|
||||
if idx := l.chunkOf(lba); idx < uint64(len(l.chunkMut)) {
|
||||
if sh := l.shadow; sh != nil {
|
||||
sh.write(idx, func() { l.chunkMut[idx].Add(1) })
|
||||
sh.write(idx, lsn, func() { l.chunkMut[idx].Add(1) })
|
||||
return
|
||||
}
|
||||
l.chunkMut[idx].Add(1)
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
// dirtyMapInsertSites parses src and returns, for every call of
|
||||
// <x>.dm.put / putAt / putAtIfNewer, "file func method noted|unnoted". A put
|
||||
// or putAt is noted when one of the next two statements of the same block
|
||||
// is the call <x>.noteChunkMutation(<lba>) itself, on the insert's receiver
|
||||
// is the call <x>.noteChunkMutation(<lba>, <lsn>) itself, on the insert's receiver
|
||||
// <x> and with the insert's first argument <lba>: not a method value, not a
|
||||
// call inside a condition or a defer, not a note of another receiver or LBA.
|
||||
func dirtyMapInsertSites(t *testing.T, file, src string) []string {
|
||||
@@ -53,14 +53,14 @@ func dirtyMapInsertSites(t *testing.T, file, src string) []string {
|
||||
}
|
||||
return "", "", ""
|
||||
}
|
||||
// notes reports whether s is the statement owner.noteChunkMutation(lba).
|
||||
// notes reports whether s is the statement owner.noteChunkMutation(lba, lsn).
|
||||
notes := func(s ast.Stmt, owner, lba string) bool {
|
||||
es, ok := s.(*ast.ExprStmt)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
call, ok := es.X.(*ast.CallExpr)
|
||||
if !ok || len(call.Args) != 1 {
|
||||
if !ok || len(call.Args) != 2 { // (lba, lsn)
|
||||
return false
|
||||
}
|
||||
sel, ok := call.Fun.(*ast.SelectorExpr)
|
||||
@@ -229,11 +229,11 @@ func TestEveryDirtyMapInsertNotesTheChunkMutation(t *testing.T) {
|
||||
"x.go w put unnoted",
|
||||
},
|
||||
"a note three statements later": {
|
||||
"package storage\nfunc w(s *WALStore) { s.dm.putAt(1, 2, 0, 3, 4); a(); b(); s.noteChunkMutation(1) }\n",
|
||||
"package storage\nfunc w(s *WALStore) { s.dm.putAt(1, 2, 0, 3, 4); a(); b(); s.noteChunkMutation(1, 3) }\n",
|
||||
"x.go w putAt unnoted",
|
||||
},
|
||||
"an insert in a defer": {
|
||||
"package storage\nfunc w(s *WALStore) { defer s.dm.put(1, 2, 3, 4); s.noteChunkMutation(1) }\n",
|
||||
"package storage\nfunc w(s *WALStore) { defer s.dm.put(1, 2, 3, 4); s.noteChunkMutation(1, 3) }\n",
|
||||
"x.go w put unnoted",
|
||||
},
|
||||
"a method value, not a call": {
|
||||
@@ -241,23 +241,23 @@ func TestEveryDirtyMapInsertNotesTheChunkMutation(t *testing.T) {
|
||||
"x.go w put unnoted",
|
||||
},
|
||||
"a note inside a condition": {
|
||||
"package storage\nfunc w(s *WALStore) { s.dm.put(1, 2, 3, 4); if false { s.noteChunkMutation(1) } }\n",
|
||||
"package storage\nfunc w(s *WALStore) { s.dm.put(1, 2, 3, 4); if false { s.noteChunkMutation(1, 3) } }\n",
|
||||
"x.go w put unnoted",
|
||||
},
|
||||
"a deferred note": {
|
||||
"package storage\nfunc w(s *WALStore) { s.dm.put(1, 2, 3, 4); defer s.noteChunkMutation(1) }\n",
|
||||
"package storage\nfunc w(s *WALStore) { s.dm.put(1, 2, 3, 4); defer s.noteChunkMutation(1, 3) }\n",
|
||||
"x.go w put unnoted",
|
||||
},
|
||||
"a note on another store": {
|
||||
"package storage\nfunc w(s, o *WALStore) { s.dm.put(1, 2, 3, 4); o.noteChunkMutation(1) }\n",
|
||||
"package storage\nfunc w(s, o *WALStore) { s.dm.put(1, 2, 3, 4); o.noteChunkMutation(1, 3) }\n",
|
||||
"x.go w put unnoted",
|
||||
},
|
||||
"a note of another LBA": {
|
||||
"package storage\nfunc w(s *WALStore, a, b uint64) { s.dm.put(a, 2, 3, 4); s.noteChunkMutation(b) }\n",
|
||||
"package storage\nfunc w(s *WALStore, a, b uint64) { s.dm.put(a, 2, 3, 4); s.noteChunkMutation(b, 3) }\n",
|
||||
"x.go w put unnoted",
|
||||
},
|
||||
"the matching note after one other statement": {
|
||||
"package storage\nfunc w(s *WALStore, a uint64) { s.dm.put(uint64(a), 2, 3, 4); x(); s.noteChunkMutation(uint64(a)) }\n",
|
||||
"package storage\nfunc w(s *WALStore, a uint64) { s.dm.put(uint64(a), 2, 3, 4); x(); s.noteChunkMutation(uint64(a), 3) }\n",
|
||||
"x.go w put noted",
|
||||
},
|
||||
} {
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/chunkkernel"
|
||||
)
|
||||
@@ -48,6 +49,9 @@ type chunkRecordShadow struct {
|
||||
settled map[uint64]uint64
|
||||
// fullScans counts the test-only scans of the whole record.
|
||||
fullScans int
|
||||
// applied is the store position through which every write has reached
|
||||
// the record (the runtime's applied position).
|
||||
applied atomic.Uint64
|
||||
}
|
||||
|
||||
// settled: chunks a delayed settlement committed, with their captured
|
||||
@@ -149,7 +153,14 @@ func (s *chunkRecordShadow) defect(chunk uint64, ev chunkkernel.Event, err error
|
||||
// write is E1: a write's version bump and its Write, in one step. The
|
||||
// argument is the resulting chunk's coverage: some while its absence stands
|
||||
// (A, P), all once its bytes are local.
|
||||
func (s *chunkRecordShadow) write(chunk uint64, bump func()) {
|
||||
//
|
||||
// lsn is the write's store position. Once its Write is applied the shell's
|
||||
// applied position rises to it (THE APPLIED POSITION of the runtime): writes
|
||||
// reach the hook serially under the store's lock, so every write at or below
|
||||
// it has been applied. A write with no position (0, a BASE block landing
|
||||
// directly) leaves it.
|
||||
func (s *chunkRecordShadow) write(chunk, lsn uint64, bump func()) {
|
||||
defer s.raiseApplied(lsn)
|
||||
_, _, err := s.rec.ApplyIf(chunk, chunkkernel.Write, func(k chunkkernel.Kind) chunkkernel.Arg {
|
||||
if k == chunkkernel.Absent || k == chunkkernel.Partial {
|
||||
return chunkkernel.Arg{Value: "some"}
|
||||
@@ -161,6 +172,16 @@ func (s *chunkRecordShadow) write(chunk uint64, bump func()) {
|
||||
}
|
||||
}
|
||||
|
||||
// raiseApplied raises the applied position to lsn, never lowering it.
|
||||
func (s *chunkRecordShadow) raiseApplied(lsn uint64) {
|
||||
for {
|
||||
cur := s.applied.Load()
|
||||
if lsn <= cur || s.applied.CompareAndSwap(cur, lsn) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// landed is E1b: the engine's per-block bitmap of an absent chunk now
|
||||
// covers every block, so the chunk's bytes are all local. Caller holds stMu
|
||||
// (the bitmap's lock).
|
||||
|
||||
@@ -293,7 +293,7 @@ func TestShadowEvictEdges(t *testing.T) {
|
||||
_ = f
|
||||
// The record meets an evict after a write it saw and the engine's clean
|
||||
// check did not: skipped and counted.
|
||||
l.shadow.write(5, func() {})
|
||||
l.shadow.write(5, 0, func() {})
|
||||
l.shadow.evict(5)
|
||||
l.shadow.mu.Lock()
|
||||
skipped := l.shadow.skippedEvicts
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package storage
|
||||
|
||||
// chunkV11Format says whether a chunk layer upgrades its store to the draft
|
||||
// v1.1 format at attach and opens it from the chunk record. It is the
|
||||
// build's constant; this package's tests turn it on for the tests that
|
||||
// exercise the format.
|
||||
var chunkV11Format = chunkV11FormatBuild
|
||||
@@ -0,0 +1,8 @@
|
||||
//go:build swblock_lab_bigvol
|
||||
|
||||
package storage
|
||||
|
||||
// chunkV11FormatBuild is true in a lab build: the draft v1.1 store format is
|
||||
// exercised on lab volumes. Never a release build (CI refuses the tag in
|
||||
// every image and release build).
|
||||
const chunkV11FormatBuild = true
|
||||
@@ -0,0 +1,10 @@
|
||||
//go:build !swblock_lab_bigvol
|
||||
|
||||
package storage
|
||||
|
||||
// chunkV11FormatBuild is false in a release build: the v1.1 store format
|
||||
// (chunk record pages, the coverage map and the chunk-state marker) is not
|
||||
// final, so no release binary upgrades a user's store to it; the v1.0 path
|
||||
// (.chunkpresence) stays. One later change declares the format, removes this
|
||||
// guard and fixes the version.
|
||||
const chunkV11FormatBuild = false
|
||||
@@ -571,7 +571,7 @@ func (s *WALStore) WriteContext(ctx context.Context, lba uint32, data []byte) (u
|
||||
}
|
||||
dirtyStart := time.Now()
|
||||
s.dm.put(uint64(lba), walRelOff, lsn, uint32(len(data)))
|
||||
s.noteChunkMutation(uint64(lba))
|
||||
s.noteChunkMutation(uint64(lba), lsn)
|
||||
s.instr.recordDirtyMapUpdate(1, time.Since(dirtyStart))
|
||||
|
||||
s.nextLSN++
|
||||
@@ -1015,9 +1015,9 @@ func (s *WALStore) noteChunkRecovery() {
|
||||
|
||||
// noteChunkMutation tells an attached chunk layer that lba changed; it
|
||||
// runs after the dirty-map insert that made the change visible.
|
||||
func (s *WALStore) noteChunkMutation(lba uint64) {
|
||||
func (s *WALStore) noteChunkMutation(lba, lsn uint64) {
|
||||
if h := s.chunk.Load(); h != nil && h.mutated != nil {
|
||||
h.mutated(lba)
|
||||
h.mutated(lba, lsn)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -828,7 +828,7 @@ func (s *WALStore) writeBatchV3Locked(startLBA uint32, blocks [][]byte, firstLSN
|
||||
dirtyStart := time.Now()
|
||||
s.dm.put(uint64(startLBA), phys, firstLSN, uint32(len(blocks[0])))
|
||||
s.instr.recordDirtyMapUpdate(1, time.Since(dirtyStart))
|
||||
s.noteChunkMutation(uint64(startLBA))
|
||||
s.noteChunkMutation(uint64(startLBA), firstLSN)
|
||||
s.advanceAfterAppendV3(firstLSN, firstLSN)
|
||||
return []uint64{firstLSN}, nil
|
||||
}
|
||||
@@ -870,7 +870,7 @@ func (s *WALStore) writeBatchV3Locked(startLBA uint32, blocks [][]byte, firstLSN
|
||||
lsns[i] = firstLSN + i
|
||||
s.recordMapWriteV3(lba, lsns[i])
|
||||
s.dm.putAt(lba, phys, uint32(i)*uint32(bs), lsns[i], uint32(bs))
|
||||
s.noteChunkMutation(lba)
|
||||
s.noteChunkMutation(lba, lsns[i])
|
||||
}
|
||||
s.instr.recordDirtyMapUpdate(len(blocks), time.Since(dirtyStart))
|
||||
s.v3.appended.Store(lastLSN)
|
||||
|
||||
Reference in new issue
Block a user