Search in sources :

Example 86 with TableName

use of org.apache.hadoop.hbase.TableName in project hbase by apache.

the class TestScannersFromClientSide method testScanOnReopenedRegion.

/**
   * Test from client side for scan while the region is reopened
   * on the same region server.
   *
   * @throws Exception
   */
@Test
public void testScanOnReopenedRegion() throws Exception {
    final TableName tableName = TableName.valueOf(name.getMethodName());
    byte[][] QUALIFIERS = HTestConst.makeNAscii(QUALIFIER, 2);
    Table ht = TEST_UTIL.createTable(tableName, FAMILY);
    Put put;
    Scan scan;
    Result result;
    ResultScanner scanner;
    boolean toLog = false;
    List<Cell> kvListExp;
    // table: row, family, c0:0, c1:1
    put = new Put(ROW);
    for (int i = 0; i < QUALIFIERS.length; i++) {
        KeyValue kv = new KeyValue(ROW, FAMILY, QUALIFIERS[i], i, VALUE);
        put.add(kv);
    }
    ht.put(put);
    scan = new Scan().withStartRow(ROW);
    scanner = ht.getScanner(scan);
    HRegionLocation loc;
    try (RegionLocator locator = TEST_UTIL.getConnection().getRegionLocator(tableName)) {
        loc = locator.getRegionLocation(ROW);
    }
    HRegionInfo hri = loc.getRegionInfo();
    MiniHBaseCluster cluster = TEST_UTIL.getMiniHBaseCluster();
    byte[] regionName = hri.getRegionName();
    int i = cluster.getServerWith(regionName);
    HRegionServer rs = cluster.getRegionServer(i);
    ProtobufUtil.closeRegion(null, rs.getRSRpcServices(), rs.getServerName(), regionName);
    long startTime = EnvironmentEdgeManager.currentTime();
    long timeOut = 300000;
    while (true) {
        if (rs.getOnlineRegion(regionName) == null) {
            break;
        }
        assertTrue("Timed out in closing the testing region", EnvironmentEdgeManager.currentTime() < startTime + timeOut);
        Thread.sleep(500);
    }
    // Now open the region again.
    HMaster master = cluster.getMaster();
    RegionStates states = master.getAssignmentManager().getRegionStates();
    states.regionOffline(hri);
    states.updateRegionState(hri, State.OPENING);
    ProtobufUtil.openRegion(null, rs.getRSRpcServices(), rs.getServerName(), hri);
    startTime = EnvironmentEdgeManager.currentTime();
    while (true) {
        if (rs.getOnlineRegion(regionName) != null) {
            break;
        }
        assertTrue("Timed out in open the testing region", EnvironmentEdgeManager.currentTime() < startTime + timeOut);
        Thread.sleep(500);
    }
    // c0:0, c1:1
    kvListExp = new ArrayList<>();
    kvListExp.add(new KeyValue(ROW, FAMILY, QUALIFIERS[0], 0, VALUE));
    kvListExp.add(new KeyValue(ROW, FAMILY, QUALIFIERS[1], 1, VALUE));
    result = scanner.next();
    verifyResult(result, kvListExp, toLog, "Testing scan on re-opened region");
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) RegionStates(org.apache.hadoop.hbase.master.RegionStates) HMaster(org.apache.hadoop.hbase.master.HMaster) Cell(org.apache.hadoop.hbase.Cell) Test(org.junit.Test)

Example 87 with TableName

use of org.apache.hadoop.hbase.TableName in project hbase by apache.

the class TestScannersFromClientSide method testSmallScan.

