feat(server): version wins in concurrent upsert#3970
Merged
ngjaying merged 2 commits intolf-edge:masterfrom Jan 14, 2026
Merged
feat(server): version wins in concurrent upsert#3970ngjaying merged 2 commits intolf-edge:masterfrom
ngjaying merged 2 commits intolf-edge:masterfrom
Conversation
7fc5a66 to
d2f6dc1
Compare
bfd36e0 to
d5228ca
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3970 +/- ##
==========================================
+ Coverage 71.93% 71.95% +0.03%
==========================================
Files 456 456
Lines 52603 52612 +9
==========================================
+ Hits 37835 37855 +20
+ Misses 11850 11844 -6
+ Partials 2918 2913 -5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Hold RuleRegistry lock for entire UpsertRule operation to ensure atomic version check, ValidateAndRun, and persist. This prevents race conditions where lower versions could win. Refactored to use ExecUpsert directly and removed unused private methods. Added unit tests to cover temp rules and DB persistence failures. Includes FVT test to verify the fix. Signed-off-by: Jiyong Huang <huangjy@emqx.io>
d5228ca to
ac11429
Compare
- Use mutex to protect 'final' variable update in TestMulShared/async_run in fvt/rulestate_test.go - Sor imports in internal/server/rule_manager_test.go Signed-off-by: Jiyong Huang <huangjy@emqx.io>
26544a9 to
c3fc654
Compare
Yisaer
approved these changes
Jan 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add version-based conflict resolution for concurrent rule creation via upsert. When multiple requests try to create the same rule concurrently (rule doesn't exist yet), the request with the higher version will win.
Note: Version-based conflict resolution already worked correctly for updates to existing rules.
Changes
save(): Persist to DB first, then update memory to ensure atomicity for new rulesTest
Includes FVT test
TestConcurrentUpdateRulethat verifies concurrent upserts result in highest version (3.0.0) winning.