Skip to content

Commit

Permalink
Fix no known bookies after reset racks for all BKs (#4128)
Browse files Browse the repository at this point in the history
* Fix no known bookies after reset racks for all BKs
  • Loading branch information
poorbarcode authored Nov 20, 2023
1 parent acde49c commit c07e72a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,9 @@ public void remove(Node node) {
if (rack == null) {
numOfRacks--;
}
if (clusterMap.numOfLeaves == 0) {
depthOfAllLeaves = -1;
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("NetworkTopology became:\n" + this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,46 @@ public void getLeavesShouldReturnNodesInScope() {
assertTrue(leavesScopeRack1.contains(bookieRack1ScopeNode));
}

@Test
public void testRestartBKWithNewRackDepth() {
NetworkTopologyImpl networkTopology = new NetworkTopologyImpl();
String dp1Rack = "/rack-1";
String dp2Rack = "/dp/rack-1";
BookieId bkId1 = BookieId.parse("bookieIdScopeRack0");
BookieId bkId2 = BookieId.parse("bookieIdScopeRack1");

// Register 2 BKs with depth 1 rack.
BookieNode dp1BkNode1 = new BookieNode(bkId1, dp1Rack);
BookieNode dp1BkNode2 = new BookieNode(bkId2, dp1Rack);
networkTopology.add(dp1BkNode1);
networkTopology.add(dp1BkNode2);

// Update one BK with depth 2 rack.
// Assert it can not be added due to different depth.
networkTopology.remove(dp1BkNode1);
BookieNode dp2BkNode1 = new BookieNode(bkId1, dp2Rack);
try {
networkTopology.add(dp2BkNode1);
fail("Expected add node failed caused by different depth of rack");
} catch (NetworkTopologyImpl.InvalidTopologyException ex) {
// Expected ex.
}
Set<Node> leaves = networkTopology.getLeaves(dp1Rack);
assertEquals(leaves.size(), 1);
assertTrue(leaves.contains(dp1BkNode2));

// Update all Bks with depth 2 rack.
// Verify update success.
networkTopology.remove(dp1BkNode2);
BookieNode dp2BkNode2 = new BookieNode(bkId2, dp2Rack);
networkTopology.add(dp2BkNode1);
networkTopology.add(dp2BkNode2);
leaves = networkTopology.getLeaves(dp2Rack);
assertEquals(leaves.size(), 2);
assertTrue(leaves.contains(dp2BkNode1));
assertTrue(leaves.contains(dp2BkNode2));
}

@Test
public void getLeavesShouldReturnLeavesThatAreNotInExcludedScope() {
// GIVEN
Expand Down

0 comments on commit c07e72a

Please sign in to comment.