use of org.apache.hadoop.hbase.NamespaceNotFoundException in project phoenix by apache.
the class DropSchemaIT method testDropSchema.
@Test
public void testDropSchema() throws Exception {
String tableName = generateUniqueName();
Properties props = new Properties();
props.setProperty(QueryServices.IS_NAMESPACE_MAPPING_ENABLED, Boolean.toString(true));
String normalizeSchemaIdentifier = SchemaUtil.normalizeIdentifier(schema);
String ddl = "DROP SCHEMA " + schema;
try (Connection conn = DriverManager.getConnection(getUrl(), props);
HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
try {
conn.createStatement().execute(ddl);
fail();
} catch (SchemaNotFoundException e) {
// expected
}
conn.createStatement().execute("CREATE SCHEMA " + schema);
conn.createStatement().execute("CREATE TABLE " + schema + "." + tableName + "(id INTEGER PRIMARY KEY)");
try {
conn.createStatement().execute(ddl);
fail();
} catch (SQLException e) {
assertEquals(e.getErrorCode(), SQLExceptionCode.CANNOT_MUTATE_SCHEMA.getErrorCode());
}
assertNotNull(admin.getNamespaceDescriptor(normalizeSchemaIdentifier));
conn.createStatement().execute("DROP TABLE " + schema + "." + tableName);
conn.createStatement().execute(ddl);
try {
admin.getNamespaceDescriptor(normalizeSchemaIdentifier);
fail();
} catch (NamespaceNotFoundException ne) {
// expected
}
conn.createStatement().execute("DROP SCHEMA IF EXISTS " + schema);
admin.createNamespace(NamespaceDescriptor.create(normalizeSchemaIdentifier).build());
conn.createStatement().execute("DROP SCHEMA IF EXISTS " + schema);
assertNotNull(admin.getNamespaceDescriptor(normalizeSchemaIdentifier));
conn.createStatement().execute("CREATE SCHEMA " + schema);
conn.createStatement().execute("DROP SCHEMA " + schema);
try {
conn.createStatement().execute("DROP SCHEMA " + schema);
fail();
} catch (SQLException e) {
assertEquals(e.getErrorCode(), SQLExceptionCode.SCHEMA_NOT_FOUND.getErrorCode());
}
}
}
use of org.apache.hadoop.hbase.NamespaceNotFoundException in project hbase by apache.
the class ModifyNamespaceProcedure method prepareModify.
/**
* Action before any real action of adding namespace.
*/
private boolean prepareModify(final MasterProcedureEnv env) throws IOException {
if (!getTableNamespaceManager(env).doesNamespaceExist(newNsDescriptor.getName())) {
setFailure("master-modify-namespace", new NamespaceNotFoundException(newNsDescriptor.getName()));
return false;
}
getTableNamespaceManager(env).validateTableAndRegionCount(newNsDescriptor);
// This is used for rollback
oldNsDescriptor = getTableNamespaceManager(env).get(newNsDescriptor.getName());
if (!Objects.equals(oldNsDescriptor.getConfigurationValue(RSGroupInfo.NAMESPACE_DESC_PROP_GROUP), newNsDescriptor.getConfigurationValue(RSGroupInfo.NAMESPACE_DESC_PROP_GROUP))) {
checkNamespaceRSGroup(env, newNsDescriptor);
}
return true;
}
use of org.apache.hadoop.hbase.NamespaceNotFoundException in project hbase by apache.
the class TestQuotaObserverChoreWithMiniCluster method testNamespaceViolatesQuota.
@Test
public void testNamespaceViolatesQuota() 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);
TableName tn3 = helper.createTableWithRegions(namespace, 5);
final long sizeLimit = 5L * SpaceQuotaHelperForTests.ONE_MEGABYTE;
final SpaceViolationPolicy violationPolicy = SpaceViolationPolicy.DISABLE;
QuotaSettings settings = QuotaSettingsFactory.limitNamespaceSpace(namespace, sizeLimit, violationPolicy);
admin.setQuota(settings);
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", 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();
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 4MB of data", 0, numSnapshotsInViolation(snapshots));
try {
Thread.sleep(DEFAULT_WAIT_MILLIS);
} catch (InterruptedException e) {
LOG.debug("Interrupted while sleeping.", e);
}
snapshots = snapshotNotifier.copySnapshots();
}
// Writing the final 2MB of data will push the namespace over the 5MB limit (6MB in total)
// and should push all three tables in the namespace into violation.
helper.writeData(tn3, 2L * SpaceQuotaHelperForTests.ONE_MEGABYTE);
admin.flush(tn3);
snapshots = snapshotNotifier.copySnapshots();
while (numSnapshotsInViolation(snapshots) < 3) {
LOG.debug("Saw fewer violations than desired (expected 3): " + 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 snapshot1 = snapshots.remove(tn1);
assertNotNull("tn1 should be in violation", snapshot1);
assertEquals(violationPolicy, snapshot1.getQuotaStatus().getPolicy().get());
SpaceQuotaSnapshot snapshot2 = snapshots.remove(tn2);
assertNotNull("tn2 should be in violation", snapshot2);
assertEquals(violationPolicy, snapshot2.getQuotaStatus().getPolicy().get());
SpaceQuotaSnapshot snapshot3 = snapshots.remove(tn3);
assertNotNull("tn3 should be in violation", snapshot3);
assertEquals(violationPolicy, snapshot3.getQuotaStatus().getPolicy().get());
assertTrue("Unexpected additional quota violations: " + snapshots, snapshots.isEmpty());
}
use of org.apache.hadoop.hbase.NamespaceNotFoundException in project hbase by apache.
the class TestDeleteNamespaceProcedure method validateNamespaceNotExist.
public static void validateNamespaceNotExist(final String nsName) throws IOException {
try {
NamespaceDescriptor nsDescriptor = UTIL.getAdmin().getNamespaceDescriptor(nsName);
assertNull(nsDescriptor);
} catch (NamespaceNotFoundException nsnfe) {
// Expected
}
}
use of org.apache.hadoop.hbase.NamespaceNotFoundException in project hbase by apache.
the class TestCreateNamespaceProcedure method testRollbackAndDoubleExecution.
@Test
public void testRollbackAndDoubleExecution() throws Exception {
final NamespaceDescriptor nsd = NamespaceDescriptor.create("testRollbackAndDoubleExecution").build();
final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
ProcedureTestingUtility.waitNoProcedureRunning(procExec);
ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, true);
// Start the CreateNamespace procedure && kill the executor
long procId = procExec.submitProcedure(new CreateNamespaceProcedure(procExec.getEnvironment(), nsd));
// failing before CREATE_NAMESPACE_CREATE_DIRECTORY
int lastStep = 2;
MasterProcedureTestingUtility.testRollbackAndDoubleExecution(procExec, procId, lastStep);
// Validate the non-existence of namespace
try {
NamespaceDescriptor nsDescriptor = UTIL.getAdmin().getNamespaceDescriptor(nsd.getName());
assertNull(nsDescriptor);
} catch (NamespaceNotFoundException nsnfe) {
// Expected
LOG.info("The namespace " + nsd.getName() + " is not created.");
}
}
Aggregations