Search in sources :

Example 16 with HBaseTableUtilFactory

use of io.cdap.cdap.data2.util.hbase.HBaseTableUtilFactory in project cdap by caskdata.

the class AbstractIncrementHandlerTest method testIncrements.

@Test
public void testIncrements() throws Exception {
    TableId tableId = TableId.from(NamespaceId.DEFAULT.getEntityName(), "incrementTest");
    createTable(tableId);
    try (Table table = new HBaseTableUtilFactory(cConf).get().createTable(conf, tableId)) {
        byte[] colA = Bytes.toBytes("a");
        byte[] row1 = Bytes.toBytes("row1");
        // test column containing only increments
        table.put(newIncrement(row1, colA, 1));
        table.put(newIncrement(row1, colA, 1));
        table.put(newIncrement(row1, colA, 1));
        assertColumn(table, row1, colA, 3);
        // test intermixed increments and puts
        table.put(tableUtil.buildPut(row1).add(FAMILY, colA, ts++, Bytes.toBytes(5L)).build());
        assertColumn(table, row1, colA, 5);
        table.put(newIncrement(row1, colA, 1));
        table.put(newIncrement(row1, colA, 1));
        assertColumn(table, row1, colA, 7);
        // test multiple increment columns
        byte[] row2 = Bytes.toBytes("row2");
        byte[] colB = Bytes.toBytes("b");
        // increment A and B twice at the same timestamp
        table.put(newIncrement(row2, colA, 1, 1));
        table.put(newIncrement(row2, colB, 1, 1));
        table.put(newIncrement(row2, colA, 2, 1));
        table.put(newIncrement(row2, colB, 2, 1));
        // increment A once more
        table.put(newIncrement(row2, colA, 1));
        assertColumns(table, row2, new byte[][] { colA, colB }, new long[] { 3, 2 });
        // overwrite B with a new put
        table.put(tableUtil.buildPut(row2).add(FAMILY, colB, ts++, Bytes.toBytes(10L)).build());
        assertColumns(table, row2, new byte[][] { colA, colB }, new long[] { 3, 10 });
    }
}
Also used : TableId(io.cdap.cdap.data2.util.TableId) HBaseTable(io.cdap.cdap.data2.dataset2.lib.table.hbase.HBaseTable) Table(org.apache.hadoop.hbase.client.Table) HBaseTableUtilFactory(io.cdap.cdap.data2.util.hbase.HBaseTableUtilFactory) Test(org.junit.Test)

Example 17 with HBaseTableUtilFactory

use of io.cdap.cdap.data2.util.hbase.HBaseTableUtilFactory in project cdap by caskdata.

the class HBaseCheck method run.

@Override
public void run() {
    LOG.info("Checking HBase version.");
    HBaseTableUtil hBaseTableUtil;
    try {
        hBaseTableUtil = new HBaseTableUtilFactory(cConf).get();
    } catch (ProvisionException e) {
        throw new RuntimeException("Unsupported Hbase version " + HBaseVersion.getVersionString());
    }
    LOG.info("  HBase version successfully verified.");
    LOG.info("Checking HBase availability.");
    try (HConnection hbaseConnection = HConnectionManager.createConnection(hConf)) {
        hbaseConnection.listTables();
        LOG.info("  HBase availability successfully verified.");
    } catch (IOException e) {
        throw new RuntimeException("Unable to connect to HBase. " + "Please check that HBase is running and that the correct HBase configuration (hbase-site.xml) " + "and libraries are included in the CDAP master classpath.", e);
    }
    if (hConf.getBoolean("hbase.security.authorization", false)) {
        if (cConf.getBoolean(TxConstants.TransactionPruning.PRUNE_ENABLE)) {
            LOG.info("HBase authorization and transaction pruning are enabled. Checking global admin privileges for cdap.");
            try {
                boolean isGlobalAdmin = hBaseTableUtil.isGlobalAdmin(hConf);
                LOG.info("Global admin privileges check status: {}", isGlobalAdmin);
                if (isGlobalAdmin) {
                    return;
                }
                // if global admin was false then depend on the TX_PRUNE_ACL_CHECK value
                if (cConf.getBoolean(Constants.Startup.TX_PRUNE_ACL_CHECK, false)) {
                    LOG.info("Found {} to be set to true. Continuing with cdap master startup even though global admin check " + "returned false", Constants.Startup.TX_PRUNE_ACL_CHECK);
                    return;
                }
                StringBuilder builder = new StringBuilder("Transaction pruning is enabled and cdap does not have global " + "admin privileges in HBase. Global admin privileges for cdap " + "are required for transaction pruning. " + "Either disable transaction pruning or grant global admin " + "privilege to cdap in HBase or can override this " + "check by setting ");
                builder.append(Constants.Startup.TX_PRUNE_ACL_CHECK);
                builder.append(" in cdap-site.xml.");
                if (HBaseVersion.get().equals(HBaseVersion.Version.HBASE_96) || HBaseVersion.get().equals(HBaseVersion.Version.HBASE_98)) {
                    builder.append(" Detected HBase version ");
                    builder.append(HBaseVersion.get());
                    builder.append(" CDAP will not be able determine if it has global admin privilege in HBase.");
                    builder.append(" After granting global admin privilege please set ");
                    builder.append(Constants.Startup.TX_PRUNE_ACL_CHECK);
                }
                throw new RuntimeException(builder.toString());
            } catch (IOException e) {
                throw new RuntimeException("Unable to determines cdap privileges as global admin in HBase.");
            }
        }
    }
    LOG.info("Hbase authorization is disabled. Skipping global admin check for transaction pruning.");
}
Also used : ProvisionException(com.google.inject.ProvisionException) HBaseTableUtilFactory(io.cdap.cdap.data2.util.hbase.HBaseTableUtilFactory) IOException(java.io.IOException) HBaseTableUtil(io.cdap.cdap.data2.util.hbase.HBaseTableUtil) HConnection(org.apache.hadoop.hbase.client.HConnection)

