use of org.apache.hadoop.hbase.MasterNotRunningException in project hbase by apache.
the class ConnectionImplementation method checkIfBaseNodeAvailable.
private void checkIfBaseNodeAvailable(ZooKeeperWatcher zkw) throws MasterNotRunningException {
String errorMsg;
try {
if (ZKUtil.checkExists(zkw, zkw.znodePaths.baseZNode) == -1) {
errorMsg = "The node " + zkw.znodePaths.baseZNode + " is not in ZooKeeper. " + "It should have been written by the master. " + "Check the value configured in 'zookeeper.znode.parent'. " + "There could be a mismatch with the one configured in the master.";
LOG.error(errorMsg);
throw new MasterNotRunningException(errorMsg);
}
} catch (KeeperException e) {
errorMsg = "Can't get connection to ZooKeeper: " + e.getMessage();
LOG.error(errorMsg);
throw new MasterNotRunningException(errorMsg, e);
}
}
use of org.apache.hadoop.hbase.MasterNotRunningException in project hbase by apache.
the class TestClientTimeouts method testAdminTimeout.
/**
* Test that a client that fails an RPC to the master retries properly and
* doesn't throw any unexpected exceptions.
* @throws Exception
*/
@Test
public void testAdminTimeout() throws Exception {
boolean lastFailed = false;
int initialInvocations = RandomTimeoutBlockingRpcChannel.invokations.get();
RandomTimeoutRpcClient rpcClient = (RandomTimeoutRpcClient) RpcClientFactory.createClient(TEST_UTIL.getConfiguration(), TEST_UTIL.getClusterKey());
try {
for (int i = 0; i < 5 || (lastFailed && i < 100); ++i) {
lastFailed = false;
// Ensure the HBaseAdmin uses a new connection by changing Configuration.
Configuration conf = HBaseConfiguration.create(TEST_UTIL.getConfiguration());
conf.set(HConstants.HBASE_CLIENT_INSTANCE_ID, String.valueOf(-1));
Admin admin = null;
Connection connection = null;
try {
connection = ConnectionFactory.createConnection(conf);
admin = connection.getAdmin();
// run some admin commands
HBaseAdmin.available(conf);
admin.setBalancerRunning(false, false);
} catch (MasterNotRunningException ex) {
// Since we are randomly throwing SocketTimeoutExceptions, it is possible to get
// a MasterNotRunningException. It's a bug if we get other exceptions.
lastFailed = true;
} finally {
if (admin != null) {
admin.close();
if (admin.getConnection().isClosed()) {
rpcClient = (RandomTimeoutRpcClient) RpcClientFactory.createClient(TEST_UTIL.getConfiguration(), TEST_UTIL.getClusterKey());
}
}
if (connection != null) {
connection.close();
}
}
}
// Ensure the RandomTimeoutRpcEngine is actually being used.
assertFalse(lastFailed);
assertTrue(RandomTimeoutBlockingRpcChannel.invokations.get() > initialInvocations);
} finally {
rpcClient.close();
}
}
use of org.apache.hadoop.hbase.MasterNotRunningException in project honeycomb by altamiracorp.
the class TableCreator method createTable.
/**
* Creates a table in HBase to store all Honeycomb tables
*
* @param configuration Configuration of the HTable
* @throws IOException
*/
public static void createTable(Configuration configuration) throws IOException {
HTableDescriptor tableDescriptor;
try {
HBaseAdmin.checkHBaseAvailable(configuration);
} catch (MasterNotRunningException e) {
logger.fatal(String.format("HMaster doesn't appear to be running. Zookeeper quorum: %s", configuration.get("hbase.zookeeper.quorum")), e);
throw e;
} catch (ZooKeeperConnectionException e) {
logger.fatal("Failed to connect to zookeeper when checking HBase. Zookeeper quorum: " + configuration.get("hbase.zookeeper.quorum"), e);
throw e;
}
String columnFamily = configuration.get(ConfigConstants.COLUMN_FAMILY);
byte[] tableName = configuration.get(ConfigConstants.TABLE_NAME).getBytes();
HColumnDescriptor columnDescriptor = new HColumnDescriptor(columnFamily);
HBaseAdmin admin = new HBaseAdmin(configuration);
columnDescriptor.setBloomFilterType(StoreFile.BloomType.ROW).setDataBlockEncoding(DataBlockEncoding.PREFIX).setMaxVersions(1);
if (!admin.tableExists(tableName)) {
logger.info("Creating HBase table");
tableDescriptor = new HTableDescriptor(tableName);
tableDescriptor.addFamily(columnDescriptor);
admin.createTable(tableDescriptor);
}
tableDescriptor = admin.getTableDescriptor(tableName);
if (!tableDescriptor.hasFamily(columnFamily.getBytes())) {
logger.info("Adding column family to HBase table");
if (!admin.isTableDisabled(tableName)) {
logger.info("Disabling HBase table");
admin.disableTable(tableName);
}
admin.addColumn(tableName, columnDescriptor);
}
if (admin.isTableDisabled(tableName)) {
logger.info("Enabling HBase table");
admin.enableTable(tableName);
}
try {
admin.flush(tableName);
} catch (InterruptedException e) {
logger.warn("HBaseAdmin flush was interrupted. Retrying.");
try {
admin.flush(tableName);
} catch (InterruptedException e1) {
throw new RuntimeException(e1);
}
}
logger.info("HBase table successfully initialized.");
}
use of org.apache.hadoop.hbase.MasterNotRunningException in project titan by thinkaurelius.
the class HBaseStoreManager method getLocalKeyPartition.
@Override
public List<KeyRange> getLocalKeyPartition() throws BackendException {
List<KeyRange> result = new LinkedList<KeyRange>();
HTable table = null;
try {
ensureTableExists(tableName, getCfNameForStoreName(GraphDatabaseConfiguration.SYSTEM_PROPERTIES_STORE_NAME), 0);
table = new HTable(hconf, tableName);
Map<KeyRange, ServerName> normed = normalizeKeyBounds(table.getRegionLocations());
for (Map.Entry<KeyRange, ServerName> e : normed.entrySet()) {
if (NetworkUtil.isLocalConnection(e.getValue().getHostname())) {
result.add(e.getKey());
logger.debug("Found local key/row partition {} on host {}", e.getKey(), e.getValue());
} else {
logger.debug("Discarding remote {}", e.getValue());
}
}
} catch (MasterNotRunningException e) {
logger.warn("Unexpected MasterNotRunningException", e);
} catch (ZooKeeperConnectionException e) {
logger.warn("Unexpected ZooKeeperConnectionException", e);
} catch (IOException e) {
logger.warn("Unexpected IOException", e);
} finally {
IOUtils.closeQuietly(table);
}
return result;
}
use of org.apache.hadoop.hbase.MasterNotRunningException in project incubator-atlas by apache.
the class HBaseStoreManager method getLocalKeyPartition.
@Override
public List<KeyRange> getLocalKeyPartition() throws BackendException {
List<KeyRange> result = new LinkedList<>();
TableMask table = null;
try {
ensureTableExists(tableName, getCfNameForStoreName(GraphDatabaseConfiguration.SYSTEM_PROPERTIES_STORE_NAME), 0);
table = cnx.getTable(tableName);
HTable hTable = (HTable) table.getTableObject();
Map<KeyRange, ServerName> normed = normalizeKeyBounds(hTable.getRegionLocations());
for (Map.Entry<KeyRange, ServerName> e : normed.entrySet()) {
if (NetworkUtil.isLocalConnection(e.getValue().getHostname())) {
result.add(e.getKey());
logger.debug("Found local key/row partition {} on host {}", e.getKey(), e.getValue());
} else {
logger.debug("Discarding remote {}", e.getValue());
}
}
} catch (MasterNotRunningException e) {
logger.warn("Unexpected MasterNotRunningException", e);
} catch (ZooKeeperConnectionException e) {
logger.warn("Unexpected ZooKeeperConnectionException", e);
} catch (IOException e) {
logger.warn("Unexpected IOException", e);
} finally {
IOUtils.closeQuietly(table);
}
return result;
}
Aggregations