use of org.apache.hadoop.hbase.quotas.SpaceQuotaHelperForTests.NoFilesToDischarge in project hbase by apache.
the class TestSnapshotQuotaObserverChore method testSnapshotSize.
@Test
public void testSnapshotSize() throws Exception {
// Create a table and set a quota
TableName tn1 = helper.createTableWithRegions(5);
admin.setQuota(QuotaSettingsFactory.limitTableSpace(tn1, SpaceQuotaHelperForTests.ONE_GIGABYTE, SpaceViolationPolicy.NO_INSERTS));
// Write some data and flush it
helper.writeData(tn1, 256L * SpaceQuotaHelperForTests.ONE_KILOBYTE);
admin.flush(tn1);
final long snapshotSize = TEST_UTIL.getMiniHBaseCluster().getRegions(tn1).stream().flatMap(r -> r.getStores().stream()).mapToLong(HStore::getHFilesSize).sum();
// Wait for the Master chore to run to see the usage (with a fudge factor)
TEST_UTIL.waitFor(30_000, new SpaceQuotaSnapshotPredicate(conn, tn1) {
@Override
boolean evaluate(SpaceQuotaSnapshot snapshot) throws Exception {
return snapshot.getUsage() == snapshotSize;
}
});
// Create a snapshot on the table
final String snapshotName = tn1 + "snapshot";
admin.snapshot(new SnapshotDescription(snapshotName, tn1, SnapshotType.SKIPFLUSH));
// Get the snapshots
Multimap<TableName, String> snapshotsToCompute = testChore.getSnapshotsToComputeSize();
assertEquals("Expected to see the single snapshot: " + snapshotsToCompute, 1, snapshotsToCompute.size());
// Get the size of our snapshot
Map<String, Long> namespaceSnapshotSizes = testChore.computeSnapshotSizes(snapshotsToCompute);
assertEquals(1, namespaceSnapshotSizes.size());
Long size = namespaceSnapshotSizes.get(tn1.getNamespaceAsString());
assertNotNull(size);
// The snapshot should take up no space since the table refers to it completely
assertEquals(0, size.longValue());
// Write some more data, flush it, and then major_compact the table
helper.writeData(tn1, 256L * SpaceQuotaHelperForTests.ONE_KILOBYTE);
admin.flush(tn1);
TEST_UTIL.compact(tn1, true);
// Test table should reflect it's original size since ingest was deterministic
TEST_UTIL.waitFor(30_000, new SpaceQuotaSnapshotPredicate(conn, tn1) {
private final long regionSize = TEST_UTIL.getMiniHBaseCluster().getRegions(tn1).stream().flatMap(r -> r.getStores().stream()).mapToLong(HStore::getHFilesSize).sum();
@Override
boolean evaluate(SpaceQuotaSnapshot snapshot) throws Exception {
LOG.debug("Current usage=" + snapshot.getUsage() + " snapshotSize=" + snapshotSize);
// The usage of table space consists of region size and snapshot size
return closeInSize(snapshot.getUsage(), snapshotSize + regionSize, SpaceQuotaHelperForTests.ONE_KILOBYTE);
}
});
// Wait for no compacted files on the regions of our table
TEST_UTIL.waitFor(30_000, new NoFilesToDischarge(TEST_UTIL.getMiniHBaseCluster(), tn1));
// Still should see only one snapshot
snapshotsToCompute = testChore.getSnapshotsToComputeSize();
assertEquals("Expected to see the single snapshot: " + snapshotsToCompute, 1, snapshotsToCompute.size());
namespaceSnapshotSizes = testChore.computeSnapshotSizes(snapshotsToCompute);
assertEquals(1, namespaceSnapshotSizes.size());
size = namespaceSnapshotSizes.get(tn1.getNamespaceAsString());
assertNotNull(size);
// The snapshot should take up the size the table originally took up
assertEquals(snapshotSize, size.longValue());
}
Aggregations