Example 18 with HBaseTableUtilFactory

use of io.cdap.cdap.data2.util.hbase.HBaseTableUtilFactory in project cdap by caskdata.

the class ReplicationStatusTool method dumpReplicationStateTable.

private static void dumpReplicationStateTable() throws Exception {
    System.out.println("\nThis is all the HBase regions on the Cluster:");
    HBaseTableUtil tableUtil = new HBaseTableUtilFactory(cConf).get();
    ScanBuilder scan = tableUtil.buildScan();
    scan.addColumn(Bytes.toBytes(ReplicationConstants.ReplicationStatusTool.TIME_FAMILY), Bytes.toBytes(ReplicationConstants.ReplicationStatusTool.WRITE_TIME_ROW_TYPE));
    scan.addColumn(Bytes.toBytes(ReplicationConstants.ReplicationStatusTool.TIME_FAMILY), Bytes.toBytes(ReplicationConstants.ReplicationStatusTool.REPLICATE_TIME_ROW_TYPE));
    try (Table table = tableUtil.createTable(hConf, getReplicationStateTableId(tableUtil));
        ResultScanner resultScanner = table.getScanner(scan.build())) {
        Result result;
        while ((result = resultScanner.next()) != null) {
            ReplicationStatusKey key = new ReplicationStatusKey(result.getRow());
            String rowType = key.getRowType();
            String region = key.getRegionName();
            UUID rsID = key.getRsID();
            Long writeTime = getTimeFromResult(result, ReplicationConstants.ReplicationStatusTool.WRITE_TIME_ROW_TYPE);
            Long replicateTime = getTimeFromResult(result, ReplicationConstants.ReplicationStatusTool.REPLICATE_TIME_ROW_TYPE);
            System.out.println("Key=>rowType:" + rowType + ":region:" + region + ":RSID:" + rsID + " writeTime:" + writeTime + ":replicateTime:" + replicateTime);
        }
    }
}
Also used : Table(org.apache.hadoop.hbase.client.Table) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) ReplicationStatusKey(io.cdap.cdap.replication.ReplicationStatusKey) ScanBuilder(io.cdap.cdap.data2.util.hbase.ScanBuilder) HBaseTableUtilFactory(io.cdap.cdap.data2.util.hbase.HBaseTableUtilFactory) UUID(java.util.UUID) HBaseTableUtil(io.cdap.cdap.data2.util.hbase.HBaseTableUtil) Result(org.apache.hadoop.hbase.client.Result)

Example 19 with HBaseTableUtilFactory

use of io.cdap.cdap.data2.util.hbase.HBaseTableUtilFactory in project cdap by caskdata.

the class IncrementHandlerTest method createTable.

