public HTableDescriptor setTablePrefix(HTableDescriptor tableDescriptor) { HTableDescriptorBuilder builder = buildHTableDescriptor(tableDescriptor); builder.setValue(Constants.Dataset.TABLE_PREFIX, tablePrefix); return builder.build(); }
@Override public MetadataTable createMetadataTable() throws IOException { TableId tableId = tableUtil.createHTableId(NamespaceId.SYSTEM, metadataTableName); HTable hTable = null; // If the table descriptor is in the cache, we assume the table exists. if (!tableDescriptors.containsKey(tableId)) { synchronized (this) { if (!tableDescriptors.containsKey(tableId)) { try (HBaseDDLExecutor ddlExecutor = ddlExecutorFactory.get()) { ColumnFamilyDescriptorBuilder cfdBuilder = HBaseTableUtil.getColumnFamilyDescriptorBuilder(Bytes.toString(COLUMN_FAMILY), hConf); TableDescriptorBuilder tdBuilder = HBaseTableUtil.getTableDescriptorBuilder(tableId, cConf).addColumnFamily(cfdBuilder.build()); ddlExecutor.createTableIfNotExists(tdBuilder.build(), null); hTable = tableUtil.createHTable(hConf, tableId); tableDescriptors.put(tableId, hTable.getTableDescriptor()); } } } } if (hTable == null) { hTable = tableUtil.createHTable(hConf, tableId); } return new HBaseMetadataTable(tableUtil, hTable, COLUMN_FAMILY, cConf.getInt(Constants.MessagingSystem.HBASE_SCAN_CACHE_ROWS), createExceptionHandler(tableId)); }
public TableId createHTableId(NamespaceId namespace, String tableName) throws IOException { return TableId.from(getHBaseNamespace(namespace), tableName); }
private void updateTableDesc(HTableDescriptor desc, HBaseDDLExecutor ddlExecutor) throws IOException { hBaseTableUtil.setVersion(desc); hBaseTableUtil.setHBaseVersion(desc); hBaseTableUtil.setTablePrefix(desc); hBaseTableUtil.modifyTable(ddlExecutor, desc); }
public HTableDescriptor setVersion(HTableDescriptor tableDescriptor) { HTableDescriptorBuilder builder = buildHTableDescriptor(tableDescriptor); setVersion(builder); return builder.build(); }
public HTableDescriptor setHBaseVersion(HTableDescriptor tableDescriptor) { HTableDescriptorBuilder builder = buildHTableDescriptor(tableDescriptor); setHBaseVersion(builder); return builder.build(); }
try (HBaseAdmin admin = new HBaseAdmin(hConf)) { if (!tableUtil.tableExists(admin, tableId)) { LOG.debug("TMS Table {} was not found. Skip upgrading coprocessor.", tableId); return; tableDescriptor = tableUtil.getHTableDescriptor(admin, tableId); ProjectInfo.Version version = HBaseTableUtil.getVersion(tableDescriptor); String hbaseVersion = HBaseTableUtil.getHBaseVersion(tableDescriptor); HTableDescriptorBuilder newDescriptor = tableUtil.buildHTableDescriptor(tableDescriptor); Map<String, HBaseTableUtil.CoprocessorInfo> coprocessorInfo = HBaseTableUtil.getCoprocessorInfo(tableDescriptor); for (Map.Entry<String, HBaseTableUtil.CoprocessorInfo> coprocessorEntry : coprocessorInfo.entrySet()) { newDescriptor.removeCoprocessor(coprocessorEntry.getValue().getClassName()); HBaseTableUtil.setVersion(newDescriptor); HBaseTableUtil.setHBaseVersion(newDescriptor); HBaseTableUtil.setTablePrefix(newDescriptor, cConf); tableUtil.modifyTable(ddlExecutor, newDescriptor.build()); LOG.debug("Enabling table '{}'...", tableId); enableTable(ddlExecutor, tableId);
@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); }
KVTableImpl(DatasetContext datasetContext, String tableName, Configuration hConf, HBaseTableUtil tableUtil) throws IOException { this.tableUtil = tableUtil; TableId tableId = tableUtil.createHTableId(new NamespaceId(datasetContext.getNamespaceId()), tableName); this.table = this.tableUtil.createHTable(hConf, tableId); }
Assert.assertFalse(tableUtil.hasNamespace(hAdmin, tableUtil.getHBaseNamespace(new NamespaceId("namespace")))); createNamespace("namespace"); createNamespace("namespace2"); Assert.assertTrue(tableUtil.hasNamespace(hAdmin, tableUtil.getHBaseNamespace(new NamespaceId("namespace")))); TableId hTableId = tableUtil.createHTableId(new NamespaceId("namespace"), "table2"); HTableDescriptorBuilder newDesc = getTableUtil().buildHTableDescriptor(desc); newDesc.setValue("mykey", "myvalue"); disable("namespace2", "table1"); getTableUtil().modifyTable(ddlExecutor, newDesc.build()); desc = getTableDescriptor("namespace2", "table1"); Assert.assertTrue(desc.getValue("mykey").equals("myvalue")); deleteNamespace("namespace"); deleteNamespace("namespace2"); Assert.assertFalse(tableUtil.hasNamespace(hAdmin, "namespace")); Assert.assertFalse(tableUtil.hasNamespace(hAdmin, "namespace2"));
/** * Creates the configuration HBase table if it does not exist. */ @VisibleForTesting void createTableIfNecessary() throws IOException { try (HBaseDDLExecutor ddlExecutor = new HBaseDDLExecutorFactory(cConf, hConf).get()) { HBaseTableUtil tableUtil = new HBaseTableUtilFactory(cConf).get(); TableId tableId = tableUtil.createHTableId(NamespaceId.SYSTEM, TABLE_NAME); ColumnFamilyDescriptorBuilder cfdBuilder = HBaseTableUtil.getColumnFamilyDescriptorBuilder(Bytes.toString(FAMILY), hConf); TableDescriptorBuilder tdBuilder = HBaseTableUtil.getTableDescriptorBuilder(tableId, cConf).addColumnFamily(cfdBuilder.build()); ddlExecutor.createTableIfNotExists(tdBuilder.build(), null); } } }
private static TableId getReplicationStateTableId(HBaseTableUtil tableUtil) throws IOException { String tableName = hConf.get(ReplicationConstants.ReplicationStatusTool.REPLICATION_STATE_TABLE_NAME); String ns = hConf.get(ReplicationConstants.ReplicationStatusTool.REPLICATION_STATE_TABLE_NAMESPACE); TableId tableId = tableUtil.createHTableId( (ns != null) ? new NamespaceId(ns) : new NamespaceId(ReplicationConstants.ReplicationStatusTool.REPLICATION_STATE_TABLE_DEFAULT_NAMESPACE), (tableName != null) ? tableName : ReplicationConstants.ReplicationStatusTool.REPLICATION_STATE_TABLE_DEFAULT_NAME); return tableId; }
public HTable createHTable(TableId hTableId) throws IOException { HTable consumerTable = hBaseTableUtil.createHTable(hConf, hTableId); // TODO: make configurable consumerTable.setWriteBufferSize(DEFAULT_WRITE_BUFFER_SIZE); consumerTable.setAutoFlushTo(false); return consumerTable; }
@Override protected void dropTable(TableId tableId) throws IOException { try (HBaseDDLExecutor ddlExecutor = ddlExecutorFactory.get(); HBaseAdmin admin = new HBaseAdmin(hConf)) { TableId hBaseTableId = tableUtil.createHTableId(new NamespaceId(tableId.getNamespace()), tableId.getTableName()); if (tableUtil.tableExists(admin, hBaseTableId)) { tableUtil.dropTable(ddlExecutor, hBaseTableId); } } }
private static void dumpReplicationStateTable() throws Exception { System.out.println("\nThis is all the HBase regions on the Cluster:"); HBaseTableUtil tableUtil = new HBaseTableUtilFactory(cConf).get(); HTable hTable = tableUtil.createHTable(hConf, getReplicationStateTableId(tableUtil)); 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)); Result result; try (ResultScanner resultScanner = hTable.getScanner(scan.build())) { 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); } } finally { hTable.close(); } }
createTable(tableId); try (HTable table = new HBaseTableUtilFactory(cConf).get().createHTable(conf, tableId)) { byte[] colA = Bytes.toBytes("a"); byte[] row1 = Bytes.toBytes("row1"); table.put(tableUtil.buildPut(row1).add(FAMILY, colA, ts++, Bytes.toBytes(5L)).build()); table.put(tableUtil.buildPut(row2).add(FAMILY, colB, ts++, Bytes.toBytes(10L)).build());
@Override public void create() throws IOException { String columnFamily = Bytes.toString(TableProperties.getColumnFamilyBytes(spec.getProperties())); ColumnFamilyDescriptorBuilder cfdBuilder = HBaseTableUtil.getColumnFamilyDescriptorBuilder(columnFamily, hConf); final TableDescriptorBuilder tdBuilder = HBaseTableUtil.getTableDescriptorBuilder(tableId, cConf); Map<String, String> permissions = TableProperties.getTablePermissions(spec.getProperties()); if (permissions != null && !permissions.isEmpty()) { tableUtil.grantPermissions(ddlExecutor, tableId, permissions);
public void upgradePayloadTable(String tableName) throws IOException { upgradeCoProcessor(tableUtil.createHTableId(NamespaceId.SYSTEM, tableName), tableUtil.getPayloadTableRegionObserverClassForVersion()); }
public void upgradeMessageTable(String tableName) throws IOException { upgradeCoProcessor(tableUtil.createHTableId(NamespaceId.SYSTEM, tableName), tableUtil.getMessageTableRegionObserverClassForVersion()); }
@Test public void testCustomNamespaceMap() throws Exception { final String tableName = "mytable"; Assert.assertEquals(HBASE_NS, getTableUtil().getHBaseNamespace(new NamespaceId(CDAP_NS))); Assert.assertFalse(getTableUtil().hasNamespace(hAdmin, HBASE_NS)); createNamespace(CDAP_NS); // Check if namespace was created - in actual run, custom namespaces' lifecycle is managed by the user and hence // we won't create the namespace Assert.assertTrue(getTableUtil().hasNamespace(hAdmin, HBASE_NS)); TableId tableId = TableId.from(CDAP_NS, tableName); create(tableId); List<TableId> actualTableIds = getTableUtil().listTablesInNamespace(hAdmin, HBASE_NS); Assert.assertEquals(1, actualTableIds.size()); getTableUtil().deleteAllInNamespace(ddlExecutor, HBASE_NS, hAdmin.getConfiguration()); actualTableIds = getTableUtil().listTablesInNamespace(hAdmin, HBASE_NS); Assert.assertTrue(actualTableIds.isEmpty()); deleteNamespace(CDAP_NS); Assert.assertFalse(getTableUtil().hasNamespace(hAdmin, HBASE_NS)); }