Skip to content

CBG-5372 make sure that principals are invalidated on one node#8318

Open
torcolvin wants to merge 3 commits into
mainfrom
CBG-5372
Open

CBG-5372 make sure that principals are invalidated on one node#8318
torcolvin wants to merge 3 commits into
mainfrom
CBG-5372

Conversation

@torcolvin

Copy link
Copy Markdown
Collaborator

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

  • Removed debug logging (fmt.Print, log.Print, ...)
  • Logging sensitive data? Make sure it's tagged (e.g. base.UD(docID), base.MD(dbName))
  • Updated relevant information in the API specifications (such as endpoint descriptions, schemas, ...) in docs/api

Dependencies (if applicable)

  • Link upstream PRs
  • Update Go module dependencies when merged

Integration Tests

Copilot AI review requested due to automatic review settings June 1, 2026 15:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 InvalidatePrincipalsProcess and newInvalidatePrincipalsManager to encapsulate principal invalidation and (optional) syncInfo updates after resync.
  • Updated ResyncManagerDCP to 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 thread db/background_mgr_resync_dcp.go
Comment thread db/background_mgr_resync_dcp.go Outdated
Comment thread db/background_mgr.go
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
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is a separate but unpleasant bug.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Comment thread db/background_mgr.go
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 adamcfraser left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Functionality looks good, some suggestions for comment tweaks.

Comment thread db/background_mgr_resync_dcp.go Outdated
Comment thread db/background_mgr_resync_dcp.go Outdated
Comment thread db/background_mgr_resync_dcp.go Outdated
Co-authored-by: Adam Fraser <adam.fraser@couchbase.com>
@torcolvin torcolvin self-assigned this Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants