diff --git hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClientScanner.java hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClientScanner.java index 90dc1fa..8d5d1ac 100644 --- hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClientScanner.java +++ hbase-client/src/main/java/org/apache/hadoop/hbase/client/ClientScanner.java @@ -17,11 +17,16 @@ */ package org.apache.hadoop.hbase.client; +import java.io.IOException; +import java.util.ArrayList; +import java.util.LinkedList; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.KeyValue; @@ -35,10 +40,6 @@ import org.apache.hadoop.hbase.protobuf.ProtobufUtil; import org.apache.hadoop.hbase.protobuf.generated.MapReduceProtos; import org.apache.hadoop.hbase.util.Bytes; -import java.io.IOException; -import java.util.ArrayList; -import java.util.LinkedList; - /** * Implements the scanner interface for the HBase client. * If there are multiple regions in a table, this scanner will iterate @@ -65,7 +66,7 @@ public class ClientScanner extends AbstractClientScanner { private final byte[] tableName; private final int scannerTimeout; private boolean scanMetricsPublished = false; - + /** * Create a new ClientScanner for the specified table. An HConnection will be * retrieved using the passed Configuration. @@ -108,7 +109,9 @@ public class ClientScanner extends AbstractClientScanner { HConstants.HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE_KEY, HConstants.DEFAULT_HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE); } - this.scannerTimeout = conf.getInt(HConstants.HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD, + this.scannerTimeout = HBaseConfiguration.getInt(conf, + HConstants.HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD, + HConstants.HBASE_REGIONSERVER_LEASE_PERIOD_KEY, HConstants.DEFAULT_HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD); // check if application wants to collect scan metrics @@ -253,6 +256,7 @@ public class ClientScanner extends AbstractClientScanner { scanMetricsPublished = true; } + @Override public Result next() throws IOException { // If the scanner is closed and there's nothing left in the cache, next is a no-op. if (cache.size() == 0 && this.closed) { @@ -377,6 +381,7 @@ public class ClientScanner extends AbstractClientScanner { * if returned array is of zero-length (We never return null). * @throws IOException */ + @Override public Result [] next(int nbRows) throws IOException { // Collect values to be returned here ArrayList resultSets = new ArrayList(nbRows); @@ -391,6 +396,7 @@ public class ClientScanner extends AbstractClientScanner { return resultSets.toArray(new Result[resultSets.size()]); } + @Override public void close() { if (!scanMetricsPublished) writeScanMetrics(); if (callable != null) { diff --git hbase-common/src/main/java/org/apache/hadoop/hbase/HBaseConfiguration.java hbase-common/src/main/java/org/apache/hadoop/hbase/HBaseConfiguration.java index 95defd3..5d37441 100644 --- hbase-common/src/main/java/org/apache/hadoop/hbase/HBaseConfiguration.java +++ hbase-common/src/main/java/org/apache/hadoop/hbase/HBaseConfiguration.java @@ -150,6 +150,35 @@ public class HBaseConfiguration extends Configuration { return isShowConf; } + /** + * Get the value of the name property as an int, possibly + * referring to the deprecated name of the configuration property. + * If no such property exists, the provided default value is returned, + * or if the specified value is not a valid int, + * then an error is thrown. + * + * @param name property name. + * @param deprecatedName a deprecatedName for the property to use + * if non-deprecated name is not used + * @param defaultValue default value. + * @throws NumberFormatException when the value is invalid + * @return property value as an int, + * or defaultValue. + */ + // TODO: developer note: This duplicates the functionality of deprecated + // property support in Configuration in Hadoop 2. But since Hadoop-1 does not + // contain these changes, we will do our own as usual. Replace these when H2 is default. + public static int getInt(Configuration conf, String name, + String deprecatedName, int defaultValue) { + if (conf.get(deprecatedName) != null) { + LOG.warn(String.format("Config option \"%s\" is deprecated. Instead, use \"%s\"" + , deprecatedName, name)); + return conf.getInt(deprecatedName, defaultValue); + } else { + return conf.getInt(name, defaultValue); + } + } + /** For debugging. Dump configurations to system output as xml format. * Master and RS configurations can also be dumped using * http services. e.g. "curl http://master:60010/dump" diff --git hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java index 7001ee9..f0dda48 100644 --- hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java +++ hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java @@ -627,6 +627,14 @@ public final class HConstants { public static String HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD = "hbase.client.scanner.timeout.period"; /** + * Use {@link #HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD} instead. + * @deprecated This config option is deprecated. Will be removed at later releases after 0.96. + */ + @Deprecated + public static String HBASE_REGIONSERVER_LEASE_PERIOD_KEY = + "hbase.regionserver.lease.period"; + + /** * Default value of {@link #HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD}. */ public static int DEFAULT_HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD = 60000; @@ -729,7 +737,7 @@ public final class HConstants { public static final boolean DEFAULT_DISALLOW_WRITES_IN_RECOVERING_CONFIG = false; /** Conf key that specifies timeout value to wait for a region ready */ - public static final String LOG_REPLAY_WAIT_REGION_TIMEOUT = + public static final String LOG_REPLAY_WAIT_REGION_TIMEOUT = "hbase.master.log.replay.wait.region.timeout"; /** @@ -796,7 +804,7 @@ public final class HConstants { /* Name of old snapshot directory. See HBASE-8352 for details on why it needs to be renamed */ public static final String OLD_SNAPSHOT_DIR_NAME = ".snapshot"; - + /** Temporary directory used for table creation and deletion */ public static final String HBASE_TEMP_DIRECTORY = ".tmp"; diff --git hbase-common/src/test/java/org/apache/hadoop/hbase/TestHBaseConfiguration.java hbase-common/src/test/java/org/apache/hadoop/hbase/TestHBaseConfiguration.java new file mode 100644 index 0000000..6e350ba --- /dev/null +++ hbase-common/src/test/java/org/apache/hadoop/hbase/TestHBaseConfiguration.java @@ -0,0 +1,54 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hbase; + + +import static org.junit.Assert.assertEquals; + +import org.apache.hadoop.conf.Configuration; +import org.junit.Test; + +public class TestHBaseConfiguration { + + @Test + public void testGetIntDeprecated() { + int VAL = 1, VAL2 = 2; + String NAME = "foo"; + String DEPRECATED_NAME = "foo.deprecated"; + + Configuration conf = HBaseConfiguration.create(); + conf.setInt(NAME, VAL); + assertEquals(VAL, HBaseConfiguration.getInt(conf, NAME, DEPRECATED_NAME, 0)); + + conf = HBaseConfiguration.create(); + conf.setInt(DEPRECATED_NAME, VAL); + assertEquals(VAL, HBaseConfiguration.getInt(conf, NAME, DEPRECATED_NAME, 0)); + + conf = HBaseConfiguration.create(); + conf.setInt(DEPRECATED_NAME, VAL); + conf.setInt(NAME, VAL); + assertEquals(VAL, HBaseConfiguration.getInt(conf, NAME, DEPRECATED_NAME, 0)); + + conf = HBaseConfiguration.create(); + conf.setInt(DEPRECATED_NAME, VAL); + conf.setInt(NAME, VAL2); // deprecated value will override this + assertEquals(VAL, HBaseConfiguration.getInt(conf, NAME, DEPRECATED_NAME, 0)); + } + +} diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java index 9edaef9..e911a5c 100644 --- hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java +++ hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java @@ -109,16 +109,15 @@ import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp; import org.apache.hadoop.hbase.fs.HFileSystem; import org.apache.hadoop.hbase.io.hfile.CacheConfig; import org.apache.hadoop.hbase.ipc.HBaseRPCErrorHandler; +import org.apache.hadoop.hbase.ipc.PayloadCarryingRpcController; import org.apache.hadoop.hbase.ipc.RpcClient; import org.apache.hadoop.hbase.ipc.RpcServer; -import org.apache.hadoop.hbase.ipc.PayloadCarryingRpcController; -import org.apache.hadoop.hbase.ipc.RpcServerInterface; import org.apache.hadoop.hbase.ipc.RpcServer.BlockingServiceAndInterface; +import org.apache.hadoop.hbase.ipc.RpcServerInterface; import org.apache.hadoop.hbase.ipc.ServerRpcController; import org.apache.hadoop.hbase.master.SplitLogManager; import org.apache.hadoop.hbase.master.TableLockManager; import org.apache.hadoop.hbase.protobuf.ProtobufUtil; -import org.apache.hadoop.hbase.protobuf.ReplicationProtbufUtil; import org.apache.hadoop.hbase.protobuf.RequestConverter; import org.apache.hadoop.hbase.protobuf.ResponseConverter; import org.apache.hadoop.hbase.protobuf.generated.AdminProtos; @@ -172,9 +171,9 @@ import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.ResultCellMeta; import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.ScanRequest; import org.apache.hadoop.hbase.protobuf.generated.ClientProtos.ScanResponse; import org.apache.hadoop.hbase.protobuf.generated.ClusterStatusProtos; +import org.apache.hadoop.hbase.protobuf.generated.ClusterStatusProtos.RegionLoad; import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.Coprocessor; import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.NameStringPair; -import org.apache.hadoop.hbase.protobuf.generated.ClusterStatusProtos.RegionLoad; import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionSpecifier; import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.RegionSpecifier.RegionSpecifierType; import org.apache.hadoop.hbase.protobuf.generated.RegionServerStatusProtos.GetLastFlushedSequenceIdRequest; @@ -527,7 +526,9 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa this.abortRequested = false; this.stopped = false; - this.scannerLeaseTimeoutPeriod = conf.getInt(HConstants.HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD, + this.scannerLeaseTimeoutPeriod = HBaseConfiguration.getInt(conf, + HConstants.HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD, + HConstants.HBASE_REGIONSERVER_LEASE_PERIOD_KEY, HConstants.DEFAULT_HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD); // Server to handle client requests. @@ -570,6 +571,7 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa regionServerAccounting = new RegionServerAccounting(); cacheConfig = new CacheConfig(conf); uncaughtExceptionHandler = new UncaughtExceptionHandler() { + @Override public void uncaughtException(Thread t, Throwable e) { abort("Uncaught exception in service thread " + t.getName(), e); } @@ -773,6 +775,7 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa /** * The HRegionServer sticks in this loop until closed. */ + @Override public void run() { try { // Do pre-registration initializations; zookeeper, lease threads, etc. @@ -1217,6 +1220,7 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa ZKUtil.deleteNode(this.zooKeeper, getMyEphemeralNodePath()); } + @Override public RegionServerAccounting getRegionServerAccounting() { return regionServerAccounting; } @@ -1578,7 +1582,7 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa // quite a while inside HConnection layer. The worker won't be available for other // tasks even after current task is preempted after a split task times out. Configuration sinkConf = HBaseConfiguration.create(conf); - sinkConf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, + sinkConf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, conf.getInt("hbase.log.replay.retries.number", 8)); // 8 retries take about 23 seconds sinkConf.setInt(HConstants.HBASE_RPC_TIMEOUT_KEY, conf.getInt("hbase.log.replay.rpc.timeout", 30000)); // default 30 seconds @@ -1741,6 +1745,7 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa * @param cause * the exception that caused the abort, or null */ + @Override public void abort(String reason, Throwable cause) { String msg = "ABORTING region server " + this + ": " + reason; if (cause != null) { @@ -1782,6 +1787,7 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa abort(reason, null); } + @Override public boolean isAborted() { return this.abortRequested; } @@ -2025,6 +2031,7 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa /** * @return true if a stop has been requested. */ + @Override public boolean isStopped() { return this.stopped; } @@ -2034,6 +2041,7 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa return this.stopping; } + @Override public Map getRecoveringRegions() { return this.recoveringRegions; } @@ -2042,6 +2050,7 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa * * @return the configuration */ + @Override public Configuration getConfiguration() { return conf; } @@ -2082,6 +2091,7 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa // we'll sort the regions in reverse SortedMap sortedRegions = new TreeMap( new Comparator() { + @Override public int compare(Long a, Long b) { return -1 * a.compareTo(b); } @@ -2101,6 +2111,7 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa } /** @return reference to FlushRequester */ + @Override public FlushRequester getFlushRequester() { return this.cacheFlusher; } @@ -2141,10 +2152,12 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa /** * @return Return the fs. */ + @Override public FileSystem getFileSystem() { return fs; } + @Override public String toString() { return getServerName().toString(); } @@ -2185,10 +2198,12 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa } + @Override public ConcurrentMap getRegionsInTransitionInRS() { return this.regionsInTransitionInRS; } + @Override public ExecutorService getExecutorService() { return service; } @@ -2324,7 +2339,8 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa * @param tableName * @return Online regions from tableName */ - public List getOnlineRegions(byte[] tableName) { + @Override + public List getOnlineRegions(byte[] tableName) { List tableRegions = new ArrayList(); synchronized (this.onlineRegions) { for (HRegion region: this.onlineRegions.values()) { @@ -2359,6 +2375,7 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa this.scannerName = n; } + @Override public void leaseExpired() { RegionScannerHolder rsh = scanners.remove(this.scannerName); if (rsh != null) { @@ -2638,6 +2655,7 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa * * @return True if we OOME'd and are aborting. */ + @Override public boolean checkOOME(final Throwable e) { boolean stop = false; try { @@ -4233,7 +4251,7 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa nodePath = ZKUtil.joinZNode(nodePath, previousRSName); ZKUtil.setData(zkw, nodePath, ZKUtil.regionSequenceIdsToByteArray(minSeqIdForLogReplay, maxSeqIdInStores)); - LOG.debug("Update last flushed sequence id of region " + region.getEncodedName() + " for " + LOG.debug("Update last flushed sequence id of region " + region.getEncodedName() + " for " + previousRSName); } else { LOG.warn("Can't find failed region server for recovering region " + region.getEncodedName());