@Override public void loadData(final Table table, byte[]... families) throws Exception { SnapshotTestingUtils.loadData(UTIL, table.getName(), 1000, families); }
public static void loadData(final HBaseTestingUtility util, final TableName tableName, int rows, byte[]... families) throws IOException, InterruptedException { BufferedMutator mutator = util.getConnection().getBufferedMutator(tableName); loadData(util, mutator, rows, families); }
private SnapshotProtos.SnapshotDescription getSnapshot() throws Exception { if (snapshot == null) { final TableName snapshotTableName = TableName.valueOf("testCloneSnapshot"); long tid = System.currentTimeMillis(); final byte[] snapshotName = Bytes.toBytes("snapshot-" + tid); Admin admin = UTIL.getAdmin(); // create Table SnapshotTestingUtils.createTable(UTIL, snapshotTableName, getNumReplicas(), CF); // Load data SnapshotTestingUtils.loadData(UTIL, snapshotTableName, 500, CF); admin.disableTable(snapshotTableName); // take a snapshot admin.snapshot(snapshotName, snapshotTableName); admin.enableTable(snapshotTableName); List<SnapshotDescription> snapshotList = admin.listSnapshots(); snapshot = ProtobufUtil.createHBaseProtosSnapshotDesc(snapshotList.get(0)); } return snapshot; }
/** * Create a table and take a snapshot of the table used by the export test. */ @Before public void setUp() throws Exception { this.admin = TEST_UTIL.getAdmin(); tableName = TableName.valueOf("testtb-" + testName.getMethodName()); snapshotName = Bytes.toBytes("snaptb0-" + testName.getMethodName()); emptySnapshotName = Bytes.toBytes("emptySnaptb0-" + testName.getMethodName()); // create Table createTable(); // Take an empty snapshot admin.snapshot(emptySnapshotName, tableName); // Add some rows SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 50, FAMILY); tableNumFiles = admin.getTableRegions(tableName).size(); // take a snapshot admin.snapshot(snapshotName, tableName); }
SnapshotTestingUtils.loadData(UTIL, snapshotTableName, rowCountCF1, CF1); SnapshotTestingUtils.loadData(UTIL, snapshotTableName, rowCountCF2, CF2); SnapshotTestingUtils.verifyRowCount(UTIL, snapshotTableName, rowCountCF1 + rowCountCF2); SnapshotTestingUtils.loadData(UTIL, snapshotTableName, rowCountCF3, CF3); SnapshotTestingUtils.loadData(UTIL, snapshotTableName, rowCountCF4, CF4); SnapshotTestingUtils.loadData(UTIL, snapshotTableName, rowCountCF1addition, CF1); HTableDescriptor currentHTD = admin.getTableDescriptor(snapshotTableName); assertTrue(currentHTD.hasFamily(CF1));
/** * Test simple flush snapshotting a table that is online * @throws Exception */ @Test public void testFlushTableSnapshotWithProcedure() throws Exception { // make sure we don't fail on listing snapshots SnapshotTestingUtils.assertNoSnapshots(admin); // put some stuff in the table SnapshotTestingUtils.loadData(UTIL, TABLE_NAME, DEFAULT_NUM_ROWS, TEST_FAM); LOG.debug("FS state before snapshot:"); UTIL.getHBaseCluster().getMaster().getMasterFileSystem().logFileSystemState(LOG); // take a snapshot of the enabled table String snapshotString = "offlineTableSnapshot"; byte[] snapshot = Bytes.toBytes(snapshotString); Map<String, String> props = new HashMap<>(); props.put("table", TABLE_NAME.getNameAsString()); admin.execProcedure(SnapshotManager.ONLINE_SNAPSHOT_CONTROLLER_DESCRIPTION, snapshotString, props); LOG.debug("Snapshot completed."); // make sure we have the snapshot List<SnapshotDescription> snapshots = SnapshotTestingUtils.assertOneSnapshotThatMatches(admin, snapshot, TABLE_NAME); // make sure its a valid snapshot LOG.debug("FS state after snapshot:"); UTIL.getHBaseCluster().getMaster().getMasterFileSystem().logFileSystemState(LOG); SnapshotTestingUtils.confirmSnapshotValid(UTIL, ProtobufUtil.createHBaseProtosSnapshotDesc(snapshots.get(0)), TABLE_NAME, TEST_FAM); }
SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 500, FAMILY); try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { snapshot0Rows = countRows(table); SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 500, FAMILY); try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { snapshot1Rows = countRows(table);
@Test @Override public void testCloneLinksAfterDelete() throws IOException, InterruptedException { // delay the flush to make sure delayFlush = true; SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 20, FAMILY); long tid = System.currentTimeMillis(); byte[] snapshotName3 = Bytes.toBytes("snaptb3-" + tid); TableName clonedTableName3 = TableName.valueOf(name.getMethodName() + System.currentTimeMillis()); admin.snapshot(snapshotName3, tableName); delayFlush = false; int snapshot3Rows = -1; try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { snapshot3Rows = TEST_UTIL.countRows(table); } admin.cloneSnapshot(snapshotName3, clonedTableName3); admin.deleteSnapshot(snapshotName3); super.testCloneLinksAfterDelete(); verifyRowCount(TEST_UTIL, clonedTableName3, snapshot3Rows); admin.disableTable(clonedTableName3); admin.deleteTable(clonedTableName3); } }
@Test public void testRestoreSnapshotAfterSplittingRegions() throws IOException, InterruptedException { List<RegionInfo> regionInfos = admin.getRegions(tableName); RegionReplicaUtil.removeNonDefaultRegions(regionInfos); // Split the first region splitRegion(regionInfos.get(0)); // Take a snapshot admin.snapshot(snapshotName1, tableName); // Load more data SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 500, FAMILY); // Split the second region splitRegion(regionInfos.get(1)); // Restore the snapshot admin.disableTable(tableName); admin.restoreSnapshot(snapshotName1); admin.enableTable(tableName); verifyRowCount(TEST_UTIL, tableName, snapshot1Rows); } }
/** * Test simple flush snapshotting a table that is online * @throws Exception */ @Test public void testFlushTableSnapshot() throws Exception { // make sure we don't fail on listing snapshots SnapshotTestingUtils.assertNoSnapshots(admin); // put some stuff in the table SnapshotTestingUtils.loadData(UTIL, TABLE_NAME, DEFAULT_NUM_ROWS, TEST_FAM); LOG.debug("FS state before snapshot:"); UTIL.getHBaseCluster().getMaster().getMasterFileSystem().logFileSystemState(LOG); // take a snapshot of the enabled table String snapshotString = "offlineTableSnapshot"; byte[] snapshot = Bytes.toBytes(snapshotString); admin.snapshot(snapshotString, TABLE_NAME, SnapshotType.FLUSH); LOG.debug("Snapshot completed."); // make sure we have the snapshot List<SnapshotDescription> snapshots = SnapshotTestingUtils.assertOneSnapshotThatMatches(admin, snapshot, TABLE_NAME); // make sure its a valid snapshot LOG.debug("FS state after snapshot:"); UTIL.getHBaseCluster().getMaster().getMasterFileSystem().logFileSystemState(LOG); SnapshotTestingUtils.confirmSnapshotValid(UTIL, ProtobufUtil.createHBaseProtosSnapshotDesc(snapshots.get(0)), TABLE_NAME, TEST_FAM); }
/** * 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.loadData(UTIL, TABLE_NAME, numRows, TEST_FAM);
SnapshotTestingUtils.loadData(UTIL, TABLE_NAME, numRows, TEST_FAM);
HBaseTestingUtility.modifyTableSync(TEST_UTIL.getAdmin(), table1Desc); SnapshotTestingUtils.loadData(TEST_UTIL, table1, 50, fam2Name); HTable t1 = (HTable) conn.getTable(table1); int rows0 = MobSnapshotTestingUtils.countMobRows(t1, fam2Name);
SnapshotTestingUtils.loadData(UTIL, tableName, 500, TEST_FAM); try (Table table = UTIL.getConnection().getTable(tableName)) { snapshot0Rows = UTIL.countRows(table); SnapshotTestingUtils.loadData(UTIL, tableName, 500, TEST_FAM); try (Table table = UTIL.getConnection().getTable(tableName)) { snapshot1Rows = UTIL.countRows(table);
private void createTableAndSnapshots() throws Exception { // create Table and disable it createTable(); admin.disableTable(tableName); // take an empty snapshot admin.snapshot(emptySnapshot, tableName); // enable table and insert data admin.enableTable(tableName); SnapshotTestingUtils.loadData(TEST_UTIL, tableName, numRowsToLoad(), FAMILY); try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { snapshot0Rows = countRows(table); } admin.disableTable(tableName); // take a snapshot admin.snapshot(snapshotName0, tableName); // enable table and insert more data admin.enableTable(tableName); SnapshotTestingUtils.loadData(TEST_UTIL, tableName, numRowsToLoad(), FAMILY); try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { snapshot1Rows = countRows(table); } admin.disableTable(tableName); // take a snapshot of the updated table admin.snapshot(snapshotName1, tableName); // re-enable table admin.enableTable(tableName); }
SnapshotTestingUtils.loadData(UTIL, tableName, 500, TEST_FAM); try (Table table = UTIL.getConnection().getTable(tableName)) { snapshot0Rows = UTIL.countRows(table); SnapshotTestingUtils.loadData(UTIL, tableName, 500, TEST_FAM); try (Table table = UTIL.getConnection().getTable(tableName)) { snapshot1Rows = UTIL.countRows(table);
@Test public void testRestoreSnapshotAfterTruncate() throws Exception { TableName tableName = TableName.valueOf(getValidMethodName()); SnapshotTestingUtils.createTable(TEST_UTIL, tableName, getNumReplicas(), FAMILY); SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 500, FAMILY); int numOfRows = 0; try (Table table = TEST_UTIL.getConnection().getTable(tableName)) { numOfRows = countRows(table); } // take snapshot admin.snapshot("snap", tableName); admin.disableTable(tableName); admin.truncateTable(tableName, false); admin.disableTable(tableName); admin.restoreSnapshot("snap"); admin.enableTable(tableName); verifyRowCount(TEST_UTIL, tableName, numOfRows); SnapshotTestingUtils.verifyReplicasCameOnline(tableName, admin, getNumReplicas()); } }
TableDescriptor htd = admin.getDescriptor(tableName); assertEquals(2, htd.getColumnFamilyCount()); SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 500, TEST_FAMILY2); long snapshot2Rows = snapshot1Rows + 500L; assertEquals(snapshot2Rows, countRows(table));