use of org.apache.hadoop.hbase.NamespaceDescriptor 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.NamespaceDescriptor 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.NamespaceDescriptor in project hbase by apache.
the class TestSpaceQuotaRemoval method testSetNamespaceSizeQuotaAndThenRemove.
@Test
public void testSetNamespaceSizeQuotaAndThenRemove() throws Exception {
Put put = new Put(Bytes.toBytes("to_reject"));
put.addColumn(Bytes.toBytes(SpaceQuotaHelperForTests.F1), Bytes.toBytes("to"), Bytes.toBytes("reject"));
SpaceViolationPolicy policy = SpaceViolationPolicy.NO_INSERTS;
// Create namespace
NamespaceDescriptor nsd = helper.createNamespace();
String ns = nsd.getName();
// Do puts until we violate space policy on table tn1
final TableName tn1 = helper.writeUntilViolationAndVerifyViolationInNamespace(ns, policy, put);
// Now, remove the quota from namespace
helper.removeQuotaFromNamespace(ns);
// Put a new row now on tn1: should not violate as quota settings removed from namespace
helper.verifyNoViolation(tn1, put);
}
use of org.apache.hadoop.hbase.NamespaceDescriptor in project hbase by apache.
the class TestSpaceQuotaRemoval method testDeleteTableUsageSnapshotsForNamespace.
@Test
public void testDeleteTableUsageSnapshotsForNamespace() throws Exception {
Put put = new Put(Bytes.toBytes("to_reject"));
put.addColumn(Bytes.toBytes(SpaceQuotaHelperForTests.F1), Bytes.toBytes("to"), Bytes.toBytes("reject"));
SpaceViolationPolicy policy = SpaceViolationPolicy.NO_INSERTS;
// Create a namespace
String ns1 = "nsnew";
NamespaceDescriptor nsd = helper.createNamespace(ns1);
// Create 2nd namespace with name similar to ns1
String ns2 = ns1 + "test";
NamespaceDescriptor nsd2 = helper.createNamespace(ns2);
// Do puts until we violate space policy on table tn1 in namesapce ns1
final TableName tn1 = helper.writeUntilViolationAndVerifyViolationInNamespace(ns1, policy, put);
// Do puts until we violate space policy on table tn2 in namespace ns2
final TableName tn2 = helper.writeUntilViolationAndVerifyViolationInNamespace(ns2, policy, put);
// Now, remove the quota from namespace ns1 which will remove table usage snapshots for ns1
helper.removeQuotaFromNamespace(ns1);
// Verify that table usage snapshot for table tn2 in namespace ns2 exist
helper.verifyTableUsageSnapshotForSpaceQuotaExist(tn2);
// Put a new row on tn2: should violate as space quota exists on namespace ns2
helper.verifyViolation(policy, tn2, put);
// Put a new row on tn1: should not violate as quota settings removed from namespace ns1
helper.verifyNoViolation(tn1, put);
}
use of org.apache.hadoop.hbase.NamespaceDescriptor in project hbase by apache.
the class TestReplicationEditsDroppedWithDroppedTable method setUpBeforeClass.
@BeforeClass
public static void setUpBeforeClass() throws Exception {
// Set true to filter replication edits for dropped table
conf1.setBoolean(HBaseInterClusterReplicationEndpoint.REPLICATION_DROP_ON_DELETED_TABLE_KEY, true);
conf1.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/1");
conf1.setInt("replication.source.nb.capacity", 1);
utility1 = new HBaseTestingUtil(conf1);
utility1.startMiniZKCluster();
MiniZooKeeperCluster miniZK = utility1.getZkCluster();
conf1 = utility1.getConfiguration();
conf2 = HBaseConfiguration.create(conf1);
conf2.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/2");
utility2 = new HBaseTestingUtil(conf2);
utility2.setZkCluster(miniZK);
utility1.startMiniCluster(1);
utility2.startMiniCluster(1);
admin1 = utility1.getAdmin();
admin2 = utility2.getAdmin();
NamespaceDescriptor nsDesc = NamespaceDescriptor.create(namespace).build();
admin1.createNamespace(nsDesc);
admin2.createNamespace(nsDesc);
}
Aggregations