Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CBG-4549: Refactor resync Init so the reason for a reset is always logged #7410

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
54 changes: 24 additions & 30 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,34 @@ 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 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.
var resetReason string
var statusDoc ResyncManagerStatusDocDCP
if clusterStatus == nil {
resetReason = "no previous run found"
} else if resetOpt, _ := options["reset"].(bool); resetOpt {
resetReason = "reset option requested"
} else if err := base.JSONUnmarshal(clusterStatus, &statusDoc); err != nil {
resetReason = "failed to unmarshal cluster status"
} else if statusDoc.State == BackgroundProcessStateCompleted {
resetReason = "previous run completed"
}
if resetReason != "" {
newID, err := uuid.NewRandom()
if err != nil {
return err
}
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)

r.ResyncID = newID.String()
base.InfofCtx(ctx, base.KeyAll, "Resync: Resetting resync process with ID: %q - %s", r.ResyncID, resetReason)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with this change but I wonder if the two common scenarios here actually should not have the log line reset? I am not convinced by this, but I worry reset implies dropping previous bad state.

clusterStatus == nil - technically this is a reset because you are "setting" but I think that this is better stated as just "Starting resync process".

Similarly with statusDoc.State == BackgroundProcessStateCompleted but this case I can see how reset seems like the right word.

return nil
}

return newRunInit()
// 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: Resuming resync with ID: %q", r.ResyncID)
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