Search in sources :

Example 11 with SpaceQuotaStatus

use of org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot.SpaceQuotaStatus in project hbase by apache.

the class QuotaObserverChore method updateTableQuota.

/**
 * Updates the hbase:quota table with the new quota policy for this <code>table</code>
 * if necessary.
 *
 * @param table The table being checked
 * @param currentSnapshot The state of the quota on this table from the previous invocation.
 * @param targetSnapshot The state the quota should be in for this table.
 */
void updateTableQuota(TableName table, SpaceQuotaSnapshot currentSnapshot, SpaceQuotaSnapshot targetSnapshot) throws IOException {
    final SpaceQuotaStatus currentStatus = currentSnapshot.getQuotaStatus();
    final SpaceQuotaStatus targetStatus = targetSnapshot.getQuotaStatus();
    // If we're changing something, log it.
    if (!currentSnapshot.equals(targetSnapshot)) {
        this.snapshotNotifier.transitionTable(table, targetSnapshot);
        // Update it in memory
        tableSnapshotStore.setCurrentState(table, targetSnapshot);
        // If the target is none, we're moving out of violation. Update the hbase:quota table
        SpaceViolationPolicy currPolicy = currentStatus.getPolicy().orElse(null);
        SpaceViolationPolicy targetPolicy = targetStatus.getPolicy().orElse(null);
        if (!targetStatus.isInViolation()) {
            // In case of Disable SVP, we need to enable the table as it moves out of violation
            if (isDisableSpaceViolationPolicy(currPolicy, targetPolicy)) {
                QuotaUtil.enableTableIfNotEnabled(conn, table);
            }
            if (LOG.isDebugEnabled()) {
                LOG.debug(table + " moved into observance of table space quota.");
            }
        } else {
            // We're either moving into violation or changing violation policies
            if (currPolicy != targetPolicy && SpaceViolationPolicy.DISABLE == currPolicy) {
                // In case of policy switch, we need to enable the table if current policy is Disable SVP
                QuotaUtil.enableTableIfNotEnabled(conn, table);
            } else if (SpaceViolationPolicy.DISABLE == targetPolicy) {
                // In case of Disable SVP, we need to disable the table as it moves into violation
                QuotaUtil.disableTableIfNotDisabled(conn, table);
            }
            if (LOG.isDebugEnabled()) {
                LOG.debug(table + " moved into violation of table space quota with policy of " + targetPolicy);
            }
        }
    } else if (LOG.isTraceEnabled()) {
        // the quota table
        if (!currentStatus.isInViolation()) {
            LOG.trace(table + " remains in observance of quota.");
        } else {
            LOG.trace(table + " remains in violation of quota.");
        }
    }
}
Also used : SpaceQuotaStatus(org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot.SpaceQuotaStatus)

Example 12 with SpaceQuotaStatus

use of org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot.SpaceQuotaStatus in project hbase by apache.

the class QuotaObserverChore method updateNamespaceQuota.

/**
 * Updates the hbase:quota table with the target quota policy for this <code>namespace</code>
 * if necessary.
 *
 * @param namespace The namespace being checked
 * @param currentSnapshot The state of the quota on this namespace from the previous invocation
 * @param targetSnapshot The state the quota should be in for this namespace
 * @param tablesByNamespace A mapping of tables in namespaces.
 */
void updateNamespaceQuota(String namespace, SpaceQuotaSnapshot currentSnapshot, SpaceQuotaSnapshot targetSnapshot, final Multimap<String, TableName> tablesByNamespace) throws IOException {
    final SpaceQuotaStatus targetStatus = targetSnapshot.getQuotaStatus();
    // When the policies differ, we need to move into or out of violation
    if (!currentSnapshot.equals(targetSnapshot)) {
        // We want to have a policy of "NONE", moving out of violation
        if (!targetStatus.isInViolation()) {
            for (TableName tableInNS : tablesByNamespace.get(namespace)) {
                // If there is a quota on this table in violation
                if (tableSnapshotStore.getCurrentState(tableInNS).getQuotaStatus().isInViolation()) {
                    // Table-level quota violation policy is being applied here.
                    if (LOG.isTraceEnabled()) {
                        LOG.trace("Not activating Namespace violation policy because a Table violation" + " policy is already in effect for " + tableInNS);
                    }
                } else {
                    LOG.info(tableInNS + " moving into observance of namespace space quota");
                    this.snapshotNotifier.transitionTable(tableInNS, targetSnapshot);
                }
            }
        // We want to move into violation at the NS level
        } else {
            // Moving tables in the namespace into violation or to a different violation policy
            for (TableName tableInNS : tablesByNamespace.get(namespace)) {
                final SpaceQuotaSnapshot tableQuotaSnapshot = tableSnapshotStore.getCurrentState(tableInNS);
                final boolean hasTableQuota = !Objects.equals(QuotaSnapshotStore.NO_QUOTA, tableQuotaSnapshot);
                if (hasTableQuota && tableQuotaSnapshot.getQuotaStatus().isInViolation()) {
                    // Table-level quota violation policy is being applied here.
                    if (LOG.isTraceEnabled()) {
                        LOG.trace("Not activating Namespace violation policy because a Table violation" + " policy is already in effect for " + tableInNS);
                    }
                } else {
                    // No table quota present or a table quota present that is not in violation
                    LOG.info(tableInNS + " moving into violation of namespace space quota with policy " + targetStatus.getPolicy());
                    this.snapshotNotifier.transitionTable(tableInNS, targetSnapshot);
                }
            }
        }
        // Update the new state in memory for this namespace
        namespaceSnapshotStore.setCurrentState(namespace, targetSnapshot);
    } else {
        // Policies are the same
        if (!targetStatus.isInViolation()) {
            // Both are NONE, so we remain in observance
            if (LOG.isTraceEnabled()) {
                LOG.trace(namespace + " remains in observance of quota.");
            }
        } else {
            // taking priority.
            for (TableName tableInNS : tablesByNamespace.get(namespace)) {
                // Does a table policy exist
                if (tableSnapshotStore.getCurrentState(tableInNS).getQuotaStatus().isInViolation()) {
                    // Table-level quota violation policy is being applied here.
                    if (LOG.isTraceEnabled()) {
                        LOG.trace("Not activating Namespace violation policy because Table violation" + " policy is already in effect for " + tableInNS);
                    }
                } else {
                    // No table policy, so enact namespace policy
                    LOG.info(tableInNS + " moving into violation of namespace space quota");
                    this.snapshotNotifier.transitionTable(tableInNS, targetSnapshot);
                }
            }
        }
    }
}
Also used : SpaceQuotaStatus(org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot.SpaceQuotaStatus) TableName(org.apache.hadoop.hbase.TableName)