@Override
public HTable createTable(TableId tableId) throws Exception {
    HBaseTableUtil tableUtil = new HBaseTableUtilFactory(cConf).get();
    HTableDescriptorBuilder tableDesc = tableUtil.buildHTableDescriptor(tableId);
    HColumnDescriptor columnDesc = new HColumnDescriptor(FAMILY);
    columnDesc.setMaxVersions(Integer.MAX_VALUE);
    columnDesc.setValue(IncrementHandlerState.PROPERTY_TRANSACTIONAL, "false");
    tableDesc.addFamily(columnDesc);
    tableDesc.addCoprocessor(IncrementHandler.class.getName());
    HTableDescriptor htd = tableDesc.build();
    TEST_HBASE.getHBaseAdmin().createTable(htd);
    TEST_HBASE.waitUntilTableAvailable(htd.getName(), 5000);
    return tableUtil.createHTable(conf, tableId);
}
Also used : HTableDescriptorBuilder(co.cask.cdap.data2.util.hbase.HTableDescriptorBuilder) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) HBaseTableUtilFactory(co.cask.cdap.data2.util.hbase.HBaseTableUtilFactory) HBaseTableUtil(co.cask.cdap.data2.util.hbase.HBaseTableUtil) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 20 with HBaseTableUtilFactory

use of io.cdap.cdap.data2.util.hbase.HBaseTableUtilFactory in project cdap by caskdata.

the class IncrementSummingScannerTest method createRegion.

static HRegion createRegion(Configuration hConf, CConfiguration cConf, TableId tableId, HColumnDescriptor cfd) throws Exception {
    HBaseTableUtil tableUtil = new HBaseTableUtilFactory(cConf).get();
    HTableDescriptorBuilder htd = tableUtil.buildHTableDescriptor(tableId);
    cfd.setMaxVersions(Integer.MAX_VALUE);
    cfd.setKeepDeletedCells(true);
    htd.addFamily(cfd);
    htd.addCoprocessor(IncrementHandler.class.getName());
    HTableDescriptor desc = htd.build();
    String tableName = desc.getNameAsString();
    Path tablePath = new Path("/tmp/" + tableName);
    Path hlogPath = new Path("/tmp/hlog-" + tableName);
    FileSystem fs = FileSystem.get(hConf);
    assertTrue(fs.mkdirs(tablePath));
    WALFactory walFactory = new WALFactory(hConf, null, hlogPath.toString());
    WAL hLog = walFactory.getWAL(new byte[] { 1 });
    HRegionInfo regionInfo = new HRegionInfo(desc.getTableName());
    HRegionFileSystem regionFS = HRegionFileSystem.createRegionOnFileSystem(hConf, fs, tablePath, regionInfo);
    return new HRegion(regionFS, hLog, hConf, desc, new LocalRegionServerServices(hConf, ServerName.valueOf(InetAddress.getLocalHost().getHostName(), 0, System.currentTimeMillis())));
}
Also used : Path(org.apache.hadoop.fs.Path) HTableDescriptorBuilder(co.cask.cdap.data2.util.hbase.HTableDescriptorBuilder) WAL(org.apache.hadoop.hbase.wal.WAL) HBaseTableUtil(co.cask.cdap.data2.util.hbase.HBaseTableUtil) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) HRegionFileSystem(org.apache.hadoop.hbase.regionserver.HRegionFileSystem) FileSystem(org.apache.hadoop.fs.FileSystem) HRegionFileSystem(org.apache.hadoop.hbase.regionserver.HRegionFileSystem) HBaseTableUtilFactory(co.cask.cdap.data2.util.hbase.HBaseTableUtilFactory) WALFactory(org.apache.hadoop.hbase.wal.WALFactory)

Aggregations

HBaseTableUtilFactory (co.cask.cdap.data2.util.hbase.HBaseTableUtilFactory)25 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)24 HBaseTableUtilFactory (io.cdap.cdap.data2.util.hbase.HBaseTableUtilFactory)21 HBaseTableUtil (co.cask.cdap.data2.util.hbase.HBaseTableUtil)18 HTableDescriptorBuilder (co.cask.cdap.data2.util.hbase.HTableDescriptorBuilder)14 HBaseTableUtil (io.cdap.cdap.data2.util.hbase.HBaseTableUtil)14 FileSystem (org.apache.hadoop.fs.FileSystem)12 Path (org.apache.hadoop.fs.Path)12 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)12 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)12 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)12 HRegionFileSystem (org.apache.hadoop.hbase.regionserver.HRegionFileSystem)12 BeforeClass (org.junit.BeforeClass)12 HTableDescriptorBuilder (io.cdap.cdap.data2.util.hbase.HTableDescriptorBuilder)10 WAL (org.apache.hadoop.hbase.wal.WAL)10 WALFactory (org.apache.hadoop.hbase.wal.WALFactory)10 LocationFactory (org.apache.twill.filesystem.LocationFactory)10 HBaseDDLExecutorFactory (co.cask.cdap.data2.util.hbase.HBaseDDLExecutorFactory)6 HBaseDDLExecutorFactory (io.cdap.cdap.data2.util.hbase.HBaseDDLExecutorFactory)6 IOException (java.io.IOException)6