Skip to content

Conversation

@torcolvin
Copy link
Collaborator

[4.0.3 backport] CBG-4934 restart db initialization if needed

cherry-pick of 068c0e7

Copilot AI review requested due to automatic review settings January 16, 2026 15:56
Copy link
Contributor

Copilot AI left a comment

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 backports changes from commit 068c0e7 to enable restarting database initialization when needed. The primary focus is on improving cancellation handling for database initialization by adding context causes and updating the RemoveDatabase method signature to include a reason parameter.

Changes:

  • Added reason parameter to RemoveDatabase and Cancel methods for better traceability of why database operations are being stopped
  • Switched from context.WithCancel to context.WithCancelCause to preserve cancellation reasons
  • Fixed test logic and race condition handling using atomic operations
  • Enhanced error handling in RetryLoop to properly propagate context causes

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
rest/database_init_manager.go Core changes to support cancellation with cause, added logic to restart initialization if cancelled
rest/server_context.go Updated RemoveDatabase signature to accept reason parameter
rest/admin_api.go Updated calls to Cancel and RemoveDatabase with descriptive reasons
rest/api.go Updated RemoveDatabase calls with context about the calling endpoint
rest/server_context_test.go Updated test to pass reason parameter
rest/replicatortest/replicator_test.go Updated test calls with descriptive reasons
rest/indextest/index_init_api_test.go Enhanced test assertions and error checking
rest/database_init_manager_test.go Fixed test expectations to handle restarted initialization, converted to atomic operations
base/util.go Updated RetryLoop to use context.Cause for better error reporting
base/util_test.go Added test for context cancellation with cause

case err := <-doneChan:
require.NoError(t, err)
case <-time.After(30 * time.Second):
require.Fail(t, "InitializeDatabase didn't complete in 10s")
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

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

The error message still references '10s' but the timeout was increased to 30 seconds on line 57. Update the message to '30s' for consistency.

Suggested change
require.Fail(t, "InitializeDatabase didn't complete in 10s")
require.Fail(t, "InitializeDatabase didn't complete in 30s")

Copilot uses AI. Check for mistakes.
}

// Initializes the database. Will establish a new cluster connection using the provided server config. Establishes a new
// InitializeDatabase will establish a new cluster connection using the provided server config. Establishes a new
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

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

The comment has inconsistent sentence structure. The first sentence is complete, but the second sentence fragment 'Establishes a new...' should be combined with the first or made into a complete sentence.

Suggested change
// InitializeDatabase will establish a new cluster connection using the provided server config. Establishes a new
// InitializeDatabase establishes a new cluster connection using the provided server config and creates a

Copilot uses AI. Check for mistakes.
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.

2 participants