Example 13 with SpaceQuotaStatus

use of org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot.SpaceQuotaStatus in project hbase by apache.

the class RegionServerSpaceQuotaManager method enforceViolationPolicy.

/**
 * Enforces the given violationPolicy on the given table in this RegionServer.
 */
public void enforceViolationPolicy(TableName tableName, SpaceQuotaSnapshot snapshot) {
    SpaceQuotaStatus status = snapshot.getQuotaStatus();
    if (!status.isInViolation()) {
        throw new IllegalStateException(tableName + " is not in violation. Violation policy should not be enabled.");
    }
    if (LOG.isTraceEnabled()) {
        LOG.trace("Enabling violation policy enforcement on " + tableName + " with policy " + status.getPolicy());
    }
    // Construct this outside of the lock
    final SpaceViolationPolicyEnforcement enforcement = getFactory().create(getRegionServerServices(), tableName, snapshot);
    // it would become a bottleneck at large clusters/number of tables.
    synchronized (enforcedPolicies) {
        try {
            enforcement.enable();
        } catch (IOException e) {
            LOG.error("Failed to enable space violation policy for " + tableName + ". This table will not enter violation.", e);
            return;
        }
        enforcedPolicies.put(tableName, enforcement);
    }
}
Also used : SpaceQuotaStatus(org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot.SpaceQuotaStatus) IOException(java.io.IOException)

Example 14 with SpaceQuotaStatus

use of org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot.SpaceQuotaStatus 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 15 with SpaceQuotaStatus

use of org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot.SpaceQuotaStatus in project hbase by apache.

the class TestRegionServerSpaceQuotaManager method testExceptionOnPolicyEnforcementEnable.

@Test
public void testExceptionOnPolicyEnforcementEnable() throws Exception {
    final TableName tableName = TableName.valueOf("foo");
    final SpaceQuotaSnapshot snapshot = new SpaceQuotaSnapshot(new SpaceQuotaStatus(SpaceViolationPolicy.DISABLE), 1024L, 2048L);
    RegionServerServices rss = mock(RegionServerServices.class);
    SpaceViolationPolicyEnforcementFactory factory = mock(SpaceViolationPolicyEnforcementFactory.class);
    SpaceViolationPolicyEnforcement enforcement = mock(SpaceViolationPolicyEnforcement.class);
    RegionServerSpaceQuotaManager realManager = new RegionServerSpaceQuotaManager(rss, factory);
    when(factory.create(rss, tableName, snapshot)).thenReturn(enforcement);
    doThrow(new IOException("Failed for test!")).when(enforcement).enable();
    realManager.enforceViolationPolicy(tableName, snapshot);
    Map<TableName, SpaceViolationPolicyEnforcement> enforcements = realManager.copyActiveEnforcements();
    assertTrue("Expected active enforcements to be empty, but were " + enforcements, enforcements.isEmpty());
}
Also used : TableName(org.apache.hadoop.hbase.TableName) SpaceQuotaStatus(org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot.SpaceQuotaStatus) RegionServerServices(org.apache.hadoop.hbase.regionserver.RegionServerServices) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

SpaceQuotaStatus (org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot.SpaceQuotaStatus)17 TableName (org.apache.hadoop.hbase.TableName)9 Test (org.junit.Test)9 IOException (java.io.IOException)3 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)3 HashMap (java.util.HashMap)2 Put (org.apache.hadoop.hbase.client.Put)2 Table (org.apache.hadoop.hbase.client.Table)2 SpaceQuotaSnapshot (org.apache.hadoop.hbase.quotas.SpaceQuotaSnapshot)2 DefaultViolationPolicyEnforcement (org.apache.hadoop.hbase.quotas.policies.DefaultViolationPolicyEnforcement)2 DisableTableViolationPolicyEnforcement (org.apache.hadoop.hbase.quotas.policies.DisableTableViolationPolicyEnforcement)2 NoInsertsViolationPolicyEnforcement (org.apache.hadoop.hbase.quotas.policies.NoInsertsViolationPolicyEnforcement)2 NoWritesCompactionsViolationPolicyEnforcement (org.apache.hadoop.hbase.quotas.policies.NoWritesCompactionsViolationPolicyEnforcement)2 NoWritesViolationPolicyEnforcement (org.apache.hadoop.hbase.quotas.policies.NoWritesViolationPolicyEnforcement)2 RegionServerServices (org.apache.hadoop.hbase.regionserver.RegionServerServices)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Result (org.apache.hadoop.hbase.client.Result)1 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)1 RetriesExhaustedWithDetailsException (org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException)1