Merge branch 'p338' into train/20261121-8

This commit is contained in:
pingqiu committed 2026-11-21 03:23:30 -08:00
commit 66e131b4e6
15 files changed
+39 -58

No files matched your search

@@ -29,7 +29,6 @@ const (
defaultChunkMaintenanceTimeout = time.Minute
defaultChunkGCGrace = time.Hour
defaultChunkIntentTTL = time.Hour
defaultChunkDirtyThreshold = 512 // chunks, 2 GiB at 4 MiB chunks
)
type chunkFlags struct {
@@ -42,7 +41,6 @@ type chunkFlags struct {
captureInterval time.Duration
maintenanceInterval time.Duration
automaticGC bool
dirtyThreshold int
uploadConcurrency int
hydrationWorkers int
hydrationQueueDepth int
@@ -61,7 +59,7 @@ func validateChunkFlags(f flags) error {
}
if f.durableImpl != "walstore-chunk" {
if c.filer != "" || c.collection != "" || c.replication != "" || c.path != defaultChunkPath ||
c.captureInterval != defaultChunkCaptureInterval || c.maintenanceInterval != defaultChunkMaintenanceInterval || c.automaticGC || c.dirtyThreshold != defaultChunkDirtyThreshold ||
c.captureInterval != defaultChunkCaptureInterval || c.maintenanceInterval != defaultChunkMaintenanceInterval || c.automaticGC ||
c.uploadConcurrency != 8 || c.hydrationWorkers != 2 || c.hydrationQueueDepth != 64 || c.controlEndpoint || c.detachPrecopy || c.hostLimit.Directory != "" {
return errors.New("--chunk-* flags require --durable-impl=walstore-chunk")
}
@@ -100,9 +98,6 @@ func validateChunkFlags(f flags) error {
if c.hydrationQueueDepth < 1 || c.hydrationQueueDepth > 65536 {
return errors.New("--chunk-hydration-queue-depth must be between 1 and 65536")
}
if c.dirtyThreshold < 0 {
return fmt.Errorf("--chunk-dirty-threshold=%d must not be negative", c.dirtyThreshold)
}
return nil
}
@@ -31,13 +31,13 @@ func TestWALStoreChunkFlags(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if d.chunk.captureInterval != 15*time.Minute || d.chunk.maintenanceInterval != time.Hour || d.chunk.automaticGC || d.chunk.dirtyThreshold != 512 {
t.Fatalf("scheduler defaults interval %s threshold %d, want capture 15m, maintenance 1h, GC off and 512", d.chunk.captureInterval, d.chunk.dirtyThreshold)
if d.chunk.captureInterval != 15*time.Minute || d.chunk.maintenanceInterval != time.Hour || d.chunk.automaticGC {
t.Fatalf("scheduler defaults interval %s, want capture 15m, maintenance 1h and GC off", d.chunk.captureInterval)
}
off, err := parseFlags(base("--durable-root=/tmp/sw-block", "--durable-impl=walstore-chunk", "--chunk-filer=x:1",
"--chunk-capture-interval=0", "--chunk-dirty-threshold=0"))
if err != nil || off.chunk.captureInterval != 0 || off.chunk.dirtyThreshold != 0 {
t.Fatalf("disabling both triggers: %+v %v", off.chunk, err)
"--chunk-capture-interval=0"))
if err != nil || off.chunk.captureInterval != 0 {
t.Fatalf("disabling the timer: %+v %v", off.chunk, err)
}
if _, err := parseFlags(base("--durable-root=/tmp/sw-block", "--durable-impl=walstore")); err != nil {
t.Fatalf("walstore with the chunk defaults untouched: %v", err)
@@ -58,8 +58,6 @@ func TestWALStoreChunkFlags(t *testing.T) {
"--chunk-filer=x:1", "--chunk-control-endpoint"),
"zero upload concurrency": base("--durable-root=/tmp/sw-block", "--durable-impl=walstore-chunk", "--chunk-filer=x:1", "--chunk-upload-concurrency=0"),
"too many uploads": base("--durable-root=/tmp/sw-block", "--durable-impl=walstore-chunk", "--chunk-filer=x:1", "--chunk-upload-concurrency=65"),
"negative threshold": base("--durable-root=/tmp/sw-block", "--durable-impl=walstore-chunk", "--chunk-filer=x:1", "--chunk-dirty-threshold=-1"),
"threshold on walstore": base("--durable-root=/tmp/sw-block", "--durable-impl=walstore", "--chunk-dirty-threshold=8"),
"interval on walstore": base("--durable-root=/tmp/sw-block", "--durable-impl=walstore", "--chunk-capture-interval=5s"),
}
for name, args := range refused {
@@ -123,3 +121,13 @@ func TestChunkHolderIsServerAndReplica(t *testing.T) {
t.Fatalf("chunk holder %q, want m02/r1", got)
}
}
// --chunk-dirty-threshold is gone: a cut stages by the
// copy-on-write budget (M5 Stage), so the flag never had an effect. A unit
// that still passes it fails at start.
func TestChunkDirtyThresholdFlagIsGone(t *testing.T) {
args := append(phase150RequiredBlockvolumeArgs(), "--durable-root=/tmp/sw-block", "--durable-impl=walstore-chunk", "--chunk-filer=x:1", "--chunk-dirty-threshold=512")
if _, err := parseFlags(args); err == nil || !strings.Contains(err.Error(), "flag provided but not defined") {
t.Fatalf("--chunk-dirty-threshold: %v; want flag provided but not defined", err)
}
}
+2 -4
View File
@@ -209,7 +209,6 @@ func parseFlags(args []string) (flags, error) {
fs.IntVar(&f.chunk.uploadConcurrency, "chunk-upload-concurrency", 8, "walstore-chunk: maximum concurrent dirty-chunk uploads (1..64)")
fs.IntVar(&f.chunk.hydrationWorkers, "chunk-hydration-workers", 2, "walstore-chunk: concurrent lazy chunk fetches per volume (1..64)")
fs.IntVar(&f.chunk.hydrationQueueDepth, "chunk-hydration-queue-depth", 64, "walstore-chunk: distinct queued/in-flight hydration chunks per volume (1..65536)")
fs.IntVar(&f.chunk.dirtyThreshold, "chunk-dirty-threshold", defaultChunkDirtyThreshold, "walstore-chunk: number of candidate chunks above which a cut pre-copies (stages) chunks before its barrier, in rounds of this size; copy-before-write copies the rest outside the barrier; never triggers a cut; 0 = no pre-copy")
fs.BoolVar(&f.chunk.controlEndpoint, "chunk-control-endpoint", false, "walstore-chunk: expose the /chunk/* control routes (cut, snapshot, snapshots, snapshot/delete, detach) on the status HTTP listener; off by default; loopback-only like the listener")
fs.UintVar(&f.durableBlocks, "durable-blocks", 2048, "number of blocks per volume on first create (ignored when opening existing)")
fs.UintVar(&f.durableBlockSize, "durable-blocksize", 4096, "block size in bytes on first create")
@@ -251,8 +250,8 @@ func parseFlags(args []string) (flags, error) {
return flags{}, err
}
memoryFlagSet := false
fs.Visit(func(f *flag.Flag) {
if f.Name == "memory-limit-mib" {
fs.Visit(func(fl *flag.Flag) {
if fl.Name == "memory-limit-mib" {
memoryFlagSet = true
}
})
@@ -667,7 +666,6 @@ func run(f flags) int {
cfg.ChunkMaintenanceTimeout = defaultChunkMaintenanceTimeout
cfg.ChunkMaintenance = chunk.maintenance
cfg.ChunkDetachPrecopy = f.chunk.detachPrecopy
cfg.ChunkDirtyThreshold = f.chunk.dirtyThreshold
cfg.ChunkUploadConcurrency = f.chunk.uploadConcurrency
cfg.ChunkHydrationWorkers = f.chunk.hydrationWorkers
cfg.ChunkHydrationQueueDepth = f.chunk.hydrationQueueDepth
@@ -199,13 +199,6 @@ type ProviderConfig struct {
// call back into the provider.
OnChunkDetach func(volumeID string) uint64
OnChunkDetachResumed func(volumeID string, attempt uint64)
// ChunkDirtyThreshold is the number of candidate chunks above which
// a cut pre-copies (stages) chunks before its barrier, in rounds of
// this size; copy-before-write copies the rest outside the barrier.
// It never triggers a cut: the remote holds snapshots, and cuts are
// published only by CaptureVolume, MakeVolumeRemoteDurable
// (snapshot, detach) and the timer. Zero: no pre-copy.
ChunkDirtyThreshold int
// ChunkUploadConcurrency bounds remote uploads; zero defaults to 8.
ChunkUploadConcurrency int
// ChunkPayloadMemoryBudget bounds one volume's cut payloads; zero uses the storage default.
@@ -385,7 +385,6 @@ func (p *DurableProvider) newChunkLayer(ctx context.Context, volumeID string, h
ReadMissTimeout: p.cfg.ChunkReadMissTimeout,
HydrationWorkers: p.cfg.ChunkHydrationWorkers,
HydrationQueueDepth: p.cfg.ChunkHydrationQueueDepth,
BarrierBound: p.cfg.ChunkDirtyThreshold,
UploadConcurrency: p.cfg.ChunkUploadConcurrency,
PayloadMemoryBudget: p.cfg.ChunkPayloadMemoryBudget,
Budget: p.cfg.ChunkBudget,
@@ -14,13 +14,12 @@ import (
"github.com/seaweedfs/seaweed-block/core/storage"
)
func schedProvider(t *testing.T, remote storage.ChunkRemote, interval time.Duration, threshold int) *durable.DurableProvider {
func schedProvider(t *testing.T, remote storage.ChunkRemote, interval time.Duration) *durable.DurableProvider {
t.Helper()
p, err := durable.NewDurableProvider(durable.ProviderConfig{
Impl: durable.ImplWALStoreChunk, StorageRoot: t.TempDir(), BlockSize: 4096,
NumBlocks: pcBlocks, ChunkBlocks: pcChunkBlocks,
ChunkCaptureInterval: interval,
ChunkDirtyThreshold: threshold,
ChunkRemoteFor: func(string) (storage.ChunkRemote, error) { return remote, nil },
}, v1View())
if err != nil {
@@ -40,12 +39,12 @@ func headGen(t *testing.T, remote storage.ChunkRemote) storage.ChunkHead {
}
// The remote holds snapshots: with the timer off, no number of dirty
// chunks publishes a cut on its own (the threshold only bounds a cut).
func TestWALStoreChunk_DirtyThresholdNeverTriggersCut(t *testing.T) {
// chunks publishes a cut on its own.
func TestWALStoreChunk_DirtyChunksNeverTriggerCut(t *testing.T) {
remote := storage.NewMemChunkRemote()
p := schedProvider(t, remote, 0, 2)
p := schedProvider(t, remote, 0)
s := openRecovered(t, p)
for c := uint32(0); c < 4; c++ { // four dirty chunks, twice the threshold
for c := uint32(0); c < 4; c++ { // four dirty chunks
if _, err := s.Write(c*pcChunkBlocks+1, block(byte(c+1))); err != nil {
t.Fatal(err)
}
@@ -71,7 +70,7 @@ func TestWALStoreChunk_DirtyThresholdNeverTriggersCut(t *testing.T) {
func TestWALStoreChunk_ExplicitCutRestartsTheTimer(t *testing.T) {
const interval = 3 * time.Second
remote := storage.NewMemChunkRemote()
p := schedProvider(t, remote, interval, 0)
p := schedProvider(t, remote, interval)
s := openRecovered(t, p)
begin := time.Now()
@@ -204,7 +203,7 @@ func TestWALStoreChunk_ExplicitCutOverlappingTheTimerRestartsIt(t *testing.T) {
var releaseOnce sync.Once
release := func() { releaseOnce.Do(func() { close(remote.release) }) }
t.Cleanup(release)
p := schedProvider(t, remote, interval, 0)
p := schedProvider(t, remote, interval)
events := make(chan loopEvent, 64)
durable.SetTestChunkLoopTrace(p, func(event string, lastCutNs int64, skipped bool) {
select {
@@ -47,9 +47,6 @@ func TestWALStoreChunk_LedgerWriteAnonymousMemory(t *testing.T) {
defer cancel()
r := &memoryDiskRemote{MemChunkRemote: storage.NewMemChunkRemote(), dir: t.TempDir(), hashes: make(map[string][32]byte)}
cfg := durable.ProviderConfig{Impl: durable.ImplWALStoreChunk, StorageRoot: t.TempDir(), BlockSize: 4096, NumBlocks: 1 << 18, ChunkBlocks: 1024, ChunkCaptureInterval: 0, ChunkRemoteFor: func(string) (storage.ChunkRemote, error) { return r, nil }}
if os.Getenv("SWBLOCK_MEMORY_STAGE") != "" {
cfg.ChunkDirtyThreshold = 64
}
p, err := durable.NewDurableProvider(cfg, v1View())
if err != nil {
t.Fatal(err)
@@ -243,9 +240,6 @@ func TestWALStoreChunk_InitialWriteAnonymousMemory(t *testing.T) {
defer cancel()
r := &memoryDiskRemote{MemChunkRemote: storage.NewMemChunkRemote(), dir: t.TempDir(), hashes: make(map[string][32]byte)}
cfg := durable.ProviderConfig{Impl: durable.ImplWALStoreChunk, StorageRoot: t.TempDir(), BlockSize: 4096, NumBlocks: 1 << 18, ChunkBlocks: 1024, ChunkCaptureInterval: 0, ChunkRemoteFor: func(string) (storage.ChunkRemote, error) { return r, nil }}
if os.Getenv("SWBLOCK_MEMORY_STAGE") != "" {
cfg.ChunkDirtyThreshold = 64
}
if raw := os.Getenv("SWBLOCK_MEMORY_CHUNKS"); raw != "" {
chunks, e := strconv.Atoi(raw)
if e != nil || chunks <= 0 {
@@ -256,7 +256,7 @@ func TestMaintenanceCoalescesWhileOnePassIsHeld(t *testing.T) {
func TestMaintenancePeriodicNoopDoesNotChurnHead(t *testing.T) {
remote := storage.NewMemChunkRemote()
p := schedProvider(t, remote, time.Millisecond, 0)
p := schedProvider(t, remote, time.Millisecond)
s := openRecovered(t, p)
lsn, err := s.Write(1, block(0x91))
if err != nil {
@@ -93,7 +93,7 @@ type ChunkCutStatsBody struct {
StagedChunks int `json:"stagedChunks"`
StagedChunksUsed int `json:"stagedChunksUsed"`
BarrierCopyChunks int `json:"barrierCopyChunks"`
BarrierOverBound bool `json:"barrierOverBound"`
BarrierOverBound bool `json:"barrierOverBound"` // always false in production: its bound is set only by legacy test fixtures
}
func cutStatsBody(s storage.ChunkCutStats) ChunkCutStatsBody {
+10 -9
View File
@@ -359,10 +359,10 @@ type chunkLayerConfig struct {
// impl3 uses its owned LSN map and never calls this optional legacy object.
Bitmap chunkBitmapStore
// BarrierBound bounds how many chunks a cut copies under its barrier:
// beyond it, chunks are pre-copied outside the barrier in staging
// rounds (at most chunkStageRounds; then the barrier takes the rest).
// Zero: unbounded, no staging.
// BarrierBound is for legacy test fixtures only: it sets
// BarrierOverBound when a cut copies more chunks than this under its
// barrier. Production staging is by the copy-on-write side budget (M5
// Stage), and production leaves this zero.
BarrierBound int
// UploadConcurrency bounds capture/pre-copy Put calls (0 defaults to 8).
@@ -443,11 +443,12 @@ type chunkCutStats struct {
MapPersistNs int64
CASResult string
TotalNs int64
// Pre-copy (BarrierBound > 0): StageRounds staging rounds staged
// StagedChunks chunks outside the barrier; StagedChunksUsed of the
// uploads in HEAD came from staging. BarrierCopyChunks were copied
// under the barrier; BarrierOverBound: more than the bound (the
// staging rounds did not converge).
// Pre-copy (staging by the copy-on-write side budget, M5 Stage):
// StageRounds staging rounds staged StagedChunks chunks outside the
// barrier; StagedChunksUsed of the uploads in HEAD came from staging.
// BarrierCopyChunks were copied under the barrier. BarrierOverBound:
// more than the legacy fixture BarrierBound; always false in
// production, where that bound is zero.
StageRounds int
StagedChunks int
StagedChunksUsed int
@@ -113,9 +113,6 @@ SWB_CHUNK_REPLICATION=
SWB_CHUNK_CAPTURE_INTERVAL=0
# --chunk-upload-concurrency (default 8; 1..64). Parallel dirty-chunk uploads.
SWB_CHUNK_UPLOAD_CONCURRENCY=8
# --chunk-dirty-threshold (default 512 chunks = 2 GiB; 0 = unbounded). Bound
# on one cut's barrier copy; never triggers a cut.
SWB_CHUNK_DIRTY_THRESHOLD=512
# --chunk-control-endpoint (default false). Expose /chunk/* (cut, snapshot,
# snapshots, snapshot/delete, detach) on the status listener; needs
# SWB_STATUS_ADDR.
@@ -60,7 +60,6 @@ ExecStart=/usr/local/bin/blockvolume \
--chunk-replication=${SWB_CHUNK_REPLICATION} \
--chunk-capture-interval=${SWB_CHUNK_CAPTURE_INTERVAL} \
--chunk-upload-concurrency=${SWB_CHUNK_UPLOAD_CONCURRENCY} \
--chunk-dirty-threshold=${SWB_CHUNK_DIRTY_THRESHOLD} \
--chunk-control-endpoint=${SWB_CHUNK_CONTROL_ENDPOINT} \
--workspace-lease=${SWB_WORKSPACE_LEASE} \
$SWB_VOLUME_EXTRA_ARGS
@@ -59,7 +59,6 @@ ExecStart=/usr/local/bin/blockvolume \
--chunk-replication=${SWB_CHUNK_REPLICATION} \
--chunk-capture-interval=${SWB_CHUNK_CAPTURE_INTERVAL} \
--chunk-upload-concurrency=${SWB_CHUNK_UPLOAD_CONCURRENCY} \
--chunk-dirty-threshold=${SWB_CHUNK_DIRTY_THRESHOLD} \
--chunk-control-endpoint=${SWB_CHUNK_CONTROL_ENDPOINT} \
--workspace-lease=${SWB_WORKSPACE_LEASE} \
$SWB_VOLUME_EXTRA_ARGS
@@ -72,7 +72,7 @@ A workspace runs one replica (RF=1). It does not use the replication engine of t
| Permanent host loss | the image at the last successful cut (HEAD `RemoteLSN`); writes after it are lost |
| Clean move (Detach) | everything written before Detach: guest I/O is stopped, then Detach publishes a final cut before the host releases the volume |
- **When cuts happen.** At semantic points chosen by the integrator, on explicit request, and by the periodic timer (default 15m, minimum 5m in the OSS CLI; 0 disables). Periodic cuts update HEAD without creating named snapshots. `--chunk-dirty-threshold` bounds staging work and never triggers a cut.
- **When cuts happen.** At semantic points chosen by the integrator, on explicit request, and by the periodic timer (default 15m, minimum 5m in the OSS CLI; 0 disables). Periodic cuts update HEAD without creating named snapshots. Dirty chunks never trigger a cut.
- **Recoverable frontier.** The confirmed remote HEAD is the recovery point after host loss. The default capture interval is 15m; failed or expired attempts retry with bounded backoff and reusable uploads, and do not claim a newly durable recovery point.
- Multi-replica workspaces combined with chunk snapshots are not supported.
@@ -122,7 +122,7 @@ Per volume, under the chunk base directory in the filer (`core/frontend/chunksto
`chunkLayerImpl.captureLocked` (`core/storage/chunk_layer.go`; contract in the `chunk_seam.go` header). A checkpoint is not a prefix image (the extent can already hold blocks newer than the checkpoint), so a cut is a quiesced point, not a checkpoint boundary.
1. **Admit:** refuse when closed, fenced, detached, during a base install, or when `CaptureAllowed` fails (healthy primary, unchanged lineage, valid lease).
2. **Pre-copy:** while more than `BarrierBound` chunks would be copied under the barrier (`--chunk-dirty-threshold`, default 512), stage up to that many per round outside the barrier, for at most `chunkStageRounds` (3) rounds (`stage`). A staged chunk with new bytes is uploaded under a fresh key named by an intent written first.
2. **Pre-copy:** while the chunks that would be copied under the barrier exceed half the copy-on-write side budget, stage the hottest of them per round outside the barrier, repeating only while the remainder shrinks (`stage`). A staged chunk with new bytes is uploaded under a fresh key named by an intent written first.
3. **Quiesce:** take the capture barrier (walstore `captureMu`) exclusively, then `Sync`. H is the synced LSN; no data newer than H exists in the WAL or the extent.
4. **Open and copy:** install the fixed candidate window under the barrier, then release it. Bounded workers copy through the validated reader outside the barrier. A first writer saves a pending candidate before mutation; a writer waits only for its own copying/saving chunk. A staged copy is reused only if its version and HEAD still match. Pause is Sync plus candidate/window installation, independent of copy bytes.
5. **LSN guard:** if H is below HEAD's `RemoteLSN`, refuse (`lsn_behind`).
@@ -124,7 +124,6 @@ the example units, which turn them into flags. blockvolume itself reads only
| `SWB_CHUNK_COLLECTION`, `SWB_CHUNK_REPLICATION` | `--chunk-collection`, `--chunk-replication` | empty (filer default) | Placement of chunk needles |
| `SWB_CHUNK_CAPTURE_INTERVAL` | `--chunk-capture-interval` | `0` (no timer) | Automatic cut interval, e.g. `15m` |
| `SWB_CHUNK_UPLOAD_CONCURRENCY` | `--chunk-upload-concurrency` | `8` | Parallel chunk uploads (1..64) |
| `SWB_CHUNK_DIRTY_THRESHOLD` | `--chunk-dirty-threshold` | `512` | Bound on one cut's barrier copy, in chunks |
| `SWB_CHUNK_CONTROL_ENDPOINT` | `--chunk-control-endpoint` | `false` | `/chunk/*` routes on the status listener |
| `SWB_WORKSPACE_LEASE` | `--workspace-lease` | `false` | Require a master lease; fail closed without one |
| `SWB_VOLUME_EXTRA_ARGS` | any | empty | Other flags (Kubernetes gate and source-gated flags) |