You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by "liangyepianzhou (via GitHub)" <gi...@apache.org> on 2025/08/14 12:06:22 UTC
[PR] ### Refactor addDefaultRackBookiesIfMinNumRacksIsEnforced to Remove Redundant Logic and Improve Robustness [bookkeeper]
liangyepianzhou opened a new pull request, #4652:
URL: https://github.com/apache/bookkeeper/pull/4652
### 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); ```
### Changes
(Describe: what changes you have made)
> ---
> In order to uphold a high standard for quality for code contributions, Apache BookKeeper runs various precommit
> checks for pull requests. A pull request can only be merged when it passes precommit checks.
>
> ---
> Be sure to do all the following to help us incorporate your contribution
> quickly and easily:
>
> If this PR is a BookKeeper Proposal (BP):
>
> - [ ] Make sure the PR title is formatted like:
> `<BP-#>: Description of bookkeeper proposal`
> `e.g. BP-1: 64 bits ledger is support`
> - [ ] Attach the master issue link in the description of this PR.
> - [ ] Attach the google doc link if the BP is written in Google Doc.
>
> Otherwise:
>
> - [ ] Make sure the PR title is formatted like:
> `<Issue #>: Description of pull request`
> `e.g. Issue 123: Description ...`
> - [ ] Make sure tests pass via `mvn clean apache-rat:check install spotbugs:check`.
> - [ ] Replace `<Issue #>` in the title with the actual Issue number.
>
> ---
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Refactor addDefaultRackBookiesIfMinNumRacksIsEnforced to Remove Redundant Logic and Improve Robustness [bookkeeper]
Posted by "StevenLuMT (via GitHub)" <gi...@apache.org>.
StevenLuMT commented on code in PR #4652:
URL: https://github.com/apache/bookkeeper/pull/4652#discussion_r2278060852
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/client/RackawareEnsemblePlacementPolicyImpl.java:
##########
@@ -364,16 +364,16 @@ protected Set<BookieId> addDefaultRackBookiesIfMinNumRacksIsEnforced(
Set<BookieId> bookiesInDefaultRack = null;
Set<Node> defaultRackLeaves = topology.getLeaves(getDefaultRack());
for (Node node : defaultRackLeaves) {
- if (node instanceof BookieNode) {
+ if (node instanceof BookieNode && ((BookieNode) node).getAddr() != null) {
Review Comment:
When does node.getAddr() return null?
To prevent this, should I throw an error or use getDefaultRack?
Also, add a test case to verify this exception scenario.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Refactor addDefaultRackBookiesIfMinNumRacksIsEnforced to Remove Redundant Logic [bookkeeper]
Posted by "liangyepianzhou (via GitHub)" <gi...@apache.org>.
liangyepianzhou commented on PR #4652:
URL: https://github.com/apache/bookkeeper/pull/4652#issuecomment-3326880515
> 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`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Refactor addDefaultRackBookiesIfMinNumRacksIsEnforced to Remove Redundant Logic [bookkeeper]
Posted by "StevenLuMT (via GitHub)" <gi...@apache.org>.
StevenLuMT commented on PR #4652:
URL: https://github.com/apache/bookkeeper/pull/4652#issuecomment-3410440187
@eolivelli Help review this PR
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Refactor addDefaultRackBookiesIfMinNumRacksIsEnforced to Remove Redundant Logic [bookkeeper]
Posted by "liangyepianzhou (via GitHub)" <gi...@apache.org>.
liangyepianzhou commented on PR #4652:
URL: https://github.com/apache/bookkeeper/pull/4652#issuecomment-3484126419
reopen due to https://github.com/apache/bookkeeper/pull/4665
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Refactor addDefaultRackBookiesIfMinNumRacksIsEnforced to Remove Redundant Logic [bookkeeper]
Posted by "lhotari (via GitHub)" <gi...@apache.org>.
lhotari commented on code in PR #4652:
URL: https://github.com/apache/bookkeeper/pull/4652#discussion_r2431345622
##########
bookkeeper-server/src/test/java/org/apache/bookkeeper/client/RackawareEnsemblePlacementPolicyImplTest.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.bookkeeper.client;
+
+import static org.apache.bookkeeper.client.TopologyAwareEnsemblePlacementPolicy.REPP_DNS_RESOLVER_CLASS;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Optional;
+import java.util.Set;
+import org.apache.bookkeeper.conf.ClientConfiguration;
+import org.apache.bookkeeper.feature.FeatureProvider;
+import org.apache.bookkeeper.net.BookieId;
+import org.apache.bookkeeper.net.BookieNode;
+import org.apache.bookkeeper.net.NetworkTopology;
+import org.apache.bookkeeper.net.Node;
+import org.apache.bookkeeper.net.ScriptBasedMapping;
+import org.apache.bookkeeper.proto.BookieAddressResolver;
+import org.apache.bookkeeper.test.TestStatsProvider;
+import org.apache.bookkeeper.util.StaticDNSResolver;
+import org.junit.Before;
+import org.junit.Test;
+
+public class RackawareEnsemblePlacementPolicyImplTest {
+
+ private RackawareEnsemblePlacementPolicyImpl policy;
+ private NetworkTopology topology;
+ private Set<BookieId> excludeBookies;
+ private BookieId bookie1;
+ private BookieId bookie2;
+
+ String defaultRack = "/default-rack";
+
+ @Before
+ public void setUp() {
+ TestStatsProvider provider = new TestStatsProvider();
+ policy = new RackawareEnsemblePlacementPolicyImpl();
+ ClientConfiguration clientConfiguration = mock(ClientConfiguration.class);
+ when(clientConfiguration.getEnforceMinNumRacksPerWriteQuorum()).thenReturn(true);
+ when(clientConfiguration.getString(REPP_DNS_RESOLVER_CLASS,
+ ScriptBasedMapping.class.getName())).thenReturn(StaticDNSResolver.class.getName());
+ policy.initialize(clientConfiguration,
+ Optional.empty(),
+ mock(io.netty.util.HashedWheelTimer.class),
+ mock(FeatureProvider.class),
+ provider.getStatsLogger(""),
+ mock(BookieAddressResolver.class));
+ topology = mock(NetworkTopology.class);
+ excludeBookies = new HashSet<>();
+ bookie1 = BookieId.parse("bookie1:3181");
+ bookie2 = BookieId.parse("bookie2:3181");
+
+ // Set the default rack
+ when(topology.getLeaves(defaultRack))
+ .thenReturn(Collections.emptySet());
+
+ // Use reflection to inject the mock topology into the policy
+ TestUtils.setField(TopologyAwareEnsemblePlacementPolicy.class, policy, "topology", topology);
+ }
+
+ @Test
+ public void testWithDefaultRackBookies() {
+ // Scenario: bookie nodes exist in the default rack
+ BookieNode node1 = new BookieNode(bookie1, defaultRack);
+ BookieNode node2 = new BookieNode(bookie2, defaultRack);
+
+ Set<Node> defaultRackNodes = new HashSet<>();
+ defaultRackNodes.add(node1);
+ defaultRackNodes.add(node2);
+
+ when(topology.getLeaves(defaultRack))
+ .thenReturn(defaultRackNodes);
+
+ // Add some bookies to be excluded
+ excludeBookies.add(BookieId.parse("other:3181"));
+
+ Set<BookieId> result = policy.addDefaultRackBookiesIfMinNumRacksIsEnforced(excludeBookies);
+
+ // Verify: the result should contain the original exclusion set + all bookies from the default rack
+ assertEquals(3, result.size());
+ assertTrue(result.contains(bookie1));
+ assertTrue(result.contains(bookie2));
+ assertTrue(result.containsAll(excludeBookies));
+ }
+
+ @Test
+ public void testMixedNodesInDefaultRack() {
+ // Scenario: default rack contains mixed BookieNode and non-BookieNode nodes
+ BookieNode bookieNode = new BookieNode(bookie1, defaultRack);
+ Node nonBookieNode = mock(Node.class);
+
+ Set<Node> defaultRackNodes = new HashSet<>();
+ defaultRackNodes.add(bookieNode);
+ defaultRackNodes.add(nonBookieNode);
+
+ when(topology.getLeaves(defaultRack))
+ .thenReturn(defaultRackNodes);
+
+ Set<BookieId> result = policy.addDefaultRackBookiesIfMinNumRacksIsEnforced(excludeBookies);
+
+ // Verify: the result should include the BookieNode but not the non-BookieNode
+ assertEquals(1, result.size());
+ assertTrue(result.contains(bookie1));
+ }
+
+ @Test
+ public void testEmptyDefaultRackBookies() {
+ // Scenario: the collection in default rack is empty
+ Set<Node> emptySet = Collections.emptySet();
+ when(topology.getLeaves(defaultRack))
+ .thenReturn(emptySet);
+
+ // Add some bookies to be excluded
+ excludeBookies.add(BookieId.parse("other:3181"));
+ Set<BookieId> result = policy.addDefaultRackBookiesIfMinNumRacksIsEnforced(excludeBookies);
+
+ // Verify: should return the original exclusion set
+ assertSame(excludeBookies, result);
+ }
+}
+
+// Utility class for setting private fields
+class TestUtils {
+ public static void setField(Class<?> tclass , Object target, String fieldName, Object value) {
Review Comment:
Apache Commons3 contains org.apache.commons.lang3.reflect.FieldUtils for this purpose.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Refactor addDefaultRackBookiesIfMinNumRacksIsEnforced to Remove Redundant Logic [bookkeeper]
Posted by "liangyepianzhou (via GitHub)" <gi...@apache.org>.
liangyepianzhou closed pull request #4652: Refactor addDefaultRackBookiesIfMinNumRacksIsEnforced to Remove Redundant Logic
URL: https://github.com/apache/bookkeeper/pull/4652
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Refactor addDefaultRackBookiesIfMinNumRacksIsEnforced to Remove Redundant Logic [bookkeeper]
Posted by "lhotari (via GitHub)" <gi...@apache.org>.
lhotari commented on code in PR #4652:
URL: https://github.com/apache/bookkeeper/pull/4652#discussion_r2428772058
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/client/RackawareEnsemblePlacementPolicyImpl.java:
##########
@@ -366,14 +366,14 @@ protected Set<BookieId> addDefaultRackBookiesIfMinNumRacksIsEnforced(
for (Node node : defaultRackLeaves) {
if (node instanceof BookieNode) {
if (bookiesInDefaultRack == null) {
- bookiesInDefaultRack = new HashSet<BookieId>(excludeBookies);
+ bookiesInDefaultRack = new HashSet<>();
}
bookiesInDefaultRack.add(((BookieNode) node).getAddr());
} else {
LOG.error("found non-BookieNode: {} as leaf of defaultrack: {}", node, getDefaultRack());
}
}
- if ((bookiesInDefaultRack == null) || bookiesInDefaultRack.isEmpty()) {
+ if (bookiesInDefaultRack == null) {
comprehensiveExclusionBookiesSet = excludeBookies;
} else {
comprehensiveExclusionBookiesSet = new HashSet<BookieId>(excludeBookies);
Review Comment:
it seems that it would be better to always initialize this to `new HashSet<>(excludeBookies)` in the first line of this method. The logic doesn't make much sense any more.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Refactor addDefaultRackBookiesIfMinNumRacksIsEnforced to Remove Redundant Logic [bookkeeper]
Posted by "lhotari (via GitHub)" <gi...@apache.org>.
lhotari commented on code in PR #4652:
URL: https://github.com/apache/bookkeeper/pull/4652#discussion_r2429010101
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/client/RackawareEnsemblePlacementPolicyImpl.java:
##########
@@ -359,30 +359,22 @@ public void uninitalize() {
*/
protected Set<BookieId> addDefaultRackBookiesIfMinNumRacksIsEnforced(
Set<BookieId> excludeBookies) {
- Set<BookieId> comprehensiveExclusionBookiesSet;
- if (enforceMinNumRacksPerWriteQuorum) {
- Set<BookieId> bookiesInDefaultRack = null;
- Set<Node> defaultRackLeaves = topology.getLeaves(getDefaultRack());
- for (Node node : defaultRackLeaves) {
- if (node instanceof BookieNode) {
- if (bookiesInDefaultRack == null) {
- bookiesInDefaultRack = new HashSet<BookieId>(excludeBookies);
- }
- bookiesInDefaultRack.add(((BookieNode) node).getAddr());
- } else {
- LOG.error("found non-BookieNode: {} as leaf of defaultrack: {}", node, getDefaultRack());
- }
- }
- if ((bookiesInDefaultRack == null) || bookiesInDefaultRack.isEmpty()) {
- comprehensiveExclusionBookiesSet = excludeBookies;
+ if (!enforceMinNumRacksPerWriteQuorum) {
+ return excludeBookies;
+ }
+
+ Set<BookieId> comprehensiveExclusionBookiesSet = new HashSet<>(excludeBookies);
+ Set<Node> defaultRackLeaves = topology.getLeaves(getDefaultRack());
+ for (Node node : defaultRackLeaves) {
+ if (node instanceof BookieNode) {
+ comprehensiveExclusionBookiesSet.add(((BookieNode) node).getAddr());
} else {
- comprehensiveExclusionBookiesSet = new HashSet<BookieId>(excludeBookies);
- comprehensiveExclusionBookiesSet.addAll(bookiesInDefaultRack);
- LOG.info("enforceMinNumRacksPerWriteQuorum is enabled, so Excluding bookies of defaultRack: {}",
- bookiesInDefaultRack);
+ LOG.error("found non-BookieNode: {} as leaf of defaultrack: {}", node, getDefaultRack());
}
- } else {
- comprehensiveExclusionBookiesSet = excludeBookies;
+ }
+ if (!comprehensiveExclusionBookiesSet.isEmpty()) {
+ LOG.info("enforceMinNumRacksPerWriteQuorum is enabled, so Excluding bookies of defaultRack: {}",
Review Comment:
this log message is not accurate?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Refactor addDefaultRackBookiesIfMinNumRacksIsEnforced to Remove Redundant Logic [bookkeeper]
Posted by "liangyepianzhou (via GitHub)" <gi...@apache.org>.
liangyepianzhou commented on code in PR #4652:
URL: https://github.com/apache/bookkeeper/pull/4652#discussion_r2429043747
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/client/RackawareEnsemblePlacementPolicyImpl.java:
##########
@@ -359,30 +359,22 @@ public void uninitalize() {
*/
protected Set<BookieId> addDefaultRackBookiesIfMinNumRacksIsEnforced(
Set<BookieId> excludeBookies) {
- Set<BookieId> comprehensiveExclusionBookiesSet;
- if (enforceMinNumRacksPerWriteQuorum) {
- Set<BookieId> bookiesInDefaultRack = null;
- Set<Node> defaultRackLeaves = topology.getLeaves(getDefaultRack());
- for (Node node : defaultRackLeaves) {
- if (node instanceof BookieNode) {
- if (bookiesInDefaultRack == null) {
- bookiesInDefaultRack = new HashSet<BookieId>(excludeBookies);
- }
- bookiesInDefaultRack.add(((BookieNode) node).getAddr());
- } else {
- LOG.error("found non-BookieNode: {} as leaf of defaultrack: {}", node, getDefaultRack());
- }
- }
- if ((bookiesInDefaultRack == null) || bookiesInDefaultRack.isEmpty()) {
- comprehensiveExclusionBookiesSet = excludeBookies;
+ if (!enforceMinNumRacksPerWriteQuorum) {
+ return excludeBookies;
+ }
+
+ Set<BookieId> comprehensiveExclusionBookiesSet = new HashSet<>(excludeBookies);
+ Set<Node> defaultRackLeaves = topology.getLeaves(getDefaultRack());
+ for (Node node : defaultRackLeaves) {
+ if (node instanceof BookieNode) {
+ comprehensiveExclusionBookiesSet.add(((BookieNode) node).getAddr());
} else {
- comprehensiveExclusionBookiesSet = new HashSet<BookieId>(excludeBookies);
- comprehensiveExclusionBookiesSet.addAll(bookiesInDefaultRack);
- LOG.info("enforceMinNumRacksPerWriteQuorum is enabled, so Excluding bookies of defaultRack: {}",
- bookiesInDefaultRack);
+ LOG.error("found non-BookieNode: {} as leaf of defaultrack: {}", node, getDefaultRack());
}
- } else {
- comprehensiveExclusionBookiesSet = excludeBookies;
+ }
+ if (!comprehensiveExclusionBookiesSet.isEmpty()) {
+ LOG.info("enforceMinNumRacksPerWriteQuorum is enabled, so Excluding bookies of defaultRack: {}",
Review Comment:
This log message has actually not changed at all.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Refactor addDefaultRackBookiesIfMinNumRacksIsEnforced to Remove Redundant Logic and Improve Robustness [bookkeeper]
Posted by "liangyepianzhou (via GitHub)" <gi...@apache.org>.
liangyepianzhou commented on code in PR #4652:
URL: https://github.com/apache/bookkeeper/pull/4652#discussion_r2278116512
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/client/RackawareEnsemblePlacementPolicyImpl.java:
##########
@@ -364,16 +364,16 @@ protected Set<BookieId> addDefaultRackBookiesIfMinNumRacksIsEnforced(
Set<BookieId> bookiesInDefaultRack = null;
Set<Node> defaultRackLeaves = topology.getLeaves(getDefaultRack());
for (Node node : defaultRackLeaves) {
- if (node instanceof BookieNode) {
+ if (node instanceof BookieNode && ((BookieNode) node).getAddr() != null) {
Review Comment:
This simply adds a bounds check, but it seems unnecessary; `addr` shouldn't be null.
This wasn't a major change and has been removed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Refactor addDefaultRackBookiesIfMinNumRacksIsEnforced to Remove Redundant Logic [bookkeeper]
Posted by "liangyepianzhou (via GitHub)" <gi...@apache.org>.
liangyepianzhou commented on code in PR #4652:
URL: https://github.com/apache/bookkeeper/pull/4652#discussion_r2430967092
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/client/RackawareEnsemblePlacementPolicyImpl.java:
##########
@@ -359,30 +359,22 @@ public void uninitalize() {
*/
protected Set<BookieId> addDefaultRackBookiesIfMinNumRacksIsEnforced(
Set<BookieId> excludeBookies) {
- Set<BookieId> comprehensiveExclusionBookiesSet;
- if (enforceMinNumRacksPerWriteQuorum) {
- Set<BookieId> bookiesInDefaultRack = null;
- Set<Node> defaultRackLeaves = topology.getLeaves(getDefaultRack());
- for (Node node : defaultRackLeaves) {
- if (node instanceof BookieNode) {
- if (bookiesInDefaultRack == null) {
- bookiesInDefaultRack = new HashSet<BookieId>(excludeBookies);
- }
- bookiesInDefaultRack.add(((BookieNode) node).getAddr());
- } else {
- LOG.error("found non-BookieNode: {} as leaf of defaultrack: {}", node, getDefaultRack());
- }
- }
- if ((bookiesInDefaultRack == null) || bookiesInDefaultRack.isEmpty()) {
- comprehensiveExclusionBookiesSet = excludeBookies;
+ if (!enforceMinNumRacksPerWriteQuorum) {
+ return excludeBookies;
+ }
+
+ Set<BookieId> comprehensiveExclusionBookiesSet = new HashSet<>(excludeBookies);
+ Set<Node> defaultRackLeaves = topology.getLeaves(getDefaultRack());
+ for (Node node : defaultRackLeaves) {
+ if (node instanceof BookieNode) {
+ comprehensiveExclusionBookiesSet.add(((BookieNode) node).getAddr());
} else {
- comprehensiveExclusionBookiesSet = new HashSet<BookieId>(excludeBookies);
- comprehensiveExclusionBookiesSet.addAll(bookiesInDefaultRack);
- LOG.info("enforceMinNumRacksPerWriteQuorum is enabled, so Excluding bookies of defaultRack: {}",
- bookiesInDefaultRack);
+ LOG.error("found non-BookieNode: {} as leaf of defaultrack: {}", node, getDefaultRack());
}
- } else {
- comprehensiveExclusionBookiesSet = excludeBookies;
+ }
+ if (!comprehensiveExclusionBookiesSet.isEmpty()) {
+ LOG.info("enforceMinNumRacksPerWriteQuorum is enabled, so Excluding bookies of defaultRack: {}",
Review Comment:
You are right, the original log content was not accurate, and we should not keep it the same as before.
Previously, the log printed the union of excludeBookies and all BookieIds under the default rack, but in fact, the intended meaning of the log is the BookieIds that are under the default rack.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Refactor addDefaultRackBookiesIfMinNumRacksIsEnforced to Remove Redundant Logic [bookkeeper]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #4652:
URL: https://github.com/apache/bookkeeper/pull/4652#discussion_r2435567618
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/client/RackawareEnsemblePlacementPolicyImpl.java:
##########
@@ -359,32 +359,31 @@ public void uninitalize() {
*/
protected Set<BookieId> addDefaultRackBookiesIfMinNumRacksIsEnforced(
Set<BookieId> excludeBookies) {
- Set<BookieId> comprehensiveExclusionBookiesSet;
- if (enforceMinNumRacksPerWriteQuorum) {
- Set<BookieId> bookiesInDefaultRack = null;
- Set<Node> defaultRackLeaves = topology.getLeaves(getDefaultRack());
- for (Node node : defaultRackLeaves) {
- if (node instanceof BookieNode) {
- if (bookiesInDefaultRack == null) {
- bookiesInDefaultRack = new HashSet<BookieId>(excludeBookies);
- }
- bookiesInDefaultRack.add(((BookieNode) node).getAddr());
- } else {
- LOG.error("found non-BookieNode: {} as leaf of defaultrack: {}", node, getDefaultRack());
+ if (!enforceMinNumRacksPerWriteQuorum) {
+ return excludeBookies;
+ }
+
+ Set<BookieId> bookiesInDefaultRack = null;
+ Set<Node> defaultRackLeaves = topology.getLeaves(getDefaultRack());
+ for (Node node : defaultRackLeaves) {
+ if (node instanceof BookieNode) {
+ if (bookiesInDefaultRack == null) {
+ bookiesInDefaultRack = new HashSet<>();
}
- }
- if ((bookiesInDefaultRack == null) || bookiesInDefaultRack.isEmpty()) {
- comprehensiveExclusionBookiesSet = excludeBookies;
+ bookiesInDefaultRack.add(((BookieNode) node).getAddr());
} else {
- comprehensiveExclusionBookiesSet = new HashSet<BookieId>(excludeBookies);
- comprehensiveExclusionBookiesSet.addAll(bookiesInDefaultRack);
- LOG.info("enforceMinNumRacksPerWriteQuorum is enabled, so Excluding bookies of defaultRack: {}",
- bookiesInDefaultRack);
+ LOG.error("found non-BookieNode: {} as leaf of defaultrack: {}", node, getDefaultRack());
}
+ }
+ if ((bookiesInDefaultRack == null) || bookiesInDefaultRack.isEmpty()) {
Review Comment:
The null check for `bookiesInDefaultRack` is redundant. Since `bookiesInDefaultRack` is only instantiated when nodes are found (line 371), it can only be null if no BookieNode was encountered. The `isEmpty()` check alone would be sufficient after removing the null check, but the logic should be restructured to check `bookiesInDefaultRack == null` separately from `isEmpty()` for clarity, or initialize it to an empty set at declaration.
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/client/RackawareEnsemblePlacementPolicyImpl.java:
##########
@@ -359,32 +359,31 @@ public void uninitalize() {
*/
protected Set<BookieId> addDefaultRackBookiesIfMinNumRacksIsEnforced(
Set<BookieId> excludeBookies) {
- Set<BookieId> comprehensiveExclusionBookiesSet;
- if (enforceMinNumRacksPerWriteQuorum) {
- Set<BookieId> bookiesInDefaultRack = null;
- Set<Node> defaultRackLeaves = topology.getLeaves(getDefaultRack());
- for (Node node : defaultRackLeaves) {
- if (node instanceof BookieNode) {
- if (bookiesInDefaultRack == null) {
- bookiesInDefaultRack = new HashSet<BookieId>(excludeBookies);
- }
- bookiesInDefaultRack.add(((BookieNode) node).getAddr());
- } else {
- LOG.error("found non-BookieNode: {} as leaf of defaultrack: {}", node, getDefaultRack());
+ if (!enforceMinNumRacksPerWriteQuorum) {
+ return excludeBookies;
+ }
+
+ Set<BookieId> bookiesInDefaultRack = null;
+ Set<Node> defaultRackLeaves = topology.getLeaves(getDefaultRack());
+ for (Node node : defaultRackLeaves) {
+ if (node instanceof BookieNode) {
+ if (bookiesInDefaultRack == null) {
+ bookiesInDefaultRack = new HashSet<>();
}
- }
- if ((bookiesInDefaultRack == null) || bookiesInDefaultRack.isEmpty()) {
- comprehensiveExclusionBookiesSet = excludeBookies;
+ bookiesInDefaultRack.add(((BookieNode) node).getAddr());
} else {
- comprehensiveExclusionBookiesSet = new HashSet<BookieId>(excludeBookies);
- comprehensiveExclusionBookiesSet.addAll(bookiesInDefaultRack);
- LOG.info("enforceMinNumRacksPerWriteQuorum is enabled, so Excluding bookies of defaultRack: {}",
- bookiesInDefaultRack);
+ LOG.error("found non-BookieNode: {} as leaf of defaultrack: {}", node, getDefaultRack());
Review Comment:
Corrected spelling of 'defaultrack' to 'defaultRack'.
```suggestion
LOG.error("found non-BookieNode: {} as leaf of defaultRack: {}", node, getDefaultRack());
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@bookkeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org