109109import org .apache .hadoop .hbase .client .TableState ;
110110import org .apache .hadoop .hbase .conf .ConfigurationManager ;
111111import org .apache .hadoop .hbase .coprocessor .CoprocessorHost ;
112+ import org .apache .hadoop .hbase .exceptions .DeserializationException ;
112113import org .apache .hadoop .hbase .exceptions .MasterStoppedException ;
113114import org .apache .hadoop .hbase .executor .ExecutorType ;
114115import org .apache .hadoop .hbase .favored .FavoredNodesManager ;
129130import org .apache .hadoop .hbase .master .balancer .BaseLoadBalancer ;
130131import org .apache .hadoop .hbase .master .balancer .ClusterStatusChore ;
131132import org .apache .hadoop .hbase .master .balancer .LoadBalancerFactory ;
133+ import org .apache .hadoop .hbase .master .balancer .LoadBalancerStateStore ;
132134import org .apache .hadoop .hbase .master .balancer .MaintenanceLoadBalancer ;
133135import org .apache .hadoop .hbase .master .cleaner .DirScanPool ;
134136import org .apache .hadoop .hbase .master .cleaner .HFileCleaner ;
145147import org .apache .hadoop .hbase .master .migrate .RollingUpgradeChore ;
146148import org .apache .hadoop .hbase .master .normalizer .RegionNormalizerFactory ;
147149import org .apache .hadoop .hbase .master .normalizer .RegionNormalizerManager ;
150+ import org .apache .hadoop .hbase .master .normalizer .RegionNormalizerStateStore ;
148151import org .apache .hadoop .hbase .master .procedure .CreateTableProcedure ;
149152import org .apache .hadoop .hbase .master .procedure .DeleteNamespaceProcedure ;
150153import org .apache .hadoop .hbase .master .procedure .DeleteTableProcedure ;
174177import org .apache .hadoop .hbase .master .replication .TransitPeerSyncReplicationStateProcedure ;
175178import org .apache .hadoop .hbase .master .replication .UpdatePeerConfigProcedure ;
176179import org .apache .hadoop .hbase .master .slowlog .SlowLogMasterService ;
180+ import org .apache .hadoop .hbase .master .snapshot .SnapshotCleanupStateStore ;
177181import org .apache .hadoop .hbase .master .snapshot .SnapshotManager ;
178182import org .apache .hadoop .hbase .master .waleventtracker .WALEventTrackerTableCreator ;
179183import org .apache .hadoop .hbase .master .zksyncer .MasterAddressSyncer ;
246250import org .apache .hadoop .hbase .util .TableDescriptorChecker ;
247251import org .apache .hadoop .hbase .util .Threads ;
248252import org .apache .hadoop .hbase .util .VersionInfo ;
249- import org .apache .hadoop .hbase .zookeeper .LoadBalancerTracker ;
250253import org .apache .hadoop .hbase .zookeeper .MasterAddressTracker ;
251254import org .apache .hadoop .hbase .zookeeper .MetaTableLocator ;
252- import org .apache .hadoop .hbase .zookeeper .RegionNormalizerTracker ;
253- import org .apache .hadoop .hbase .zookeeper .SnapshotCleanupTracker ;
254255import org .apache .hadoop .hbase .zookeeper .ZKClusterId ;
255256import org .apache .hadoop .hbase .zookeeper .ZKUtil ;
256257import org .apache .hadoop .hbase .zookeeper .ZKWatcher ;
@@ -306,17 +307,17 @@ public class HMaster extends HBaseServerBase<MasterRpcServices> implements Maste
306307 // Draining region server tracker
307308 private DrainingServerTracker drainingServerTracker ;
308309 // Tracker for load balancer state
309- LoadBalancerTracker loadBalancerTracker ;
310+ LoadBalancerStateStore loadBalancerStateStore ;
310311 // Tracker for meta location, if any client ZK quorum specified
311312 private MetaLocationSyncer metaLocationSyncer ;
312313 // Tracker for active master location, if any client ZK quorum specified
313314 @ InterfaceAudience .Private
314315 MasterAddressSyncer masterAddressSyncer ;
315316 // Tracker for auto snapshot cleanup state
316- SnapshotCleanupTracker snapshotCleanupTracker ;
317+ SnapshotCleanupStateStore snapshotCleanupStateStore ;
317318
318319 // Tracker for split and merge state
319- private SplitOrMergeTracker splitOrMergeTracker ;
320+ private SplitOrMergeStateStore splitOrMergeStateStore ;
320321
321322 private ClusterSchemaService clusterSchemaService ;
322323
@@ -750,24 +751,22 @@ public MetricsMaster getMasterMetrics() {
750751 * should have already been initialized along with {@link ServerManager}.
751752 */
752753 private void initializeZKBasedSystemTrackers ()
753- throws IOException , KeeperException , ReplicationException {
754+ throws IOException , KeeperException , ReplicationException , DeserializationException {
754755 if (maintenanceMode ) {
755756 // in maintenance mode, always use MaintenanceLoadBalancer.
756757 conf .unset (LoadBalancer .HBASE_RSGROUP_LOADBALANCER_CLASS );
757758 conf .setClass (HConstants .HBASE_MASTER_LOADBALANCER_CLASS , MaintenanceLoadBalancer .class ,
758759 LoadBalancer .class );
759760 }
760761 this .balancer = new RSGroupBasedLoadBalancer ();
761- this .loadBalancerTracker = new LoadBalancerTracker (zooKeeper , this );
762- this .loadBalancerTracker .start ();
762+ this .loadBalancerStateStore = new LoadBalancerStateStore (masterRegion , zooKeeper );
763763
764764 this .regionNormalizerManager =
765- RegionNormalizerFactory .createNormalizerManager (conf , zooKeeper , this );
765+ RegionNormalizerFactory .createNormalizerManager (conf , masterRegion , zooKeeper , this );
766766 this .configurationManager .registerObserver (regionNormalizerManager );
767767 this .regionNormalizerManager .start ();
768768
769- this .splitOrMergeTracker = new SplitOrMergeTracker (zooKeeper , conf , this );
770- this .splitOrMergeTracker .start ();
769+ this .splitOrMergeStateStore = new SplitOrMergeStateStore (masterRegion , zooKeeper , conf );
771770
772771 // This is for backwards compatible. We do not need the CP for rs group now but if user want to
773772 // load it, we need to enable rs group.
@@ -787,8 +786,7 @@ private void initializeZKBasedSystemTrackers()
787786 this .drainingServerTracker = new DrainingServerTracker (zooKeeper , this , this .serverManager );
788787 this .drainingServerTracker .start ();
789788
790- this .snapshotCleanupTracker = new SnapshotCleanupTracker (zooKeeper , this );
791- this .snapshotCleanupTracker .start ();
789+ this .snapshotCleanupStateStore = new SnapshotCleanupStateStore (masterRegion , zooKeeper );
792790
793791 String clientQuorumServers = conf .get (HConstants .CLIENT_ZOOKEEPER_QUORUM );
794792 boolean clientZkObserverMode = conf .getBoolean (HConstants .CLIENT_ZOOKEEPER_OBSERVER_MODE ,
@@ -910,8 +908,8 @@ private void tryMigrateMetaLocationsFromZooKeeper() throws IOException, KeeperEx
910908 * Notice that now we will not schedule a special procedure to make meta online(unless the first
911909 * time where meta has not been created yet), we will rely on SCP to bring meta online.
912910 */
913- private void finishActiveMasterInitialization (MonitoredTask status )
914- throws IOException , InterruptedException , KeeperException , ReplicationException {
911+ private void finishActiveMasterInitialization (MonitoredTask status ) throws IOException ,
912+ InterruptedException , KeeperException , ReplicationException , DeserializationException {
915913 /*
916914 * We are active master now... go initialize components we need to run.
917915 */
@@ -1640,7 +1638,7 @@ conf, getMasterFileSystem().getFileSystem(), new Path(archiveDir, path),
16401638 new ReplicationBarrierCleaner (conf , this , getConnection (), replicationPeerManager );
16411639 getChoreService ().scheduleChore (replicationBarrierCleaner );
16421640
1643- final boolean isSnapshotChoreEnabled = this .snapshotCleanupTracker . isSnapshotCleanupEnabled ();
1641+ final boolean isSnapshotChoreEnabled = this .snapshotCleanupStateStore . get ();
16441642 this .snapshotCleanerChore = new SnapshotCleanerChore (this , conf , getSnapshotManager ());
16451643 if (isSnapshotChoreEnabled ) {
16461644 getChoreService ().scheduleChore (this .snapshotCleanerChore );
@@ -1762,7 +1760,7 @@ protected void startProcedureExecutor() throws IOException {
17621760 * Turn on/off Snapshot Cleanup Chore
17631761 * @param on indicates whether Snapshot Cleanup Chore is to be run
17641762 */
1765- void switchSnapshotCleanup (final boolean on , final boolean synchronous ) {
1763+ void switchSnapshotCleanup (final boolean on , final boolean synchronous ) throws IOException {
17661764 if (synchronous ) {
17671765 synchronized (this .snapshotCleanerChore ) {
17681766 switchSnapshotCleanup (on );
@@ -1772,16 +1770,12 @@ void switchSnapshotCleanup(final boolean on, final boolean synchronous) {
17721770 }
17731771 }
17741772
1775- private void switchSnapshotCleanup (final boolean on ) {
1776- try {
1777- snapshotCleanupTracker .setSnapshotCleanupEnabled (on );
1778- if (on ) {
1779- getChoreService ().scheduleChore (this .snapshotCleanerChore );
1780- } else {
1781- this .snapshotCleanerChore .cancel ();
1782- }
1783- } catch (KeeperException e ) {
1784- LOG .error ("Error updating snapshot cleanup mode to {}" , on , e );
1773+ private void switchSnapshotCleanup (final boolean on ) throws IOException {
1774+ snapshotCleanupStateStore .set (on );
1775+ if (on ) {
1776+ getChoreService ().scheduleChore (this .snapshotCleanerChore );
1777+ } else {
1778+ this .snapshotCleanerChore .cancel ();
17851779 }
17861780 }
17871781
@@ -1955,9 +1949,7 @@ public BalanceResponse balance(BalanceRequest request) throws IOException {
19551949
19561950 BalanceResponse .Builder responseBuilder = BalanceResponse .newBuilder ();
19571951
1958- if (
1959- loadBalancerTracker == null || !(loadBalancerTracker .isBalancerOn () || request .isDryRun ())
1960- ) {
1952+ if (loadBalancerStateStore == null || !(loadBalancerStateStore .get () || request .isDryRun ())) {
19611953 return responseBuilder .build ();
19621954 }
19631955
@@ -2889,8 +2881,8 @@ public ClusterMetrics getClusterMetricsWithoutCoprocessor(EnumSet<Option> option
28892881 break ;
28902882 }
28912883 case BALANCER_ON : {
2892- if (loadBalancerTracker != null ) {
2893- builder .setBalancerOn (loadBalancerTracker . isBalancerOn ());
2884+ if (loadBalancerStateStore != null ) {
2885+ builder .setBalancerOn (loadBalancerStateStore . get ());
28942886 }
28952887 break ;
28962888 }
@@ -3727,33 +3719,32 @@ public void reportMobCompactionEnd(TableName tableName) throws IOException {
37273719 }
37283720
37293721 /**
3730- * Queries the state of the {@link LoadBalancerTracker }. If the balancer is not initialized, false
3731- * is returned.
3722+ * Queries the state of the {@link LoadBalancerStateStore }. If the balancer is not initialized,
3723+ * false is returned.
37323724 * @return The state of the load balancer, or false if the load balancer isn't defined.
37333725 */
37343726 public boolean isBalancerOn () {
3735- return !isInMaintenanceMode () && loadBalancerTracker != null
3736- && loadBalancerTracker .isBalancerOn ();
3727+ return !isInMaintenanceMode () && loadBalancerStateStore != null && loadBalancerStateStore .get ();
37373728 }
37383729
37393730 /**
3740- * Queries the state of the {@link RegionNormalizerTracker }. If it's not initialized, false is
3731+ * Queries the state of the {@link RegionNormalizerStateStore }. If it's not initialized, false is
37413732 * returned.
37423733 */
37433734 public boolean isNormalizerOn () {
37443735 return !isInMaintenanceMode () && getRegionNormalizerManager ().isNormalizerOn ();
37453736 }
37463737
37473738 /**
3748- * Queries the state of the {@link SplitOrMergeTracker }. If it is not initialized, false is
3739+ * Queries the state of the {@link SplitOrMergeStateStore }. If it is not initialized, false is
37493740 * returned. If switchType is illegal, false will return.
37503741 * @param switchType see {@link org.apache.hadoop.hbase.client.MasterSwitchType}
37513742 * @return The state of the switch
37523743 */
37533744 @ Override
37543745 public boolean isSplitOrMergeEnabled (MasterSwitchType switchType ) {
3755- return !isInMaintenanceMode () && splitOrMergeTracker != null
3756- && splitOrMergeTracker .isSplitOrMergeEnabled (switchType );
3746+ return !isInMaintenanceMode () && splitOrMergeStateStore != null
3747+ && splitOrMergeStateStore .isSplitOrMergeEnabled (switchType );
37573748 }
37583749
37593750 /**
@@ -3768,8 +3759,8 @@ public String getLoadBalancerClassName() {
37683759 LoadBalancerFactory .getDefaultLoadBalancerClass ().getName ());
37693760 }
37703761
3771- public SplitOrMergeTracker getSplitOrMergeTracker () {
3772- return splitOrMergeTracker ;
3762+ public SplitOrMergeStateStore getSplitOrMergeStateStore () {
3763+ return splitOrMergeStateStore ;
37733764 }
37743765
37753766 @ Override
0 commit comments