Package com.github.ambry.quota.storage
Interface StorageQuotaEnforcer
-
public interface StorageQuotaEnforcer
StorageQuotaEnforcer
enforces the traffic throttling based on the storage quota and the current storage usage. Each traffic that changes storage usage is targeted at a specific account and container. Enforcer enforces storage quota on each container. Before evaluating any traffic, enforcer has to retrieve storage quota of each container fromStorageQuotaSource
and current storage usage of each container fromStorageUsageRefresher
, by callinginitStorageQuota(java.util.Map<java.lang.String, java.util.Map<java.lang.String, java.lang.Long>>)
andinitStorageUsage(java.util.Map<java.lang.String, java.util.Map<java.lang.String, java.lang.Long>>)
respectively. Container storage quota can be dynamic, it can be updated to increase or decrease the quota for specific containers. To listen on these changes, Enforcer would return aStorageQuotaSource.Listener
. Container storage usage is changing all the the time because of expired blobs and compacted deleted blobs. That's the reason why relying on the incoming traffic won't give you a correct answer about the current storage usage. For instance, if 1GB blob is uploaded to containerA and the TTL for this blob is one day. Then one day later, without any traffic from client, the storage usage for containerA becomes 0. Since the storage usage fromStorageUsageRefresher
is the source of the truth, enforcer has to listen on the changes for storage usage and replace the value in memory with the value fromStorageUsageRefresher
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
StorageQuotaEnforcer.QuotaExceededCallback
Interface of callback method when the quota of certain account and container's quota is exceeded.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
initStorageQuota(java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.Long>> quota)
Initialize the storage quota inStorageQuotaSource
.void
initStorageUsage(java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.Long>> usage)
Initialize the storage usage inStorageQuotaEnforcer
.void
registerListeners(StorageQuotaSource storageQuotaSource, StorageUsageRefresher storageUsageRefresher)
Register listeners inStorageQuotaSource
andStorageUsageRefresher
.void
setQuotaMode(QuotaMode mode)
Change theStorageQuotaEnforcer
's mode to the given value.boolean
shouldThrottle(short accountId, short containerId, QuotaOperation op, long size)
Return true if the givenQuotaOperation
should be throttled.
-
-
-
Method Detail
-
initStorageUsage
void initStorageUsage(java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.Long>> usage)
Initialize the storage usage inStorageQuotaEnforcer
.- Parameters:
usage
- The initial storage usage fromStorageUsageRefresher
.
-
initStorageQuota
void initStorageQuota(java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.Long>> quota)
Initialize the storage quota inStorageQuotaSource
.- Parameters:
quota
- The initial quota fromStorageQuotaSource
.
-
registerListeners
void registerListeners(StorageQuotaSource storageQuotaSource, StorageUsageRefresher storageUsageRefresher)
Register listeners inStorageQuotaSource
andStorageUsageRefresher
.- Parameters:
storageQuotaSource
- TheStorageQuotaSource
to register listener.storageUsageRefresher
- TheStorageUsageRefresher
to register listener.
-
shouldThrottle
boolean shouldThrottle(short accountId, short containerId, QuotaOperation op, long size)
Return true if the givenQuotaOperation
should be throttled.- Parameters:
accountId
- The accountId of this operation.containerId
- The containerId of this operation.op
- TheQuotaOperation
.size
- The size of this operation. eg, if the op isQuotaOperation.Post
, size if the size of the content.- Returns:
- True if the given
QuotaOperation
should be throttled.
-
setQuotaMode
void setQuotaMode(QuotaMode mode)
Change theStorageQuotaEnforcer
's mode to the given value. If the mode isQuotaMode.Tracking
, thenStorageQuotaEnforcer
should never return true inshouldThrottle(short, short, com.github.ambry.quota.storage.QuotaOperation, long)
method.- Parameters:
mode
- The new value forQuotaMode
.
-
-