Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 22 additions & 29 deletions db/background_mgr_resync_dcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,6 @@ func (r *ResyncManagerDCP) Init(ctx context.Context, options map[string]interfac
db := options["database"].(*Database)
resyncCollections := options["collections"].(ResyncCollections)

newRunInit := func() error {
uniqueUUID, err := uuid.NewRandom()
if err != nil {
return err
}

r.ResyncID = uniqueUUID.String()
base.InfofCtx(ctx, base.KeyAll, "Resync: Starting new resync run with resync ID: %q", r.ResyncID)
return nil
}

// Get collectionIds and store in manager for use in DCP client later
collectionIDs, hasAllCollections, collectionNames, err := getCollectionIdsAndNames(db, resyncCollections)
if err != nil {
Expand All @@ -85,29 +74,33 @@ func (r *ResyncManagerDCP) Init(ctx context.Context, options map[string]interfac
// add collection list to manager for use in status call
r.SetCollectionStatus(collectionNames)

if clusterStatus != nil {
var statusDoc ResyncManagerStatusDocDCP
err := base.JSONUnmarshal(clusterStatus, &statusDoc)

reset, ok := options["reset"].(bool)
if reset && ok {
base.InfofCtx(ctx, base.KeyAll, "Resync: Resetting resync process. Will not resume any partially completed process")
}

// If the previous run completed, or there was an error during unmarshalling the status we will start the
// process from scratch with a new resync ID. Otherwise, we should resume with the resync ID, stats specified in the doc.
if statusDoc.State == BackgroundProcessStateCompleted || err != nil || (reset && ok) {
return newRunInit()
}
// If the previous run completed, or we couldn't determine, we will start the resync with a new resync ID.
// Otherwise, we should resume with the resync ID, and the previous stats specified in the doc.
var resetMsg string // an optional message about why we're resetting
var statusDoc ResyncManagerStatusDocDCP
if clusterStatus == nil {
resetMsg = "no previous run found"
} else if resetOpt, _ := options["reset"].(bool); resetOpt {
resetMsg = "reset option requested"
} else if err := base.JSONUnmarshal(clusterStatus, &statusDoc); err != nil {
resetMsg = "failed to unmarshal cluster status"
} else if statusDoc.State == BackgroundProcessStateCompleted {
resetMsg = "previous run completed"
} else {
// use the resync ID from the status doc to resume
r.ResyncID = statusDoc.ResyncID
r.SetStatus(statusDoc.DocsChanged, statusDoc.DocsProcessed)

base.InfofCtx(ctx, base.KeyAll, "Resync: Attempting to resume resync with resync ID: %s", r.ResyncID)

base.InfofCtx(ctx, base.KeyAll, "Resync: Resuming resync with ID: %q", r.ResyncID)
return nil
}

return newRunInit()
newID, err := uuid.NewRandom()
if err != nil {
return err
}
r.ResyncID = newID.String()
base.InfofCtx(ctx, base.KeyAll, "Resync: Running new resync process with ID: %q - %s", r.ResyncID, resetMsg)
return nil
}

func (r *ResyncManagerDCP) Run(ctx context.Context, options map[string]interface{}, persistClusterStatusCallback updateStatusCallbackFunc, terminator *base.SafeTerminator) error {
Expand Down
2 changes: 0 additions & 2 deletions docs/api/paths/admin/db-_resync.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ post:

A resync operation cannot be run if the database is online. The database can be taken offline by calling the `POST /{db}/_offline` endpoint.

In a multi-node cluster, the resync operation *must* be run on only a single node. Therefore, users should bring other nodes offline before initiating this action. Undefined system behaviour will happen if running resync on more than 1 node.

The `requireUser()` and `requireRole()` calls in the sync function will always return `true`.

- **action=start** - This is an asynchronous operation, and will start resync in the background.
Expand Down
Loading