Skip to content

fix: Use selective updates for scale rules(#6709) - #6974

Open
juicewcode wants to merge 3 commits into
apache:masterfrom
juicewcode:fix/6709-scale-rule-partial-update
Open

fix: Use selective updates for scale rules(#6709)#6974
juicewcode wants to merge 3 commits into
apache:masterfrom
juicewcode:fix/6709-scale-rule-partial-update

Conversation

@juicewcode

Copy link
Copy Markdown
Contributor

Fixes #6709
ScaleRuleServiceImpl#update previously called updateByPrimaryKey, which performs a full-column update.
When a partial update request omits optional fields such as minimum, maximum, sort, or status, those fields may
be written as NULL, unintentionally removing existing scale rule configuration.

Changes

Replace:
scaleRuleMapper.updateByPrimaryKey(after);
with:
scaleRuleMapper.updateByPrimaryKeySelective(after);

Make sure that:

  • You have read the contribution guidelines.
  • You submit test cases (unit or integration tests) that back your changes.
  • Your local test passed ./mvnw clean install -Dmaven.javadoc.skip=true.

  - Replace updateByPrimaryKey with updateByPrimaryKeySelective.

@Aias00 Aias00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@juicewcode

Copy link
Copy Markdown
Contributor Author

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?

This change updates scale-rule handling in two ways:

  • Use updateByPrimaryKeySelective so fields omitted from the request remain unchanged in the database.
  • Reload the persisted ScaleRuleDO after the update and use the complete entity to refresh the cache, preventing omitted
    fields from becoming null in the cache.

The stale cache entry caused by changing metricName is addressed separately in PR #6975

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] ScaleRuleServiceImpl.update uses full updateByPrimaryKey, nulling omitted fields

2 participants