HBASE-3904 HBA.createTable(final HTableDescriptor desc, byte [][] splitKeys)
should be synchronous git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1143522 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
be7cee5901
commit
e3f8560143
|
@ -148,6 +148,8 @@ Release 0.91.0 - Unreleased
|
|||
initialized
|
||||
HBASE-4059 If a region is split during RS shutdown process, the daughter
|
||||
regions are NOT made online by master
|
||||
HBASE-3904 HBA.createTable(final HTableDescriptor desc, byte [][] splitKeys)
|
||||
should be synchronous
|
||||
|
||||
IMPROVEMENTS
|
||||
HBASE-3290 Max Compaction Size (Nicolas Spiegelberg via Stack)
|
||||
|
|
|
@ -21,9 +21,13 @@ package org.apache.hadoop.hbase.client;
|
|||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
@ -49,11 +53,13 @@ import org.apache.hadoop.hbase.UnknownRegionException;
|
|||
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
|
||||
import org.apache.hadoop.hbase.catalog.CatalogTracker;
|
||||
import org.apache.hadoop.hbase.catalog.MetaReader;
|
||||
import org.apache.hadoop.hbase.client.MetaScanner.MetaScannerVisitor;
|
||||
import org.apache.hadoop.hbase.ipc.HMasterInterface;
|
||||
import org.apache.hadoop.hbase.ipc.HRegionInterface;
|
||||
import org.apache.hadoop.hbase.util.Addressing;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
import org.apache.hadoop.hbase.util.Pair;
|
||||
import org.apache.hadoop.hbase.util.Writables;
|
||||
import org.apache.hadoop.ipc.RemoteException;
|
||||
import org.apache.hadoop.util.StringUtils;
|
||||
|
||||
|
@ -319,16 +325,47 @@ public class HBaseAdmin implements Abortable, Closeable {
|
|||
* and attempt-at-creation).
|
||||
* @throws IOException
|
||||
*/
|
||||
public void createTable(HTableDescriptor desc, byte [][] splitKeys)
|
||||
public void createTable(final HTableDescriptor desc, byte [][] splitKeys)
|
||||
throws IOException {
|
||||
HTableDescriptor.isLegalTableName(desc.getName());
|
||||
createTableAsync(desc, splitKeys);
|
||||
try {
|
||||
createTableAsync(desc, splitKeys);
|
||||
} catch (SocketTimeoutException ste) {
|
||||
LOG.warn("Creating " + desc.getNameAsString() + " took too long", ste);
|
||||
}
|
||||
int numRegs = splitKeys == null ? 1 : splitKeys.length+1;
|
||||
for (int tries = 0; tries < numRetries; tries++) {
|
||||
try {
|
||||
// Wait for new table to come on-line
|
||||
connection.locateRegion(desc.getName(), HConstants.EMPTY_START_ROW);
|
||||
break;
|
||||
final AtomicInteger actualRegCount = new AtomicInteger(0);
|
||||
|
||||
MetaScannerVisitor visitor = new MetaScannerVisitor() {
|
||||
public boolean processRow(Result rowResult) throws IOException {
|
||||
HRegionInfo info = Writables.getHRegionInfo(
|
||||
rowResult.getValue(HConstants.CATALOG_FAMILY,
|
||||
HConstants.REGIONINFO_QUALIFIER));
|
||||
|
||||
if (!(Bytes.equals(info.getTableName(), desc.getName()))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String hostAndPort = null;
|
||||
byte [] value = rowResult.getValue(HConstants.CATALOG_FAMILY,
|
||||
HConstants.SERVER_QUALIFIER);
|
||||
if (value != null && value.length > 0) {
|
||||
hostAndPort = Bytes.toString(value);
|
||||
}
|
||||
|
||||
if (!(info.isOffline() || info.isSplit()) && hostAndPort != null) {
|
||||
actualRegCount.incrementAndGet();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
MetaScanner.metaScan(conf, visitor, desc.getName());
|
||||
if (actualRegCount.get() == numRegs)
|
||||
break;
|
||||
} catch (RegionException e) {
|
||||
if (tries == numRetries - 1) {
|
||||
// Ran out of tries
|
||||
|
|
Loading…
Reference in New Issue