fix: Fix scale rule cache eviction by using rule ids(#6972) - #6975
fix: Fix scale rule cache eviction by using rule ids(#6972)#6975juicewcode wants to merge 4 commits into
Conversation
- Add cache eviction by database primary key. - Keep metric names as cache keys. - Add scale rule deletion to remove entries by rule ID.
Aias00
left a comment
There was a problem hiding this comment.
This delete-by-ID eviction still depends on the cached rule ID matching the database row ID, but this PR is based on master, where ScaleRuleServiceImpl#create still inserts one ScaleRuleDO and then caches a second ScaleRuleDO built from the blank-id DTO. ScaleRuleDO.buildScaleRuleDO generates a fresh UUID when the DTO id is empty, so rules created through the service can still have a cached id that differs from the DB id being deleted. Could you include the create-side cache fix here, or base this after the fix from #6973, so delete-by-ID eviction can actually find newly created cached rules?
- Reuse the persisted entity after create. - Reuse the updated entity after update.
This change is based on the cache consistency fix from PR #6973 . The following cache consistency issues are addressed:
The PR body has also been updated to reflect these changes and the problems they resolve. |
- Base the change on the cache consistency fix from pr apache#6973 - Remove stale cache entries by database rule id during deletion - Remove the old metric-name cache key when a rule is renamed - Keep the persisted entity id when caching newly created rules
Fixes #6972
Fixes #6623
Fix scale rule cache consistency for create, update, and delete operations.
ScaleRuleCache stores rules in a map keyed by metricName, while database operations identify rules by their primary key id. This difference could cause cached rules to become inconsistent with the database:
record.
incorrectly treated as a metric-name key.
##Changes
preserving the database-generated id.
These changes ensure that the in-memory scale-rule cache remains consistent with the database after rules are created, renamed, or deleted.
Make sure that:
./mvnw clean install -Dmaven.javadoc.skip=true.