Search in sources :

Example 71 with NamespaceDescriptor

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);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) HashSet(java.util.HashSet)

Example 72 with NamespaceDescriptor

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);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) Test(org.junit.Test)

Example 73 with NamespaceDescriptor

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);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) IOException(java.io.IOException) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) TableExistsException(org.apache.hadoop.hbase.TableExistsException) IOException(java.io.IOException) ConstraintException(org.apache.hadoop.hbase.constraint.ConstraintException) Test(org.junit.Test)

Example 74 with NamespaceDescriptor

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));
}
Also used : Table(org.apache.hadoop.hbase.client.Table) MasterThread(org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) Put(org.apache.hadoop.hbase.client.Put) Test(org.junit.Test)

Example 75 with NamespaceDescriptor

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));
}
Also used : NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) Test(org.junit.Test)

Aggregations

NamespaceDescriptor (org.apache.hadoop.hbase.NamespaceDescriptor)97 Test (org.junit.Test)51 TableName (org.apache.hadoop.hbase.TableName)26 IOException (java.io.IOException)17 Admin (org.apache.hadoop.hbase.client.Admin)15 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)13 ColumnFamilyDescriptor (org.apache.hadoop.hbase.client.ColumnFamilyDescriptor)11 TableDescriptorBuilder (org.apache.hadoop.hbase.client.TableDescriptorBuilder)11 QuotaExceededException (org.apache.hadoop.hbase.quotas.QuotaExceededException)9 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)8 Table (org.apache.hadoop.hbase.client.Table)8 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)7 NamespaceNotFoundException (org.apache.hadoop.hbase.NamespaceNotFoundException)7 Connection (org.apache.hadoop.hbase.client.Connection)7 ConstraintException (org.apache.hadoop.hbase.constraint.ConstraintException)7 RestoreSnapshotException (org.apache.hadoop.hbase.snapshot.RestoreSnapshotException)7 KeeperException (org.apache.zookeeper.KeeperException)7 ArrayList (java.util.ArrayList)6 ExecutionException (java.util.concurrent.ExecutionException)5 NamespaceExistException (org.apache.hadoop.hbase.NamespaceExistException)5