Search in sources :

Example 1 with NamespaceNotFoundException

use of org.apache.hadoop.hbase.NamespaceNotFoundException in project hbase by apache.

the class RestoreTool method checkAndCreateTable.

/**
 * Prepare the table for bulkload, most codes copied from {@code createTable} method in
 * {@code BulkLoadHFilesTool}.
 * @param conn connection
 * @param tableBackupPath path
 * @param tableName table name
 * @param targetTableName target table name
 * @param regionDirList region directory list
 * @param htd table descriptor
 * @param truncateIfExists truncates table if exists
 * @throws IOException exception
 */
private void checkAndCreateTable(Connection conn, Path tableBackupPath, TableName tableName, TableName targetTableName, ArrayList<Path> regionDirList, TableDescriptor htd, boolean truncateIfExists) throws IOException {
    try (Admin admin = conn.getAdmin()) {
        boolean createNew = false;
        if (admin.tableExists(targetTableName)) {
            if (truncateIfExists) {
                LOG.info("Truncating exising target table '" + targetTableName + "', preserving region splits");
                admin.disableTable(targetTableName);
                admin.truncateTable(targetTableName, true);
            } else {
                LOG.info("Using exising target table '" + targetTableName + "'");
            }
        } else {
            createNew = true;
        }
        if (createNew) {
            LOG.info("Creating target table '" + targetTableName + "'");
            byte[][] keys = null;
            try {
                if (regionDirList == null || regionDirList.size() == 0) {
                    admin.createTable(htd);
                } else {
                    keys = generateBoundaryKeys(regionDirList);
                    // create table using table descriptor and region boundaries
                    admin.createTable(htd, keys);
                }
            } catch (NamespaceNotFoundException e) {
                LOG.warn("There was no namespace and the same will be created");
                String namespaceAsString = targetTableName.getNamespaceAsString();
                LOG.info("Creating target namespace '" + namespaceAsString + "'");
                admin.createNamespace(NamespaceDescriptor.create(namespaceAsString).build());
                if (null == keys) {
                    admin.createTable(htd);
                } else {
                    admin.createTable(htd, keys);
                }
            }
        }
        long startTime = EnvironmentEdgeManager.currentTime();
        while (!admin.isTableAvailable(targetTableName)) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException ie) {
                Thread.currentThread().interrupt();
            }
            if (EnvironmentEdgeManager.currentTime() - startTime > TABLE_AVAILABILITY_WAIT_TIME) {
                throw new IOException("Time out " + TABLE_AVAILABILITY_WAIT_TIME + "ms expired, table " + targetTableName + " is still not available");
            }
        }
    }
}
Also used : IOException(java.io.IOException) Admin(org.apache.hadoop.hbase.client.Admin) NamespaceNotFoundException(org.apache.hadoop.hbase.NamespaceNotFoundException)

Example 2 with NamespaceNotFoundException

use of org.apache.hadoop.hbase.NamespaceNotFoundException in project hbase by apache.

the class DeleteNamespaceProcedure method prepareDelete.

/**
 * Action before any real action of deleting namespace.
 * @param env MasterProcedureEnv
 */
private boolean prepareDelete(final MasterProcedureEnv env) throws IOException {
    if (getTableNamespaceManager(env).doesNamespaceExist(namespaceName) == false) {
        setFailure("master-delete-namespace", new NamespaceNotFoundException(namespaceName));
        return false;
    }
    if (NamespaceDescriptor.RESERVED_NAMESPACES.contains(namespaceName)) {
        setFailure("master-delete-namespace", new ConstraintException("Reserved namespace " + namespaceName + " cannot be removed."));
        return false;
    }
    int tableCount = 0;
    try {
        tableCount = env.getMasterServices().listTableDescriptorsByNamespace(namespaceName).size();
    } catch (FileNotFoundException fnfe) {
        setFailure("master-delete-namespace", new NamespaceNotFoundException(namespaceName));
        return false;
    }
    if (tableCount > 0) {
        setFailure("master-delete-namespace", new ConstraintException("Only empty namespaces can be removed. Namespace " + namespaceName + " has " + tableCount + " tables"));
        return false;
    }
    // This is used for rollback
    nsDescriptor = getTableNamespaceManager(env).get(namespaceName);
    return true;
}
Also used : FileNotFoundException(java.io.FileNotFoundException) NamespaceNotFoundException(org.apache.hadoop.hbase.NamespaceNotFoundException) ConstraintException(org.apache.hadoop.hbase.constraint.ConstraintException)

