/** * Checks if the given <code>snapshot</code> is in violation, allowing the snapshot to be null. * If the snapshot is null, this is interpreted as no snapshot which implies not in violation. * * @param snapshot The snapshot to operate on. * @return true if the snapshot is in violation, false otherwise. */ boolean isInViolation(SpaceQuotaSnapshot snapshot) { if (snapshot == null) { return false; } return snapshot.getQuotaStatus().isInViolation(); }
private int numSnapshotsInViolation(Map<TableName,SpaceQuotaSnapshot> snapshots) { int sum = 0; for (SpaceQuotaSnapshot snapshot : snapshots.values()) { if (snapshot.getQuotaStatus().isInViolation()) { sum++; } } return sum; }
TableName table, SpaceQuotaSnapshot currentSnapshot, SpaceQuotaSnapshot targetSnapshot) throws IOException { final SpaceQuotaStatus currentStatus = currentSnapshot.getQuotaStatus(); final SpaceQuotaStatus targetStatus = targetSnapshot.getQuotaStatus();
SpaceQuotaStatus status = snapshot.getQuotaStatus(); if (!status.isInViolation()) { throw new IllegalStateException(
if (!isInViolation(currentSnapshot) && newSnapshot.getQuotaStatus().isInViolation()) { if (LOG.isTraceEnabled()) { LOG.trace("Enabling " + newSnapshot + " on " + tableName); if (isInViolation(currentSnapshot) && !newSnapshot.getQuotaStatus().isInViolation()) { if (LOG.isTraceEnabled()) { LOG.trace("Removing quota violation policy on " + tableName);
@Override public boolean evaluate() throws Exception { Map<TableName,SpaceQuotaSnapshot> snapshots = rs.getRegionServerSpaceQuotaManager().copyQuotaSnapshots(); SpaceQuotaSnapshot snapshot = snapshots.get(tn); if (snapshot == null) { LOG.info("Found no snapshot for " + tn); return false; } LOG.info("Found snapshot " + snapshot); return snapshot.getQuotaStatus().isInViolation(); } });
if (targetSnapshot.getQuotaStatus().isInViolation()) { numTablesInViolation++;
if (targetSnapshot.getQuotaStatus().isInViolation()) { numNamespacesInViolation++;
/** * Creates the "default" {@link SpaceViolationPolicyEnforcement} for a table that isn't in * violation. This is used to have uniform policy checking for tables in and not quotas. This * policy will still verify that new bulk loads do not exceed the configured quota limit. * * @param rss RegionServerServices instance the policy enforcement should use. * @param tableName The target HBase table. * @param snapshot The current quota snapshot for the {@code tableName}, can be null. */ public SpaceViolationPolicyEnforcement createWithoutViolation( RegionServerServices rss, TableName tableName, SpaceQuotaSnapshot snapshot) { if (snapshot == null) { // If we have no snapshot, this is equivalent to no quota for this table. // We should do use the (singleton instance) of this policy to do nothing. return MissingSnapshotViolationPolicyEnforcement.getInstance(); } // We have a snapshot which means that there is a quota set on this table, but it's not in // violation of that quota. We need to construct a policy for this table. SpaceQuotaStatus status = snapshot.getQuotaStatus(); if (status.isInViolation()) { throw new IllegalArgumentException( tableName + " is in violation. Logic error. Snapshot=" + snapshot); } // We have a unique size snapshot to use. Create an instance for this tablename + snapshot. DefaultViolationPolicyEnforcement enforcement = new DefaultViolationPolicyEnforcement(); enforcement.initialize(rss, tableName, snapshot); return enforcement; } }
@Override public boolean evaluate() throws Exception { SpaceQuotaSnapshot snapshot = (SpaceQuotaSnapshot) conn.getAdmin().getCurrentSpaceQuotaSnapshot(tn); LOG.info("Table snapshot after second ingest: " + snapshot); if (snapshot == null) { return false; } return snapshot.getQuotaStatus().isInViolation(); } });
/** * Constructs the appropriate {@link SpaceViolationPolicyEnforcement} for tables that are * in violation of their space quota. */ public SpaceViolationPolicyEnforcement create( RegionServerServices rss, TableName tableName, SpaceQuotaSnapshot snapshot) { SpaceViolationPolicyEnforcement enforcement; SpaceQuotaStatus status = snapshot.getQuotaStatus(); if (!status.isInViolation()) { throw new IllegalArgumentException(tableName + " is not in violation. Snapshot=" + snapshot); } switch (status.getPolicy().get()) { case DISABLE: enforcement = new DisableTableViolationPolicyEnforcement(); break; case NO_WRITES_COMPACTIONS: enforcement = new NoWritesCompactionsViolationPolicyEnforcement(); break; case NO_WRITES: enforcement = new NoWritesViolationPolicyEnforcement(); break; case NO_INSERTS: enforcement = new NoInsertsViolationPolicyEnforcement(); break; default: throw new IllegalArgumentException("Unhandled SpaceViolationPolicy: " + status.getPolicy()); } enforcement.initialize(rss, tableName, snapshot); return enforcement; }
if (currentSnapshot.getQuotaStatus().isInViolation()) { if (LOG.isTraceEnabled()) { LOG.trace("Moving " + tableInLimbo + " out of violation because fewer region sizes were"
@Override public boolean evaluate() throws Exception { SpaceQuotaSnapshot snapshot = (SpaceQuotaSnapshot) conn.getAdmin() .getCurrentSpaceQuotaSnapshot(tn.getNamespaceAsString()); LOG.debug("Namespace snapshot after second ingest: " + snapshot); if (snapshot == null) { return false; } return snapshot.getUsage() > nsUsage.get() && !snapshot.getQuotaStatus().isInViolation(); } });
public static QuotaProtos.SpaceQuotaSnapshot toProtoSnapshot(SpaceQuotaSnapshot snapshot) { return QuotaProtos.SpaceQuotaSnapshot.newBuilder() .setQuotaStatus(SpaceQuotaStatus.toProto(snapshot.getQuotaStatus())) .setQuotaUsage(snapshot.getUsage()).setQuotaLimit(snapshot.getLimit()).build(); }
@Override public boolean evaluate() throws Exception { ActivePolicyEnforcement enforcements = manager.getActiveEnforcements(); SpaceViolationPolicyEnforcement enforcement = enforcements.getPolicyEnforcement(tn); // Signifies that we're waiting on the quota snapshot to be fetched if (enforcement instanceof MissingSnapshotViolationPolicyEnforcement) { return false; } return enforcement.getQuotaSnapshot().getQuotaStatus().isInViolation(); } });
assertEquals(false, store.getTargetState(NS, quota).getQuotaStatus().isInViolation()); assertEquals(false, store.getTargetState(NS, quota).getQuotaStatus().isInViolation()); assertEquals(true, store.getTargetState(NS, quota).getQuotaStatus().isInViolation()); assertEquals(SpaceViolationPolicy.DISABLE, store.getTargetState(NS, quota).getQuotaStatus().getPolicy().get());
assertEquals(tn, entry.getKey()); final SpaceQuotaSnapshot snapshot = entry.getValue(); if (!snapshot.getQuotaStatus().isInViolation()) { LOG.info("Found a snapshot, but it was not yet in violation. " + snapshot); sleepWithInterrupt(DEFAULT_WAIT_MILLIS); final SpaceQuotaSnapshot snapshot = entry.getValue(); assertEquals("Snapshot was " + snapshot, violationPolicy, snapshot.getQuotaStatus().getPolicy().get()); assertEquals(sizeLimit, snapshot.getLimit()); assertTrue("The usage should be greater than the limit, but were " + snapshot.getUsage() +
SpaceQuotaSnapshot snapshot = snapshots.get(tn); assertNotNull("Did not find snapshot for " + tn, snapshot); assertTrue(snapshot.getQuotaStatus().isInViolation()); assertEquals(SpaceViolationPolicy.NO_INSERTS, snapshot.getQuotaStatus().getPolicy().get());
master.getQuotaObserverChore().getTableSnapshotStore(); SpaceQuotaSnapshot snapshot = tableStore.getCurrentState(tn); assertFalse("Quota should not be in violation", snapshot.getQuotaStatus().isInViolation());
snapshot.getUsage() >= tableSize); assertEquals(sizeLimit, snapshot.getLimit()); SpaceQuotaStatus pbStatus = snapshot.getQuotaStatus(); assertFalse(pbStatus.isInViolation());