/** * Take a snapshot of the specified table and verify that the given family is * not empty. Note that this will leave the table disabled * in the case of an offline snapshot. */ public static void createSnapshotAndValidate(Admin admin, TableName tableName, String familyName, String snapshotNameString, Path rootDir, FileSystem fs, boolean onlineSnapshot) throws Exception { ArrayList<byte[]> nonEmptyFamilyNames = new ArrayList<>(1); nonEmptyFamilyNames.add(Bytes.toBytes(familyName)); createSnapshotAndValidate(admin, tableName, nonEmptyFamilyNames, /* emptyFamilyNames= */ null, snapshotNameString, rootDir, fs, onlineSnapshot); }
/** * Takes the snapshot of originalTable and clones the snapshot to another tables. * If {@code online} is false, the original table is disabled during taking snapshot, so also * enables it again. * @param online - Whether the table is online or not during the snapshot */ private void createAndCloneSnapshot(boolean online) throws Exception { SnapshotTestingUtils.createSnapshotAndValidate(admin, originalTableName, TEST_FAM_STR, snapshotNameAsString, rootDir, fs, online); // If offline, enable the table disabled by snapshot testing util. if (!online) { admin.enableTable(originalTableName); UTIL.waitTableAvailable(originalTableName); } admin.cloneSnapshot(snapshotName, cloneTableName); UTIL.waitUntilAllRegionsAssigned(cloneTableName); }
SnapshotTestingUtils.createSnapshotAndValidate(admin, tableName, Arrays.asList(FAMILIES), null, snapshotName, rootDir, fs, true);
@BeforeClass public static void setUpSnapshots() throws Exception { TEST_UTIL.enableDebug(MultiTableSnapshotInputFormat.class); TEST_UTIL.enableDebug(MultiTableSnapshotInputFormatImpl.class); // take a snapshot of every table we have. for (String tableName : TABLES) { SnapshotTestingUtils .createSnapshotAndValidate(TEST_UTIL.getAdmin(), TableName.valueOf(tableName), ImmutableList.of(INPUT_FAMILY), null, snapshotNameForTable(tableName), FSUtils.getRootDir(TEST_UTIL.getConfiguration()), TEST_UTIL.getTestFileSystem(), true); } }
/** * Basic end-to-end test of simple-flush-based snapshots */ @Test public void testFlushCreateListDestroy() throws Exception { LOG.debug("------- Starting Snapshot test -------------"); // make sure we don't fail on listing snapshots SnapshotTestingUtils.assertNoSnapshots(admin); // load the table so we have some data SnapshotTestingUtils.loadData(UTIL, TABLE_NAME, DEFAULT_NUM_ROWS, TEST_FAM); String snapshotName = "flushSnapshotCreateListDestroy"; FileSystem fs = UTIL.getHBaseCluster().getMaster().getMasterFileSystem().getFileSystem(); Path rootDir = UTIL.getHBaseCluster().getMaster().getMasterFileSystem().getRootDir(); SnapshotTestingUtils.createSnapshotAndValidate(admin, TABLE_NAME, Bytes.toString(TEST_FAM), snapshotName, rootDir, fs, true); }
SnapshotTestingUtils.createSnapshotAndValidate(admin, originalTableName, null, familiesList, snapshotNameAsString, rootDir, fs, /* onlineSnapshot= */ false);
public static void createTableAndSnapshot(HBaseTestingUtility util, TableName tableName, String snapshotName, int numRegions) throws Exception { try { util.deleteTable(tableName); } catch(Exception ex) { // ignore } if (numRegions > 1) { util.createTable(tableName, FAMILIES, 1, bbb, yyy, numRegions); } else { util.createTable(tableName, FAMILIES); } Admin admin = util.getAdmin(); // put some stuff in the table Table table = util.getConnection().getTable(tableName); util.loadTable(table, FAMILIES); Path rootDir = FSUtils.getRootDir(util.getConfiguration()); FileSystem fs = rootDir.getFileSystem(util.getConfiguration()); SnapshotTestingUtils.createSnapshotAndValidate(admin, tableName, Arrays.asList(FAMILIES), null, snapshotName, rootDir, fs, true); // load different values byte[] value = Bytes.toBytes("after_snapshot_value"); util.loadTable(table, FAMILIES, value); // cause flush to create new files in the region admin.flush(tableName); table.close(); }
final byte[] snapshotName = Bytes.toBytes(snapshotNameAsString); SnapshotTestingUtils.createSnapshotAndValidate(admin, originalTableName, familiesWithDataList, emptyFamiliesList, snapshotNameAsString, rootDir, fs, /* onlineSnapshot= */ false);
FileSystem fs = rootDir.getFileSystem(conf1); String sourceSnapshotName = "sourceSnapshot-" + System.currentTimeMillis(); SnapshotTestingUtils.createSnapshotAndValidate(utility1.getAdmin(), tableName, new String(famName), sourceSnapshotName, rootDir, fs, true); FileSystem peerFs = peerRootDir.getFileSystem(conf2); String peerSnapshotName = "peerSnapshot-" + System.currentTimeMillis(); SnapshotTestingUtils.createSnapshotAndValidate(utility2.getAdmin(), tableName, new String(famName), peerSnapshotName, peerRootDir, peerFs, true); SnapshotTestingUtils.createSnapshotAndValidate(utility1.getAdmin(), tableName, new String(famName), sourceSnapshotName, rootDir, fs, true); SnapshotTestingUtils.createSnapshotAndValidate(utility2.getAdmin(), tableName, new String(famName), peerSnapshotName, peerRootDir, peerFs, true);
FileSystem fs = rootDir.getFileSystem(UTIL.getConfiguration()); SnapshotTestingUtils.createSnapshotAndValidate(admin, tableName, Arrays.asList(FAMILIES), null, snapshotName, rootDir, fs, true);
FileSystem fs = rootDir.getFileSystem(UTIL.getConfiguration()); SnapshotTestingUtils.createSnapshotAndValidate(admin, tableName, Arrays.asList(FAMILIES), null, snapshotName, rootDir, fs, true);
/** * Take a snapshot of the specified table and verify that the given family is * not empty. Note that this will leave the table disabled * in the case of an offline snapshot. */ public static void createSnapshotAndValidate(Admin admin, TableName tableName, String familyName, String snapshotNameString, Path rootDir, FileSystem fs, boolean onlineSnapshot) throws Exception { ArrayList<byte[]> nonEmptyFamilyNames = new ArrayList<>(1); nonEmptyFamilyNames.add(Bytes.toBytes(familyName)); createSnapshotAndValidate(admin, tableName, nonEmptyFamilyNames, /* emptyFamilyNames= */ null, snapshotNameString, rootDir, fs, onlineSnapshot); }
/** * Takes the snapshot of originalTable and clones the snapshot to another tables. * If {@code online} is false, the original table is disabled during taking snapshot, so also * enables it again. * @param online - Whether the table is online or not during the snapshot */ private void createAndCloneSnapshot(boolean online) throws Exception { SnapshotTestingUtils.createSnapshotAndValidate(admin, originalTableName, TEST_FAM_STR, snapshotNameAsString, rootDir, fs, online); // If offline, enable the table disabled by snapshot testing util. if (!online) { admin.enableTable(originalTableName); UTIL.waitTableAvailable(originalTableName); } admin.cloneSnapshot(snapshotName, cloneTableName); UTIL.waitUntilAllRegionsAssigned(cloneTableName); }
SnapshotTestingUtils.createSnapshotAndValidate(admin, tableName, Arrays.asList(FAMILIES), null, snapshotName, rootDir, fs, true);
SnapshotTestingUtils.createSnapshotAndValidate(admin, tableName, Arrays.asList(FAMILIES), null, snapshotName, rootDir, fs, true);
@BeforeClass public static void setUpSnapshots() throws Exception { TEST_UTIL.enableDebug(MultiTableSnapshotInputFormat.class); TEST_UTIL.enableDebug(MultiTableSnapshotInputFormatImpl.class); // take a snapshot of every table we have. for (String tableName : TABLES) { SnapshotTestingUtils .createSnapshotAndValidate(TEST_UTIL.getAdmin(), TableName.valueOf(tableName), ImmutableList.of(INPUT_FAMILY), null, snapshotNameForTable(tableName), FSUtils.getRootDir(TEST_UTIL.getConfiguration()), TEST_UTIL.getTestFileSystem(), true); } }
@BeforeClass public static void setUpSnapshots() throws Exception { TEST_UTIL.enableDebug(MultiTableSnapshotInputFormat.class); TEST_UTIL.enableDebug(MultiTableSnapshotInputFormatImpl.class); // take a snapshot of every table we have. for (String tableName : TABLES) { SnapshotTestingUtils .createSnapshotAndValidate(TEST_UTIL.getAdmin(), TableName.valueOf(tableName), ImmutableList.of(INPUT_FAMILY), null, snapshotNameForTable(tableName), FSUtils.getRootDir(TEST_UTIL.getConfiguration()), TEST_UTIL.getTestFileSystem(), true); } }
/** * Basic end-to-end test of simple-flush-based snapshots */ @Test public void testFlushCreateListDestroy() throws Exception { LOG.debug("------- Starting Snapshot test -------------"); // make sure we don't fail on listing snapshots SnapshotTestingUtils.assertNoSnapshots(admin); // load the table so we have some data SnapshotTestingUtils.loadData(UTIL, TABLE_NAME, DEFAULT_NUM_ROWS, TEST_FAM); String snapshotName = "flushSnapshotCreateListDestroy"; FileSystem fs = UTIL.getHBaseCluster().getMaster().getMasterFileSystem().getFileSystem(); Path rootDir = UTIL.getHBaseCluster().getMaster().getMasterFileSystem().getRootDir(); SnapshotTestingUtils.createSnapshotAndValidate(admin, TABLE_NAME, Bytes.toString(TEST_FAM), snapshotName, rootDir, fs, true); }
SnapshotTestingUtils.createSnapshotAndValidate(admin, originalTableName, null, familiesList, snapshotNameAsString, rootDir, fs, /* onlineSnapshot= */ false);
public static void createTableAndSnapshot(HBaseTestingUtility util, TableName tableName, String snapshotName, int numRegions) throws Exception { try { util.deleteTable(tableName); } catch(Exception ex) { // ignore } if (numRegions > 1) { util.createTable(tableName, FAMILIES, 1, bbb, yyy, numRegions); } else { util.createTable(tableName, FAMILIES); } Admin admin = util.getAdmin(); // put some stuff in the table Table table = util.getConnection().getTable(tableName); util.loadTable(table, FAMILIES); Path rootDir = FSUtils.getRootDir(util.getConfiguration()); FileSystem fs = rootDir.getFileSystem(util.getConfiguration()); SnapshotTestingUtils.createSnapshotAndValidate(admin, tableName, Arrays.asList(FAMILIES), null, snapshotName, rootDir, fs, true); // load different values byte[] value = Bytes.toBytes("after_snapshot_value"); util.loadTable(table, FAMILIES, value); // cause flush to create new files in the region admin.flush(tableName); table.close(); }