Example 3 with NamespaceNotFoundException

use of org.apache.hadoop.hbase.NamespaceNotFoundException in project hbase by apache.

the class TestModifyNamespaceProcedure method testModifyNonExistNamespace.

@Test
public void testModifyNonExistNamespace() throws Exception {
    final String namespaceName = "testModifyNonExistNamespace";
    final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
    try {
        NamespaceDescriptor nsDescriptor = UTIL.getAdmin().getNamespaceDescriptor(namespaceName);
        assertNull(nsDescriptor);
    } catch (NamespaceNotFoundException nsnfe) {
        // Expected
        LOG.debug("The namespace " + namespaceName + " does not exist.  This is expected.");
    }
    final NamespaceDescriptor nsd = NamespaceDescriptor.create(namespaceName).build();
    long procId = procExec.submitProcedure(new ModifyNamespaceProcedure(procExec.getEnvironment(), nsd));
    // Wait the completion
    ProcedureTestingUtility.waitProcedure(procExec, procId);
    // Expect fail with NamespaceNotFoundException
    Procedure<?> result = procExec.getResult(procId);
    assertTrue(result.isFailed());
    LOG.debug("modify namespace failed with exception: " + result.getException());
    assertTrue(ProcedureTestingUtility.getExceptionCause(result) instanceof NamespaceNotFoundException);
}
Also used : NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) NamespaceNotFoundException(org.apache.hadoop.hbase.NamespaceNotFoundException) Test(org.junit.Test)

Example 4 with NamespaceNotFoundException

use of org.apache.hadoop.hbase.NamespaceNotFoundException in project hbase by apache.

the class TestQuotaObserverChoreWithMiniCluster method testTableQuotaOverridesNamespaceQuota.

@Test
public void testTableQuotaOverridesNamespaceQuota() throws Exception {
    final String namespace = testName.getMethodName();
    final Admin admin = TEST_UTIL.getAdmin();
    // Ensure the namespace exists
    try {
        admin.getNamespaceDescriptor(namespace);
    } catch (NamespaceNotFoundException e) {
        NamespaceDescriptor desc = NamespaceDescriptor.create(namespace).build();
        admin.createNamespace(desc);
    }
    TableName tn1 = helper.createTableWithRegions(namespace, 5);
    TableName tn2 = helper.createTableWithRegions(namespace, 5);
    final long namespaceSizeLimit = 3L * SpaceQuotaHelperForTests.ONE_MEGABYTE;
    final SpaceViolationPolicy namespaceViolationPolicy = SpaceViolationPolicy.DISABLE;
    QuotaSettings namespaceSettings = QuotaSettingsFactory.limitNamespaceSpace(namespace, namespaceSizeLimit, namespaceViolationPolicy);
    admin.setQuota(namespaceSettings);
    helper.writeData(tn1, 2L * SpaceQuotaHelperForTests.ONE_MEGABYTE);
    admin.flush(tn1);
    Map<TableName, SpaceQuotaSnapshot> snapshots = snapshotNotifier.copySnapshots();
    for (int i = 0; i < 5; i++) {
        // Check a few times to make sure we don't prematurely move to violation
        assertEquals("Should not see any quota violations after writing 2MB of data: " + snapshots, 0, numSnapshotsInViolation(snapshots));
        try {
            Thread.sleep(DEFAULT_WAIT_MILLIS);
        } catch (InterruptedException e) {
            LOG.debug("Interrupted while sleeping.", e);
        }
        snapshots = snapshotNotifier.copySnapshots();
    }
    helper.writeData(tn2, 2L * SpaceQuotaHelperForTests.ONE_MEGABYTE);
    admin.flush(tn2);
    snapshots = snapshotNotifier.copySnapshots();
    while (numSnapshotsInViolation(snapshots) < 2) {
        LOG.debug("Saw fewer violations than desired (expected 2): " + snapshots + ". Current reports: " + master.getMasterQuotaManager().snapshotRegionSizes());
        try {
            Thread.sleep(DEFAULT_WAIT_MILLIS);
        } catch (InterruptedException e) {
            LOG.debug("Interrupted while sleeping.", e);
            Thread.currentThread().interrupt();
        }
        snapshots = snapshotNotifier.copySnapshots();
    }
    SpaceQuotaSnapshot actualPolicyTN1 = snapshots.get(tn1);
    assertNotNull("Expected to see violation policy for tn1", actualPolicyTN1);
    assertEquals(namespaceViolationPolicy, actualPolicyTN1.getQuotaStatus().getPolicy().get());
    SpaceQuotaSnapshot actualPolicyTN2 = snapshots.get(tn2);
    assertNotNull("Expected to see violation policy for tn2", actualPolicyTN2);
    assertEquals(namespaceViolationPolicy, actualPolicyTN2.getQuotaStatus().getPolicy().get());
    // Override the namespace quota with a table quota
    final long tableSizeLimit = SpaceQuotaHelperForTests.ONE_MEGABYTE;
    final SpaceViolationPolicy tableViolationPolicy = SpaceViolationPolicy.NO_INSERTS;
    QuotaSettings tableSettings = QuotaSettingsFactory.limitTableSpace(tn1, tableSizeLimit, tableViolationPolicy);
    admin.setQuota(tableSettings);
    // Keep checking for the table quota policy to override the namespace quota
    while (true) {
        snapshots = snapshotNotifier.copySnapshots();
        SpaceQuotaSnapshot actualTableSnapshot = snapshots.get(tn1);
        assertNotNull("Violation policy should never be null", actualTableSnapshot);
        if (tableViolationPolicy != actualTableSnapshot.getQuotaStatus().getPolicy().orElse(null)) {
            LOG.debug("Saw unexpected table violation policy, waiting and re-checking.");
            try {
                Thread.sleep(DEFAULT_WAIT_MILLIS);
            } catch (InterruptedException e) {
                LOG.debug("Interrupted while sleeping");
                Thread.currentThread().interrupt();
            }
            continue;
        }
        assertEquals(tableViolationPolicy, actualTableSnapshot.getQuotaStatus().getPolicy().get());
        break;
    }
    // This should not change with the introduction of the table quota for tn1
    actualPolicyTN2 = snapshots.get(tn2);
    assertNotNull("Expected to see violation policy for tn2", actualPolicyTN2);
    assertEquals(namespaceViolationPolicy, actualPolicyTN2.getQuotaStatus().getPolicy().get());
}
Also used : TableName(org.apache.hadoop.hbase.TableName) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) Admin(org.apache.hadoop.hbase.client.Admin) NamespaceNotFoundException(org.apache.hadoop.hbase.NamespaceNotFoundException) Test(org.junit.Test)

