HBASE-7622 Add table descriptor verification after snapshot restore (Matteo Bertozzi)
git-svn-id: https://svn.apache.org/repos/asf/hbase/branches/hbase-7290@1445859 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
03d5cb8082
commit
d0906be22c
|
@ -2219,8 +2219,9 @@ public class HBaseAdmin implements Abortable, Closeable {
|
||||||
long max = response.getExpectedTimeout();
|
long max = response.getExpectedTimeout();
|
||||||
long maxPauseTime = max / this.numRetries;
|
long maxPauseTime = max / this.numRetries;
|
||||||
int tries = 0;
|
int tries = 0;
|
||||||
LOG.debug("Waiting a max of " + max + " ms for snapshot to complete. (max " + maxPauseTime
|
LOG.debug("Waiting a max of " + max + " ms for snapshot '" +
|
||||||
+ " ms per retry)");
|
SnapshotDescriptionUtils.toString(snapshot) + "'' to complete. (max " +
|
||||||
|
maxPauseTime + " ms per retry)");
|
||||||
while (tries == 0
|
while (tries == 0
|
||||||
|| ((EnvironmentEdgeManager.currentTimeMillis() - start) < max && !done.getDone())) {
|
|| ((EnvironmentEdgeManager.currentTimeMillis() - start) < max && !done.getDone())) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -118,80 +118,89 @@ public class TestRestoreSnapshotFromClient {
|
||||||
admin.snapshot(emptySnapshot, tableName);
|
admin.snapshot(emptySnapshot, tableName);
|
||||||
|
|
||||||
HTable table = new HTable(TEST_UTIL.getConfiguration(), tableName);
|
HTable table = new HTable(TEST_UTIL.getConfiguration(), tableName);
|
||||||
|
try {
|
||||||
|
// enable table and insert data
|
||||||
|
admin.enableTable(tableName);
|
||||||
|
loadData(table, 500, FAMILY);
|
||||||
|
snapshot0Rows = TEST_UTIL.countRows(table);
|
||||||
|
admin.disableTable(tableName);
|
||||||
|
|
||||||
// enable table and insert data
|
// take a snapshot
|
||||||
admin.enableTable(tableName);
|
admin.snapshot(snapshotName0, tableName);
|
||||||
loadData(table, 500, FAMILY);
|
|
||||||
snapshot0Rows = TEST_UTIL.countRows(table);
|
|
||||||
admin.disableTable(tableName);
|
|
||||||
|
|
||||||
// take a snapshot
|
// enable table and insert more data
|
||||||
admin.snapshot(snapshotName0, tableName);
|
admin.enableTable(tableName);
|
||||||
|
loadData(table, 500, FAMILY);
|
||||||
|
snapshot1Rows = TEST_UTIL.countRows(table);
|
||||||
|
admin.disableTable(tableName);
|
||||||
|
|
||||||
// enable table and insert more data
|
// take a snapshot of the updated table
|
||||||
admin.enableTable(tableName);
|
admin.snapshot(snapshotName1, tableName);
|
||||||
loadData(table, 500, FAMILY);
|
|
||||||
snapshot1Rows = TEST_UTIL.countRows(table);
|
|
||||||
admin.disableTable(tableName);
|
|
||||||
|
|
||||||
// take a snapshot of the updated table
|
// re-enable table
|
||||||
admin.snapshot(snapshotName1, tableName);
|
admin.enableTable(tableName);
|
||||||
|
} finally {
|
||||||
// re-enable table
|
table.close();
|
||||||
admin.enableTable(tableName);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
if (admin.tableExists(tableName)) {
|
if (admin.tableExists(tableName)) {
|
||||||
admin.disableTable(tableName);
|
TEST_UTIL.deleteTable(tableName);
|
||||||
admin.deleteTable(tableName);
|
|
||||||
}
|
}
|
||||||
admin.deleteSnapshot(snapshotName0);
|
admin.deleteSnapshot(snapshotName0);
|
||||||
admin.deleteSnapshot(snapshotName1);
|
admin.deleteSnapshot(snapshotName1);
|
||||||
waitCleanerRun();
|
|
||||||
|
// Ensure the archiver to be empty
|
||||||
|
MasterFileSystem mfs = TEST_UTIL.getMiniHBaseCluster().getMaster().getMasterFileSystem();
|
||||||
|
mfs.getFileSystem().delete(
|
||||||
|
new Path(mfs.getRootDir(), HConstants.HFILE_ARCHIVE_DIRECTORY), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRestoreSnapshot() throws IOException {
|
public void testRestoreSnapshot() throws IOException {
|
||||||
HTable table = new HTable(TEST_UTIL.getConfiguration(), tableName);
|
verifyRowCount(tableName, snapshot1Rows);
|
||||||
assertEquals(snapshot1Rows, TEST_UTIL.countRows(table));
|
|
||||||
|
|
||||||
// Restore from snapshot-0
|
// Restore from snapshot-0
|
||||||
admin.disableTable(tableName);
|
admin.disableTable(tableName);
|
||||||
admin.restoreSnapshot(snapshotName0);
|
admin.restoreSnapshot(snapshotName0);
|
||||||
admin.enableTable(tableName);
|
admin.enableTable(tableName);
|
||||||
table = new HTable(TEST_UTIL.getConfiguration(), tableName);
|
verifyRowCount(tableName, snapshot0Rows);
|
||||||
assertEquals(snapshot0Rows, TEST_UTIL.countRows(table));
|
|
||||||
|
|
||||||
// Restore from emptySnapshot
|
// Restore from emptySnapshot
|
||||||
admin.disableTable(tableName);
|
admin.disableTable(tableName);
|
||||||
admin.restoreSnapshot(emptySnapshot);
|
admin.restoreSnapshot(emptySnapshot);
|
||||||
admin.enableTable(tableName);
|
admin.enableTable(tableName);
|
||||||
table = new HTable(TEST_UTIL.getConfiguration(), tableName);
|
verifyRowCount(tableName, 0);
|
||||||
assertEquals(0, TEST_UTIL.countRows(table));
|
|
||||||
|
|
||||||
// Restore from snapshot-1
|
// Restore from snapshot-1
|
||||||
admin.disableTable(tableName);
|
admin.disableTable(tableName);
|
||||||
admin.restoreSnapshot(snapshotName1);
|
admin.restoreSnapshot(snapshotName1);
|
||||||
admin.enableTable(tableName);
|
admin.enableTable(tableName);
|
||||||
table = new HTable(TEST_UTIL.getConfiguration(), tableName);
|
verifyRowCount(tableName, snapshot1Rows);
|
||||||
assertEquals(snapshot1Rows, TEST_UTIL.countRows(table));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRestoreSchemaChange() throws IOException {
|
public void testRestoreSchemaChange() throws IOException {
|
||||||
byte[] TEST_FAMILY2 = Bytes.toBytes("cf2");
|
byte[] TEST_FAMILY2 = Bytes.toBytes("cf2");
|
||||||
|
|
||||||
|
HTable table = new HTable(TEST_UTIL.getConfiguration(), tableName);
|
||||||
|
|
||||||
// Add one column family and put some data in it
|
// Add one column family and put some data in it
|
||||||
admin.disableTable(tableName);
|
admin.disableTable(tableName);
|
||||||
admin.addColumn(tableName, new HColumnDescriptor(TEST_FAMILY2));
|
admin.addColumn(tableName, new HColumnDescriptor(TEST_FAMILY2));
|
||||||
admin.enableTable(tableName);
|
admin.enableTable(tableName);
|
||||||
HTable table = new HTable(TEST_UTIL.getConfiguration(), tableName);
|
assertEquals(2, table.getTableDescriptor().getFamilies().size());
|
||||||
|
HTableDescriptor htd = admin.getTableDescriptor(tableName);
|
||||||
|
assertEquals(2, htd.getFamilies().size());
|
||||||
loadData(table, 500, TEST_FAMILY2);
|
loadData(table, 500, TEST_FAMILY2);
|
||||||
long snapshot2Rows = snapshot1Rows + 500;
|
long snapshot2Rows = snapshot1Rows + 500;
|
||||||
assertEquals(snapshot2Rows, TEST_UTIL.countRows(table));
|
assertEquals(snapshot2Rows, TEST_UTIL.countRows(table));
|
||||||
assertEquals(500, TEST_UTIL.countRows(table, TEST_FAMILY2));
|
assertEquals(500, TEST_UTIL.countRows(table, TEST_FAMILY2));
|
||||||
|
Set<String> fsFamilies = getFamiliesFromFS(tableName);
|
||||||
|
assertEquals(2, fsFamilies.size());
|
||||||
|
table.close();
|
||||||
|
|
||||||
// Take a snapshot
|
// Take a snapshot
|
||||||
admin.disableTable(tableName);
|
admin.disableTable(tableName);
|
||||||
|
@ -200,7 +209,7 @@ public class TestRestoreSnapshotFromClient {
|
||||||
// Restore the snapshot (without the cf)
|
// Restore the snapshot (without the cf)
|
||||||
admin.restoreSnapshot(snapshotName0);
|
admin.restoreSnapshot(snapshotName0);
|
||||||
admin.enableTable(tableName);
|
admin.enableTable(tableName);
|
||||||
table = new HTable(TEST_UTIL.getConfiguration(), tableName);
|
assertEquals(1, table.getTableDescriptor().getFamilies().size());
|
||||||
try {
|
try {
|
||||||
TEST_UTIL.countRows(table, TEST_FAMILY2);
|
TEST_UTIL.countRows(table, TEST_FAMILY2);
|
||||||
fail("family '" + Bytes.toString(TEST_FAMILY2) + "' should not exists");
|
fail("family '" + Bytes.toString(TEST_FAMILY2) + "' should not exists");
|
||||||
|
@ -208,18 +217,24 @@ public class TestRestoreSnapshotFromClient {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
assertEquals(snapshot0Rows, TEST_UTIL.countRows(table));
|
assertEquals(snapshot0Rows, TEST_UTIL.countRows(table));
|
||||||
Set<String> fsFamilies = getFamiliesFromFS(tableName);
|
htd = admin.getTableDescriptor(tableName);
|
||||||
|
assertEquals(1, htd.getFamilies().size());
|
||||||
|
fsFamilies = getFamiliesFromFS(tableName);
|
||||||
assertEquals(1, fsFamilies.size());
|
assertEquals(1, fsFamilies.size());
|
||||||
|
table.close();
|
||||||
|
|
||||||
// Restore back the snapshot (with the cf)
|
// Restore back the snapshot (with the cf)
|
||||||
admin.disableTable(tableName);
|
admin.disableTable(tableName);
|
||||||
admin.restoreSnapshot(snapshotName2);
|
admin.restoreSnapshot(snapshotName2);
|
||||||
admin.enableTable(tableName);
|
admin.enableTable(tableName);
|
||||||
table = new HTable(TEST_UTIL.getConfiguration(), tableName);
|
htd = admin.getTableDescriptor(tableName);
|
||||||
|
assertEquals(2, htd.getFamilies().size());
|
||||||
|
assertEquals(2, table.getTableDescriptor().getFamilies().size());
|
||||||
assertEquals(500, TEST_UTIL.countRows(table, TEST_FAMILY2));
|
assertEquals(500, TEST_UTIL.countRows(table, TEST_FAMILY2));
|
||||||
assertEquals(snapshot2Rows, TEST_UTIL.countRows(table));
|
assertEquals(snapshot2Rows, TEST_UTIL.countRows(table));
|
||||||
fsFamilies = getFamiliesFromFS(tableName);
|
fsFamilies = getFamiliesFromFS(tableName);
|
||||||
assertEquals(2, fsFamilies.size());
|
assertEquals(2, fsFamilies.size());
|
||||||
|
table.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=SnapshotDoesNotExistException.class)
|
@Test(expected=SnapshotDoesNotExistException.class)
|
||||||
|
@ -241,8 +256,7 @@ public class TestRestoreSnapshotFromClient {
|
||||||
int snapshotRows) throws IOException, InterruptedException {
|
int snapshotRows) throws IOException, InterruptedException {
|
||||||
// create a new table from snapshot
|
// create a new table from snapshot
|
||||||
admin.cloneSnapshot(snapshotName, tableName);
|
admin.cloneSnapshot(snapshotName, tableName);
|
||||||
HTable table = new HTable(TEST_UTIL.getConfiguration(), tableName);
|
verifyRowCount(tableName, snapshotRows);
|
||||||
assertEquals(snapshotRows, TEST_UTIL.countRows(table));
|
|
||||||
|
|
||||||
admin.disableTable(tableName);
|
admin.disableTable(tableName);
|
||||||
admin.deleteTable(tableName);
|
admin.deleteTable(tableName);
|
||||||
|
@ -252,16 +266,14 @@ public class TestRestoreSnapshotFromClient {
|
||||||
public void testRestoreSnapshotOfCloned() throws IOException, InterruptedException {
|
public void testRestoreSnapshotOfCloned() throws IOException, InterruptedException {
|
||||||
byte[] clonedTableName = Bytes.toBytes("clonedtb-" + System.currentTimeMillis());
|
byte[] clonedTableName = Bytes.toBytes("clonedtb-" + System.currentTimeMillis());
|
||||||
admin.cloneSnapshot(snapshotName0, clonedTableName);
|
admin.cloneSnapshot(snapshotName0, clonedTableName);
|
||||||
HTable table = new HTable(TEST_UTIL.getConfiguration(), clonedTableName);
|
verifyRowCount(clonedTableName, snapshot0Rows);
|
||||||
assertEquals(snapshot0Rows, TEST_UTIL.countRows(table));
|
|
||||||
admin.disableTable(clonedTableName);
|
admin.disableTable(clonedTableName);
|
||||||
admin.snapshot(snapshotName2, clonedTableName);
|
admin.snapshot(snapshotName2, clonedTableName);
|
||||||
admin.deleteTable(clonedTableName);
|
admin.deleteTable(clonedTableName);
|
||||||
waitCleanerRun();
|
waitCleanerRun();
|
||||||
|
|
||||||
admin.cloneSnapshot(snapshotName2, clonedTableName);
|
admin.cloneSnapshot(snapshotName2, clonedTableName);
|
||||||
table = new HTable(TEST_UTIL.getConfiguration(), clonedTableName);
|
verifyRowCount(clonedTableName, snapshot0Rows);
|
||||||
assertEquals(snapshot0Rows, TEST_UTIL.countRows(table));
|
|
||||||
admin.disableTable(clonedTableName);
|
admin.disableTable(clonedTableName);
|
||||||
admin.deleteTable(clonedTableName);
|
admin.deleteTable(clonedTableName);
|
||||||
}
|
}
|
||||||
|
@ -274,8 +286,7 @@ public class TestRestoreSnapshotFromClient {
|
||||||
// Clone a table from the first snapshot
|
// Clone a table from the first snapshot
|
||||||
byte[] clonedTableName = Bytes.toBytes("clonedtb1-" + System.currentTimeMillis());
|
byte[] clonedTableName = Bytes.toBytes("clonedtb1-" + System.currentTimeMillis());
|
||||||
admin.cloneSnapshot(snapshotName0, clonedTableName);
|
admin.cloneSnapshot(snapshotName0, clonedTableName);
|
||||||
HTable table = new HTable(TEST_UTIL.getConfiguration(), clonedTableName);
|
verifyRowCount(clonedTableName, snapshot0Rows);
|
||||||
assertEquals(snapshot0Rows, TEST_UTIL.countRows(table));
|
|
||||||
|
|
||||||
// Take a snapshot of this cloned table.
|
// Take a snapshot of this cloned table.
|
||||||
admin.disableTable(clonedTableName);
|
admin.disableTable(clonedTableName);
|
||||||
|
@ -284,8 +295,7 @@ public class TestRestoreSnapshotFromClient {
|
||||||
// Clone the snapshot of the cloned table
|
// Clone the snapshot of the cloned table
|
||||||
byte[] clonedTableName2 = Bytes.toBytes("clonedtb2-" + System.currentTimeMillis());
|
byte[] clonedTableName2 = Bytes.toBytes("clonedtb2-" + System.currentTimeMillis());
|
||||||
admin.cloneSnapshot(snapshotName2, clonedTableName2);
|
admin.cloneSnapshot(snapshotName2, clonedTableName2);
|
||||||
table = new HTable(TEST_UTIL.getConfiguration(), clonedTableName2);
|
verifyRowCount(clonedTableName2, snapshot0Rows);
|
||||||
assertEquals(snapshot0Rows, TEST_UTIL.countRows(table));
|
|
||||||
admin.disableTable(clonedTableName2);
|
admin.disableTable(clonedTableName2);
|
||||||
|
|
||||||
// Remove the original table
|
// Remove the original table
|
||||||
|
@ -295,13 +305,11 @@ public class TestRestoreSnapshotFromClient {
|
||||||
|
|
||||||
// Verify the first cloned table
|
// Verify the first cloned table
|
||||||
admin.enableTable(clonedTableName);
|
admin.enableTable(clonedTableName);
|
||||||
table = new HTable(TEST_UTIL.getConfiguration(), clonedTableName);
|
verifyRowCount(clonedTableName, snapshot0Rows);
|
||||||
assertEquals(snapshot0Rows, TEST_UTIL.countRows(table));
|
|
||||||
|
|
||||||
// Verify the second cloned table
|
// Verify the second cloned table
|
||||||
admin.enableTable(clonedTableName2);
|
admin.enableTable(clonedTableName2);
|
||||||
table = new HTable(TEST_UTIL.getConfiguration(), clonedTableName2);
|
verifyRowCount(clonedTableName2, snapshot0Rows);
|
||||||
assertEquals(snapshot0Rows, TEST_UTIL.countRows(table));
|
|
||||||
admin.disableTable(clonedTableName2);
|
admin.disableTable(clonedTableName2);
|
||||||
|
|
||||||
// Delete the first cloned table
|
// Delete the first cloned table
|
||||||
|
@ -311,14 +319,12 @@ public class TestRestoreSnapshotFromClient {
|
||||||
|
|
||||||
// Verify the second cloned table
|
// Verify the second cloned table
|
||||||
admin.enableTable(clonedTableName2);
|
admin.enableTable(clonedTableName2);
|
||||||
table = new HTable(TEST_UTIL.getConfiguration(), clonedTableName2);
|
verifyRowCount(clonedTableName2, snapshot0Rows);
|
||||||
assertEquals(snapshot0Rows, TEST_UTIL.countRows(table));
|
|
||||||
|
|
||||||
// Clone a new table from cloned
|
// Clone a new table from cloned
|
||||||
byte[] clonedTableName3 = Bytes.toBytes("clonedtb3-" + System.currentTimeMillis());
|
byte[] clonedTableName3 = Bytes.toBytes("clonedtb3-" + System.currentTimeMillis());
|
||||||
admin.cloneSnapshot(snapshotName2, clonedTableName3);
|
admin.cloneSnapshot(snapshotName2, clonedTableName3);
|
||||||
table = new HTable(TEST_UTIL.getConfiguration(), clonedTableName3);
|
verifyRowCount(clonedTableName3, snapshot0Rows);
|
||||||
assertEquals(snapshot0Rows, TEST_UTIL.countRows(table));
|
|
||||||
|
|
||||||
// Delete the cloned tables
|
// Delete the cloned tables
|
||||||
admin.disableTable(clonedTableName2);
|
admin.disableTable(clonedTableName2);
|
||||||
|
@ -376,4 +382,10 @@ public class TestRestoreSnapshotFromClient {
|
||||||
}
|
}
|
||||||
return families;
|
return families;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void verifyRowCount(final byte[] tableName, long expectedRows) throws IOException {
|
||||||
|
HTable table = new HTable(TEST_UTIL.getConfiguration(), tableName);
|
||||||
|
assertEquals(expectedRows, TEST_UTIL.countRows(table));
|
||||||
|
table.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.hadoop.fs.FileStatus;
|
import org.apache.hadoop.fs.FileStatus;
|
||||||
import org.apache.hadoop.fs.Path;
|
import org.apache.hadoop.fs.Path;
|
||||||
|
import org.apache.hadoop.hbase.HConstants;
|
||||||
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||||
import org.apache.hadoop.hbase.HColumnDescriptor;
|
import org.apache.hadoop.hbase.HColumnDescriptor;
|
||||||
import org.apache.hadoop.hbase.HTableDescriptor;
|
import org.apache.hadoop.hbase.HTableDescriptor;
|
||||||
|
@ -105,35 +106,45 @@ public class TestRestoreFlushSnapshotFromClient {
|
||||||
// create Table and disable it
|
// create Table and disable it
|
||||||
createTable(tableName, FAMILY);
|
createTable(tableName, FAMILY);
|
||||||
HTable table = new HTable(TEST_UTIL.getConfiguration(), tableName);
|
HTable table = new HTable(TEST_UTIL.getConfiguration(), tableName);
|
||||||
loadData(table, 500, FAMILY);
|
try {
|
||||||
snapshot0Rows = TEST_UTIL.countRows(table);
|
loadData(table, 500, FAMILY);
|
||||||
LOG.info("=== before snapshot with 500 rows");
|
snapshot0Rows = TEST_UTIL.countRows(table);
|
||||||
logFSTree();
|
LOG.info("=== before snapshot with 500 rows");
|
||||||
|
logFSTree();
|
||||||
|
|
||||||
// take a snapshot
|
// take a snapshot
|
||||||
admin.snapshot(Bytes.toString(snapshotName0), Bytes.toString(tableName), SnapshotDescription.Type.FLUSH);
|
admin.snapshot(Bytes.toString(snapshotName0), Bytes.toString(tableName),
|
||||||
|
SnapshotDescription.Type.FLUSH);
|
||||||
|
|
||||||
LOG.info("=== after snapshot with 500 rows");
|
LOG.info("=== after snapshot with 500 rows");
|
||||||
logFSTree();
|
logFSTree();
|
||||||
|
|
||||||
// insert more data
|
// insert more data
|
||||||
loadData(table, 500, FAMILY);
|
loadData(table, 500, FAMILY);
|
||||||
snapshot1Rows = TEST_UTIL.countRows(table);
|
snapshot1Rows = TEST_UTIL.countRows(table);
|
||||||
LOG.info("=== before snapshot with 1000 rows");
|
LOG.info("=== before snapshot with 1000 rows");
|
||||||
logFSTree();
|
logFSTree();
|
||||||
|
|
||||||
// take a snapshot of the updated table
|
// take a snapshot of the updated table
|
||||||
admin.snapshot(Bytes.toString(snapshotName1), Bytes.toString(tableName), SnapshotDescription.Type.FLUSH);
|
admin.snapshot(Bytes.toString(snapshotName1), Bytes.toString(tableName),
|
||||||
LOG.info("=== after snapshot with 1000 rows");
|
SnapshotDescription.Type.FLUSH);
|
||||||
logFSTree();
|
LOG.info("=== after snapshot with 1000 rows");
|
||||||
|
logFSTree();
|
||||||
|
} finally {
|
||||||
|
table.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
admin.disableTable(tableName);
|
TEST_UTIL.deleteTable(tableName);
|
||||||
admin.deleteTable(tableName);
|
|
||||||
admin.deleteSnapshot(snapshotName0);
|
admin.deleteSnapshot(snapshotName0);
|
||||||
admin.deleteSnapshot(snapshotName1);
|
admin.deleteSnapshot(snapshotName1);
|
||||||
|
|
||||||
|
// Ensure the archiver to be empty
|
||||||
|
MasterFileSystem mfs = TEST_UTIL.getMiniHBaseCluster().getMaster().getMasterFileSystem();
|
||||||
|
mfs.getFileSystem().delete(
|
||||||
|
new Path(mfs.getRootDir(), HConstants.HFILE_ARCHIVE_DIRECTORY), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -143,27 +154,22 @@ public class TestRestoreFlushSnapshotFromClient {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRestoreSnapshot() throws IOException {
|
public void testRestoreSnapshot() throws IOException {
|
||||||
HTable table = new HTable(TEST_UTIL.getConfiguration(), tableName);
|
verifyRowCount(tableName, snapshot1Rows);
|
||||||
assertEquals(snapshot1Rows, TEST_UTIL.countRows(table));
|
|
||||||
|
|
||||||
// Restore from snapshot-0
|
// Restore from snapshot-0
|
||||||
admin.disableTable(tableName);
|
admin.disableTable(tableName);
|
||||||
admin.restoreSnapshot(snapshotName0);
|
admin.restoreSnapshot(snapshotName0);
|
||||||
logFSTree();
|
logFSTree();
|
||||||
admin.enableTable(tableName);
|
admin.enableTable(tableName);
|
||||||
table = new HTable(TEST_UTIL.getConfiguration(), tableName);
|
|
||||||
|
|
||||||
LOG.info("=== after restore with 500 row snapshot");
|
LOG.info("=== after restore with 500 row snapshot");
|
||||||
logFSTree();
|
logFSTree();
|
||||||
|
verifyRowCount(tableName, snapshot0Rows);
|
||||||
assertEquals(snapshot0Rows, TEST_UTIL.countRows(table));
|
|
||||||
|
|
||||||
// Restore from snapshot-1
|
// Restore from snapshot-1
|
||||||
admin.disableTable(tableName);
|
admin.disableTable(tableName);
|
||||||
admin.restoreSnapshot(snapshotName1);
|
admin.restoreSnapshot(snapshotName1);
|
||||||
admin.enableTable(tableName);
|
admin.enableTable(tableName);
|
||||||
table = new HTable(TEST_UTIL.getConfiguration(), tableName);
|
verifyRowCount(tableName, snapshot1Rows);
|
||||||
assertEquals(snapshot1Rows, TEST_UTIL.countRows(table));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=SnapshotDoesNotExistException.class)
|
@Test(expected=SnapshotDoesNotExistException.class)
|
||||||
|
@ -184,28 +190,22 @@ public class TestRestoreFlushSnapshotFromClient {
|
||||||
int snapshotRows) throws IOException, InterruptedException {
|
int snapshotRows) throws IOException, InterruptedException {
|
||||||
// create a new table from snapshot
|
// create a new table from snapshot
|
||||||
admin.cloneSnapshot(snapshotName, tableName);
|
admin.cloneSnapshot(snapshotName, tableName);
|
||||||
HTable table = new HTable(TEST_UTIL.getConfiguration(), tableName);
|
verifyRowCount(tableName, snapshotRows);
|
||||||
assertEquals(snapshotRows, TEST_UTIL.countRows(table));
|
|
||||||
|
|
||||||
admin.disableTable(tableName);
|
TEST_UTIL.deleteTable(tableName);
|
||||||
admin.deleteTable(tableName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRestoreSnapshotOfCloned() throws IOException, InterruptedException {
|
public void testRestoreSnapshotOfCloned() throws IOException, InterruptedException {
|
||||||
byte[] clonedTableName = Bytes.toBytes("clonedtb-" + System.currentTimeMillis());
|
byte[] clonedTableName = Bytes.toBytes("clonedtb-" + System.currentTimeMillis());
|
||||||
admin.cloneSnapshot(snapshotName0, clonedTableName);
|
admin.cloneSnapshot(snapshotName0, clonedTableName);
|
||||||
HTable table = new HTable(TEST_UTIL.getConfiguration(), clonedTableName);
|
verifyRowCount(clonedTableName, snapshot0Rows);
|
||||||
assertEquals(snapshot0Rows, TEST_UTIL.countRows(table));
|
|
||||||
admin.snapshot(Bytes.toString(snapshotName2), Bytes.toString(clonedTableName), SnapshotDescription.Type.FLUSH);
|
admin.snapshot(Bytes.toString(snapshotName2), Bytes.toString(clonedTableName), SnapshotDescription.Type.FLUSH);
|
||||||
admin.disableTable(clonedTableName);
|
TEST_UTIL.deleteTable(clonedTableName);
|
||||||
admin.deleteTable(clonedTableName);
|
|
||||||
|
|
||||||
admin.cloneSnapshot(snapshotName2, clonedTableName);
|
admin.cloneSnapshot(snapshotName2, clonedTableName);
|
||||||
table = new HTable(TEST_UTIL.getConfiguration(), clonedTableName);
|
verifyRowCount(clonedTableName, snapshot0Rows);
|
||||||
assertEquals(snapshot0Rows, TEST_UTIL.countRows(table));
|
TEST_UTIL.deleteTable(clonedTableName);
|
||||||
admin.disableTable(clonedTableName);
|
|
||||||
admin.deleteTable(clonedTableName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
@ -245,4 +245,10 @@ public class TestRestoreFlushSnapshotFromClient {
|
||||||
MasterFileSystem mfs = TEST_UTIL.getMiniHBaseCluster().getMaster().getMasterFileSystem();
|
MasterFileSystem mfs = TEST_UTIL.getMiniHBaseCluster().getMaster().getMasterFileSystem();
|
||||||
FSUtils.logFileSystemState(mfs.getFileSystem(), mfs.getRootDir(), LOG);
|
FSUtils.logFileSystemState(mfs.getFileSystem(), mfs.getRootDir(), LOG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void verifyRowCount(final byte[] tableName, long expectedRows) throws IOException {
|
||||||
|
HTable table = new HTable(TEST_UTIL.getConfiguration(), tableName);
|
||||||
|
assertEquals(expectedRows, TEST_UTIL.countRows(table));
|
||||||
|
table.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue