Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,9 @@ private void finishActiveMasterInitialization(MonitoredTask status) throws IOExc
this.clusterStatusChore = new ClusterStatusChore(this, balancer);
getChoreService().scheduleChore(clusterStatusChore);
this.balancerChore = new BalancerChore(this);
getChoreService().scheduleChore(balancerChore);
if (this.loadBalancerTracker.isBalancerOn()) {
getChoreService().scheduleChore(balancerChore);
}
this.normalizerChore = new RegionNormalizerChore(this);
getChoreService().scheduleChore(normalizerChore);
this.catalogJanitorChore = new CatalogJanitor(this);
Expand Down Expand Up @@ -1673,6 +1675,29 @@ private void balanceThrottling(long nextBalanceStartTime, int maxRegionsInTransi
if (interrupted) Thread.currentThread().interrupt();
}

/**
* Turn the balancer on/off
*
* @param on boolean value indicates whether to turn the balancer on
*/
void switchBalancer(boolean on) {
if (on) {
scheduleBalancerChore();
} else {
cancelBalancerChore();
}
}

private synchronized void scheduleBalancerChore() {
if (!getChoreService().isChoreScheduled(this.balancerChore)) {
getChoreService().scheduleChore(this.balancerChore);
}
}

private void cancelBalancerChore() {
getChoreService().cancelChore(this.balancerChore);
}

public boolean balance() throws IOException {
return balance(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,11 @@ boolean switchBalancer(final boolean b, BalanceSwitchMode mode) throws IOExcepti
if (mode == BalanceSwitchMode.SYNC) {
synchronized (master.getLoadBalancer()) {
master.loadBalancerTracker.setBalancerOn(newValue);
master.switchBalancer(newValue);
}
} else {
master.loadBalancerTracker.setBalancerOn(newValue);
master.switchBalancer(newValue);
}
} catch (KeeperException ke) {
throw new IOException(ke);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ public void testMoveRegion() throws Exception {
}
Thread.sleep(100);
}
admin.balancerSwitch(true).join();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ public void testRITStateForRollback() throws Exception {
}
assertTrue(cluster.getMaster().getAssignmentManager().getRegionStates().isRegionOnline(hri));
} finally {
admin.balancerSwitch(true, false);
master.setCatalogJanitorEnabled(true);
abortAndWaitForMaster();
TESTING_UTIL.deleteTable(tableName);
Expand Down Expand Up @@ -346,7 +345,6 @@ public void testSplitRollbackOnRegionClosing() throws Exception {
checkAndGetDaughters(tableName);
// OK, so split happened after we cleared the blocking node.
} finally {
admin.balancerSwitch(true, false);
cluster.getMaster().setCatalogJanitorEnabled(true);
t.close();
}
Expand Down Expand Up @@ -423,7 +421,6 @@ public void testShutdownFixupWhenDaughterHasSplit() throws Exception {
}
} finally {
LOG.info("EXITING");
admin.balancerSwitch(true, false);
cluster.getMaster().setCatalogJanitorEnabled(true);
t.close();
}
Expand Down Expand Up @@ -549,7 +546,6 @@ public void testMasterRestartAtRegionSplitPendingCatalogJanitor()
ServerName regionServerOfRegion = regionStates.getRegionServerOfRegion(hri);
assertEquals(null, regionServerOfRegion);
} finally {
TESTING_UTIL.getAdmin().balancerSwitch(true, false);
cluster.getMaster().setCatalogJanitorEnabled(true);
}
}
Expand Down Expand Up @@ -621,7 +617,6 @@ public void testSplitWithRegionReplicas() throws Exception {
SlowMeCopro.getPrimaryCdl().get().countDown();
} finally {
SlowMeCopro.getPrimaryCdl().get().countDown();
admin.balancerSwitch(true, false);
cluster.getMaster().setCatalogJanitorEnabled(true);
t.close();
}
Expand Down Expand Up @@ -730,7 +725,6 @@ public void testSplitRegionWithNoStoreFiles() throws Exception {
assertFalse("Split region can't be unassigned", regionStates.isRegionInTransition(hri));
assertTrue(regionStates.isRegionInState(hri, State.SPLIT));
} finally {
admin.balancerSwitch(true, false);
cluster.getMaster().setCatalogJanitorEnabled(true);
}
}
Expand Down