fix: Use selective updates for scale rules(#6709) - #6974
Conversation
- Replace updateByPrimaryKey with updateByPrimaryKeySelective.
Aias00
left a comment
There was a problem hiding this comment.
Switching the mapper to updateByPrimaryKeySelective preserves omitted columns in the database, but the cache update still replaces the whole cached rule with ScaleRuleDO.buildScaleRuleDO(scaleRuleDTO). For a partial update, any field left null in the DTO remains unchanged in the DB but becomes null in ScaleRuleCache, because addOrUpdateRuleToCache stores that partial object directly. Could we refresh the persisted row after the selective update, or merge the existing cached/DB rule before updating the cache, so the in-memory scale rule matches the database after partial updates?
- Use selective update for scale rules - Reload the persisted rule before updating the cache - Preserve fields omitted from partial update requests
This change updates scale-rule handling in two ways:
The stale cache entry caused by changing metricName is addressed separately in PR #6975 |
Fixes #6709
ScaleRuleServiceImpl#updatepreviously calledupdateByPrimaryKey, which performs a full-column update.When a partial update request omits optional fields such as
minimum,maximum,sort, orstatus, those fields maybe written as
NULL, unintentionally removing existing scale rule configuration.Changes
Replace:
scaleRuleMapper.updateByPrimaryKey(after);with:
scaleRuleMapper.updateByPrimaryKeySelective(after);Make sure that:
./mvnw clean install -Dmaven.javadoc.skip=true.