From a909b0b6f90dba49d751681f35cffbd312c7eb85 Mon Sep 17 00:00:00 2001 From: brycezhongqing Date: Tue, 2 Jan 2024 14:02:51 -0800 Subject: [PATCH 1/4] 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 From 1bde9b1177ec697d451995a24b51d266011fc94b Mon Sep 17 00:00:00 2001 From: brycezhongqing Date: Tue, 2 Jan 2024 19:32:07 -0800 Subject: [PATCH 2/4] resolve comments --- .../d2/balancer/dualread/DualReadStateManager.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) 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 f513b35d74..1c9bb3195e 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 @@ -188,16 +188,14 @@ public void checkAndSwitchMode(String d2ServiceName) LOG.info("Dual read mode executor is shut down already. Skipping getting the latest dual read mode."); return; } - + if (d2ServiceName == null) + { + return; + } _executorService.execute(() -> { - if(d2ServiceName == null){ - return; - } - RateLimiter serviceRateLimiter = _serviceToRateLimiterMap.computeIfAbsent( - d2ServiceName, - key -> RateLimiter.create((double) 1 / DUAL_READ_MODE_SWITCH_MIN_INTERVAL) - ); + RateLimiter serviceRateLimiter = _serviceToRateLimiterMap.computeIfAbsent(d2ServiceName, + key -> RateLimiter.create((double) 1 / DUAL_READ_MODE_SWITCH_MIN_INTERVAL)); boolean shouldCheck = serviceRateLimiter.tryAcquire(); if (shouldCheck) { From 99b2c446d1a62897968d86327c32ae0de5ad754a Mon Sep 17 00:00:00 2001 From: brycezhongqing Date: Wed, 3 Jan 2024 10:07:31 -0800 Subject: [PATCH 3/4] resolve comments --- .../dualread/DualReadStateManager.java | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) 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 1c9bb3195e..eafd26f0fa 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,6 +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; @@ -78,6 +79,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<>(); @@ -188,23 +190,24 @@ public void checkAndSwitchMode(String d2ServiceName) LOG.info("Dual read mode executor is shut down already. Skipping getting the latest dual read mode."); return; } - if (d2ServiceName == null) - { - return; - } + _executorService.execute(() -> { - RateLimiter serviceRateLimiter = _serviceToRateLimiterMap.computeIfAbsent(d2ServiceName, - key -> RateLimiter.create((double) 1 / DUAL_READ_MODE_SWITCH_MIN_INTERVAL)); - boolean shouldCheck = serviceRateLimiter.tryAcquire(); - if (shouldCheck) + if (d2ServiceName == null) { - // Check and switch global dual read mode - updateGlobal(_dualReadModeProvider.getDualReadMode()); - - // Check and switch service-level dual read mode - if (d2ServiceName != null) + if (_rateLimiter.tryAcquire()) + { + // Check and switch global dual read mode + updateGlobal(_dualReadModeProvider.getDualReadMode()); + } + } + else + { + RateLimiter serviceRateLimiter = _serviceToRateLimiterMap.computeIfAbsent(d2ServiceName, + key -> RateLimiter.create((double) 1 / DUAL_READ_MODE_SWITCH_MIN_INTERVAL)); + if (serviceRateLimiter.tryAcquire()) { + // Check and switch service-level dual read mode updateService(d2ServiceName, _dualReadModeProvider.getDualReadMode(d2ServiceName)); } } From c6257382c9b6ec230cd02574e9cac0e72286de7f Mon Sep 17 00:00:00 2001 From: brycezhongqing Date: Wed, 3 Jan 2024 11:25:52 -0800 Subject: [PATCH 4/4] update release version --- CHANGELOG.md | 5 +++-- gradle.properties | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f54e8ebfc..a470ab134b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ 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 +## [29.49.3] - 2024-01-03 - Fix rate limiter for dual-read mode switch ## [29.49.2] - 2024-01-02 @@ -5602,7 +5602,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.2...master +[Unreleased]: https://github.com/linkedin/rest.li/compare/v29.49.3...master +[29.49.3]: https://github.com/linkedin/rest.li/compare/v29.49.2...v29.49.3 [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 diff --git a/gradle.properties b/gradle.properties index d4de7b8043..1065fc8c24 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version=29.49.2 +version=29.49.3 group=com.linkedin.pegasus org.gradle.configureondemand=true org.gradle.parallel=true