Search in sources :

Example 86 with NamespaceDescriptor

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

Example 87 with NamespaceDescriptor

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());
}
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 88 with NamespaceDescriptor

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

Example 89 with NamespaceDescriptor

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

Example 90 with NamespaceDescriptor

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

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