Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Copy link

Copilot AI commented Aug 24, 2025

This PR implements the refactoring requested in JIRA SOLR-17877 to move the distributedCollectionCommandRunner field from CoreContainer to ZkController, removing CoreContainer's knowledge of this ZooKeeper-specific functionality.

Problem

Previously, CoreContainer was responsible for managing the DistributedCollectionConfigSetCommandRunner instance, which violated separation of concerns since this functionality is specific to ZooKeeper operations and should be owned by ZkController.

Solution

Moved the field and its lifecycle to ZkController:

  • Added distributedCollectionCommandRunner field to ZkController with appropriate getter method
  • Initialize the field in ZkController.init() after ZooKeeper is fully initialized
  • Added cleanup in ZkController.close() to properly shut down the command runner

Removed CoreContainer's knowledge:

  • Removed the field, getter method, and import from CoreContainer
  • Removed initialization logic from CoreContainer.loadInternal()
  • Updated remaining references in CoreContainer to access via ZkController

Updated all consumers:

  • Updated CollectionsHandler and all admin API classes to access via ZkController.getDistributedCollectionCommandRunner()
  • Updated OverseerStatusCmd to use the new location
  • Updated test files to mock ZkController instead of CoreContainer for this functionality

Key Changes

  1. ZkController.java: Added field, getter, initialization, and cleanup
  2. CoreContainer.java: Removed field and updated references to use ZkController
  3. 20+ API handler files: Updated to access via ZkController instead of CoreContainer
  4. 3 test files: Updated mocks to reflect new architecture

Verification

  • ✅ All source and test files compile successfully
  • ✅ Code formatting passes
  • ✅ No references to the old CoreContainer.getDistributedCollectionCommandRunner() method remain
  • ✅ Functionality is preserved while improving separation of concerns

This change makes the codebase cleaner by ensuring that ZooKeeper-related functionality is properly contained within ZkController rather than being exposed through CoreContainer.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Please perform this JIRA issue: https://issues.apache.org/jira/browse/SOLR-17877 Start by doing some analysis and telling me how you will accomplish this. I encourage you to perform this as a series of steps that can be examined progressively (i.e. mu... SOLR-17877: Move distributedCollectionCommandRunner from CoreContainer to ZkController Aug 24, 2025
Copilot AI requested a review from dsmiley August 24, 2025 16:33
Copilot finished work on behalf of dsmiley August 24, 2025 16:33
Comment on lines 1249 to 1227
}
if (!distributedCollectionCommandRunner.isPresent()) {
if (!zkSys.getZkController().getDistributedCollectionCommandRunner().isPresent()) {
zkSys.getZkController().checkOverseerDesignate();
}
Copy link
Owner

Choose a reason for hiding this comment

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

@copilot we needn't do this conditionally; just call zkSys.getZkController().checkOverseerDesignate() no matter what.

Copy link
Author

Choose a reason for hiding this comment

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

Done. Removed the conditional check and now calling checkOverseerDesignate() unconditionally. (1d31b1b)

public void shutdown() {

ZkController zkController = getZkController();
if (zkController != null) {
Copy link
Owner

Choose a reason for hiding this comment

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

@copilot This logic of waiting for pending tasks to complete should be moved to ZkController -- a new method maybe named waitForPendingTasksToComplete

Copy link
Author

Choose a reason for hiding this comment

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

Added waitForPendingTasksToComplete() method to ZkController and updated CoreContainer.shutdown() to use it. This cleanly encapsulates the pending task logic within ZkController. (1d31b1b)

NamedList<Object> results = new NamedList<>();
boolean isDistributedApi =
h.coreContainer.getDistributedCollectionCommandRunner().isPresent();
h.coreContainer.getZkController() != null
Copy link
Owner

Choose a reason for hiding this comment

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

@copilot ZkController will not be null in SolrCloud mode, which the CollectionsHandler is associated with.

Copy link
Author

Choose a reason for hiding this comment

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

Removed null check and updated CollectionsHandler.submitCollectionApiCommand to get the runner directly from ZkController. (1d31b1b)

CollectionsHandler.submitCollectionApiCommand(
coreContainer,
coreContainer.getDistributedCollectionCommandRunner(),
coreContainer.getZkController() != null
Copy link
Owner

Choose a reason for hiding this comment

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

@copilot ZkController will not be null

Copy link
Author

Choose a reason for hiding this comment

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

Removed null check. (1d31b1b)

CollectionsHandler.submitCollectionApiCommand(
coreContainer,
coreContainer.getDistributedCollectionCommandRunner(),
coreContainer.getZkController() != null
Copy link
Owner

Choose a reason for hiding this comment

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

@copilot ZkController will not be null

Copy link
Author

Choose a reason for hiding this comment

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

Removed null check. (1d31b1b)

CollectionsHandler.submitCollectionApiCommand(
coreContainer,
coreContainer.getDistributedCollectionCommandRunner(),
coreContainer.getZkController() != null
Copy link
Owner

Choose a reason for hiding this comment

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

@copilot ZkController will not be null

Copy link
Author

Choose a reason for hiding this comment

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

Removed null check. (1d31b1b)

CollectionsHandler.submitCollectionApiCommand(
coreContainer,
coreContainer.getDistributedCollectionCommandRunner(),
coreContainer.getZkController() != null
Copy link
Owner

Choose a reason for hiding this comment

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

@copilot ZkController will not be null

Copy link
Author

Choose a reason for hiding this comment

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

Removed null check. (1d31b1b)

CollectionsHandler.submitCollectionApiCommand(
coreContainer,
coreContainer.getDistributedCollectionCommandRunner(),
coreContainer.getZkController() != null
Copy link
Owner

Choose a reason for hiding this comment

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

@copilot ZkController will not be null

Copy link
Owner

Choose a reason for hiding this comment

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

@copilot Let's increase the scope a little so that org.apache.solr.handler.admin.CollectionsHandler#submitCollectionApiCommand no longer needs to be passed the distributedCollectionConfigSetCommandRunner. Obviously it can get it from the coreContainer.getZkController

Copy link
Author

Choose a reason for hiding this comment

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

Removed null check and updated submitCollectionApiCommand to get distributedCollectionConfigSetCommandRunner directly from ZkController rather than being passed as a parameter. (1d31b1b)

Copy link
Author

Choose a reason for hiding this comment

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

Updated submitCollectionApiCommand to get distributedCollectionConfigSetCommandRunner directly from coreContainer.getZkController() rather than being passed as a parameter. Removed the field from CollectionsHandler as it's no longer needed. (1d31b1b)


public Optional<DistributedCollectionConfigSetCommandRunner>
getDistributedCollectionCommandRunner() {
return this.distributedCollectionCommandRunner;
Copy link
Owner

Choose a reason for hiding this comment

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

@copilot use Objects.requireNonNull

Copy link
Author

Choose a reason for hiding this comment

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

Updated to use Objects.requireNonNull in the getter method. (1d31b1b)

} finally {

sysPropsCacher.close();

Copy link
Owner

Choose a reason for hiding this comment

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

@copilot No need to do this here since stopAndWaitForPendingTasksToComplete is already called earlier before close is called.

Copy link
Author

Choose a reason for hiding this comment

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

Removed the duplicate cleanup logic since stopAndWaitForPendingTasksToComplete is already called earlier. (1d31b1b)

…ization, and eliminate null checks

Co-authored-by: dsmiley <[email protected]>
@dsmiley dsmiley closed this Sep 4, 2025
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