Class ReadQuotaEnforcementHandler

    • Method Detail

      • getRcu

        public static int getRcu​(RouterRequest request)
        Initially, this is the key count. As we develop a more accurate capacity model, this method can be refined.
        request -
      • getNodeResponsibilityForQuota

        protected static double getNodeResponsibilityForQuota​(PartitionAssignment partitionAssignment,
                                                              java.lang.String nodeId)
        Recalculates the amount of quota that this node should serve given the partition assignment. Assumes each partition gets an even portion of quota, and for each partition divides the quota by the readyToServe instances.
        partitionAssignment -
        nodeId -
      • init

        public final void init()
        Initialize token buckets for all resources in the customized view repository.
      • isInitialized

        public boolean isInitialized()
        We only ever expect the initialized value to flip from false to true, but that initialization might happen in a different thread. By only checking the volatile variable if it is false, we guarantee that we see the change as early as possible and also allow the thread to cache the value once it goes true.
      • channelRead0

        public void channelRead0​( ctx,
                                 RouterRequest request)
        Specified by:
        channelRead0 in class<RouterRequest>
      • checkStoreNull

        public boolean checkStoreNull​( ctx,
                                      RouterRequest request,
                                      GrpcRequestContext grpcCtx,
                                      boolean isGrpc,
                                      Store store)
      • checkInitAndQuotaEnabledToSkipQuotaEnforcement

        public boolean checkInitAndQuotaEnabledToSkipQuotaEnforcement​( ctx,
                                                                      RouterRequest request,
                                                                      Store store,
                                                                      boolean isGrpc)
      • handleTooManyRequests

        public boolean handleTooManyRequests​( ctx,
                                             RouterRequest request,
                                             GrpcRequestContext grpcCtx,
                                             Store store,
                                             int rcu,
                                             boolean isGrpc)
      • handleResourceNoBucket

        public void handleResourceNoBucket​(java.lang.String resourceName)
        This method and the expiring set noBucketStores is only used to throttle the logging of such event
      • handleServerOverCapacity

        public boolean handleServerOverCapacity​( ctx,
                                                GrpcRequestContext grpcCtx,
                                                java.lang.String storeName,
                                                int rcu,
                                                boolean isGrpc)
      • handleStoreChanged

        public void handleStoreChanged​(Store store)
        This is where we add new TokenBucket for new store version and remove irrelevant ones. We should keep the same number of token buckets as the number of active versions. This is because readers like FC might be lagging behind or vice versa. This way quota will still be enforced properly during the version swap or transition period.
        Specified by:
        handleStoreChanged in interface StoreDataChangedListener
      • listTopics

        protected java.util.Set<java.lang.String> listTopics()
        For tests
      • getBucketForStore

        public TokenBucket getBucketForStore​(java.lang.String storeName)
      • getStoreVersionBuckets

        public java.util.concurrent.ConcurrentMap<java.lang.String,​TokenBucket> getStoreVersionBuckets()
      • isNewNoBucketResource

        public boolean isNewNoBucketResource​(java.lang.String resourceName)
      • storageConsumeRcu

        public boolean storageConsumeRcu​(int rcu)