use of org.apache.hadoop.hbase.HTableDescriptor in project hbase by apache.
the class TestFromClientSide method testDuplicateAppend.
/**
* Test append result when there are duplicate rpc request.
*/
@Test
public void testDuplicateAppend() throws Exception {
HTableDescriptor hdt = TEST_UTIL.createTableDescriptor(name.getMethodName());
Map<String, String> kvs = new HashMap<>();
kvs.put(HConnectionTestingUtility.SleepAtFirstRpcCall.SLEEP_TIME_CONF_KEY, "2000");
hdt.addCoprocessor(HConnectionTestingUtility.SleepAtFirstRpcCall.class.getName(), null, 1, kvs);
TEST_UTIL.createTable(hdt, new byte[][] { ROW }).close();
Configuration c = new Configuration(TEST_UTIL.getConfiguration());
c.setInt(HConstants.HBASE_CLIENT_PAUSE, 50);
// Client will retry beacuse rpc timeout is small than the sleep time of first rpc call
c.setInt(HConstants.HBASE_RPC_TIMEOUT_KEY, 1500);
Connection connection = ConnectionFactory.createConnection(c);
Table t = connection.getTable(TableName.valueOf(name.getMethodName()));
if (t instanceof HTable) {
HTable table = (HTable) t;
table.setOperationTimeout(3 * 1000);
try {
Append append = new Append(ROW);
append.add(TEST_UTIL.fam1, QUALIFIER, VALUE);
Result result = table.append(append);
// Verify expected result
Cell[] cells = result.rawCells();
assertEquals(1, cells.length);
assertKey(cells[0], ROW, TEST_UTIL.fam1, QUALIFIER, VALUE);
// Verify expected result again
Result readResult = table.get(new Get(ROW));
cells = readResult.rawCells();
assertEquals(1, cells.length);
assertKey(cells[0], ROW, TEST_UTIL.fam1, QUALIFIER, VALUE);
} finally {
table.close();
connection.close();
}
}
}
use of org.apache.hadoop.hbase.HTableDescriptor in project hbase by apache.
the class TestEnableTable method testEnableTableWithNoRegionServers.
@Test(timeout = 300000)
public void testEnableTableWithNoRegionServers() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
final MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
final HMaster m = cluster.getMaster();
final Admin admin = TEST_UTIL.getAdmin();
final HTableDescriptor desc = new HTableDescriptor(tableName);
desc.addFamily(new HColumnDescriptor(FAMILYNAME));
admin.createTable(desc);
admin.disableTable(tableName);
TEST_UTIL.waitTableDisabled(tableName.getName());
admin.enableTable(tableName);
TEST_UTIL.waitTableEnabled(tableName);
// disable once more
admin.disableTable(tableName);
TEST_UTIL.waitUntilNoRegionsInTransition(60000);
// now stop region servers
JVMClusterUtil.RegionServerThread rs = cluster.getRegionServerThreads().get(0);
rs.getRegionServer().stop("stop");
cluster.waitForRegionServerToStop(rs.getRegionServer().getServerName(), 10000);
LOG.debug("Now enabling table " + tableName);
admin.enableTable(tableName);
assertTrue(admin.isTableEnabled(tableName));
JVMClusterUtil.RegionServerThread rs2 = cluster.startRegionServer();
cluster.waitForRegionServerToStart(rs2.getRegionServer().getServerName().getHostname(), rs2.getRegionServer().getServerName().getPort(), 60000);
List<HRegionInfo> regions = TEST_UTIL.getAdmin().getTableRegions(tableName);
assertEquals(1, regions.size());
for (HRegionInfo region : regions) {
TEST_UTIL.getAdmin().assign(region.getEncodedNameAsBytes());
}
LOG.debug("Waiting for table assigned " + tableName);
TEST_UTIL.waitUntilAllRegionsAssigned(tableName);
List<HRegionInfo> onlineRegions = admin.getOnlineRegions(rs2.getRegionServer().getServerName());
ArrayList<HRegionInfo> tableRegions = filterTableRegions(tableName, onlineRegions);
assertEquals(1, tableRegions.size());
}
use of org.apache.hadoop.hbase.HTableDescriptor in project hbase by apache.
the class TestFastFail method testFastFail.
@Ignore("Can go zombie -- see HBASE-14421; FIX")
@Test
public void testFastFail() throws IOException, InterruptedException {
Admin admin = TEST_UTIL.getAdmin();
final String tableName = name.getMethodName();
HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(Bytes.toBytes(tableName)));
desc.addFamily(new HColumnDescriptor(FAMILY));
admin.createTable(desc, Bytes.toBytes("aaaa"), Bytes.toBytes("zzzz"), 32);
final long numRows = 1000;
Configuration conf = TEST_UTIL.getConfiguration();
conf.setLong(HConstants.HBASE_CLIENT_OPERATION_TIMEOUT, SLEEPTIME * 100);
conf.setInt(HConstants.HBASE_CLIENT_PAUSE, SLEEPTIME / 10);
conf.setBoolean(HConstants.HBASE_CLIENT_FAST_FAIL_MODE_ENABLED, true);
conf.setLong(HConstants.HBASE_CLIENT_FAST_FAIL_THREASHOLD_MS, 0);
conf.setClass(HConstants.HBASE_CLIENT_FAST_FAIL_INTERCEPTOR_IMPL, MyPreemptiveFastFailInterceptor.class, PreemptiveFastFailInterceptor.class);
final Connection connection = ConnectionFactory.createConnection(conf);
/**
* Write numRows worth of data, so that the workers can arbitrarily read.
*/
List<Put> puts = new ArrayList<>();
for (long i = 0; i < numRows; i++) {
byte[] rowKey = longToByteArrayKey(i);
Put put = new Put(rowKey);
// value is the same as the row key
byte[] value = rowKey;
put.addColumn(FAMILY, QUALIFIER, value);
puts.add(put);
}
try (Table table = connection.getTable(TableName.valueOf(tableName))) {
table.put(puts);
LOG.info("Written all puts.");
}
/**
* The number of threads that are going to perform actions against the test
* table.
*/
int nThreads = 100;
ExecutorService service = Executors.newFixedThreadPool(nThreads);
final CountDownLatch continueOtherHalf = new CountDownLatch(1);
final CountDownLatch doneHalfway = new CountDownLatch(nThreads);
final AtomicInteger numSuccessfullThreads = new AtomicInteger(0);
final AtomicInteger numFailedThreads = new AtomicInteger(0);
// The total time taken for the threads to perform the second put;
final AtomicLong totalTimeTaken = new AtomicLong(0);
final AtomicInteger numBlockedWorkers = new AtomicInteger(0);
final AtomicInteger numPreemptiveFastFailExceptions = new AtomicInteger(0);
List<Future<Boolean>> futures = new ArrayList<>();
for (int i = 0; i < nThreads; i++) {
futures.add(service.submit(new Callable<Boolean>() {
/**
* The workers are going to perform a couple of reads. The second read
* will follow the killing of a regionserver so that we make sure that
* some of threads go into PreemptiveFastFailExcception
*/
public Boolean call() throws Exception {
try (Table table = connection.getTable(TableName.valueOf(tableName))) {
// Add some jitter here
Thread.sleep(Math.abs(random.nextInt()) % 250);
byte[] row = longToByteArrayKey(Math.abs(random.nextLong()) % numRows);
Get g = new Get(row);
g.addColumn(FAMILY, QUALIFIER);
try {
table.get(g);
} catch (Exception e) {
LOG.debug("Get failed : ", e);
doneHalfway.countDown();
return false;
}
// Done with one get, proceeding to do the next one.
doneHalfway.countDown();
continueOtherHalf.await();
long startTime = System.currentTimeMillis();
g = new Get(row);
g.addColumn(FAMILY, QUALIFIER);
try {
table.get(g);
// The get was successful
numSuccessfullThreads.addAndGet(1);
} catch (Exception e) {
if (e instanceof PreemptiveFastFailException) {
// We were issued a PreemptiveFastFailException
numPreemptiveFastFailExceptions.addAndGet(1);
}
// Irrespective of PFFE, the request failed.
numFailedThreads.addAndGet(1);
return false;
} finally {
long enTime = System.currentTimeMillis();
totalTimeTaken.addAndGet(enTime - startTime);
if ((enTime - startTime) >= SLEEPTIME) {
// Considering the slow workers as the blockedWorkers.
// This assumes that the threads go full throttle at performing
// actions. In case the thread scheduling itself is as slow as
// SLEEPTIME, then this test might fail and so, we might have
// set it to a higher number on slower machines.
numBlockedWorkers.addAndGet(1);
}
}
return true;
} catch (Exception e) {
LOG.error("Caught unknown exception", e);
doneHalfway.countDown();
return false;
}
}
}));
}
doneHalfway.await();
// Kill a regionserver
TEST_UTIL.getHBaseCluster().getRegionServer(0).getRpcServer().stop();
TEST_UTIL.getHBaseCluster().getRegionServer(0).stop("Testing");
// Let the threads continue going
continueOtherHalf.countDown();
Thread.sleep(2 * SLEEPTIME);
// Start a RS in the cluster
TEST_UTIL.getHBaseCluster().startRegionServer();
int numThreadsReturnedFalse = 0;
int numThreadsReturnedTrue = 0;
int numThreadsThrewExceptions = 0;
for (Future<Boolean> f : futures) {
try {
numThreadsReturnedTrue += f.get() ? 1 : 0;
numThreadsReturnedFalse += f.get() ? 0 : 1;
} catch (Exception e) {
numThreadsThrewExceptions++;
}
}
LOG.debug("numThreadsReturnedFalse:" + numThreadsReturnedFalse + " numThreadsReturnedTrue:" + numThreadsReturnedTrue + " numThreadsThrewExceptions:" + numThreadsThrewExceptions + " numFailedThreads:" + numFailedThreads.get() + " numSuccessfullThreads:" + numSuccessfullThreads.get() + " numBlockedWorkers:" + numBlockedWorkers.get() + " totalTimeWaited: " + totalTimeTaken.get() / (numBlockedWorkers.get() == 0 ? Long.MAX_VALUE : numBlockedWorkers.get()) + " numPFFEs: " + numPreemptiveFastFailExceptions.get());
assertEquals("The expected number of all the successfull and the failed " + "threads should equal the total number of threads that we spawned", nThreads, numFailedThreads.get() + numSuccessfullThreads.get());
assertEquals("All the failures should be coming from the secondput failure", numFailedThreads.get(), numThreadsReturnedFalse);
assertEquals("Number of threads that threw execution exceptions " + "otherwise should be 0", numThreadsThrewExceptions, 0);
assertEquals("The regionservers that returned true should equal to the" + " number of successful threads", numThreadsReturnedTrue, numSuccessfullThreads.get());
assertTrue("There will be atleast one thread that retried instead of failing", MyPreemptiveFastFailInterceptor.numBraveSouls.get() > 0);
assertTrue("There will be atleast one PreemptiveFastFail exception," + " otherwise, the test makes little sense." + "numPreemptiveFastFailExceptions: " + numPreemptiveFastFailExceptions.get(), numPreemptiveFastFailExceptions.get() > 0);
assertTrue("Only few thread should ideally be waiting for the dead " + "regionserver to be coming back. numBlockedWorkers:" + numBlockedWorkers.get() + " threads that retried : " + MyPreemptiveFastFailInterceptor.numBraveSouls.get(), numBlockedWorkers.get() <= MyPreemptiveFastFailInterceptor.numBraveSouls.get());
}
use of org.apache.hadoop.hbase.HTableDescriptor in project hbase by apache.
the class TestAsyncTableAdminApi method testListTables.
@Test
public void testListTables() throws Exception {
int numTables = admin.listTables().get().length;
final TableName tableName1 = TableName.valueOf(name.getMethodName() + "1");
final TableName tableName2 = TableName.valueOf(name.getMethodName() + "2");
final TableName tableName3 = TableName.valueOf(name.getMethodName() + "3");
TableName[] tables = new TableName[] { tableName1, tableName2, tableName3 };
for (int i = 0; i < tables.length; i++) {
TEST_UTIL.createTable(tables[i], FAMILY);
}
HTableDescriptor[] tableDescs = admin.listTables().get();
int size = tableDescs.length;
assertTrue(size >= tables.length);
for (int i = 0; i < tables.length && i < size; i++) {
boolean found = false;
for (int j = 0; j < tableDescs.length; j++) {
if (tableDescs[j].getTableName().equals(tables[i])) {
found = true;
break;
}
}
assertTrue("Not found: " + tables[i], found);
}
TableName[] tableNames = admin.listTableNames().get();
size = tableNames.length;
assertTrue(size == (numTables + tables.length));
for (int i = 0; i < tables.length && i < size; i++) {
boolean found = false;
for (int j = 0; j < tableNames.length; j++) {
if (tableNames[j].equals(tables[i])) {
found = true;
break;
}
}
assertTrue("Not found: " + tables[i], found);
}
for (int i = 0; i < tables.length; i++) {
TEST_UTIL.deleteTable(tables[i]);
}
tableDescs = admin.listTables((Pattern) null, true).get();
assertTrue("Not found system tables", tableDescs.length > 0);
tableNames = admin.listTableNames((Pattern) null, true).get();
assertTrue("Not found system tables", tableNames.length > 0);
}
use of org.apache.hadoop.hbase.HTableDescriptor in project hbase by apache.
the class TestAsyncTableAdminApi method testDeleteTable.
@Test(timeout = 300000)
public void testDeleteTable() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
admin.createTable(new HTableDescriptor(tableName).addFamily(new HColumnDescriptor(FAMILY))).join();
assertTrue(admin.tableExists(tableName).get());
TEST_UTIL.getAdmin().disableTable(tableName);
admin.deleteTable(tableName).join();
assertFalse(admin.tableExists(tableName).get());
}
Aggregations