public TableDescriptorBuilder setCoprocessor(String className) throws IOException { return setCoprocessor(CoprocessorDescriptorBuilder.of(className)); }
@Test (expected=IOException.class) public void testAddCoprocessorTwice() throws IOException { String cpName = "a.b.c.d"; TableDescriptor htd = TableDescriptorBuilder.newBuilder(TableName.META_TABLE_NAME) .setCoprocessor(cpName) .setCoprocessor(cpName) .build(); }
@Test public void testPartialSuccess() throws IOException, InterruptedException, ExecutionException { Admin admin = TEST_UTIL.getAdmin(); TableDescriptor htd = TableDescriptorBuilder.newBuilder(admin.getDescriptor(TABLE_NAME)) .setCoprocessor(ErrorInjectObserver.class.getName()).build(); admin.modifyTable(htd); AsyncTable<?> table = tableGetter.apply(TABLE_NAME); table.putAll(Arrays.asList(SPLIT_KEYS).stream().map(k -> new Put(k).addColumn(FAMILY, CQ, k)) .collect(Collectors.toList())).get(); List<CompletableFuture<Result>> futures = table .get(Arrays.asList(SPLIT_KEYS).stream().map(k -> new Get(k)).collect(Collectors.toList())); for (int i = 0; i < SPLIT_KEYS.length - 1; i++) { assertArrayEquals(SPLIT_KEYS[i], futures.get(i).get().getValue(FAMILY, CQ)); } try { futures.get(SPLIT_KEYS.length - 1).get(); } catch (ExecutionException e) { assertThat(e.getCause(), instanceOf(RetriesExhaustedException.class)); } } }
/** * Modify table {@code getTableName()} to carry {@link SlowMeCoproScanOperations}. */ private void installSlowingCoproc() throws IOException, InterruptedException { int replicaCount = conf.getInt(NUM_REPLICA_COUNT_KEY, NUM_REPLICA_COUNT_DEFAULT); if (replicaCount == NUM_REPLICA_COUNT_DEFAULT) return; TableName t = getTablename(); Admin admin = util.getAdmin(); TableDescriptor desc = admin.getDescriptor(t); TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(desc); builder.setCoprocessor(SlowMeCoproScanOperations.class.getName()); HBaseTestingUtility.modifyTableSync(admin, builder.build()); }
@BeforeClass public static void setUp() throws Exception { Configuration conf = UTIL.getConfiguration(); // Will schedule a abort timeout task after SLEEP_TIME_WHEN_CLOSE_REGION ms conf.setLong(HRegionServer.ABORT_TIMEOUT, SLEEP_TIME_WHEN_CLOSE_REGION); conf.set(HRegionServer.ABORT_TIMEOUT_TASK, TestAbortTimeoutTask.class.getName()); StartMiniClusterOption option = StartMiniClusterOption.builder().numRegionServers(2).build(); UTIL.startMiniCluster(option); TableDescriptor td = TableDescriptorBuilder.newBuilder(TABLE_NAME) .setCoprocessor(SleepWhenCloseCoprocessor.class.getName()) .setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(CF).build()).build(); UTIL.getAdmin().createTable(td, Bytes.toBytes("0"), Bytes.toBytes("9"), REGIONS_NUM); }
@BeforeClass public static void setUp() throws Exception { UTIL.startMiniCluster(1); UTIL.getAdmin() .createTable(TableDescriptorBuilder.newBuilder(NAME) .setCoprocessor(ScanModifyingObserver.class.getName()) .setValue(ScanModifyingObserver.FAMILY_TO_ADD_KEY, Bytes.toString(FAMILY)) .setValue(ScanModifyingObserver.QUALIFIER_TO_ADD_KEY, Bytes.toString(IMPLICIT_QUAL)) .setColumnFamily(CFD).build()); }
@Before public void setUp() throws IOException { tableName = TableName.valueOf(name.getMethodName()); TableDescriptor htd = TableDescriptorBuilder.newBuilder(tableName) .setCoprocessor(SleepAndFailFirstTime.class.getName()) .setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAM_NAM)).build(); TEST_UTIL.getAdmin().createTable(htd); }
@Before public void setUp() throws IOException { tableName = TableName.valueOf(name.getMethodName()); TableDescriptor htd = TableDescriptorBuilder.newBuilder(tableName).setCoprocessor(SleepCoprocessor.class.getName()) .setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAM_NAM)).build(); TEST_UTIL.getAdmin().createTable(htd); }
@Before public void setUp() throws IOException { UTIL.getAdmin() .createTable(TableDescriptorBuilder.newBuilder(NAME) .setColumnFamily(ColumnFamilyDescriptorBuilder.of(CF)) .setCoprocessor(FlushObserver.class.getName()).build()); region = UTIL.getHBaseCluster().getRegions(NAME).get(0); }
@BeforeClass public static void setUpBeforeClass() throws Exception { TEST_UTIL.startMiniCluster(3); TableDescriptor desc = TableDescriptorBuilder.newBuilder(TABLE_NAME) .setCoprocessor(MyObserver.class.getName()) .setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY)) .build(); TEST_UTIL.getAdmin().createTable(desc); }
@BeforeClass public static void setUp() throws Exception { UTIL.startMiniCluster(1); UTIL.getAdmin() .createTable(TableDescriptorBuilder.newBuilder(NAME) .setCoprocessor(ValueRewritingObserver.class.getName()) .setValue(ValueRewritingObserver.ORIGINAL_VALUE_KEY, value) .setValue(ValueRewritingObserver.REPLACED_VALUE_KEY, replacedValue) .setColumnFamily(CFD).build()); }
@BeforeClass public static void setUp() throws Exception { UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 2); UTIL.startMiniCluster(); UTIL.getAdmin().createTable(TableDescriptorBuilder.newBuilder(TABLE_DONOT_RETRY) .setCoprocessor(ThrowDoNotRetryIOExceptionCoprocessor.class.getName()) .setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(CF).build()).build()); UTIL.getAdmin().createTable(TableDescriptorBuilder.newBuilder(TABLE_RETRY) .setCoprocessor(ThrowIOExceptionCoprocessor.class.getName()) .setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(CF).build()).build()); tableDoNotRetry = UTIL.getConnection().getTable(TABLE_DONOT_RETRY); tableRetry = UTIL.getConnection().getTable(TABLE_RETRY); }
@BeforeClass public static void setUp() throws Exception { WriteHeavyIncrementObserverTestBase.setUp(); UTIL.getAdmin() .createTable(TableDescriptorBuilder.newBuilder(NAME) .setCoprocessor(WriteHeavyIncrementObserver.class.getName()) .setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY)).build()); TABLE = UTIL.getConnection().getTable(NAME); }
@Before public void clearTable() throws IOException { RegionObserverImpl.COUNT.set(0); tableName = TableName.valueOf(testName.getMethodName()); if (table != null) { table.close(); } try (Admin admin = UTIL.getAdmin()) { for (TableName name : admin.listTableNames()) { try { admin.disableTable(name); } catch (IOException e) { } admin.deleteTable(name); } table = UTIL.createTable(TableDescriptorBuilder.newBuilder(tableName) .setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY)) .setCoprocessor(RegionObserverImpl.class.getName()) .build(), null); } }
@BeforeClass public static void setUp() throws Exception { WriteHeavyIncrementObserverTestBase.setUp(); UTIL.getAdmin() .createTable(TableDescriptorBuilder.newBuilder(NAME) .setCoprocessor(WriteHeavyIncrementObserver.class.getName()) .setValue(CompactingMemStore.COMPACTING_MEMSTORE_TYPE_KEY, MemoryCompactionPolicy.EAGER.name()) .setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY)).build()); TABLE = UTIL.getConnection().getTable(NAME); }
public static void createMobTable(HBaseTestingUtility util, TableName tableName, byte[][] splitKeys, int regionReplication, String cpClassName, byte[]... families) throws IOException, InterruptedException { TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName).setRegionReplication(regionReplication); for (byte[] family : families) { builder.setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(family).setMobEnabled(true) .setMobThreshold(0L).build()); } if (!StringUtils.isBlank(cpClassName)) { builder.setCoprocessor(cpClassName); } util.getAdmin().createTable(builder.build(), splitKeys); SnapshotTestingUtils.waitForTableToBeOnline(util, tableName); assertEquals((splitKeys.length + 1) * regionReplication, util.getAdmin().getRegions(tableName).size()); }
/** * Test cps in the table description * @throws Exception */ @Test public void testGetSetRemoveCP() throws Exception { // simple CP String className = "org.apache.hadoop.hbase.coprocessor.SimpleRegionObserver"; TableDescriptor desc = TableDescriptorBuilder.newBuilder(TableName.valueOf(name.getMethodName())) .setCoprocessor(className) // add and check that it is present .build(); assertTrue(desc.hasCoprocessor(className)); desc = TableDescriptorBuilder.newBuilder(desc) .removeCoprocessor(className) // remove it and check that it is gone .build(); assertFalse(desc.hasCoprocessor(className)); }
private void createTableWithCoprocessor(TableName tableName, String coprocessor) throws IOException { TableDescriptor tableDesc = TableDescriptorBuilder.newBuilder(tableName) .setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(CF1_BYTES).build()) .setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(CF2_BYTES).build()) .setCoprocessor(coprocessor).build(); connection.getAdmin().createTable(tableDesc); }
@Test public void testDropTimeoutRequest() throws Exception { // Simulate the situation that the server is slow and client retries for several times because // of timeout. When a request can be handled after waiting in the queue, we will drop it if // it has been considered as timeout at client. If we don't drop it, the server will waste time // on handling timeout requests and finally all requests timeout and client throws exception. TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(TableName.valueOf(name.getMethodName())); builder.setCoprocessor(SleepLongerAtFirstCoprocessor.class.getName()); ColumnFamilyDescriptor cfd = ColumnFamilyDescriptorBuilder.newBuilder(FAM_NAM).build(); builder.setColumnFamily(cfd); TableDescriptor td = builder.build(); try (Admin admin = TEST_UTIL.getConnection().getAdmin()) { admin.createTable(td); } TableBuilder tb = TEST_UTIL.getConnection().getTableBuilder(td.getTableName(), null); tb.setReadRpcTimeout(SleepLongerAtFirstCoprocessor.SLEEP_TIME * 2); tb.setWriteRpcTimeout(SleepLongerAtFirstCoprocessor.SLEEP_TIME * 2); try (Table table = tb.build()) { table.get(new Get(FAM_NAM)); } } }
@BeforeClass public static void setUp() throws Exception { UTIL.startMiniCluster(3); UTIL.getAdmin() .createTable(TableDescriptorBuilder.newBuilder(NAME) .setCoprocessor(ZooKeeperScanPolicyObserver.class.getName()) .setValue(ZooKeeperScanPolicyObserver.ZK_ENSEMBLE_KEY, "localhost:" + UTIL.getZkCluster().getClientPort()) .setValue(ZooKeeperScanPolicyObserver.ZK_SESSION_TIMEOUT_KEY, "2000") .setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(FAMILY).build()).build()); TABLE = UTIL.getConnection().getTable(NAME); }