Search in sources :

Example 6 with SpaceQuotaSnapshot

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);
    }
}
Also used : SpaceQuotaSnapshot(org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot) TableName(org.apache.hadoop.hbase.TableName) ServiceException(org.apache.hbase.thirdparty.com.google.protobuf.ServiceException) QuotaObserverChore(org.apache.hadoop.hbase.quotas.QuotaObserverChore) GetQuotaStatesResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.GetQuotaStatesResponse) ByteString(org.apache.hbase.thirdparty.com.google.protobuf.ByteString) ReplicationException(org.apache.hadoop.hbase.replication.ReplicationException) ServerNotRunningYetException(org.apache.hadoop.hbase.ipc.ServerNotRunningYetException) UnknownProtocolException(org.apache.hadoop.hbase.exceptions.UnknownProtocolException) ServiceException(org.apache.hbase.thirdparty.com.google.protobuf.ServiceException) ForeignException(org.apache.hadoop.hbase.errorhandling.ForeignException) IOException(java.io.IOException) RemoteProcedureException(org.apache.hadoop.hbase.procedure2.RemoteProcedureException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) UnknownRegionException(org.apache.hadoop.hbase.UnknownRegionException) KeeperException(org.apache.zookeeper.KeeperException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 7 with SpaceQuotaSnapshot

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;
}
Also used : SpaceQuotaSnapshot(org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot) TableName(org.apache.hadoop.hbase.TableName) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) Entry(java.util.Map.Entry) HashMap(java.util.HashMap) QuotaObserverChore(org.apache.hadoop.hbase.quotas.QuotaObserverChore)

Example 8 with SpaceQuotaSnapshot

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());
}
Also used : SpaceQuotaSnapshot(org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot) SpaceQuotaStatus(org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot.SpaceQuotaStatus) CompactionLifeCycleTracker(org.apache.hadoop.hbase.regionserver.compactions.CompactionLifeCycleTracker) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 9 with SpaceQuotaSnapshot

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);
}
Also used : Path(org.apache.hadoop.fs.Path) SpaceQuotaSnapshot(org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot) FileStatus(org.apache.hadoop.fs.FileStatus) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 10 with SpaceQuotaSnapshot

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);
}
Also used : Path(org.apache.hadoop.fs.Path) SpaceQuotaSnapshot(org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot) FileStatus(org.apache.hadoop.fs.FileStatus) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

SpaceQuotaSnapshot (org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot)10 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)4 FileStatus (org.apache.hadoop.fs.FileStatus)4 Path (org.apache.hadoop.fs.Path)4 TableName (org.apache.hadoop.hbase.TableName)3 QuotaObserverChore (org.apache.hadoop.hbase.quotas.QuotaObserverChore)3 IOException (java.io.IOException)2 SimpleImmutableEntry (java.util.AbstractMap.SimpleImmutableEntry)2 HashMap (java.util.HashMap)2 Entry (java.util.Map.Entry)2 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)2 UnknownProtocolException (org.apache.hadoop.hbase.exceptions.UnknownProtocolException)2 ServerNotRunningYetException (org.apache.hadoop.hbase.ipc.ServerNotRunningYetException)2 SpaceQuotaStatus (org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot.SpaceQuotaStatus)2 ServiceException (org.apache.hbase.thirdparty.com.google.protobuf.ServiceException)2 FileNotFoundException (java.io.FileNotFoundException)1 UncheckedIOException (java.io.UncheckedIOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 BindException (java.net.BindException)1