Index: src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java =================================================================== --- src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java (revision 1198129) +++ src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java (working copy) @@ -413,7 +413,7 @@ this.passedZkCluster = false; this.zkCluster = new MiniZooKeeperCluster(); int clientPort = this.zkCluster.startup(dir,zooKeeperServerNum); - this.conf.set("hbase.zookeeper.property.clientPort", + this.conf.set(HConstants.ZOOKEEPER_CLIENT_PORT, Integer.toString(clientPort)); return this.zkCluster; } @@ -1308,6 +1308,7 @@ public void setZkCluster(MiniZooKeeperCluster zkCluster) { this.passedZkCluster = true; this.zkCluster = zkCluster; + conf.setInt(HConstants.ZOOKEEPER_CLIENT_PORT, zkCluster.getClientPort()); } public MiniDFSCluster getDFSCluster() { Index: src/test/java/org/apache/hadoop/hbase/TestHBaseTestingUtility.java =================================================================== --- src/test/java/org/apache/hadoop/hbase/TestHBaseTestingUtility.java (revision 1198129) +++ src/test/java/org/apache/hadoop/hbase/TestHBaseTestingUtility.java (working copy) @@ -69,8 +69,8 @@ // Cluster 2 HBaseTestingUtility htu2 = new HBaseTestingUtility(); htu2.getConfiguration().set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/2"); - htu2.getConfiguration().set("hbase.zookeeper.property.clientPort", - htu1.getConfiguration().get("hbase.zookeeper.property.clientPort", "-1")); + htu2.getConfiguration().set(HConstants.ZOOKEEPER_CLIENT_PORT, + htu1.getConfiguration().get(HConstants.ZOOKEEPER_CLIENT_PORT, "-1")); htu2.setZkCluster(htu1.getZkCluster()); // Cluster 3; seed it with the conf from htu1 so we pickup the 'right' @@ -78,8 +78,8 @@ // start of minizkcluster. HBaseTestingUtility htu3 = new HBaseTestingUtility(); htu3.getConfiguration().set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/3"); - htu3.getConfiguration().set("hbase.zookeeper.property.clientPort", - htu1.getConfiguration().get("hbase.zookeeper.property.clientPort", "-1")); + htu3.getConfiguration().set(HConstants.ZOOKEEPER_CLIENT_PORT, + htu1.getConfiguration().get(HConstants.ZOOKEEPER_CLIENT_PORT, "-1")); htu3.setZkCluster(htu1.getZkCluster()); try { Index: src/test/java/org/apache/hadoop/hbase/zookeeper/TestZooKeeperMainServerArg.java =================================================================== --- src/test/java/org/apache/hadoop/hbase/zookeeper/TestZooKeeperMainServerArg.java (revision 1198129) +++ src/test/java/org/apache/hadoop/hbase/zookeeper/TestZooKeeperMainServerArg.java (working copy) @@ -24,6 +24,7 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; +import org.apache.hadoop.hbase.HConstants; import org.junit.Test; @@ -32,10 +33,10 @@ @Test public void test() { Configuration c = HBaseConfiguration.create(); - assertEquals("localhost:" + c.get("hbase.zookeeper.property.clientPort"), + assertEquals("localhost:" + c.get(HConstants.ZOOKEEPER_CLIENT_PORT), parser.parse(c)); final String port = "1234"; - c.set("hbase.zookeeper.property.clientPort", port); + c.set(HConstants.ZOOKEEPER_CLIENT_PORT, port); c.set("hbase.zookeeper.quorum", "example.com"); assertEquals("example.com:" + port, parser.parse(c)); c.set("hbase.zookeeper.quorum", "example1.com,example2.com,example3.com"); Index: src/test/java/org/apache/hadoop/hbase/zookeeper/TestHQuorumPeer.java =================================================================== --- src/test/java/org/apache/hadoop/hbase/zookeeper/TestHQuorumPeer.java (revision 1198129) +++ src/test/java/org/apache/hadoop/hbase/zookeeper/TestHQuorumPeer.java (working copy) @@ -50,8 +50,8 @@ @Before public void setup() throws IOException { // Set it to a non-standard port. - TEST_UTIL.getConfiguration().setInt("hbase.zookeeper.property.clientPort", - PORT_NO); + TEST_UTIL.getConfiguration().setInt(HConstants.ZOOKEEPER_CLIENT_PORT, + PORT_NO); this.dataDir = TEST_UTIL.getDataTestDir(this.getClass().getName()); FileSystem fs = FileSystem.get(TEST_UTIL.getConfiguration()); if (fs.exists(this.dataDir)) { @@ -66,7 +66,7 @@ @Test public void testMakeZKProps() { Configuration conf = new Configuration(TEST_UTIL.getConfiguration()); - conf.set("hbase.zookeeper.property.dataDir", this.dataDir.toString()); + conf.set(HConstants.ZOOKEEPER_DATA_DIR, this.dataDir.toString()); Properties properties = ZKConfig.makeZKProps(conf); assertEquals(dataDir.toString(), (String)properties.get("dataDir")); assertEquals(Integer.valueOf(PORT_NO), Index: src/test/java/org/apache/hadoop/hbase/thrift2/TestThriftHBaseServiceHandler.java =================================================================== --- src/test/java/org/apache/hadoop/hbase/thrift2/TestThriftHBaseServiceHandler.java (revision 1198129) +++ src/test/java/org/apache/hadoop/hbase/thrift2/TestThriftHBaseServiceHandler.java (working copy) @@ -113,9 +113,13 @@ } + private ThriftHBaseServiceHandler createHandler() { + return new ThriftHBaseServiceHandler(UTIL.getConfiguration()); + } + @Test public void testExists() throws TIOError, TException { - ThriftHBaseServiceHandler handler = new ThriftHBaseServiceHandler(); + ThriftHBaseServiceHandler handler = createHandler(); byte[] rowName = "testExists".getBytes(); ByteBuffer table = ByteBuffer.wrap(tableAname); @@ -137,7 +141,7 @@ @Test public void testPutGet() throws Exception { - ThriftHBaseServiceHandler handler = new ThriftHBaseServiceHandler(); + ThriftHBaseServiceHandler handler = createHandler(); byte[] rowName = "testPutGet".getBytes(); ByteBuffer table = ByteBuffer.wrap(tableAname); @@ -162,7 +166,7 @@ @Test public void testPutGetMultiple() throws Exception { - ThriftHBaseServiceHandler handler = new ThriftHBaseServiceHandler(); + ThriftHBaseServiceHandler handler = createHandler(); ByteBuffer table = ByteBuffer.wrap(tableAname); byte[] rowName1 = "testPutGetMultiple1".getBytes(); byte[] rowName2 = "testPutGetMultiple2".getBytes(); @@ -194,7 +198,7 @@ @Test public void testDeleteMultiple() throws Exception { - ThriftHBaseServiceHandler handler = new ThriftHBaseServiceHandler(); + ThriftHBaseServiceHandler handler = createHandler(); ByteBuffer table = ByteBuffer.wrap(tableAname); byte[] rowName1 = "testDeleteMultiple1".getBytes(); byte[] rowName2 = "testDeleteMultiple2".getBytes(); @@ -224,7 +228,7 @@ @Test public void testDelete() throws Exception { - ThriftHBaseServiceHandler handler = new ThriftHBaseServiceHandler(); + ThriftHBaseServiceHandler handler = createHandler(); byte[] rowName = "testDelete".getBytes(); ByteBuffer table = ByteBuffer.wrap(tableAname); @@ -261,7 +265,7 @@ @Test public void testDeleteAllTimestamps() throws Exception { - ThriftHBaseServiceHandler handler = new ThriftHBaseServiceHandler(); + ThriftHBaseServiceHandler handler = createHandler(); byte[] rowName = "testDeleteAllTimestamps".getBytes(); ByteBuffer table = ByteBuffer.wrap(tableAname); @@ -301,7 +305,7 @@ @Test public void testDeleteSingleTimestamp() throws Exception { - ThriftHBaseServiceHandler handler = new ThriftHBaseServiceHandler(); + ThriftHBaseServiceHandler handler = createHandler(); byte[] rowName = "testDeleteSingleTimestamp".getBytes(); ByteBuffer table = ByteBuffer.wrap(tableAname); @@ -346,7 +350,7 @@ @Test public void testIncrement() throws Exception { - ThriftHBaseServiceHandler handler = new ThriftHBaseServiceHandler(); + ThriftHBaseServiceHandler handler = createHandler(); byte[] rowName = "testIncrement".getBytes(); ByteBuffer table = ByteBuffer.wrap(tableAname); @@ -379,7 +383,7 @@ */ @Test public void testCheckAndPut() throws Exception { - ThriftHBaseServiceHandler handler = new ThriftHBaseServiceHandler(); + ThriftHBaseServiceHandler handler = createHandler(); byte[] rowName = "testCheckAndPut".getBytes(); ByteBuffer table = ByteBuffer.wrap(tableAname); @@ -426,7 +430,7 @@ */ @Test public void testCheckAndDelete() throws Exception { - ThriftHBaseServiceHandler handler = new ThriftHBaseServiceHandler(); + ThriftHBaseServiceHandler handler = createHandler(); byte[] rowName = "testCheckAndDelete".getBytes(); ByteBuffer table = ByteBuffer.wrap(tableAname); @@ -469,7 +473,7 @@ @Test public void testScan() throws Exception { - ThriftHBaseServiceHandler handler = new ThriftHBaseServiceHandler(); + ThriftHBaseServiceHandler handler = createHandler(); ByteBuffer table = ByteBuffer.wrap(tableAname); TScan scan = new TScan(); Index: src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java =================================================================== --- src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java (revision 1198129) +++ src/test/java/org/apache/hadoop/hbase/TestZooKeeper.java (working copy) @@ -235,7 +235,7 @@ assertEquals(znode, parts[2]); ZKUtil.applyClusterKeyToConf(conf, key); assertEquals(parts[0], conf.get(HConstants.ZOOKEEPER_QUORUM)); - assertEquals(parts[1], conf.get("hbase.zookeeper.property.clientPort")); + assertEquals(parts[1], conf.get(HConstants.ZOOKEEPER_CLIENT_PORT)); assertEquals(parts[2], conf.get(HConstants.ZOOKEEPER_ZNODE_PARENT)); String reconstructedKey = ZKUtil.getZooKeeperClusterKey(conf); assertEquals(key, reconstructedKey); Index: src/test/java/org/apache/hadoop/hbase/replication/TestMultiSlaveReplication.java =================================================================== --- src/test/java/org/apache/hadoop/hbase/replication/TestMultiSlaveReplication.java (revision 1198129) +++ src/test/java/org/apache/hadoop/hbase/replication/TestMultiSlaveReplication.java (working copy) @@ -112,10 +112,10 @@ new ZooKeeperWatcher(conf3, "cluster3", null, true); clusterKey2 = conf2.get(HConstants.ZOOKEEPER_QUORUM)+":" + - conf2.get("hbase.zookeeper.property.clientPort")+":/2"; + conf2.get(HConstants.ZOOKEEPER_CLIENT_PORT)+":/2"; clusterKey3 = conf3.get(HConstants.ZOOKEEPER_QUORUM)+":" + - conf3.get("hbase.zookeeper.property.clientPort")+":/3"; + conf3.get(HConstants.ZOOKEEPER_CLIENT_PORT)+":/3"; table = new HTableDescriptor(tableName); HColumnDescriptor fam = new HColumnDescriptor(famName); Index: src/test/java/org/apache/hadoop/hbase/replication/TestMasterReplication.java =================================================================== --- src/test/java/org/apache/hadoop/hbase/replication/TestMasterReplication.java (revision 1198129) +++ src/test/java/org/apache/hadoop/hbase/replication/TestMasterReplication.java (working copy) @@ -125,13 +125,13 @@ new ZooKeeperWatcher(conf3, "cluster3", null, true); clusterKey1 = conf1.get(HConstants.ZOOKEEPER_QUORUM)+":" + - conf1.get("hbase.zookeeper.property.clientPort")+":/1"; + conf1.get(HConstants.ZOOKEEPER_CLIENT_PORT)+":/1"; clusterKey2 = conf2.get(HConstants.ZOOKEEPER_QUORUM)+":" + - conf2.get("hbase.zookeeper.property.clientPort")+":/2"; + conf2.get(HConstants.ZOOKEEPER_CLIENT_PORT)+":/2"; clusterKey3 = conf3.get(HConstants.ZOOKEEPER_QUORUM)+":" + - conf3.get("hbase.zookeeper.property.clientPort")+":/3"; + conf3.get(HConstants.ZOOKEEPER_CLIENT_PORT)+":/3"; table = new HTableDescriptor(tableName); HColumnDescriptor fam = new HColumnDescriptor(famName); Index: src/test/java/org/apache/hadoop/hbase/replication/TestReplication.java =================================================================== --- src/test/java/org/apache/hadoop/hbase/replication/TestReplication.java (revision 1198129) +++ src/test/java/org/apache/hadoop/hbase/replication/TestReplication.java (working copy) @@ -123,7 +123,7 @@ zkw2 = new ZooKeeperWatcher(conf2, "cluster2", null, true); slaveClusterKey = conf2.get(HConstants.ZOOKEEPER_QUORUM)+":" + - conf2.get("hbase.zookeeper.property.clientPort")+":/2"; + conf2.get(HConstants.ZOOKEEPER_CLIENT_PORT)+":/2"; admin.addPeer("2", slaveClusterKey); setIsReplication(true); Index: src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceManager.java =================================================================== --- src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceManager.java (revision 1198129) +++ src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceManager.java (working copy) @@ -105,7 +105,7 @@ ZKUtil.createWithParents(zkw, "/hbase/replication/peers/1"); ZKUtil.setData(zkw, "/hbase/replication/peers/1",Bytes.toBytes( conf.get(HConstants.ZOOKEEPER_QUORUM)+":" + - conf.get("hbase.zookeeper.property.clientPort")+":/1")); + conf.get(HConstants.ZOOKEEPER_CLIENT_PORT)+":/1")); ZKUtil.createWithParents(zkw, "/hbase/replication/state"); ZKUtil.setData(zkw, "/hbase/replication/state", Bytes.toBytes("true")); Index: src/test/java/org/apache/hadoop/hbase/PerformanceEvaluation.java =================================================================== --- src/test/java/org/apache/hadoop/hbase/PerformanceEvaluation.java (revision 1198129) +++ src/test/java/org/apache/hadoop/hbase/PerformanceEvaluation.java (working copy) @@ -1137,7 +1137,7 @@ // just started up FileSystem fs = dfsCluster.getFileSystem(); conf.set("fs.default.name", fs.getUri().toString()); - conf.set("hbase.zookeeper.property.clientPort", Integer.toString(zooKeeperPort)); + conf.set(HConstants.ZOOKEEPER_CLIENT_PORT, Integer.toString(zooKeeperPort)); Path parentdir = fs.getHomeDirectory(); conf.set(HConstants.HBASE_DIR, parentdir.toString()); fs.mkdirs(parentdir); Index: src/test/java/org/apache/hadoop/hbase/util/TestRegionSplitter.java =================================================================== --- src/test/java/org/apache/hadoop/hbase/util/TestRegionSplitter.java (revision 1198129) +++ src/test/java/org/apache/hadoop/hbase/util/TestRegionSplitter.java (working copy) @@ -336,18 +336,4 @@ } return -1; } - - /** - * Inserts some meaningless data into a CF so the regions can be split. - */ - static void insertSomeData(String table) throws IOException { - HTable hTable = new HTable(table); - for(byte b=Byte.MIN_VALUE; b entry : conf) { String key = entry.getKey(); - if (key.startsWith(ZK_CFG_PROPERTY)) { - String zkKey = key.substring(ZK_CFG_PROPERTY_SIZE); + if (key.startsWith(HConstants.ZK_CFG_PROPERTY_PREFIX)) { + String zkKey = key.substring(HConstants.ZK_CFG_PROPERTY_PREFIX_LEN); String value = entry.getValue(); // If the value has variables substitutions, need to do a get. if (value.contains(VARIABLE_START)) { @@ -90,8 +86,8 @@ } // If clientPort is not set, assign the default - if (zkProperties.getProperty(ZK_CLIENT_PORT_KEY) == null) { - zkProperties.put(ZK_CLIENT_PORT_KEY, + if (zkProperties.getProperty(HConstants.CLIENT_PORT_STR) == null) { + zkProperties.put(HConstants.CLIENT_PORT_STR, HConstants.DEFAULT_ZOOKEPER_CLIENT_PORT); } Index: src/main/java/org/apache/hadoop/hbase/zookeeper/MiniZooKeeperCluster.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/zookeeper/MiniZooKeeperCluster.java (revision 1198129) +++ src/main/java/org/apache/hadoop/hbase/zookeeper/MiniZooKeeperCluster.java (working copy) @@ -30,6 +30,7 @@ import java.net.Socket; import java.util.ArrayList; import java.util.List; +import java.util.Random; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -52,7 +53,7 @@ private boolean started; private int defaultClientPort = 21818; // use non-standard port - private int clientPort = defaultClientPort; + private int clientPort; private List standaloneServerFactoryList; private List zooKeeperServers; @@ -68,6 +69,7 @@ zooKeeperServers = new ArrayList(); clientPortList = new ArrayList(); standaloneServerFactoryList = new ArrayList(); + clientPort = getRandomPort(); } public void setDefaultClientPort(int clientPort) { @@ -78,6 +80,10 @@ return defaultClientPort; } + public int getRandomPort() { + return 0xc000 + new Random().nextInt(0x3f00); + } + public void setTickTime(int tickTime) { this.tickTime = tickTime; } @@ -124,7 +130,7 @@ for (int i = 0; i < numZooKeeperServers; i++) { File dir = new File(baseDir, "zookeeper_"+i).getAbsoluteFile(); recreateDir(dir); - clientPort = defaultClientPort; + clientPort = getRandomPort(); int tickTimeToUse; if (this.tickTime > 0) { tickTimeToUse = this.tickTime; @@ -138,7 +144,7 @@ standaloneServerFactory = new NIOServerCnxn.Factory(new InetSocketAddress(clientPort)); } catch (BindException e) { - LOG.info("Failed binding ZK Server to client port: " + clientPort); + LOG.debug("Failed binding ZK Server to client port: " + clientPort); //this port is already in use. try to use another clientPort++; continue; @@ -162,7 +168,7 @@ started = true; clientPort = clientPortList.get(activeZKServerIndex); LOG.info("Started MiniZK Cluster and connect 1 ZK server " + - "on client port: " + clientPort); + "on client port: " + clientPort); return clientPort; } @@ -345,4 +351,8 @@ } return false; } + + public int getClientPort() { + return clientPort; + } } Index: src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java (revision 1198129) +++ src/main/java/org/apache/hadoop/hbase/zookeeper/ZKUtil.java (working copy) @@ -183,7 +183,7 @@ throws IOException{ String[] parts = transformClusterKey(key); conf.set(HConstants.ZOOKEEPER_QUORUM, parts[0]); - conf.set("hbase.zookeeper.property.clientPort", parts[1]); + conf.set(HConstants.ZOOKEEPER_CLIENT_PORT, parts[1]); conf.set(HConstants.ZOOKEEPER_ZNODE_PARENT, parts[2]); } Index: src/main/java/org/apache/hadoop/hbase/HConstants.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/HConstants.java (revision 1198129) +++ src/main/java/org/apache/hadoop/hbase/HConstants.java (working copy) @@ -99,9 +99,23 @@ /** Name of ZooKeeper config file in conf/ directory. */ public static final String ZOOKEEPER_CONFIG_NAME = "zoo.cfg"; + /** Common prefix of ZooKeeper configuration properties */ + public static final String ZK_CFG_PROPERTY_PREFIX = + "hbase.zookeeper.property."; + + public static final int ZK_CFG_PROPERTY_PREFIX_LEN = + ZK_CFG_PROPERTY_PREFIX.length(); + + /** + * The ZK client port key in the ZK properties map. The name reflects the + * fact that this is not an HBase configuration key. + */ + public static final String CLIENT_PORT_STR = "clientPort"; + /** Parameter name for the client port that the zookeeper listens on */ - public static final String ZOOKEEPER_CLIENT_PORT = "hbase.zookeeper.property.clientPort"; - + public static final String ZOOKEEPER_CLIENT_PORT = + ZK_CFG_PROPERTY_PREFIX + CLIENT_PORT_STR; + /** Default client port that the zookeeper listens on */ public static final int DEFAULT_ZOOKEPER_CLIENT_PORT = 2181; @@ -116,9 +130,17 @@ public static final String DEFAULT_ZOOKEEPER_ZNODE_PARENT = "/hbase"; - /** Parameter name for the limit on concurrent client-side zookeeper connections */ - public static final String ZOOKEEPER_MAX_CLIENT_CNXNS = "hbase.zookeeper.property.maxClientCnxns"; + /** + * Parameter name for the limit on concurrent client-side zookeeper + * connections + */ + public static final String ZOOKEEPER_MAX_CLIENT_CNXNS = + ZK_CFG_PROPERTY_PREFIX + "maxClientCnxns"; + /** Parameter name for the ZK data directory */ + public static final String ZOOKEEPER_DATA_DIR = + ZK_CFG_PROPERTY_PREFIX + "dataDir"; + /** Default limit on concurrent client-side zookeeper connections */ public static final int DEFAULT_ZOOKEPER_MAX_CLIENT_CNXNS = 30; Index: src/main/java/org/apache/hadoop/hbase/thrift2/ThriftHBaseServiceHandler.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/thrift2/ThriftHBaseServiceHandler.java (revision 1198129) +++ src/main/java/org/apache/hadoop/hbase/thrift2/ThriftHBaseServiceHandler.java (working copy) @@ -23,6 +23,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.client.Delete; import org.apache.hadoop.hbase.client.HTableInterface; import org.apache.hadoop.hbase.client.HTablePool; @@ -52,14 +54,23 @@ public class ThriftHBaseServiceHandler implements THBaseService.Iface { // TODO: Size of pool configuraple - private final HTablePool htablePool = new HTablePool(); + private final HTablePool htablePool; private static final Log LOG = LogFactory.getLog(ThriftHBaseServiceHandler.class); // nextScannerId and scannerMap are used to manage scanner state // TODO: Cleanup thread for Scanners, Scanner id wrap private final AtomicInteger nextScannerId = new AtomicInteger(0); - private final Map scannerMap = new ConcurrentHashMap(); + private final Map scannerMap = + new ConcurrentHashMap(); + public ThriftHBaseServiceHandler() { + htablePool = new HTablePool(HBaseConfiguration.create(), Integer.MAX_VALUE); + } + + public ThriftHBaseServiceHandler(Configuration conf) { + htablePool = new HTablePool(conf, Integer.MAX_VALUE); + } + private HTableInterface getTable(byte[] tableName) { return htablePool.getTable(tableName); } Index: src/main/java/org/apache/hadoop/hbase/util/FSTableDescriptors.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/util/FSTableDescriptors.java (revision 1198129) +++ src/main/java/org/apache/hadoop/hbase/util/FSTableDescriptors.java (working copy) @@ -429,8 +429,11 @@ Configuration conf) throws IOException { FileSystem fs = FSUtils.getCurrentFileSystem(conf); FileStatus status = getTableInfoPath(fs, FSUtils.getRootDir(conf), tableName); - // The below deleteDirectory works for either file or directory. - if (fs.exists(status.getPath())) FSUtils.deleteDirectory(fs, status.getPath()); + + if (status != null && fs.exists(status.getPath())) { + // The below deleteDirectory works for either file or directory. + FSUtils.deleteDirectory(fs, status.getPath()); + } } /** Index: src/main/java/org/apache/hadoop/hbase/util/RegionSplitter.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/util/RegionSplitter.java (revision 1198129) +++ src/main/java/org/apache/hadoop/hbase/util/RegionSplitter.java (working copy) @@ -373,7 +373,7 @@ if (!conf.getBoolean("split.verify", true)) { // NOTE: createTable is synchronous on the table, but not on the regions - HTable table = new HTable(tableName); + HTable table = new HTable(conf, tableName); int onlineRegions = 0; while (onlineRegions < splitCount) { onlineRegions = table.getRegionsInfo().size(); Index: src/main/java/org/apache/hadoop/hbase/client/HTable.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/client/HTable.java (revision 1198129) +++ src/main/java/org/apache/hadoop/hbase/client/HTable.java (working copy) @@ -125,40 +125,9 @@ private boolean closed; private int operationTimeout; private static final int DOPUT_WB_CHECK = 10; // i.e., doPut checks the writebuffer every X Puts. - - /** - * Creates an object to access a HBase table. - * Internally it creates a new instance of {@link Configuration} and a new - * client to zookeeper as well as other resources. It also comes up with - * a fresh view of the cluster and must do discovery from scratch of region - * locations; i.e. it will not make use of already-cached region locations if - * available. Use only when being quick and dirty. - * @throws IOException if a remote or network exception occurs - * @see #HTable(Configuration, String) - */ - public HTable(final String tableName) - throws IOException { - this(HBaseConfiguration.create(), Bytes.toBytes(tableName)); - } /** * Creates an object to access a HBase table. - * Internally it creates a new instance of {@link Configuration} and a new - * client to zookeeper as well as other resources. It also comes up with - * a fresh view of the cluster and must do discovery from scratch of region - * locations; i.e. it will not make use of already-cached region locations if - * available. Use only when being quick and dirty. - * @param tableName Name of the table. - * @throws IOException if a remote or network exception occurs - * @see #HTable(Configuration, String) - */ - public HTable(final byte [] tableName) - throws IOException { - this(HBaseConfiguration.create(), tableName); - } - - /** - * Creates an object to access a HBase table. * Shares zookeeper connection and other resources with other HTable instances * created with the same conf instance. Uses already-populated * region cache if one is available, populated by any other HTable instances @@ -237,7 +206,9 @@ } /** - * Tells whether or not a table is enabled or not. + * Tells whether or not a table is enabled or not. This method creates a + * new HBase configuration, so it might make your unit tests fail due to + * incorrect ZK client port. * @param tableName Name of table to check. * @return {@code true} if table is online. * @throws IOException if a remote or network exception occurs @@ -249,11 +220,13 @@ } /** - * Tells whether or not a table is enabled or not. + * Tells whether or not a table is enabled or not. This method creates a + * new HBase configuration, so it might make your unit tests fail due to + * incorrect ZK client port. * @param tableName Name of table to check. * @return {@code true} if table is online. * @throws IOException if a remote or network exception occurs - * @deprecated use {@link HBaseAdmin#isTableEnabled(byte[])} + * @deprecated use {@link HBaseAdmin#isTableEnabled(byte[])} */ @Deprecated public static boolean isTableEnabled(byte[] tableName) throws IOException { Index: src/main/java/org/apache/hadoop/hbase/master/HMasterCommandLine.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/master/HMasterCommandLine.java (revision 1198129) +++ src/main/java/org/apache/hadoop/hbase/master/HMasterCommandLine.java (working copy) @@ -117,10 +117,11 @@ if (LocalHBaseCluster.isLocal(conf)) { final MiniZooKeeperCluster zooKeeperCluster = new MiniZooKeeperCluster(); - File zkDataPath = new File(conf.get("hbase.zookeeper.property.dataDir")); - int zkClientPort = conf.getInt("hbase.zookeeper.property.clientPort", 0); + File zkDataPath = new File(conf.get(HConstants.ZOOKEEPER_DATA_DIR)); + int zkClientPort = conf.getInt(HConstants.ZOOKEEPER_CLIENT_PORT, 0); if (zkClientPort == 0) { - throw new IOException("No config value for hbase.zookeeper.property.clientPort"); + throw new IOException("No config value for " + + HConstants.ZOOKEEPER_CLIENT_PORT); } zooKeeperCluster.setDefaultClientPort(zkClientPort); int clientPort = zooKeeperCluster.startup(zkDataPath); @@ -131,7 +132,7 @@ System.err.println(errorMsg); throw new IOException(errorMsg); } - conf.set("hbase.zookeeper.property.clientPort", + conf.set(HConstants.ZOOKEEPER_CLIENT_PORT, Integer.toString(clientPort)); // Need to have the zk cluster shutdown when master is shutdown. // Run a subclass that does the zk cluster shutdown on its way out. Index: src/main/java/org/apache/hadoop/hbase/coprocessor/CoprocessorHost.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/coprocessor/CoprocessorHost.java (revision 1198129) +++ src/main/java/org/apache/hadoop/hbase/coprocessor/CoprocessorHost.java (working copy) @@ -345,7 +345,7 @@ public HTableWrapper(byte[] tableName) throws IOException { this.tableName = tableName; - this.table = new HTable(tableName); + this.table = new HTable(conf, tableName); openTables.add(this); } Index: src/main/java/org/apache/hadoop/hbase/mapreduce/TableOutputFormat.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/mapreduce/TableOutputFormat.java (revision 1198129) +++ src/main/java/org/apache/hadoop/hbase/mapreduce/TableOutputFormat.java (working copy) @@ -28,7 +28,6 @@ import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.client.Delete; -import org.apache.hadoop.hbase.client.HConnectionManager; import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.zookeeper.ZKUtil; @@ -62,6 +61,9 @@ */ public static final String QUORUM_ADDRESS = "hbase.mapred.output.quorum"; + /** Optional job parameter to specify peer cluster's ZK client port */ + public static final String QUORUM_PORT = "hbase.mapred.output.quorum.port"; + /** Optional specification of the rs class name of the peer cluster */ public static final String REGION_SERVER_CLASS = "hbase.mapred.output.rs.class"; @@ -182,6 +184,7 @@ throw new IllegalArgumentException("Must specify table name"); } String address = this.conf.get(QUORUM_ADDRESS); + int zkClientPort = conf.getInt(QUORUM_PORT, 0); String serverClass = this.conf.get(REGION_SERVER_CLASS); String serverImpl = this.conf.get(REGION_SERVER_IMPL); try { @@ -192,6 +195,9 @@ this.conf.set(HConstants.REGION_SERVER_CLASS, serverClass); this.conf.set(HConstants.REGION_SERVER_IMPL, serverImpl); } + if (zkClientPort != 0) { + conf.setInt(HConstants.ZOOKEEPER_CLIENT_PORT, zkClientPort); + } this.table = new HTable(this.conf, tableName); this.table.setAutoFlush(false); LOG.info("Created table instance for " + tableName);