Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -724,8 +724,7 @@ private synchronized long submitSnapshotProcedure(SnapshotDescription snapshot,
.submitProcedure(new MasterProcedureUtil.NonceProcedureRunnable(master, nonceGroup, nonce) {
@Override
protected void run() throws IOException {
TableDescriptor tableDescriptor =
master.getTableDescriptors().get(TableName.valueOf(snapshot.getTable()));
TableDescriptor tableDescriptor = sanityCheckBeforeSnapshot(snapshot, false);
MasterCoprocessorHost cpHost = getMaster().getMasterCoprocessorHost();
User user = RpcServer.getRequestUser().orElse(null);
org.apache.hadoop.hbase.client.SnapshotDescription snapshotDesc =
Expand All @@ -735,8 +734,6 @@ protected void run() throws IOException {
cpHost.preSnapshot(snapshotDesc, tableDescriptor, user);
}

sanityCheckBeforeSnapshot(snapshot, false);

long procId = submitProcedure(new SnapshotProcedure(
getMaster().getMasterProcedureExecutor().getEnvironment(), snapshot));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.IOException;
import java.util.List;
Expand All @@ -32,6 +34,7 @@
import org.apache.hadoop.hbase.HBaseTestingUtil;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.TableNameTestRule;
import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
import org.apache.hadoop.hbase.master.MasterCoprocessorHost;
import org.apache.hadoop.hbase.security.User;
Expand All @@ -40,17 +43,23 @@
import org.apache.hadoop.hbase.security.access.Permission;
import org.apache.hadoop.hbase.security.access.PermissionStorage;
import org.apache.hadoop.hbase.security.access.SecureTestUtil;
import org.apache.hadoop.hbase.snapshot.SnapshotCreationException;
import org.apache.hadoop.hbase.snapshot.SnapshotDescriptionUtils;
import org.apache.hadoop.hbase.snapshot.SnapshotDoesNotExistException;
import org.apache.hadoop.hbase.snapshot.SnapshotManifest;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;

public abstract class SnapshotWithAclTestBase extends SecureTestUtil {

@Rule
public TableNameTestRule name = new TableNameTestRule();

private TableName TEST_TABLE = TableName.valueOf(TEST_UTIL.getRandomUUID().toString());

private static final int ROW_COUNT = 30000;
Expand Down Expand Up @@ -314,4 +323,39 @@ public void testDeleteSnapshot() throws Exception {
TEST_UTIL.getAdmin().listSnapshots(Pattern.compile(testSnapshotName));
assertEquals(0, snapshotsAfterDelete.size());
}

@Test
public void testCreateSnapshotWithNonExistingTable() throws Exception {
final TableName tableName = name.getTableName();
String snapshotName = tableName.getNameAsString() + "snap1";

try {
try {
// Create snapshot without creating table
TEST_UTIL.getAdmin().snapshot(snapshotName, tableName);
fail("Snapshot operation should fail, table doesn't exist");
} catch (Exception e) {
assertTrue(e instanceof SnapshotCreationException);
}

// Create the table
TableDescriptor htd = TableDescriptorBuilder.newBuilder(tableName).build();
TEST_UTIL.createTable(htd, new byte[][] { TEST_FAMILY }, TEST_UTIL.getConfiguration());
try {
TEST_UTIL.getAdmin().snapshot(snapshotName, tableName);
} catch (Exception e) {
fail("Snapshot should have been created successfully");
}
assertTrue(TEST_UTIL.getAdmin().listSnapshots().stream()
.anyMatch(name -> name.getName().equals(snapshotName)));
} finally {
try {
TEST_UTIL.getAdmin().deleteSnapshot(snapshotName);
} catch (SnapshotDoesNotExistException e) {
}
if (TEST_UTIL.getAdmin().tableExists(tableName)) {
TEST_UTIL.deleteTable(tableName);
}
}
}
}
Loading