use of org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot in project hbase by apache.
the class MasterRpcServices method getQuotaStates.
@Override
public GetQuotaStatesResponse getQuotaStates(RpcController controller, GetQuotaStatesRequest request) throws ServiceException {
try {
server.checkInitialized();
QuotaObserverChore quotaChore = this.server.getQuotaObserverChore();
GetQuotaStatesResponse.Builder builder = GetQuotaStatesResponse.newBuilder();
if (quotaChore != null) {
// The "current" view of all tables with quotas
Map<TableName, SpaceQuotaSnapshot> tableSnapshots = quotaChore.getTableQuotaSnapshots();
for (Entry<TableName, SpaceQuotaSnapshot> entry : tableSnapshots.entrySet()) {
builder.addTableSnapshots(TableQuotaSnapshot.newBuilder().setTableName(ProtobufUtil.toProtoTableName(entry.getKey())).setSnapshot(SpaceQuotaSnapshot.toProtoSnapshot(entry.getValue())).build());
}
// The "current" view of all namespaces with quotas
Map<String, SpaceQuotaSnapshot> nsSnapshots = quotaChore.getNamespaceQuotaSnapshots();
for (Entry<String, SpaceQuotaSnapshot> entry : nsSnapshots.entrySet()) {
builder.addNsSnapshots(NamespaceQuotaSnapshot.newBuilder().setNamespace(entry.getKey()).setSnapshot(SpaceQuotaSnapshot.toProtoSnapshot(entry.getValue())).build());
}
return builder.build();
}
return builder.build();
} catch (Exception e) {
throw new ServiceException(e);
}
}
use of org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot in project hbase by apache.
the class MetricsMasterWrapperImpl method getTableSpaceUtilization.
@Override
public Map<String, Entry<Long, Long>> getTableSpaceUtilization() {
if (master == null) {
return Collections.emptyMap();
}
QuotaObserverChore quotaChore = master.getQuotaObserverChore();
if (quotaChore == null) {
return Collections.emptyMap();
}
Map<TableName, SpaceQuotaSnapshot> tableSnapshots = quotaChore.getTableQuotaSnapshots();
Map<String, Entry<Long, Long>> convertedData = new HashMap<>();
for (Entry<TableName, SpaceQuotaSnapshot> entry : tableSnapshots.entrySet()) {
convertedData.put(entry.getKey().toString(), convertSnapshot(entry.getValue()));
}
return convertedData;
}
use of org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot in project hbase by apache.
the class TestCompactionLifeCycleTracker method testSpaceQuotaViolation.
// This test assumes that compaction wouldn't happen with null user.
// But null user means system generated compaction so compaction should happen
// even if the space quota is violated. So this test should be removed/ignored.
@Ignore
@Test
public void testSpaceQuotaViolation() throws IOException, InterruptedException {
region.getRegionServerServices().getRegionServerSpaceQuotaManager().enforceViolationPolicy(NAME, new SpaceQuotaSnapshot(new SpaceQuotaStatus(SpaceViolationPolicy.NO_WRITES_COMPACTIONS), 10L, 100L));
Tracker tracker = new Tracker();
TRACKER = tracker;
region.requestCompaction("test", Store.PRIORITY_USER, false, tracker);
tracker.await();
assertEquals(2, tracker.notExecutedStores.size());
tracker.notExecutedStores.sort((p1, p2) -> p1.getFirst().getColumnFamilyName().compareTo(p2.getFirst().getColumnFamilyName()));
assertEquals(Bytes.toString(CF2), tracker.notExecutedStores.get(1).getFirst().getColumnFamilyName());
assertThat(tracker.notExecutedStores.get(1).getSecond(), containsString("space quota violation"));
assertTrue(tracker.beforeExecuteStores.isEmpty());
assertTrue(tracker.afterExecuteStores.isEmpty());
}
use of org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot in project hbase by apache.
the class TestBulkLoadCheckingViolationPolicyEnforcement method testSumOfFilesOverLimit.
@Test(expected = SpaceLimitingException.class)
public void testSumOfFilesOverLimit() throws Exception {
final List<String> paths = new ArrayList<>();
final List<FileStatus> statuses = new ArrayList<>();
final long length = 1024L;
for (int i = 0; i < 5; i++) {
String path = "/" + i;
FileStatus status = mock(FileStatus.class);
when(fs.getFileStatus(new Path(path))).thenReturn(status);
when(status.getLen()).thenReturn(length);
when(status.isFile()).thenReturn(true);
paths.add(path);
statuses.add(status);
}
// Quota is not in violation now, but 5*1024 files would push us to violation
SpaceQuotaSnapshot snapshot = new SpaceQuotaSnapshot(SpaceQuotaStatus.notInViolation(), 0, 5000L);
policy.initialize(rss, tableName, snapshot);
policy.computeBulkLoadSize(fs, paths);
}
use of org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot in project hbase by apache.
the class TestBulkLoadCheckingViolationPolicyEnforcement method testFileIsNotAFile.
@Test(expected = IllegalArgumentException.class)
public void testFileIsNotAFile() throws Exception {
final List<String> paths = new ArrayList<>();
String path = "/1";
FileStatus status = mock(FileStatus.class);
when(fs.getFileStatus(new Path(path))).thenReturn(status);
when(status.getLen()).thenReturn(1000L);
when(status.isFile()).thenReturn(false);
paths.add(path);
// Quota is not in violation now
SpaceQuotaSnapshot snapshot = new SpaceQuotaSnapshot(SpaceQuotaStatus.notInViolation(), 0, Long.MAX_VALUE);
policy.initialize(rss, tableName, snapshot);
// If the file to bulk load isn't a file, this should throw an exception
policy.computeBulkLoadSize(fs, paths);
}
Aggregations