@Override public HTableDescriptor getTableDescriptor(String tableString) throws TableNotFoundException, IOException { return adm.getTableDescriptor(TableName.valueOf(tableString)); }
public void check(List<String> segFullNameList) { issueExistHTables = Lists.newArrayList(); inconsistentHTables = Lists.newArrayList(); for (String segFullName : segFullNameList) { String[] sepNameList = segFullName.split(","); try { HTableDescriptor hTableDescriptor = hbaseAdmin.getTableDescriptor(TableName.valueOf(sepNameList[0])); String host = hTableDescriptor.getValue(IRealizationConstants.HTableTag); if (!dstCfg.getMetadataUrlPrefix().equalsIgnoreCase(host)) { inconsistentHTables.add(segFullName); } } catch (IOException e) { issueExistHTables.add(segFullName); continue; } } }
private void updateHtable(String tableName) throws IOException { HTableDescriptor desc = hbaseAdmin.getTableDescriptor(TableName.valueOf(tableName)); if (oldHostValue.equals(desc.getValue(IRealizationConstants.HTableTag))) { desc.setValue(IRealizationConstants.HTableTag, kylinConfig.getMetadataUrlPrefix()); hbaseAdmin.disableTable(TableName.valueOf(tableName)); hbaseAdmin.modifyTable(TableName.valueOf(tableName), desc); hbaseAdmin.enableTable(TableName.valueOf(tableName)); updatedResources.add(tableName); } }
@Override protected String createMetaStoreUUID() throws IOException { try (final Admin hbaseAdmin = HBaseConnection.get(metadataUrl).getAdmin()) { final String metaStoreName = metadataUrl.getIdentifier(); final HTableDescriptor desc = hbaseAdmin.getTableDescriptor(TableName.valueOf(metaStoreName)); String uuid = desc.getValue(HBaseConnection.HTABLE_UUID_TAG); if (uuid != null) return uuid; return UUID.randomUUID().toString(); } catch (Exception e) { return null; } }
@Override public void call(Admin admin) throws Exception { admin.getTableDescriptor(TableName.valueOf(name.getMethodName())); } @Override
protected HColumnDescriptor getColumnDesc(Admin admin) throws TableNotFoundException, IOException { return admin.getTableDescriptor(TABLE).getFamily(CF); }
/** * Allows to set HTableDescriptor * * @param connection with a server * @param tableName the name of table */ protected void setTableDesc(Connection connection, String tableName) { try { tableDesc = connection.getAdmin().getTableDescriptor(TableName.valueOf(tableName)); } catch (IOException e) { throw UserException.dataReadError() .message("Failure while loading table %s in database %s.", tableName, getStorageEngineName()) .addContext("Message: ", e.getMessage()) .build(logger); } }
@Override public Object run() throws Exception { try (Connection conn = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration()); Admin admin = conn.getAdmin()) { return admin.getTableDescriptor(TEST_TABLE); } } };
/** * Set the number of Region replicas. */ public static void setReplicas(Admin admin, TableName table, int replicaCount) throws IOException, InterruptedException { admin.disableTable(table); HTableDescriptor desc = new HTableDescriptor(admin.getTableDescriptor(table)); desc.setRegionReplication(replicaCount); admin.modifyTable(desc.getTableName(), desc); admin.enableTable(table); }
private void modifyTableSync(Admin admin, TableName tableName, HTableDescriptor htd) throws IOException { admin.modifyTable(tableName, htd); //wait until modify table finishes for (int t = 0; t < 100; t++) { //10 sec timeout HTableDescriptor td = admin.getTableDescriptor(htd.getTableName()); if (td.equals(htd)) { break; } Threads.sleep(100); } }
@Test public void testMetaHTDReplicaCount() throws Exception { assertTrue(TEST_UTIL.getAdmin().getTableDescriptor(TableName.META_TABLE_NAME) .getRegionReplication() == 3); }
private void undeployRegions(HbckInfo hi) throws IOException, InterruptedException { undeployRegionsForHbi(hi); // undeploy replicas of the region (but only if the method is invoked for the primary) if (hi.getReplicaId() != RegionInfo.DEFAULT_REPLICA_ID) { return; } int numReplicas = admin.getTableDescriptor(hi.getTableName()).getRegionReplication(); for (int i = 1; i < numReplicas; i++) { if (hi.getPrimaryHRIForDeployedReplica() == null) continue; RegionInfo hri = RegionReplicaUtil.getRegionInfoForReplica( hi.getPrimaryHRIForDeployedReplica(), i); HbckInfo h = regionInfoMap.get(hri.getEncodedName()); if (h != null) { undeployRegionsForHbi(h); //set skip checks; we undeployed it, and we don't want to evaluate this anymore //in consistency checks h.setSkipChecks(true); } } }
@Test public void disableNotFullReplication() throws Exception { HTableDescriptor table = new HTableDescriptor(admin2.getTableDescriptor(tableName)); HColumnDescriptor f = new HColumnDescriptor("notReplicatedFamily"); table.addFamily(f); admin1.disableTable(tableName); admin1.modifyTable(tableName, table); admin1.enableTable(tableName); admin1.disableTableReplication(tableName); table = admin1.getTableDescriptor(tableName); for (HColumnDescriptor fam : table.getColumnFamilies()) { assertEquals(HConstants.REPLICATION_SCOPE_LOCAL, fam.getScope()); } admin1.deleteColumnFamily(table.getTableName(), f.getName()); }
private void alter() throws IOException { Connection conn = HBaseConnection.get(KylinConfig.getInstanceFromEnv().getStorageUrl()); Admin hbaseAdmin = null; try { hbaseAdmin = conn.getAdmin(); HTableDescriptor table = hbaseAdmin.getTableDescriptor(TableName.valueOf(tableName)); hbaseAdmin.disableTable(table.getTableName()); table.setValue(metadataKey, metadataValue); hbaseAdmin.modifyTable(table.getTableName(), table); hbaseAdmin.enableTable(table.getTableName()); } finally { if (hbaseAdmin != null) { hbaseAdmin.close(); } } }
@Test public void testDisableAndEnableReplication() throws Exception { admin1.disableTableReplication(tableName); HTableDescriptor table = admin1.getTableDescriptor(tableName); for (HColumnDescriptor fam : table.getColumnFamilies()) { assertEquals(HConstants.REPLICATION_SCOPE_LOCAL, fam.getScope()); } admin1.enableTableReplication(tableName); table = admin1.getTableDescriptor(tableName); for (HColumnDescriptor fam : table.getColumnFamilies()) { assertEquals(HConstants.REPLICATION_SCOPE_GLOBAL, fam.getScope()); } }
@Test public void createDoubleTest() throws IOException, InterruptedException { String nsName = prefix + "_" + name.getMethodName(); LOG.info(name.getMethodName()); final TableName tableName = TableName.valueOf(name.getMethodName()); final TableName tableNameFoo = TableName.valueOf(nsName + ":" + name.getMethodName()); //create namespace and verify admin.createNamespace(NamespaceDescriptor.create(nsName).build()); TEST_UTIL.createTable(tableName, Bytes.toBytes(nsName)); TEST_UTIL.createTable(tableNameFoo,Bytes.toBytes(nsName)); assertEquals(2, admin.listTables().length); assertNotNull(admin .getTableDescriptor(tableName)); assertNotNull(admin .getTableDescriptor(tableNameFoo)); //remove namespace and verify admin.disableTable(tableName); admin.deleteTable(tableName); assertEquals(1, admin.listTables().length); }
@Test public void testEnableReplicationWhenReplicationNotEnabled() throws Exception { HTableDescriptor table = new HTableDescriptor(admin1.getTableDescriptor(tableName)); for (HColumnDescriptor fam : table.getColumnFamilies()) { fam.setScope(HConstants.REPLICATION_SCOPE_LOCAL); } admin1.disableTable(tableName); admin1.modifyTable(tableName, table); admin1.enableTable(tableName); admin2.disableTable(tableName); admin2.modifyTable(tableName, table); admin2.enableTable(tableName); admin1.enableTableReplication(tableName); table = admin1.getTableDescriptor(tableName); for (HColumnDescriptor fam : table.getColumnFamilies()) { assertEquals(HConstants.REPLICATION_SCOPE_GLOBAL, fam.getScope()); } }
@Override protected void initTable() throws IOException { super.initTable(); TableName tableName = getTablename(); try (Connection connection = ConnectionFactory.createConnection(); Admin admin = connection.getAdmin()) { HTableDescriptor tableDesc = admin.getTableDescriptor(tableName); LOG.info("Disabling table " + getTablename()); admin.disableTable(tableName); ColumnFamilyDescriptor mobColumn = tableDesc.getColumnFamily(mobColumnFamily); ColumnFamilyDescriptor cfd = ColumnFamilyDescriptorBuilder.newBuilder(mobColumn) .setMobEnabled(true) .setMobThreshold((long) threshold) .build(); admin.modifyColumnFamily(tableName, cfd); LOG.info("Enabling table " + getTablename()); admin.enableTable(tableName); } }
private void validateSnapshotRestore() throws IOException { try { UTIL.getAdmin().enableTable(snapshotTableName); HTableDescriptor currentHTD = UTIL.getAdmin().getTableDescriptor(snapshotTableName); assertTrue(currentHTD.hasFamily(CF1)); assertTrue(currentHTD.hasFamily(CF2)); assertFalse(currentHTD.hasFamily(CF3)); assertFalse(currentHTD.hasFamily(CF4)); assertEquals(currentHTD.getFamiliesKeys().size(), snapshotHTD.getFamiliesKeys().size()); SnapshotTestingUtils.verifyRowCount(UTIL, snapshotTableName, rowCountCF1 + rowCountCF2); } finally { UTIL.getAdmin().disableTable(snapshotTableName); } } }
private void verifyTableDescriptor(final TableName tableName, final byte[]... families) throws IOException { Admin admin = TEST_UTIL.getAdmin(); // Verify descriptor from master HTableDescriptor htd = admin.getTableDescriptor(tableName); verifyTableDescriptor(htd, tableName, families); // Verify descriptor from HDFS MasterFileSystem mfs = TEST_UTIL.getMiniHBaseCluster().getMaster().getMasterFileSystem(); Path tableDir = FSUtils.getTableDir(mfs.getRootDir(), tableName); TableDescriptor td = FSTableDescriptors.getTableDescriptorFromFs(mfs.getFileSystem(), tableDir); verifyTableDescriptor(td, tableName, families); }