@@ -52,6 +52,17 @@ var errBackgroundManagerProcessAlreadyRunning = base.HTTPErrorf(http.StatusServi
5252// errBackgroundManagerProcessAlreadyStopped is returned when an action to Stop a process occurs but it is already stopped.
5353var errBackgroundManagerProcessAlreadyStopped = base .HTTPErrorf (http .StatusServiceUnavailable , "Process already stopped" )
5454
55+ // backgroundManagerInitMode is the return type of BackgroundManagerProcessI.Init, indicating whether
56+ // the process is starting fresh or resuming a prior run.
57+ type backgroundManagerInitMode int
58+
59+ const (
60+ // backgroundManagerInitReset means Init started a new run, discarding any previous state.
61+ backgroundManagerInitReset backgroundManagerInitMode = iota
62+ // backgroundManagerInitResume means Init found a previous run and will continue from where it left off.
63+ backgroundManagerInitResume
64+ )
65+
5566// backgroundManagerUpdateClusterStatusMode controls whether updateMultiNodeClusterAwareStatus enforces
5667// consistency between the local and cluster states.
5768type backgroundManagerUpdateClusterStatusMode int
@@ -130,7 +141,8 @@ type BackgroundManagerStatus struct {
130141// Examples of this: ReSync, Compaction, Attachment Migration
131142type BackgroundManagerProcessI [O any ] interface {
132143 // Init is called before Run for setup purposes. If Init errors, Run will not happen.
133- Init (ctx context.Context , options O , clusterStatus []byte ) error
144+ // Returns backgroundManagerInitResume if resuming an existing (stopped) run, backgroundManagerInitReset if starting a new one.
145+ Init (ctx context.Context , options O , clusterStatus []byte ) (backgroundManagerInitMode , error )
134146 // Run implements all of the work of the process.
135147 Run (ctx context.Context , options O , persistClusterStatusCallback updateStatusCallbackFunc , terminator * base.SafeTerminator ) error
136148 // GetProcessStatus accepts the current BackgroundManagerStatus and the previousStatus that was serialized. previousStatus is
@@ -252,7 +264,7 @@ func (b *BackgroundManager[O]) start(ctx context.Context, options O, processClus
252264 b .setStartTime (previousStatus .StartTime )
253265 }
254266
255- err = b .Process .Init (ctx , options , processClusterStatus )
267+ initMode , err : = b .Process .Init (ctx , options , processClusterStatus )
256268 if err != nil {
257269 return err
258270 }
@@ -317,7 +329,7 @@ func (b *BackgroundManager[O]) start(ctx context.Context, options O, processClus
317329 var err error
318330 if b .mode () == backgroundManagerModeMultiNode {
319331 mode := backgroundManagerStatusStart
320- if isResume {
332+ if isResume || initMode == backgroundManagerInitResume {
321333 mode = backgroundManagerStatusResume
322334 }
323335 err = b .updateMultiNodeClusterAwareStatus (ctx , mode )
0 commit comments