View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.apache.hadoop.hbase.master;
20  
21  import org.apache.hadoop.conf.Configuration;
22  import org.apache.hadoop.hbase.ChoreService;
23  import org.apache.hadoop.hbase.HConstants;
24  import org.apache.hadoop.hbase.classification.InterfaceAudience;
25  import org.apache.hadoop.hbase.conf.ConfigurationObserver;
26  import org.slf4j.Logger;
27  import org.slf4j.LoggerFactory;
28  
29  /**
30   * Config manager for RegionsRecovery Chore - Dynamically reload config and update chore
31   * accordingly
32   */
33  @InterfaceAudience.Private
34  public class RegionsRecoveryConfigManager implements ConfigurationObserver {
35  
36    private static final Logger LOG = LoggerFactory.getLogger(RegionsRecoveryConfigManager.class);
37  
38    private final HMaster hMaster;
39    private int prevMaxStoreFileRefCount;
40    private int prevRegionsRecoveryInterval;
41  
42    RegionsRecoveryConfigManager(final HMaster hMaster) {
43      this.hMaster = hMaster;
44      Configuration conf = hMaster.getConfiguration();
45      this.prevMaxStoreFileRefCount = getMaxStoreFileRefCount(conf);
46      this.prevRegionsRecoveryInterval = getRegionsRecoveryChoreInterval(conf);
47    }
48  
49    @Override
50    public void onConfigurationChange(Configuration conf) {
51      final int newMaxStoreFileRefCount = getMaxStoreFileRefCount(conf);
52      final int newRegionsRecoveryInterval = getRegionsRecoveryChoreInterval(conf);
53  
54      if (prevMaxStoreFileRefCount == newMaxStoreFileRefCount
55          && prevRegionsRecoveryInterval == newRegionsRecoveryInterval) {
56        // no need to re-schedule the chore with updated config
57        // as there is no change in desired configs
58        return;
59      }
60  
61      LOG.info("Config Reload for RegionsRecovery Chore. prevMaxStoreFileRefCount: {}," +
62          " newMaxStoreFileRefCount: {}, prevRegionsRecoveryInterval: {}, " +
63          "newRegionsRecoveryInterval: {}", prevMaxStoreFileRefCount, newMaxStoreFileRefCount,
64        prevRegionsRecoveryInterval, newRegionsRecoveryInterval);
65  
66      RegionsRecoveryChore regionsRecoveryChore = new RegionsRecoveryChore(this.hMaster,
67        conf, this.hMaster);
68      ChoreService choreService = this.hMaster.getChoreService();
69  
70      // Regions Reopen based on very high storeFileRefCount is considered enabled
71      // only if hbase.regions.recovery.store.file.ref.count has value > 0
72  
73      synchronized (this) {
74        if (newMaxStoreFileRefCount > 0) {
75          // reschedule the chore
76          // provide mayInterruptIfRunning - false to take care of completion
77          // of in progress task if any
78          choreService.cancelChore(regionsRecoveryChore, false);
79          choreService.scheduleChore(regionsRecoveryChore);
80        } else {
81          choreService.cancelChore(regionsRecoveryChore, false);
82        }
83        this.prevMaxStoreFileRefCount = newMaxStoreFileRefCount;
84        this.prevRegionsRecoveryInterval = newRegionsRecoveryInterval;
85      }
86    }
87  
88    private int getMaxStoreFileRefCount(Configuration configuration) {
89      return configuration.getInt(
90        HConstants.STORE_FILE_REF_COUNT_THRESHOLD,
91        HConstants.DEFAULT_STORE_FILE_REF_COUNT_THRESHOLD);
92    }
93  
94    private int getRegionsRecoveryChoreInterval(Configuration configuration) {
95      return configuration.getInt(
96        HConstants.REGIONS_RECOVERY_INTERVAL,
97        HConstants.DEFAULT_REGIONS_RECOVERY_INTERVAL);
98    }
99  
100 }