use of org.apache.hadoop.hbase.NamespaceDescriptor in project hbase by apache.
the class TestRSGroupsBase method removeGroup.
protected final void removeGroup(String groupName) throws IOException {
Set<TableName> tables = new HashSet<>();
for (TableDescriptor td : ADMIN.listTableDescriptors(true)) {
RSGroupInfo groupInfo = ADMIN.getRSGroup(td.getTableName());
if (groupInfo != null && groupInfo.getName().equals(groupName)) {
tables.add(td.getTableName());
}
}
ADMIN.setRSGroup(tables, RSGroupInfo.DEFAULT_GROUP);
for (NamespaceDescriptor nd : ADMIN.listNamespaceDescriptors()) {
if (groupName.equals(nd.getConfigurationValue(RSGroupInfo.NAMESPACE_DESC_PROP_GROUP))) {
nd.removeConfiguration(RSGroupInfo.NAMESPACE_DESC_PROP_GROUP);
ADMIN.modifyNamespace(nd);
}
}
RSGroupInfo groupInfo = ADMIN.getRSGroup(groupName);
ADMIN.moveServersToRSGroup(groupInfo.getServers(), RSGroupInfo.DEFAULT_GROUP);
ADMIN.removeRSGroup(groupName);
}
use of org.apache.hadoop.hbase.NamespaceDescriptor in project hbase by apache.
the class TestRSGroupsAdmin1 method testTableConstraint.
@Test
public void testTableConstraint() throws Exception {
String prefix = name.getMethodName();
String ns = prefix + "_ns";
TableName tableName = TableName.valueOf(ns + ":" + "t");
String nsGroup = prefix + "_nsg";
String tableGroup = prefix + "_tg";
addGroup(nsGroup, 1);
addGroup(tableGroup, 1);
ADMIN.createNamespace(NamespaceDescriptor.create(ns).build());
TEST_UTIL.createTable(tableName, "C");
TEST_UTIL.waitTableAvailable(tableName);
assertEquals(ADMIN.getRSGroup(tableName).getName(), RSGroupInfo.DEFAULT_GROUP);
// set table's rsgroup
TableDescriptor td = TableDescriptorBuilder.newBuilder(ADMIN.getDescriptor(tableName)).setRegionServerGroup(tableGroup).build();
ADMIN.modifyTable(td);
TEST_UTIL.waitUntilNoRegionsInTransition();
assertEquals(ADMIN.getRSGroup(tableName).getName(), tableGroup);
// set namespace's rsgroup
NamespaceDescriptor nd = NamespaceDescriptor.create(ADMIN.getNamespaceDescriptor(ns)).addConfiguration(RSGroupInfo.NAMESPACE_DESC_PROP_GROUP, nsGroup).build();
ADMIN.modifyNamespace(nd);
assertEquals(ADMIN.getRSGroup(tableName).getName(), tableGroup);
// clear table's rsgroup
td = TableDescriptorBuilder.newBuilder(ADMIN.getDescriptor(tableName)).setRegionServerGroup(null).build();
ADMIN.modifyTable(td);
TEST_UTIL.waitUntilNoRegionsInTransition();
assertEquals(ADMIN.getRSGroup(tableName).getName(), nsGroup);
TEST_UTIL.deleteTable(tableName);
ADMIN.deleteNamespace(ns);
}
use of org.apache.hadoop.hbase.NamespaceDescriptor in project hbase by apache.
the class TestRSGroupsAdmin1 method testRSGroupListDoesNotContainFailedTableCreation.
@Test
public void testRSGroupListDoesNotContainFailedTableCreation() throws Exception {
toggleQuotaCheckAndRestartMiniCluster(true);
String nsp = "np1";
NamespaceDescriptor nspDesc = NamespaceDescriptor.create(nsp).addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "5").addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "2").build();
ADMIN.createNamespace(nspDesc);
assertEquals(3, ADMIN.listNamespaceDescriptors().length);
ColumnFamilyDescriptor fam1 = ColumnFamilyDescriptorBuilder.of("fam1");
TableDescriptor tableDescOne = TableDescriptorBuilder.newBuilder(TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table1")).setColumnFamily(fam1).build();
ADMIN.createTable(tableDescOne);
TableDescriptor tableDescTwo = TableDescriptorBuilder.newBuilder(TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table2")).setColumnFamily(fam1).build();
boolean constraintViolated = false;
try {
ADMIN.createTable(tableDescTwo, Bytes.toBytes("AAA"), Bytes.toBytes("ZZZ"), 6);
fail("Creation table should fail because of quota violation.");
} catch (Exception exp) {
assertTrue(exp instanceof IOException);
constraintViolated = true;
} finally {
assertTrue("Constraint not violated for table " + tableDescTwo.getTableName(), constraintViolated);
}
List<RSGroupInfo> rsGroupInfoList = ADMIN.listRSGroups();
boolean foundTable2 = false;
boolean foundTable1 = false;
for (int i = 0; i < rsGroupInfoList.size(); i++) {
Set<TableName> tables = Sets.newHashSet(ADMIN.listTablesInRSGroup(rsGroupInfoList.get(i).getName()));
if (tables.contains(tableDescTwo.getTableName())) {
foundTable2 = true;
}
if (tables.contains(tableDescOne.getTableName())) {
foundTable1 = true;
}
}
assertFalse("Found table2 in rsgroup list.", foundTable2);
assertTrue("Did not find table1 in rsgroup list", foundTable1);
TEST_UTIL.deleteTable(tableDescOne.getTableName());
ADMIN.deleteNamespace(nspDesc.getName());
toggleQuotaCheckAndRestartMiniCluster(false);
}
use of org.apache.hadoop.hbase.NamespaceDescriptor in project hbase by apache.
the class TestMigrateNamespaceTable method testMigrate.
@Test
public void testMigrate() throws IOException, InterruptedException {
UTIL.getAdmin().createTable(TableDescriptorBuilder.NAMESPACE_TABLEDESC);
try (Table table = UTIL.getConnection().getTable(TableName.NAMESPACE_TABLE_NAME)) {
for (int i = 0; i < 5; i++) {
NamespaceDescriptor nd = NamespaceDescriptor.create("Test-NS-" + i).addConfiguration("key-" + i, "value-" + i).build();
table.put(new Put(Bytes.toBytes(nd.getName())).addColumn(TableDescriptorBuilder.NAMESPACE_FAMILY_INFO_BYTES, TableDescriptorBuilder.NAMESPACE_COL_DESC_BYTES, ProtobufUtil.toProtoNamespaceDescriptor(nd).toByteArray()));
AbstractStateMachineNamespaceProcedure.createDirectory(UTIL.getMiniHBaseCluster().getMaster().getMasterFileSystem(), nd);
}
}
MasterThread masterThread = UTIL.getMiniHBaseCluster().getMasterThread();
masterThread.getMaster().stop("For testing");
masterThread.join();
UTIL.getMiniHBaseCluster().startMaster();
// 5 + default and system('hbase')
assertEquals(7, UTIL.getAdmin().listNamespaceDescriptors().length);
for (int i = 0; i < 5; i++) {
NamespaceDescriptor nd = UTIL.getAdmin().getNamespaceDescriptor("Test-NS-" + i);
assertEquals("Test-NS-" + i, nd.getName());
assertEquals(1, nd.getConfiguration().size());
assertEquals("value-" + i, nd.getConfigurationValue("key-" + i));
}
UTIL.waitFor(30000, () -> UTIL.getAdmin().isTableDisabled(TableName.NAMESPACE_TABLE_NAME));
masterThread = UTIL.getMiniHBaseCluster().getMasterThread();
masterThread.getMaster().stop("For testing");
masterThread.join();
UTIL.getMiniHBaseCluster().startMaster();
// make sure that we could still restart the cluster after disabling the namespace table.
assertEquals(7, UTIL.getAdmin().listNamespaceDescriptors().length);
// let's delete the namespace table
UTIL.getAdmin().deleteTable(TableName.NAMESPACE_TABLE_NAME);
assertFalse(UTIL.getAdmin().tableExists(TableName.NAMESPACE_TABLE_NAME));
}
use of org.apache.hadoop.hbase.NamespaceDescriptor in project hbase by apache.
the class TestModifyNamespaceProcedure method testRollbackAndDoubleExecution.
@Test
public void testRollbackAndDoubleExecution() throws Exception {
final NamespaceDescriptor nsd = NamespaceDescriptor.create("testRollbackAndDoubleExecution").build();
final String nsKey = "foo";
final String nsValue = "bar";
final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
createNamespaceForTesting(nsd);
ProcedureTestingUtility.waitNoProcedureRunning(procExec);
ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, true);
// Modify
// Start the Modify procedure && kill the executor
long procId = procExec.submitProcedure(new ModifyNamespaceProcedure(procExec.getEnvironment(), NamespaceDescriptor.create(nsd).addConfiguration(nsKey, nsValue).build()));
// failing before MODIFY_NAMESPACE_UPDATE_NS_TABLE
int lastStep = 2;
MasterProcedureTestingUtility.testRollbackAndDoubleExecution(procExec, procId, lastStep);
// Validate
NamespaceDescriptor currentNsDescriptor = UTIL.getAdmin().getNamespaceDescriptor(nsd.getName());
assertNull(currentNsDescriptor.getConfigurationValue(nsKey));
}
Aggregations