Copilot commented on code in PR #6975:
URL: https://github.com/apache/shenyu/pull/6975#discussion_r4038059079
##########
shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ScaleRuleServiceImpl.java:
##########
@@ -122,9 +123,13 @@ public int create(final ScaleRuleDTO scaleRuleDTO) {
*/
@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()));
Review Comment:
Removing by the old metric-name key can evict a different rule. The schema
does not make `metric_name` unique, so if two rows share a metric and the cache
currently contains the other row, renaming this row removes that other row;
after the rename the database may have two distinct metric names while the
cache is still missing one. Use the ID-aware removal so eviction is tied to the
row being updated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]