@Test
public void testSmallScan() throws Exception {
    final TableName tableName = TableName.valueOf(name.getMethodName());
    int numRows = 10;
    byte[][] ROWS = HTestConst.makeNAscii(ROW, numRows);
    int numQualifiers = 10;
    byte[][] QUALIFIERS = HTestConst.makeNAscii(QUALIFIER, numQualifiers);
    Table ht = TEST_UTIL.createTable(tableName, FAMILY);
    Put put;
    List<Put> puts = new ArrayList<>();
    for (int row = 0; row < ROWS.length; row++) {
        put = new Put(ROWS[row]);
        for (int qual = 0; qual < QUALIFIERS.length; qual++) {
            KeyValue kv = new KeyValue(ROWS[row], FAMILY, QUALIFIERS[qual], VALUE);
            put.add(kv);
        }
        puts.add(put);
    }
    ht.put(puts);
    int expectedRows = numRows;
    int expectedCols = numRows * numQualifiers;
    // Test normal and reversed
    testSmallScan(ht, true, expectedRows, expectedCols);
    testSmallScan(ht, false, expectedRows, expectedCols);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) KeyValue(org.apache.hadoop.hbase.KeyValue) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 88 with TableName

use of org.apache.hadoop.hbase.TableName in project hbase by apache.

the class TestMasterObserver method testQueueLockAndLockHeartbeatOperations.

@Test
public void testQueueLockAndLockHeartbeatOperations() throws Exception {
    HMaster master = UTIL.getMiniHBaseCluster().getMaster();
    CPMasterObserver cp = (CPMasterObserver) master.getMasterCoprocessorHost().findCoprocessor(CPMasterObserver.class.getName());
    cp.resetStates();
    final TableName tableName = TableName.valueOf("testLockedTable");
    long procId = master.getLockManager().remoteLocks().requestTableLock(tableName, LockProcedure.LockType.EXCLUSIVE, "desc", null);
    master.getLockManager().remoteLocks().lockHeartbeat(procId, false);
    assertTrue(cp.preAndPostForQueueLockAndHeartbeatLockCalled());
    ProcedureTestingUtility.waitNoProcedureRunning(master.getMasterProcedureExecutor());
    ProcedureTestingUtility.assertProcNotFailed(master.getMasterProcedureExecutor(), procId);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) HMaster(org.apache.hadoop.hbase.master.HMaster) Test(org.junit.Test)

Example 89 with TableName

use of org.apache.hadoop.hbase.TableName in project hbase by apache.

the class TestMasterObserver method testTableDescriptorsEnumeration.

@Test(timeout = 180000)
public void testTableDescriptorsEnumeration() throws Exception {
    MiniHBaseCluster cluster = UTIL.getHBaseCluster();
    HMaster master = cluster.getMaster();
    MasterCoprocessorHost host = master.getMasterCoprocessorHost();
    CPMasterObserver cp = (CPMasterObserver) host.findCoprocessor(CPMasterObserver.class.getName());
    cp.resetStates();
    GetTableDescriptorsRequest req = RequestConverter.buildGetTableDescriptorsRequest((List<TableName>) null);
    master.getMasterRpcServices().getTableDescriptors(null, req);
    assertTrue("Coprocessor should be called on table descriptors request", cp.wasGetTableDescriptorsCalled());
}
Also used : TableName(org.apache.hadoop.hbase.TableName) MasterCoprocessorHost(org.apache.hadoop.hbase.master.MasterCoprocessorHost) HMaster(org.apache.hadoop.hbase.master.HMaster) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) GetTableDescriptorsRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetTableDescriptorsRequest) Test(org.junit.Test)

Example 90 with TableName

use of org.apache.hadoop.hbase.TableName in project hbase by apache.

the class TestMasterObserver method testTableOperations.

