Files
seaweedfs/sw-block/engine/replication/runtime/rebuild_status.go
T
pingqiu 16ba70f856 refactor: make bounded recovery observation events replica-scoped
Carry replica-scoped addressing through bounded recovery planning and completion events so the core no longer depends on a volume-only observation seam. This preserves the current single-replica catch-up and rebuilding behavior while aligning the observation side with the replica-scoped command path.

Made-with: Cursor
2026-04-04 09:18:07 -07:00

37 lines
1.2 KiB
Go

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, replicaID 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{
ReplicaID: replicaID,
ID: volumeID,
AchievedLSN: achievedLSN,
FlushedLSN: flushedLSN,
CheckpointLSN: checkpointLSN,
}
}