From a909b0b6f90dba49d751681f35cffbd312c7eb85 Mon Sep 17 00:00:00 2001 From: brycezhongqing Date: Tue, 2 Jan 2024 14:02:51 -0800 Subject: [PATCH] Fix dual-read lix switch issue --- CHANGELOG.md | 5 ++++- .../d2/balancer/dualread/DualReadStateManager.java | 13 ++++++++++--- gradle.properties | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b36b02e5f3..afd628d4c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ When updating the changelog, remember to be very clear about what behavior has c and what APIs have changed, if applicable. ## [Unreleased] +## [29.49.2] - 2024-01-02 +- Fix rate limiter for dual-read mode switch ## [29.49.1] - 2023-12-21 - Use a separate indis warmup executor service @@ -5597,7 +5599,8 @@ patch operations can re-use these classes for generating patch messages. ## [0.14.1] -[Unreleased]: https://github.com/linkedin/rest.li/compare/v29.49.1...master +[Unreleased]: https://github.com/linkedin/rest.li/compare/v29.49.2...master +[29.49.2]: https://github.com/linkedin/rest.li/compare/v29.49.1...v29.49.2 [29.49.1]: https://github.com/linkedin/rest.li/compare/v29.49.0...v29.49.1 [29.49.0]: https://github.com/linkedin/rest.li/compare/v29.48.9...v29.49.0 [29.48.9]: https://github.com/linkedin/rest.li/compare/v29.48.8...v29.48.9 diff --git a/d2/src/main/java/com/linkedin/d2/balancer/dualread/DualReadStateManager.java b/d2/src/main/java/com/linkedin/d2/balancer/dualread/DualReadStateManager.java index d00c6a413f..f513b35d74 100644 --- a/d2/src/main/java/com/linkedin/d2/balancer/dualread/DualReadStateManager.java +++ b/d2/src/main/java/com/linkedin/d2/balancer/dualread/DualReadStateManager.java @@ -50,7 +50,7 @@ public class DualReadStateManager private final ConcurrentMap _clusterDualReadModes; private final DualReadModeProvider _dualReadModeProvider; private final ScheduledExecutorService _executorService; - private final RateLimiter _rateLimiter; + private final ConcurrentMap _serviceToRateLimiterMap; // Stores global dual read mode private volatile DualReadModeProvider.DualReadMode _dualReadMode = DualReadModeProvider.DualReadMode.OLD_LB_ONLY; private final Set _globalDualReadModeWatchers; @@ -78,7 +78,7 @@ public DualReadStateManager(DualReadModeProvider dualReadModeProvider, Scheduled _clusterDualReadModes = new ConcurrentHashMap<>(); _dualReadModeProvider = dualReadModeProvider; _executorService = executorService; - _rateLimiter = RateLimiter.create((double) 1 / DUAL_READ_MODE_SWITCH_MIN_INTERVAL); + _serviceToRateLimiterMap = new ConcurrentHashMap<>(); _globalDualReadModeWatchers = ConcurrentHashMap.newKeySet(); _serviceDualReadModeWatchers = new ConcurrentHashMap<>(); _clusterDualReadModeWatchers = new ConcurrentHashMap<>(); @@ -191,7 +191,14 @@ public void checkAndSwitchMode(String d2ServiceName) _executorService.execute(() -> { - boolean shouldCheck = _rateLimiter.tryAcquire(); + if(d2ServiceName == null){ + return; + } + RateLimiter serviceRateLimiter = _serviceToRateLimiterMap.computeIfAbsent( + d2ServiceName, + key -> RateLimiter.create((double) 1 / DUAL_READ_MODE_SWITCH_MIN_INTERVAL) + ); + boolean shouldCheck = serviceRateLimiter.tryAcquire(); if (shouldCheck) { // Check and switch global dual read mode diff --git a/gradle.properties b/gradle.properties index 2e9ea961fb..d4de7b8043 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version=29.49.1 +version=29.49.2 group=com.linkedin.pegasus org.gradle.configureondemand=true org.gradle.parallel=true