@Test(timeout = 180000)
public void testTableOperations() throws Exception {
    MiniHBaseCluster cluster = UTIL.getHBaseCluster();
    final TableName tableName = TableName.valueOf(name.getMethodName());
    HMaster master = cluster.getMaster();
    MasterCoprocessorHost host = master.getMasterCoprocessorHost();
    CPMasterObserver cp = (CPMasterObserver) host.findCoprocessor(CPMasterObserver.class.getName());
    cp.enableBypass(true);
    cp.resetStates();
    assertFalse("No table created yet", cp.wasCreateTableCalled());
    // create a table
    HTableDescriptor htd = new HTableDescriptor(tableName);
    htd.addFamily(new HColumnDescriptor(TEST_FAMILY));
    try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration());
        Admin admin = connection.getAdmin()) {
        tableCreationLatch = new CountDownLatch(1);
        admin.createTable(htd, Arrays.copyOfRange(HBaseTestingUtility.KEYS, 1, HBaseTestingUtility.KEYS.length));
        // preCreateTable can't bypass default action.
        assertTrue("Test table should be created", cp.wasCreateTableCalled());
        tableCreationLatch.await();
        assertTrue("Table pre create handler called.", cp.wasPreCreateTableActionCalled());
        assertTrue("Table create handler should be called.", cp.wasCreateTableActionCalled());
        RegionLocator regionLocator = connection.getRegionLocator(htd.getTableName());
        List<HRegionLocation> regions = regionLocator.getAllRegionLocations();
        admin.mergeRegionsAsync(regions.get(0).getRegionInfo().getEncodedNameAsBytes(), regions.get(1).getRegionInfo().getEncodedNameAsBytes(), true);
        assertTrue("Coprocessor should have been called on region merge", cp.wasMergeRegionsCalled());
        tableCreationLatch = new CountDownLatch(1);
        admin.disableTable(tableName);
        assertTrue(admin.isTableDisabled(tableName));
        // preDisableTable can't bypass default action.
        assertTrue("Coprocessor should have been called on table disable", cp.wasDisableTableCalled());
        assertTrue("Disable table handler should be called.", cp.wasDisableTableActionCalled());
        // enable
        assertFalse(cp.wasEnableTableCalled());
        admin.enableTable(tableName);
        assertTrue(admin.isTableEnabled(tableName));
        // preEnableTable can't bypass default action.
        assertTrue("Coprocessor should have been called on table enable", cp.wasEnableTableCalled());
        assertTrue("Enable table handler should be called.", cp.wasEnableTableActionCalled());
        admin.disableTable(tableName);
        assertTrue(admin.isTableDisabled(tableName));
        // modify table
        htd.setMaxFileSize(512 * 1024 * 1024);
        modifyTableSync(admin, tableName, htd);
        // preModifyTable can't bypass default action.
        assertTrue("Test table should have been modified", cp.wasModifyTableCalled());
        // add a column family
        admin.addColumnFamily(tableName, new HColumnDescriptor(TEST_FAMILY2));
        assertTrue("New column family shouldn't have been added to test table", cp.preAddColumnCalledOnly());
        // modify a column family
        HColumnDescriptor hcd1 = new HColumnDescriptor(TEST_FAMILY2);
        hcd1.setMaxVersions(25);
        admin.modifyColumnFamily(tableName, hcd1);
        assertTrue("Second column family should be modified", cp.preModifyColumnCalledOnly());
        // truncate table
        admin.truncateTable(tableName, false);
        // delete table
        admin.disableTable(tableName);
        assertTrue(admin.isTableDisabled(tableName));
        deleteTable(admin, tableName);
        assertFalse("Test table should have been deleted", admin.tableExists(tableName));
        // preDeleteTable can't bypass default action.
        assertTrue("Coprocessor should have been called on table delete", cp.wasDeleteTableCalled());
        assertTrue("Delete table handler should be called.", cp.wasDeleteTableActionCalled());
        // turn off bypass, run the tests again
        cp.enableBypass(false);
        cp.resetStates();
        admin.createTable(htd);
        assertTrue("Test table should be created", cp.wasCreateTableCalled());
        tableCreationLatch.await();
        assertTrue("Table pre create handler called.", cp.wasPreCreateTableActionCalled());
        assertTrue("Table create handler should be called.", cp.wasCreateTableActionCalled());
        // disable
        assertFalse(cp.wasDisableTableCalled());
        assertFalse(cp.wasDisableTableActionCalled());
        admin.disableTable(tableName);
        assertTrue(admin.isTableDisabled(tableName));
        assertTrue("Coprocessor should have been called on table disable", cp.wasDisableTableCalled());
        assertTrue("Disable table handler should be called.", cp.wasDisableTableActionCalled());
        // modify table
        htd.setMaxFileSize(512 * 1024 * 1024);
        modifyTableSync(admin, tableName, htd);
        assertTrue("Test table should have been modified", cp.wasModifyTableCalled());
        // add a column family
        admin.addColumnFamily(tableName, new HColumnDescriptor(TEST_FAMILY2));
        assertTrue("New column family should have been added to test table", cp.wasAddColumnCalled());
        assertTrue("Add column handler should be called.", cp.wasAddColumnFamilyActionCalled());
        // modify a column family
        HColumnDescriptor hcd = new HColumnDescriptor(TEST_FAMILY2);
        hcd.setMaxVersions(25);
        admin.modifyColumnFamily(tableName, hcd);
        assertTrue("Second column family should be modified", cp.wasModifyColumnCalled());
        assertTrue("Modify table handler should be called.", cp.wasModifyColumnFamilyActionCalled());
        // enable
        assertFalse(cp.wasEnableTableCalled());
        assertFalse(cp.wasEnableTableActionCalled());
        admin.enableTable(tableName);
        assertTrue(admin.isTableEnabled(tableName));
        assertTrue("Coprocessor should have been called on table enable", cp.wasEnableTableCalled());
        assertTrue("Enable table handler should be called.", cp.wasEnableTableActionCalled());
        // disable again
        admin.disableTable(tableName);
        assertTrue(admin.isTableDisabled(tableName));
        // delete column
        assertFalse("No column family deleted yet", cp.wasDeleteColumnCalled());
        assertFalse("Delete table column handler should not be called.", cp.wasDeleteColumnFamilyActionCalled());
        admin.deleteColumnFamily(tableName, TEST_FAMILY2);
        HTableDescriptor tableDesc = admin.getTableDescriptor(tableName);
        assertNull("'" + Bytes.toString(TEST_FAMILY2) + "' should have been removed", tableDesc.getFamily(TEST_FAMILY2));
        assertTrue("Coprocessor should have been called on column delete", cp.wasDeleteColumnCalled());
        assertTrue("Delete table column handler should be called.", cp.wasDeleteColumnFamilyActionCalled());
        // delete table
        assertFalse("No table deleted yet", cp.wasDeleteTableCalled());
        assertFalse("Delete table handler should not be called.", cp.wasDeleteTableActionCalled());
        deleteTable(admin, tableName);
        assertFalse("Test table should have been deleted", admin.tableExists(tableName));
        assertTrue("Coprocessor should have been called on table delete", cp.wasDeleteTableCalled());
        assertTrue("Delete table handler should be called.", cp.wasDeleteTableActionCalled());
    }
}
Also used : RegionLocator(org.apache.hadoop.hbase.client.RegionLocator) MasterCoprocessorHost(org.apache.hadoop.hbase.master.MasterCoprocessorHost) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) Connection(org.apache.hadoop.hbase.client.Connection) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) Admin(org.apache.hadoop.hbase.client.Admin) CountDownLatch(java.util.concurrent.CountDownLatch) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) TableName(org.apache.hadoop.hbase.TableName) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) HMaster(org.apache.hadoop.hbase.master.HMaster) Test(org.junit.Test)

Aggregations

TableName (org.apache.hadoop.hbase.TableName)1033 Test (org.junit.Test)695 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)257 Table (org.apache.hadoop.hbase.client.Table)228 IOException (java.io.IOException)225 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)215 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)203 Result (org.apache.hadoop.hbase.client.Result)125 ArrayList (java.util.ArrayList)120 Put (org.apache.hadoop.hbase.client.Put)118 Path (org.apache.hadoop.fs.Path)113 Connection (org.apache.hadoop.hbase.client.Connection)103 Scan (org.apache.hadoop.hbase.client.Scan)98 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)89 ServerName (org.apache.hadoop.hbase.ServerName)85 Admin (org.apache.hadoop.hbase.client.Admin)85 Cell (org.apache.hadoop.hbase.Cell)77 HashMap (java.util.HashMap)75 Delete (org.apache.hadoop.hbase.client.Delete)66 InterruptedIOException (java.io.InterruptedIOException)63