Example 5 with NamespaceNotFoundException

use of org.apache.hadoop.hbase.NamespaceNotFoundException in project hbase by apache.

the class TestDeleteNamespaceProcedure method testDeleteNonExistNamespace.

@Test(timeout = 60000)
public void testDeleteNonExistNamespace() throws Exception {
    final String namespaceName = "testDeleteNonExistNamespace";
    final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
    validateNamespaceNotExist(namespaceName);
    long procId = procExec.submitProcedure(new DeleteNamespaceProcedure(procExec.getEnvironment(), namespaceName));
    // Wait the completion
    ProcedureTestingUtility.waitProcedure(procExec, procId);
    // Expect fail with NamespaceNotFoundException
    ProcedureInfo result = procExec.getResult(procId);
    assertTrue(result.isFailed());
    LOG.debug("Delete namespace failed with exception: " + result.getExceptionFullMessage());
    assertTrue(ProcedureTestingUtility.getExceptionCause(result) instanceof NamespaceNotFoundException);
}
Also used : ProcedureInfo(org.apache.hadoop.hbase.ProcedureInfo) NamespaceNotFoundException(org.apache.hadoop.hbase.NamespaceNotFoundException) Test(org.junit.Test)

Aggregations

NamespaceNotFoundException (org.apache.hadoop.hbase.NamespaceNotFoundException)10 Test (org.junit.Test)6 NamespaceDescriptor (org.apache.hadoop.hbase.NamespaceDescriptor)5 Admin (org.apache.hadoop.hbase.client.Admin)3 TableName (org.apache.hadoop.hbase.TableName)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 Properties (java.util.Properties)1 ProcedureInfo (org.apache.hadoop.hbase.ProcedureInfo)1 HBaseAdmin (org.apache.hadoop.hbase.client.HBaseAdmin)1 ConstraintException (org.apache.hadoop.hbase.constraint.ConstraintException)1 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)1 SchemaNotFoundException (org.apache.phoenix.schema.SchemaNotFoundException)1