@@ -45,7 +45,7 @@ type ResyncManagerDCP struct {
4545 ResyncID string
4646 VBUUIDs []uint64
4747 ResyncedCollections base.CollectionNames
48- startOptions map [ string ] any // options from the most recent Start call, persisted to meta for Resume
48+ startOptions ResyncOptions // options from the most recent Start call, persisted to meta for Resume
4949 resyncCollectionInfo
5050 lock sync.RWMutex
5151 Distributed bool
@@ -94,13 +94,20 @@ type resyncCollectionInfo struct {
9494 hasAllCollections bool
9595}
9696
97- var _ BackgroundManagerProcessI = & ResyncManagerDCP {}
97+ // ResyncOptions are used to initialize a resync process.
98+ type ResyncOptions struct {
99+ Collections base.CollectionNames `json:"collections,omitempty"`
100+ Reset bool `json:"reset,omitempty"`
101+ RegenerateSequences bool `json:"regenerateSequences,omitempty"`
102+ }
103+
104+ var _ BackgroundManagerProcessI [ResyncOptions ] = & ResyncManagerDCP {}
98105
99106// NewResyncManagerDCP returns a new instance of ResyncManagerDCP wrapped in a BackgroundManager. If distributed is
100107// true, the manager will be set up to run in a distributed manner across multiple nodes, otherwise it will run on a
101108// single node.
102- func NewResyncManagerDCP (db * DatabaseContext , distributed bool ) * BackgroundManager {
103- b := & BackgroundManager {
109+ func NewResyncManagerDCP (db * DatabaseContext , distributed bool ) * BackgroundManager [ ResyncOptions ] {
110+ b := & BackgroundManager [ ResyncOptions ] {
104111 name : "resync" ,
105112 Process : & ResyncManagerDCP {
106113 db : db ,
@@ -126,18 +133,14 @@ func NewResyncManagerDCP(db *DatabaseContext, distributed bool) *BackgroundManag
126133 return b
127134}
128135
129- // Init processes the options to start a resync process and sets them as struct memebers.
130- func (r * ResyncManagerDCP ) Init (ctx context.Context , options map [string ]any , clusterStatus []byte ) error {
131- resyncCollections , ok := options ["collections" ].(base.CollectionNames )
132- if ! ok {
133- return errors .New ("collections option is required and must be of type base.CollectionNames" )
134- }
136+ // Init processes the options to start a resync process and sets them as struct members.
137+ func (r * ResyncManagerDCP ) Init (ctx context.Context , options ResyncOptions , clusterStatus []byte ) error {
135138 r .setStartOptions (options )
136139
137140 var collections DatabaseCollections
138- if len (resyncCollections ) > 0 {
141+ if len (options . Collections ) > 0 {
139142 var err error
140- collections , err = r .db .collections (resyncCollections )
143+ collections , err = r .db .collections (options . Collections )
141144 if err != nil {
142145 return err
143146 }
@@ -154,7 +157,7 @@ func (r *ResyncManagerDCP) Init(ctx context.Context, options map[string]any, clu
154157 var statusDoc ResyncManagerStatusDocDCP
155158 if clusterStatus == nil {
156159 resetMsg = "no previous run found"
157- } else if resetOpt , _ := options [ "reset" ].( bool ); resetOpt {
160+ } else if options . Reset {
158161 resetMsg = "reset option requested"
159162 } else if err := base .JSONUnmarshal (clusterStatus , & statusDoc ); err != nil {
160163 resetMsg = "failed to unmarshal cluster status"
@@ -216,7 +219,7 @@ func (r *ResyncManagerDCP) purgeCheckpoints(ctx context.Context, resyncID string
216219}
217220
218221// setStartOptions stores the options used to start the current run so that Resume can reconstruct them.
219- func (r * ResyncManagerDCP ) setStartOptions (options map [ string ] any ) {
222+ func (r * ResyncManagerDCP ) setStartOptions (options ResyncOptions ) {
220223 r .lock .Lock ()
221224 defer r .lock .Unlock ()
222225 r .startOptions = options
@@ -230,12 +233,9 @@ func (r *ResyncManagerDCP) SetVBUUIDs(vbuuids []uint64) {
230233}
231234
232235// Run starts a DCP feed to process documents for resync.
233- func (r * ResyncManagerDCP ) Run (ctx context.Context , options map [ string ] any , persistClusterStatusCallback updateStatusCallbackFunc , terminator * base.SafeTerminator ) (err error ) {
236+ func (r * ResyncManagerDCP ) Run (ctx context.Context , options ResyncOptions , persistClusterStatusCallback updateStatusCallbackFunc , terminator * base.SafeTerminator ) (err error ) {
234237 db := r .db
235- regenerateSequences , ok := options ["regenerateSequences" ].(bool )
236- if ! ok {
237- return errors .New ("regenerateSequences option is required and must be of type bool" )
238- }
238+ regenerateSequences := options .RegenerateSequences
239239 ctx = context .WithoutCancel (ctx ) // drop cancellation from parent context
240240 ctx = base .CorrelationIDLogCtx (ctx , r .ResyncID )
241241 ctx , cancelResync := context .WithCancelCause (ctx )
@@ -789,9 +789,9 @@ type resyncManagerCompletedVBuckets struct {
789789}
790790
791791type ResyncManagerMeta struct {
792- VBUUIDs []uint64 `json:"vbuuids"`
793- CollectionIDs []uint32 `json:"collection_ids,omitempty"`
794- Options map [ string ] any `json:"options,omitempty"` // start options, persisted for Resume
792+ VBUUIDs []uint64 `json:"vbuuids"`
793+ CollectionIDs []uint32 `json:"collection_ids,omitempty"`
794+ Options ResyncOptions `json:"options,omitempty"` // start options, persisted for Resume
795795 resyncManagerCompletedVBuckets
796796}
797797
0 commit comments