Search in sources :

Example 11 with RestoreSnapshotException

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

the class RawAsyncHBaseAdmin method restoreSnapshot.

private CompletableFuture<Void> restoreSnapshot(String snapshotName, TableName tableName, boolean takeFailSafeSnapshot, boolean restoreAcl) {
    if (takeFailSafeSnapshot) {
        CompletableFuture<Void> future = new CompletableFuture<>();
        // Step.1 Take a snapshot of the current state
        String failSafeSnapshotSnapshotNameFormat = this.connection.getConfiguration().get(HConstants.SNAPSHOT_RESTORE_FAILSAFE_NAME, HConstants.DEFAULT_SNAPSHOT_RESTORE_FAILSAFE_NAME);
        final String failSafeSnapshotSnapshotName = failSafeSnapshotSnapshotNameFormat.replace("{snapshot.name}", snapshotName).replace("{table.name}", tableName.toString().replace(TableName.NAMESPACE_DELIM, '.')).replace("{restore.timestamp}", String.valueOf(EnvironmentEdgeManager.currentTime()));
        LOG.info("Taking restore-failsafe snapshot: " + failSafeSnapshotSnapshotName);
        addListener(snapshot(failSafeSnapshotSnapshotName, tableName), (ret, err) -> {
            if (err != null) {
                future.completeExceptionally(err);
            } else {
                // Step.2 Restore snapshot
                addListener(internalRestoreSnapshot(snapshotName, tableName, restoreAcl, null), (void2, err2) -> {
                    if (err2 != null) {
                        // Step.3.a Something went wrong during the restore and try to rollback.
                        addListener(internalRestoreSnapshot(failSafeSnapshotSnapshotName, tableName, restoreAcl, null), (void3, err3) -> {
                            if (err3 != null) {
                                future.completeExceptionally(err3);
                            } else {
                                String msg = "Restore snapshot=" + snapshotName + " failed. Rollback to snapshot=" + failSafeSnapshotSnapshotName + " succeeded.";
                                future.completeExceptionally(new RestoreSnapshotException(msg, err2));
                            }
                        });
                    } else {
                        // Step.3.b If the restore is succeeded, delete the pre-restore snapshot.
                        LOG.info("Deleting restore-failsafe snapshot: " + failSafeSnapshotSnapshotName);
                        addListener(deleteSnapshot(failSafeSnapshotSnapshotName), (ret3, err3) -> {
                            if (err3 != null) {
                                LOG.error("Unable to remove the failsafe snapshot: " + failSafeSnapshotSnapshotName, err3);
                            }
                            future.complete(ret3);
                        });
                    }
                });
            }
        });
        return future;
    } else {
        return internalRestoreSnapshot(snapshotName, tableName, restoreAcl, null);
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RestoreSnapshotException(org.apache.hadoop.hbase.snapshot.RestoreSnapshotException)

Example 12 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");
    ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("fam1")).build();
    TableDescriptorBuilder tableDescOne = TableDescriptorBuilder.newBuilder(tableName1);
    tableDescOne.setColumnFamily(columnFamilyDescriptor);
    ADMIN.createTable(tableDescOne.build(), 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.build());
    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) NamespaceDescriptor(org.apache.hadoop.hbase.NamespaceDescriptor) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor) RestoreSnapshotException(org.apache.hadoop.hbase.snapshot.RestoreSnapshotException) Test(org.junit.Test)

Aggregations

RestoreSnapshotException (org.apache.hadoop.hbase.snapshot.RestoreSnapshotException)12 IOException (java.io.IOException)9 TableName (org.apache.hadoop.hbase.TableName)9 ForeignException (org.apache.hadoop.hbase.errorhandling.ForeignException)6 SnapshotCreationException (org.apache.hadoop.hbase.snapshot.SnapshotCreationException)6 HBaseSnapshotException (org.apache.hadoop.hbase.snapshot.HBaseSnapshotException)5 UnknownSnapshotException (org.apache.hadoop.hbase.snapshot.UnknownSnapshotException)5 KeeperException (org.apache.zookeeper.KeeperException)5 FileNotFoundException (java.io.FileNotFoundException)4 Configuration (org.apache.hadoop.conf.Configuration)4 TableExistsException (org.apache.hadoop.hbase.TableExistsException)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 TableNotDisabledException (org.apache.hadoop.hbase.TableNotDisabledException)3 AccessDeniedException (org.apache.hadoop.hbase.security.AccessDeniedException)3 SnapshotDoesNotExistException (org.apache.hadoop.hbase.snapshot.SnapshotDoesNotExistException)3 SnapshotExistsException (org.apache.hadoop.hbase.snapshot.SnapshotExistsException)3 TablePartiallyOpenException (org.apache.hadoop.hbase.snapshot.TablePartiallyOpenException)3 InterruptedIOException (java.io.InterruptedIOException)2 CompletableFuture (java.util.concurrent.CompletableFuture)2