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);
if (!targetStatus.isInViolation()) { if (LOG.isDebugEnabled()) { LOG.debug(table + " moving into observance of table space quota."); if (!currentStatus.isInViolation()) { LOG.trace(table + " remains in observance of quota."); } else {
if (!status.isInViolation()) { throw new IllegalStateException( tableName + " is not in violation. Violation policy should not be enabled.");
master.getQuotaObserverChore().getTableSnapshotStore(); SpaceQuotaSnapshot snapshot = tableStore.getCurrentState(tn); assertFalse("Quota should not be in violation", snapshot.getQuotaStatus().isInViolation());
if (currentSnapshot.getQuotaStatus().isInViolation()) { if (LOG.isTraceEnabled()) { LOG.trace("Moving " + tableInLimbo + " out of violation because fewer region sizes were"
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());
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());
if (targetSnapshot.getQuotaStatus().isInViolation()) { numNamespacesInViolation++;
if (targetSnapshot.getQuotaStatus().isInViolation()) { numTablesInViolation++;
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);
/** * 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; }
/** * 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; } }
assertEquals(sizeLimit, snapshot.getLimit()); SpaceQuotaStatus pbStatus = snapshot.getQuotaStatus(); assertFalse(pbStatus.isInViolation());
private int numSnapshotsInViolation(Map<TableName,SpaceQuotaSnapshot> snapshots) { int sum = 0; for (SpaceQuotaSnapshot snapshot : snapshots.values()) { if (snapshot.getQuotaStatus().isInViolation()) { sum++; } } return sum; }
@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(); } });
@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(); } });
@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(); } });
/** * 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(); }
public static QuotaProtos.SpaceQuotaStatus toProto(SpaceQuotaStatus status) { QuotaProtos.SpaceQuotaStatus.Builder builder = QuotaProtos.SpaceQuotaStatus.newBuilder(); builder.setInViolation(status.inViolation); if (status.isInViolation()) { builder.setViolationPolicy(ProtobufUtil.toProtoViolationPolicy(status.getPolicy().get())); } return builder.build(); }
@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(); } });