Skip to content

Commit

Permalink
changes for review suggestions considering the mutex relevant to the …
Browse files Browse the repository at this point in the history
…metadata based policies

minor improvement
  • Loading branch information
slahirucd7 committed Jul 6, 2024
1 parent 0ce07d2 commit d6377fa
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions adapter/internal/discovery/xds/rate_limiter_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ type rateLimitPolicyCache struct {
metadataBasedPolicies map[string]map[string]map[string]*rls_config.RateLimitDescriptor
// mutex for API level
apiLevelMu sync.RWMutex
// mutex for metadata based policies
metadataBasedMu sync.RWMutex
}

// AddAPILevelRateLimitPolicies adds inline Rate Limit policies in APIs to be updated in the Rate Limiter service.
Expand Down Expand Up @@ -347,17 +349,17 @@ func AddSubscriptionLevelRateLimitPolicies(policyList *types.SubscriptionPolicyL

// RemoveSubscriptionRateLimitPolicy removes a subscription level rate limit policy from the rate-limit cache.
func RemoveSubscriptionRateLimitPolicy(policy types.SubscriptionPolicy) {
rlsPolicyCache.apiLevelMu.Lock()
defer rlsPolicyCache.apiLevelMu.Unlock()
rlsPolicyCache.metadataBasedMu.Lock()
defer rlsPolicyCache.metadataBasedMu.Unlock()
if policiesForOrg , ok := rlsPolicyCache.metadataBasedPolicies[subscriptionPolicyType][policy.Organization]; ok {
delete(policiesForOrg, policy.Name)
}
}

// UpdateSubscriptionRateLimitPolicy updates a subscription level rate limit policy to the rate-limit cache.
// UpdateSubscriptionRateLimitPolicy updates a subscription level rate limit policy in the rate-limit cache.
func UpdateSubscriptionRateLimitPolicy(policy types.SubscriptionPolicy) {
rlsPolicyCache.apiLevelMu.Lock()
defer rlsPolicyCache.apiLevelMu.Unlock()
rlsPolicyCache.metadataBasedMu.Lock()
defer rlsPolicyCache.metadataBasedMu.Unlock()
if policiesForOrg , ok := rlsPolicyCache.metadataBasedPolicies[subscriptionPolicyType][policy.Organization]; ok {
delete(policiesForOrg, policy.Name)
}
Expand Down

0 comments on commit d6377fa

Please sign in to comment.