use of org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota in project hbase by apache.
the class GlobalQuotaSettingsImpl method merge.
@Override
protected GlobalQuotaSettingsImpl merge(QuotaSettings other) throws IOException {
// Validate the quota subject
validateQuotaTarget(other);
// Propagate the Throttle
QuotaProtos.Throttle.Builder throttleBuilder = throttleProto == null ? null : throttleProto.toBuilder();
if (other instanceof ThrottleSettings) {
ThrottleSettings otherThrottle = (ThrottleSettings) other;
if (!otherThrottle.proto.hasType() || !otherThrottle.proto.hasTimedQuota()) {
// It means it's a remove request
// To prevent the "empty" row in QuotaTableUtil.QUOTA_TABLE_NAME
QuotaProtos.ThrottleRequest otherProto = otherThrottle.proto;
if (throttleBuilder != null && !otherThrottle.proto.hasTimedQuota() && otherThrottle.proto.hasType()) {
switch(otherProto.getType()) {
case REQUEST_NUMBER:
throttleBuilder.clearReqNum();
break;
case REQUEST_SIZE:
throttleBuilder.clearReqSize();
break;
case WRITE_NUMBER:
throttleBuilder.clearWriteNum();
break;
case WRITE_SIZE:
throttleBuilder.clearWriteSize();
break;
case READ_NUMBER:
throttleBuilder.clearReadNum();
break;
case READ_SIZE:
throttleBuilder.clearReadSize();
break;
case REQUEST_CAPACITY_UNIT:
throttleBuilder.clearReqCapacityUnit();
break;
case READ_CAPACITY_UNIT:
throttleBuilder.clearReadCapacityUnit();
break;
case WRITE_CAPACITY_UNIT:
throttleBuilder.clearWriteCapacityUnit();
break;
default:
}
boolean hasThrottle = false;
for (QuotaProtos.ThrottleType quotaType : QuotaProtos.ThrottleType.values()) {
hasThrottle = hasThrottle(quotaType, throttleBuilder);
if (hasThrottle) {
break;
}
}
if (!hasThrottle) {
throttleBuilder = null;
}
} else {
throttleBuilder = null;
}
} else {
QuotaProtos.ThrottleRequest otherProto = otherThrottle.proto;
validateTimedQuota(otherProto.getTimedQuota());
if (throttleBuilder == null) {
throttleBuilder = QuotaProtos.Throttle.newBuilder();
}
switch(otherProto.getType()) {
case REQUEST_NUMBER:
throttleBuilder.setReqNum(otherProto.getTimedQuota());
break;
case REQUEST_SIZE:
throttleBuilder.setReqSize(otherProto.getTimedQuota());
break;
case WRITE_NUMBER:
throttleBuilder.setWriteNum(otherProto.getTimedQuota());
break;
case WRITE_SIZE:
throttleBuilder.setWriteSize(otherProto.getTimedQuota());
break;
case READ_NUMBER:
throttleBuilder.setReadNum(otherProto.getTimedQuota());
break;
case READ_SIZE:
throttleBuilder.setReadSize(otherProto.getTimedQuota());
break;
case REQUEST_CAPACITY_UNIT:
throttleBuilder.setReqCapacityUnit(otherProto.getTimedQuota());
break;
case READ_CAPACITY_UNIT:
throttleBuilder.setReadCapacityUnit(otherProto.getTimedQuota());
break;
case WRITE_CAPACITY_UNIT:
throttleBuilder.setWriteCapacityUnit(otherProto.getTimedQuota());
break;
default:
}
}
}
// Propagate the space quota portion
QuotaProtos.SpaceQuota.Builder spaceBuilder = (spaceProto == null ? null : spaceProto.toBuilder());
if (other instanceof SpaceLimitSettings) {
if (spaceBuilder == null) {
spaceBuilder = QuotaProtos.SpaceQuota.newBuilder();
}
SpaceLimitSettings settingsToMerge = (SpaceLimitSettings) other;
QuotaProtos.SpaceLimitRequest spaceRequest = settingsToMerge.getProto();
// The message contained the expect SpaceQuota object
if (spaceRequest.hasQuota()) {
SpaceQuota quotaToMerge = spaceRequest.getQuota();
// SpaceQuotas either apply to a table or a namespace (no user spacequota).
if (!Objects.equals(getTableName(), settingsToMerge.getTableName()) && !Objects.equals(getNamespace(), settingsToMerge.getNamespace())) {
throw new IllegalArgumentException("Cannot merge " + settingsToMerge + " into " + this);
}
if (quotaToMerge.getRemove()) {
// It means it's a remove request
// Update the builder to propagate the removal
spaceBuilder.setRemove(true).clearSoftLimit().clearViolationPolicy();
} else {
// Add the new settings to the existing settings
spaceBuilder.mergeFrom(quotaToMerge);
}
}
}
boolean removeSpaceBuilder = (spaceBuilder == null) || (spaceBuilder.hasRemove() && spaceBuilder.getRemove());
Boolean bypassGlobals = this.bypassGlobals;
if (other instanceof QuotaGlobalsSettingsBypass) {
bypassGlobals = ((QuotaGlobalsSettingsBypass) other).getBypass();
}
if (throttleBuilder == null && removeSpaceBuilder && bypassGlobals == null) {
return null;
}
return new GlobalQuotaSettingsImpl(getUserName(), getTableName(), getNamespace(), getRegionServer(), (throttleBuilder == null ? null : throttleBuilder.build()), bypassGlobals, (removeSpaceBuilder ? null : spaceBuilder.build()));
}
use of org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota in project hbase by apache.
the class QuotaObserverChore method processNamespacesWithQuotas.
/**
* Processes each namespace which has a quota defined and moves all of the tables contained
* in that namespace into or out of violation of the quota. Tables which are already in
* violation of a quota at the table level which <em>also</em> have a reside in a namespace
* with a violated quota will not have the namespace quota enacted. The table quota takes
* priority over the namespace quota.
*
* @param namespacesWithQuotas The set of namespaces that have quotas defined
* @param tablesByNamespace A mapping of namespaces and the tables contained in those namespaces
*/
void processNamespacesWithQuotas(final Set<String> namespacesWithQuotas, final Multimap<String, TableName> tablesByNamespace) throws IOException {
long numNamespacesInViolation = 0L;
for (String namespace : namespacesWithQuotas) {
// Get the quota definition for the namespace
final SpaceQuota spaceQuota = namespaceSnapshotStore.getSpaceQuota(namespace);
if (spaceQuota == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Could not get Namespace space quota for " + namespace + ", maybe it was recently deleted.");
}
continue;
}
final SpaceQuotaSnapshot currentSnapshot = namespaceSnapshotStore.getCurrentState(namespace);
final SpaceQuotaSnapshot targetSnapshot = namespaceSnapshotStore.getTargetState(namespace, spaceQuota);
if (LOG.isTraceEnabled()) {
LOG.trace("Processing " + namespace + " with current=" + currentSnapshot + ", target=" + targetSnapshot);
}
updateNamespaceQuota(namespace, currentSnapshot, targetSnapshot, tablesByNamespace);
if (targetSnapshot.getQuotaStatus().isInViolation()) {
numNamespacesInViolation++;
}
}
// Report the number of namespaces in violation
if (metrics != null) {
metrics.setNumNamespacesInSpaceQuotaViolation(numNamespacesInViolation);
}
}
use of org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota in project hbase by apache.
the class QuotaObserverChore method processTablesWithQuotas.
/**
* Processes each {@code TableName} which has a quota defined and moves it in or out of
* violation based on the space use.
*
* @param tablesWithTableQuotas The HBase tables which have quotas defined
*/
void processTablesWithQuotas(final Set<TableName> tablesWithTableQuotas) throws IOException {
long numTablesInViolation = 0L;
for (TableName table : tablesWithTableQuotas) {
final SpaceQuota spaceQuota = tableSnapshotStore.getSpaceQuota(table);
if (spaceQuota == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Unexpectedly did not find a space quota for " + table + ", maybe it was recently deleted.");
}
continue;
}
final SpaceQuotaSnapshot currentSnapshot = tableSnapshotStore.getCurrentState(table);
final SpaceQuotaSnapshot targetSnapshot = tableSnapshotStore.getTargetState(table, spaceQuota);
if (LOG.isTraceEnabled()) {
LOG.trace("Processing " + table + " with current=" + currentSnapshot + ", target=" + targetSnapshot);
}
updateTableQuota(table, currentSnapshot, targetSnapshot);
if (targetSnapshot.getQuotaStatus().isInViolation()) {
numTablesInViolation++;
}
}
// Report the number of tables in violation
if (metrics != null) {
metrics.setNumTableInSpaceQuotaViolation(numTablesInViolation);
}
}
use of org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota in project hbase by apache.
the class TestQuotaSettingsFactory method testAllQuotasAddedToList.
@Test
public void testAllQuotasAddedToList() {
final SpaceQuota spaceQuota = SpaceQuota.newBuilder().setSoftLimit(// 50G
1024L * 1024L * 1024L * 50L).setViolationPolicy(// Disable the table
QuotaProtos.SpaceViolationPolicy.DISABLE).build();
final long readLimit = 1000;
final long writeLimit = 500;
final Throttle throttle = Throttle.newBuilder().setReadNum(TimedQuota.newBuilder().setSoftLimit(readLimit).setTimeUnit(HBaseProtos.TimeUnit.MINUTES).build()).setWriteNum(TimedQuota.newBuilder().setSoftLimit(writeLimit).setTimeUnit(HBaseProtos.TimeUnit.MINUTES).build()).build();
final Quotas quotas = Quotas.newBuilder().setSpace(// Set the FS quotas
spaceQuota).setThrottle(// Set some RPC limits
throttle).build();
final TableName tn = TableName.valueOf("my_table");
List<QuotaSettings> settings = QuotaSettingsFactory.fromTableQuotas(tn, quotas);
assertEquals(3, settings.size());
boolean seenRead = false;
boolean seenWrite = false;
boolean seenSpace = false;
for (QuotaSettings setting : settings) {
if (setting instanceof ThrottleSettings) {
ThrottleSettings throttleSettings = (ThrottleSettings) setting;
switch(throttleSettings.getThrottleType()) {
case READ_NUMBER:
assertFalse("Should not have multiple read quotas", seenRead);
assertEquals(readLimit, throttleSettings.getSoftLimit());
assertEquals(TimeUnit.MINUTES, throttleSettings.getTimeUnit());
assertEquals(tn, throttleSettings.getTableName());
assertNull("Username should be null", throttleSettings.getUserName());
assertNull("Namespace should be null", throttleSettings.getNamespace());
assertNull("RegionServer should be null", throttleSettings.getRegionServer());
seenRead = true;
break;
case WRITE_NUMBER:
assertFalse("Should not have multiple write quotas", seenWrite);
assertEquals(writeLimit, throttleSettings.getSoftLimit());
assertEquals(TimeUnit.MINUTES, throttleSettings.getTimeUnit());
assertEquals(tn, throttleSettings.getTableName());
assertNull("Username should be null", throttleSettings.getUserName());
assertNull("Namespace should be null", throttleSettings.getNamespace());
assertNull("RegionServer should be null", throttleSettings.getRegionServer());
seenWrite = true;
break;
default:
fail("Unexpected throttle type: " + throttleSettings.getThrottleType());
}
} else if (setting instanceof SpaceLimitSettings) {
assertFalse("Should not have multiple space quotas", seenSpace);
SpaceLimitSettings spaceLimit = (SpaceLimitSettings) setting;
assertEquals(tn, spaceLimit.getTableName());
assertNull("Username should be null", spaceLimit.getUserName());
assertNull("Namespace should be null", spaceLimit.getNamespace());
assertNull("RegionServer should be null", spaceLimit.getRegionServer());
assertTrue("SpaceLimitSettings should have a SpaceQuota", spaceLimit.getProto().hasQuota());
assertEquals(spaceQuota, spaceLimit.getProto().getQuota());
seenSpace = true;
} else {
fail("Unexpected QuotaSettings implementation: " + setting.getClass());
}
}
assertTrue("Should have seen a read quota", seenRead);
assertTrue("Should have seen a write quota", seenWrite);
assertTrue("Should have seen a space quota", seenSpace);
}
use of org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.SpaceQuota in project hbase by apache.
the class TestQuotaSettingsFactory method testBothTableAndNamespace.
@Test(expected = IllegalArgumentException.class)
public void testBothTableAndNamespace() {
final SpaceQuota spaceQuota = SpaceQuota.newBuilder().setSoftLimit(1L).setViolationPolicy(QuotaProtos.SpaceViolationPolicy.DISABLE).build();
QuotaSettingsFactory.fromSpace(TableName.valueOf("foo"), "bar", spaceQuota);
}
Aggregations