Search in sources :

Example 6 with RestoreSnapshotException

use of org.apache.hadoop.hbase.snapshot.RestoreSnapshotException in project hbase by apache.

the class TestNamespaceAuditor method testRestoreSnapshotQuotaExceed.

@Test
public void testRestoreSnapshotQuotaExceed() throws Exception {
    String nsp = prefix + "_testRestoreSnapshotQuotaExceed";
    NamespaceDescriptor nspDesc = NamespaceDescriptor.create(nsp).addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "10").build();
    ADMIN.createNamespace(nspDesc);
    NamespaceDescriptor ndesc = ADMIN.getNamespaceDescriptor(nsp);
    assertNotNull("Namespace descriptor found null.", ndesc);
    TableName tableName1 = TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table1");
    HTableDescriptor tableDescOne = new HTableDescriptor(tableName1);
    HColumnDescriptor fam1 = new HColumnDescriptor("fam1");
    tableDescOne.addFamily(fam1);
    ADMIN.createTable(tableDescOne, Bytes.toBytes("AAA"), Bytes.toBytes("ZZZ"), 4);
    NamespaceTableAndRegionInfo nstate = getNamespaceState(nsp);
    assertEquals("Intial region count should be 4.", 4, nstate.getRegionCount());
    String snapshot = "snapshot_testRestoreSnapshotQuotaExceed";
    // snapshot has 4 regions
    ADMIN.snapshot(snapshot, tableName1);
    // recreate table with 1 region and set max regions to 3 for namespace
    ADMIN.disableTable(tableName1);
    ADMIN.deleteTable(tableName1);
    ADMIN.createTable(tableDescOne);
    ndesc.setConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "3");
    ADMIN.modifyNamespace(ndesc);
    ADMIN.disableTable(tableName1);
    try {
        ADMIN.restoreSnapshot(snapshot);
        fail("Region quota is exceeded so QuotaExceededException should be thrown but HBaseAdmin" + " wraps IOException into RestoreSnapshotException");
    } catch (RestoreSnapshotException ignore) {
        assertTrue(ignore.getCause() instanceof QuotaExceededException);
    }
    assertEquals(1, getNamespaceState(nsp).getRegionCount());
    ADMIN.enableTable(tableName1);
    ADMIN.deleteSnapshot(snapshot);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) QuotaExceededException(org.apache.hadoop.hbase.quotas.QuotaExceededException) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) RestoreSnapshotException(org.apache.hadoop.hbase.snapshot.RestoreSnapshotException) Test(org.junit.Test)

Aggregations

RestoreSnapshotException (org.apache.hadoop.hbase.snapshot.RestoreSnapshotException)6 IOException (java.io.IOException)5 TableName (org.apache.hadoop.hbase.TableName)5 ForeignException (org.apache.hadoop.hbase.errorhandling.ForeignException)3 HBaseSnapshotException (org.apache.hadoop.hbase.snapshot.HBaseSnapshotException)3 SnapshotCreationException (org.apache.hadoop.hbase.snapshot.SnapshotCreationException)3 UnknownSnapshotException (org.apache.hadoop.hbase.snapshot.UnknownSnapshotException)3 KeeperException (org.apache.zookeeper.KeeperException)3 FileNotFoundException (java.io.FileNotFoundException)2 InterruptedIOException (java.io.InterruptedIOException)2 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)2 TableExistsException (org.apache.hadoop.hbase.TableExistsException)2 TableNotDisabledException (org.apache.hadoop.hbase.TableNotDisabledException)2 TimeoutIOException (org.apache.hadoop.hbase.exceptions.TimeoutIOException)2 AccessDeniedException (org.apache.hadoop.hbase.security.AccessDeniedException)2 SnapshotDoesNotExistException (org.apache.hadoop.hbase.snapshot.SnapshotDoesNotExistException)2 SnapshotExistsException (org.apache.hadoop.hbase.snapshot.SnapshotExistsException)2 TablePartiallyOpenException (org.apache.hadoop.hbase.snapshot.TablePartiallyOpenException)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1