refactor: Batch 4 steps 2+3 — rebuild status port + recovery bundle factory

Step 2: Rebuild completion status port
- New runtime.RebuildCompletionStatus + DeriveRebuildCommitted:
  reusable shaping logic for post-rebuild snapshot → RebuildCommitted event
- block_recovery.go OnRebuildCompleted: delegates to DeriveRebuildCommitted,
  host only reads raw snapshot via readRebuildStatus (thin binding)
- Removed 15 lines of inline flushedLSN/checkpointLSN/achievedLSN computation

Step 3: Recovery bundle factory
- New buildRecoveryBundle: shared host-side setup for both catch-up and rebuild
  (creates Reader + Pinner + StorageAdapter + Executor + RecoveryDriver)
- runCatchUp and runRebuild both use buildRecoveryBundle instead of
  duplicating the WithVolume → NewReader → NewPinner → NewStorageAdapter →
  NewExecutor → RecoveryDriver chain
- runCatchUp/runRebuild are now thin host-shell methods

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 4.6 committed 2026-04-04 01:32:34 -07:00
1 parent 0bcfc678d0
commit ded84b25e6
2 files changed
+94 -58

No files matched your search

@@ -0,0 +1,35 @@
package runtime
import engine "github.com/seaweedfs/seaweedfs/sw-block/engine/replication"
// RebuildCompletionStatus holds the post-rebuild state read from the backend.
// The host adapter fills this after a successful rebuild; the runtime helper
// uses it to emit the core RebuildCommitted event.
type RebuildCompletionStatus struct {
CommittedLSN uint64
CheckpointLSN uint64
}
// DeriveRebuildCommitted computes the RebuildCommitted event from
// post-rebuild status and the original plan. This is the reusable
// shaping logic — the host only needs to supply the raw snapshot values.
func DeriveRebuildCommitted(volumeID string, status RebuildCompletionStatus, plan *engine.RecoveryPlan) engine.RebuildCommitted {
flushedLSN := status.CommittedLSN
if flushedLSN == 0 {
flushedLSN = plan.RebuildTargetLSN
}
checkpointLSN := status.CheckpointLSN
if checkpointLSN == 0 {
checkpointLSN = plan.RebuildTargetLSN
}
achievedLSN := flushedLSN
if checkpointLSN > achievedLSN {
achievedLSN = checkpointLSN
}
return engine.RebuildCommitted{
ID: volumeID,
AchievedLSN: achievedLSN,
FlushedLSN: flushedLSN,
CheckpointLSN: checkpointLSN,
}
}