Fix policy synchronization failure with database unique constraints in distributed watcher scenarios#1593
Open
Fix policy synchronization failure with database unique constraints in distributed watcher scenarios#1593
Conversation
|
|
Co-authored-by: mserico <140243407+mserico@users.noreply.github.com>
When multiple instances receive watcher notifications, all instances try to add the same policy. With unique constraints in the database, the adapter fails on all but the first instance. The fix ensures that policies are still added to the in-memory model even when the adapter fails, allowing instances to stay synchronized. The behavior is: - If adapter fails but policy can be added to model => success (handles duplicates) - If adapter fails and model validation fails => return adapter error - Remove policies don't change (still require to use the current endpoint in the other library without interface changes) Co-authored-by: mserico <140243407+mserico@users.noreply.github.com>
- Fix inefficient string concatenation in toString function - Add missing import for strings package - Fix godot linter issues (missing periods in comments) - Fix ineffassign issues (unused return values) Co-authored-by: mserico <140243407+mserico@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix Redis Watcherex update failure due to unique constraint
Fix policy synchronization failure with database unique constraints in distributed watcher scenarios
Dec 7, 2025
|
@copilot fix failed CI check: |
Reduced nesting complexity by using early returns instead of nested if blocks in addPoliciesWithoutNotify functions. Changed from nested if-else structure to sequential if checks with early returns, making the code more readable and passing the nestif linter check. Co-authored-by: mserico <140243407+mserico@users.noreply.github.com>
Contributor
Author
... Fixed in commit 3a31759. Refactored the nested if blocks to use early returns instead, which reduces the complexity from 6 to an acceptable level. The nestif linter now passes, and all tests continue to pass. |
c622095 to
b190fce
Compare
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.
addPolicyWithoutNotifyto handle unique constraint errorsaddPoliciesWithoutNotifyto handle unique constraint errorsSummary
Fixed a critical bug where Redis WatcherEX notifications would fail to update policies in instances when the database has unique constraints.
Problem
When multiple instances receive watcher notifications, they all try to add the same policy. With unique constraints, only the first instance succeeds at the database level, but all other instances would fail completely and not update their in-memory model, leading to inconsistent state.
Solution
Modified the policy add functions to continue updating the in-memory model even when the adapter fails, as long as:
If both adapter and model/validation fail, the policy is removed from the model and the adapter error is returned.
Latest Changes (CI Fix)
Refactored nested if blocks to use early returns, reducing code complexity and fixing nestif linter warnings.
Security Summary
CodeQL analysis completed with 0 security alerts. All tests passing. All linter checks passing.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.