Skip to content

Conversation

@bbrks
Copy link
Member

@bbrks bbrks commented Nov 26, 2025

CBG-5007

Unclean cherry-pick of #7889 for 4.0.2

Integration Tests

Copilot AI review requested due to automatic review settings November 26, 2025 13:47
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 splits the single ServerContext.lock mutex into two separate locks (_databasesLock and _httpServersLock) to reduce mutex contention and improve concurrency. The change renames database-related maps to have underscore prefixes (_databases, _dbConfigs, _dbRegistry, _collectionRegistry) and updates all references throughout the codebase to use the appropriate lock for each data structure.

Key Changes

  • Introduced separate locks: _databasesLock for database state and _httpServersLock for HTTP server management
  • Renamed internal maps with underscore prefixes to indicate they are protected by _databasesLock
  • Refactored Close() method to stop HTTP servers first, then clean up databases and other resources in a logical order

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
rest/server_context.go Core changes: split mutex into _databasesLock and _httpServersLock, renamed maps with underscore prefixes, refactored Close() method
rest/utilities_testing.go Updated lock usage to _databasesLock, added updatePersistedConfig helper for testing
rest/handler_config_database.go Updated to use _databasesLock instead of lock
rest/admin_api.go Updated all database map accesses to use _databasesLock
rest/config.go Updated all database configuration operations to use _databasesLock
rest/serverless_test.go Updated test assertions to use renamed underscore-prefixed map fields
rest/config_test.go Updated test assertions to use renamed _dbConfigs field
rest/api_test.go Updated tests to use new updatePersistedConfig helper instead of direct map access

defer sc._databasesLock.RUnlock()

databases := make(map[string]*db.DatabaseContext, len(sc.databases_))
databases := make(map[string]*db.DatabaseContext, len(sc._databases))
Copy link

Copilot AI Nov 26, 2025

Choose a reason for hiding this comment

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

The function creates a map with the same size as sc._databases and then copies all entries. This is redundant - maps.Copy can copy into an empty map without pre-sizing. Consider removing the size parameter from make() or using a simple loop if pre-sizing is intentional for performance.

Suggested change
databases := make(map[string]*db.DatabaseContext, len(sc._databases))
databases := make(map[string]*db.DatabaseContext)

Copilot uses AI. Check for mistakes.
@bbrks bbrks merged commit 93ac0ec into release/4.0.2 Nov 26, 2025
42 checks passed
@bbrks bbrks deleted the CBG-5007 branch November 26, 2025 17:50
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