clarax commented on a change in pull request #3575:
URL: https://github.com/apache/hbase/pull/3575#discussion_r686547061
##########
File path:
hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/BalancerClusterState.java
##########
@@ -572,26 +550,22 @@ public void doAction(BalanceAction action) {
// FindBugs: Having the assert quietens FB BC_UNCONFIRMED_CAST warnings
assert action instanceof AssignRegionAction : action.getClass();
AssignRegionAction ar = (AssignRegionAction) action;
- regionsPerServer[ar.getServer()] =
- addRegion(regionsPerServer[ar.getServer()], ar.getRegion());
+ regionsPerServer.get(ar.getServer()).add(ar.getRegion());
regionMoved(ar.getRegion(), -1, ar.getServer());
break;
case MOVE_REGION:
assert action instanceof MoveRegionAction : action.getClass();
MoveRegionAction mra = (MoveRegionAction) action;
- regionsPerServer[mra.getFromServer()] =
- removeRegion(regionsPerServer[mra.getFromServer()], mra.getRegion());
- regionsPerServer[mra.getToServer()] =
- addRegion(regionsPerServer[mra.getToServer()], mra.getRegion());
+ // remove by value
+
regionsPerServer.get(mra.getFromServer()).remove(Integer.valueOf(mra.getRegion()));
+ regionsPerServer.get(mra.getToServer()).add(mra.getRegion());
regionMoved(mra.getRegion(), mra.getFromServer(), mra.getToServer());
break;
case SWAP_REGIONS:
assert action instanceof SwapRegionsAction : action.getClass();
SwapRegionsAction a = (SwapRegionsAction) action;
- regionsPerServer[a.getFromServer()] =
- replaceRegion(regionsPerServer[a.getFromServer()],
a.getFromRegion(), a.getToRegion());
- regionsPerServer[a.getToServer()] =
- replaceRegion(regionsPerServer[a.getToServer()], a.getToRegion(),
a.getFromRegion());
+ replaceRegion(regionsPerServer.get(a.getFromServer()),
a.getFromRegion(), a.getToRegion());
+ replaceRegion(regionsPerServer.get(a.getToServer()), a.getToRegion(),
a.getFromRegion());
Review comment:
O(n)->O(1) for removing an element by its value
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]