Skip to content

Conversation

@liangyepianzhou
Copy link
Contributor

@liangyepianzhou liangyepianzhou commented Aug 14, 2025

Motivation

The current implementation of addDefaultRackBookiesIfMinNumRacksIsEnforced has the following issues:

  • Redundant logic: The initialization and merging process for collecting Bookie nodes on the default rack involves unnecessary data copying and checks.
  • Incorrect logging: The log claims to print only the defaultRack Bookies that are being excluded, while it actually prints all the nodes, including those already in excludeBookies.
LOG.info("enforceMinNumRacksPerWriteQuorum is enabled, so Excluding bookies of defaultRack: {}", bookiesInDefaultRack); 

Modification

  • When creating bookiesInDefaultRack, do not copy elements from excludeBookies.
  • Remove unnecessary null checks for bookiesInDefaultRack.

@liangyepianzhou liangyepianzhou changed the title ### Refactor addDefaultRackBookiesIfMinNumRacksIsEnforced to Remove Redundant Logic and Improve Robustness Refactor addDefaultRackBookiesIfMinNumRacksIsEnforced to Remove Redundant Logic and Improve Robustness Aug 14, 2025
…dant Logic and Improve Robustness

### Motivation

The current implementation of `addDefaultRackBookiesIfMinNumRacksIsEnforced` has the following issues:

- **Redundant logic**: The initialization and merging process for collecting Bookie nodes on the default rack involves unnecessary data copying and checks.
- **Potential robustness issue**: There is no null check for the address returned by `BookieNode.getAddr()`, which may result in `null` values being included in the exclusion set.
- **Incorrect logging**: The log claims to print only the defaultRack Bookies that are being excluded, while it actually prints all the nodes, including those already in `excludeBookies`.
  ```java
  LOG.info("enforceMinNumRacksPerWriteQuorum is enabled, so Excluding bookies of defaultRack: {}", bookiesInDefaultRack);
  ```

---

### Modification

- When creating `bookiesInDefaultRack`, do not copy elements from `excludeBookies`.
- Add a null check for the address returned by `BookieNode.getAddr()`.
- Remove unnecessary null checks for `bookiesInDefaultRack`.
@liangyepianzhou liangyepianzhou force-pushed the addDefaultRackBookiesIfMinNumRacksIsEnforced branch from 4c7eee7 to a5b6830 Compare August 14, 2025 12:08
@liangyepianzhou liangyepianzhou changed the title Refactor addDefaultRackBookiesIfMinNumRacksIsEnforced to Remove Redundant Logic and Improve Robustness Refactor addDefaultRackBookiesIfMinNumRacksIsEnforced to Remove Redundant Logic Aug 15, 2025
Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

which test cases are covering this change ?

@liangyepianzhou
Copy link
Contributor Author

which test cases are covering this change ?

It seems that there was previously no test coverage for this method, so I have added some test cases for addDefaultRackBookiesIfMinNumRacksIsEnforced.

Copy link
Member

@lhotari lhotari left a comment

Choose a reason for hiding this comment

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

LGTM, good work @liangyepianzhou

@eolivelli eolivelli dismissed their stale review October 15, 2025 11:26

Canceling my review.
Thanks for following up with my requests

I don't have time to complete my review this week

Copy link
Member

@StevenLuMT StevenLuMT left a comment

Choose a reason for hiding this comment

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

good jobs

@StevenLuMT
Copy link
Member

@eolivelli Help review this PR

Copy link

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 refactors the addDefaultRackBookiesIfMinNumRacksIsEnforced method to eliminate redundant logic and improve code clarity. The method is responsible for adding bookies from the default rack to an exclusion set when minimum rack enforcement is enabled.

Key changes:

  • Streamlined control flow by early-returning when enforceMinNumRacksPerWriteQuorum is false
  • Removed unnecessary initialization of bookiesInDefaultRack with excludeBookies content
  • Eliminated redundant null checks for bookiesInDefaultRack

Reviewed Changes

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

File Description
RackawareEnsemblePlacementPolicyImpl.java Refactored the method to remove redundant data copying, simplified control flow with early returns, and removed unnecessary null checks
RackawareEnsemblePlacementPolicyImplTest.java Added comprehensive test coverage for the refactored method with three test scenarios: bookies in default rack, mixed node types, and empty default rack

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

…ackawareEnsemblePlacementPolicyImpl.java

Co-authored-by: Copilot <[email protected]>
@liangyepianzhou
Copy link
Contributor Author

reopen due to #4665

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.

4 participants