use of org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Throttle 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.Throttle in project hbase by apache.
the class QuotaUtil method checkRSQuotaToEnableExceedThrottle.
private static void checkRSQuotaToEnableExceedThrottle(Quotas quotas) throws IOException {
if (quotas != null && quotas.hasThrottle()) {
Throttle throttle = quotas.getThrottle();
// If enable exceed throttle quota, make sure that there are at least one read(req/read +
// num/size/cu) and one write(req/write + num/size/cu) region server throttle quotas.
boolean hasReadQuota = false;
boolean hasWriteQuota = false;
if (throttle.hasReqNum() || throttle.hasReqSize() || throttle.hasReqCapacityUnit()) {
hasReadQuota = true;
hasWriteQuota = true;
}
if (!hasReadQuota && (throttle.hasReadNum() || throttle.hasReadSize() || throttle.hasReadCapacityUnit())) {
hasReadQuota = true;
}
if (!hasReadQuota) {
throw new DoNotRetryIOException("Please set at least one read region server quota before enable exceed throttle quota");
}
if (!hasWriteQuota && (throttle.hasWriteNum() || throttle.hasWriteSize() || throttle.hasWriteCapacityUnit())) {
hasWriteQuota = true;
}
if (!hasWriteQuota) {
throw new DoNotRetryIOException("Please set at least one write region server quota " + "before enable exceed throttle quota");
}
// If enable exceed throttle quota, make sure that region server throttle quotas are in
// seconds time unit. Because once previous requests exceed their quota and consume region
// server quota, quota in other time units may be refilled in a long time, this may affect
// later requests.
List<Pair<Boolean, TimedQuota>> list = Arrays.asList(Pair.newPair(throttle.hasReqNum(), throttle.getReqNum()), Pair.newPair(throttle.hasReadNum(), throttle.getReadNum()), Pair.newPair(throttle.hasWriteNum(), throttle.getWriteNum()), Pair.newPair(throttle.hasReqSize(), throttle.getReqSize()), Pair.newPair(throttle.hasReadSize(), throttle.getReadSize()), Pair.newPair(throttle.hasWriteSize(), throttle.getWriteSize()), Pair.newPair(throttle.hasReqCapacityUnit(), throttle.getReqCapacityUnit()), Pair.newPair(throttle.hasReadCapacityUnit(), throttle.getReadCapacityUnit()), Pair.newPair(throttle.hasWriteCapacityUnit(), throttle.getWriteCapacityUnit()));
for (Pair<Boolean, TimedQuota> pair : list) {
if (pair.getFirst()) {
if (pair.getSecond().getTimeUnit() != TimeUnit.SECONDS) {
throw new DoNotRetryIOException("All region server quota must be " + "in seconds time unit if enable exceed throttle quota");
}
}
}
} else {
// If enable exceed throttle quota, make sure that region server quota is already set
throw new DoNotRetryIOException("Please set region server quota before enable exceed throttle quota");
}
}
use of org.apache.hadoop.hbase.shaded.protobuf.generated.QuotaProtos.Throttle 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);
}
Aggregations