This is an automated email from the ASF dual-hosted git repository.
dengliming pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new ca9d0080d8 fix: scale rule cache entity inconsistency (#6973)
ca9d0080d8 is described below
commit ca9d0080d8373d6edd59d68dabb59993630aab2f
Author: Southern <[email protected]>
AuthorDate: Thu Sep 17 22:57:54 2026 +0800
fix: scale rule cache entity inconsistency (#6973)
* fix: Fix scale rule cache entity inconsistency.
- Reuse the persisted entity after create.
- Reuse the updated entity after update.
* fix: remove stale scale rule cache key on update
---------
Co-authored-by: aias00 <[email protected]>
Co-authored-by: Liming Deng <[email protected]>
---
.../org/apache/shenyu/admin/service/impl/ScaleRuleServiceImpl.java | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ScaleRuleServiceImpl.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ScaleRuleServiceImpl.java
index 6810040d0c..af678e3c6b 100644
---
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ScaleRuleServiceImpl.java
+++
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ScaleRuleServiceImpl.java
@@ -32,6 +32,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
+import java.util.Objects;
import java.util.stream.Collectors;
/**
@@ -109,7 +110,7 @@ public class ScaleRuleServiceImpl implements
ScaleRuleService {
final ScaleRuleDO scaleRuleDO =
ScaleRuleDO.buildScaleRuleDO(scaleRuleDTO);
int rows = scaleRuleMapper.insertSelective(scaleRuleDO);
if (rows > 0) {
-
scaleRuleCache.addOrUpdateRuleToCache(ScaleRuleDO.buildScaleRuleDO(scaleRuleDTO));
+ scaleRuleCache.addOrUpdateRuleToCache(scaleRuleDO);
}
return rows;
}
@@ -122,9 +123,13 @@ public class ScaleRuleServiceImpl implements
ScaleRuleService {
*/
@Override
public int update(final ScaleRuleDTO scaleRuleDTO) {
+ final ScaleRuleDO before =
scaleRuleMapper.selectByPrimaryKey(scaleRuleDTO.getId());
final ScaleRuleDO after = ScaleRuleDO.buildScaleRuleDO(scaleRuleDTO);
int rows = scaleRuleMapper.updateByPrimaryKeySelective(after);
if (rows > 0) {
+ if (Objects.nonNull(before) &&
!Objects.equals(before.getMetricName(), after.getMetricName())) {
+
scaleRuleCache.removeRulesFromCache(List.of(before.getMetricName()));
+ }
final ScaleRuleDO persisted =
scaleRuleMapper.selectByPrimaryKey(scaleRuleDTO.getId());
scaleRuleCache.addOrUpdateRuleToCache(persisted);
}