Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a dedicated background-manager process to run the post-resync “invalidate principals + syncInfo update” work, and adds logic in the resync DCP manager to start/poll/restart that process until it reaches a terminal state.
Changes:
- Added
InvalidatePrincipalsProcessandnewInvalidatePrincipalsManagerto encapsulate principal invalidation and (optional)syncInfoupdates after resync. - Updated
ResyncManagerDCPto start the invalidate-principals manager and poll for completion/error/stopped, restarting when stopped. - Added unit tests covering the invalidate-principals manager/loop behavior, and added
BackgroundManager.getLastError()for error retrieval.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| db/background_mgr.go | Adds getLastError() accessor on BackgroundManager. |
| db/background_mgr_resync_dcp.go | Runs invalidate principals via a BackgroundManager and polls/restarts until completion. |
| db/background_mgr_invalidate_principals.go | New BackgroundManager process implementation for invalidating principals and updating syncInfo. |
| db/background_mgr_invalidate_principals_test.go | New tests for completion/restart/terminator-exit behaviors of the invalidate-principals loop. |
Comment on lines
+546
to
+551
| // getLastError returns the last error recorded by the manager. | ||
| func (b *BackgroundManager) getLastError() error { | ||
| b.lock.Lock() | ||
| defer b.lock.Unlock() | ||
| return b.lastError | ||
| } |
Collaborator
Author
There was a problem hiding this comment.
This is a separate but unpleasant bug.
Comment on lines
+546
to
+551
| // getLastError returns the last error recorded by the manager. | ||
| func (b *BackgroundManager) getLastError() error { | ||
| b.lock.Lock() | ||
| defer b.lock.Unlock() | ||
| return b.lastError | ||
| } |
Comment on lines
+488
to
+509
| ticker := time.NewTicker(pollWait) | ||
| defer ticker.Stop() | ||
| for { | ||
| select { | ||
| case <-ticker.C: | ||
| switch r.invalidatePrincipalsManager.GetRunState() { | ||
| case BackgroundProcessStateCompleted: | ||
| return true, nil | ||
| case BackgroundProcessStateError: | ||
| return false, r.invalidatePrincipalsManager.getLastError() | ||
| case BackgroundProcessStateStopped: | ||
| return false, nil | ||
| case BackgroundProcessStateRunning, BackgroundProcessStateStopping: | ||
| // still in progress, keep polling | ||
| } | ||
| case <-terminator.Done(): | ||
| if err := r.invalidatePrincipalsManager.Stop(ctx); err != nil { | ||
| base.WarnfCtx(ctx, "Failed to stop invalidate principals manager: %v", err) | ||
| } | ||
| return true, nil | ||
| } | ||
| } |
Comment on lines
+456
to
+459
| // invalidatePrincipals starts the invalidate principals background manager and polls until it completes. | ||
| // If the manager is stopped before completing (e.g. due to a node failure), it is restarted. The loop exits | ||
| // when the manager completes successfully, returns an error, or the resync terminator fires. | ||
| func (r *ResyncManagerDCP) invalidatePrincipals(ctx context.Context, db *DatabaseContext, regenerateSequences bool, hasAllCollections bool, terminator *base.SafeTerminator) error { |
adamcfraser
requested changes
Jun 1, 2026
adamcfraser
left a comment
Collaborator
There was a problem hiding this comment.
Functionality looks good, some suggestions for comment tweaks.
Co-authored-by: Adam Fraser <adam.fraser@couchbase.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CBG-5372 make sure that principals are invalidated on one node
Create a BackgroundManager process that all nodes will write to. wait for
Pre-review checklist
fmt.Print,log.Print, ...)base.UD(docID),base.MD(dbName))docs/apiDependencies (if applicable)
Integration Tests