2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 package org
.apache
.hadoop
.hbase
.quotas
;
21 import org
.apache
.yetus
.audience
.InterfaceAudience
;
22 import org
.apache
.yetus
.audience
.InterfaceStability
;
23 import org
.apache
.hadoop
.hbase
.shaded
.protobuf
.generated
.QuotaProtos
.Quotas
;
24 import org
.apache
.hadoop
.hbase
.util
.EnvironmentEdgeManager
;
27 * In-Memory state of table or namespace quotas
29 @InterfaceAudience.Private
30 @InterfaceStability.Evolving
31 @edu.umd
.cs
.findbugs
.annotations
.SuppressWarnings(value
="IS2_INCONSISTENT_SYNC",
32 justification
="FindBugs seems confused; says globalLimiter and lastUpdate " +
33 "are mostly synchronized...but to me it looks like they are totally synchronized")
34 public class QuotaState
{
35 protected long lastUpdate
= 0;
36 protected long lastQuery
= 0;
38 protected QuotaLimiter globalLimiter
= NoopQuotaLimiter
.get();
44 public QuotaState(final long updateTs
) {
45 lastUpdate
= updateTs
;
48 public synchronized long getLastUpdate() {
52 public synchronized long getLastQuery() {
57 public synchronized String
toString() {
58 StringBuilder builder
= new StringBuilder();
59 builder
.append("QuotaState(ts=" + getLastUpdate());
61 builder
.append(" bypass");
63 if (globalLimiter
!= NoopQuotaLimiter
.get()) {
64 //builder.append(" global-limiter");
65 builder
.append(" " + globalLimiter
);
69 return builder
.toString();
73 * @return true if there is no quota information associated to this object
75 public synchronized boolean isBypass() {
76 return globalLimiter
== NoopQuotaLimiter
.get();
80 * Setup the global quota information.
81 * (This operation is part of the QuotaState setup)
83 public synchronized void setQuotas(final Quotas quotas
) {
84 if (quotas
.hasThrottle()) {
85 globalLimiter
= QuotaLimiterFactory
.fromThrottle(quotas
.getThrottle());
87 globalLimiter
= NoopQuotaLimiter
.get();
92 * Perform an update of the quota info based on the other quota info object.
93 * (This operation is executed by the QuotaCache)
95 public synchronized void update(final QuotaState other
) {
96 if (globalLimiter
== NoopQuotaLimiter
.get()) {
97 globalLimiter
= other
.globalLimiter
;
98 } else if (other
.globalLimiter
== NoopQuotaLimiter
.get()) {
99 globalLimiter
= NoopQuotaLimiter
.get();
101 globalLimiter
= QuotaLimiterFactory
.update(globalLimiter
, other
.globalLimiter
);
103 lastUpdate
= other
.lastUpdate
;
107 * Return the limiter associated with this quota.
108 * @return the quota limiter
110 public synchronized QuotaLimiter
getGlobalLimiter() {
111 lastQuery
= EnvironmentEdgeManager
.currentTime();
112 return globalLimiter
;
116 * Return the limiter associated with this quota without updating internal last query stats
117 * @return the quota limiter
119 synchronized QuotaLimiter
getGlobalLimiterWithoutUpdatingLastQuery() {
120 return globalLimiter
;