-
Notifications
You must be signed in to change notification settings - Fork 4
fix: repair spock-diff against spock-enabled clusters #125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| // /////////////////////////////////////////////////////////////////////////// | ||
| // | ||
| // # ACE - Active Consistency Engine | ||
| // | ||
| // Copyright (C) 2023 - 2026, pgEdge (https://www.pgedge.com/) | ||
| // | ||
| // This software is released under the PostgreSQL License: | ||
| // https://opensource.org/license/postgresql | ||
| // | ||
| // /////////////////////////////////////////////////////////////////////////// | ||
|
|
||
| package diff | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/pgedge/ace/pkg/types" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| // spockCfg is a small helper to build a node config for comparison tests. | ||
| func spockCfg(nodeName string, subs ...types.SpockSubscription) SpockNodeConfig { | ||
| return SpockNodeConfig{NodeName: nodeName, Subscriptions: subs} | ||
| } | ||
|
|
||
| // Healthy reciprocal pair with matching repsets. Names are deliberately | ||
| // arbitrary: matching must rely on the provider node, not a name convention. | ||
| func TestCompareSubscriptions_HealthyReciprocalIgnoresNames(t *testing.T) { | ||
| n1 := spockCfg("n1", types.SpockSubscription{ | ||
| SubName: "custom_name_a", ProviderNode: "n2", SubEnabled: true, | ||
| ReplicationSets: []string{"default", "default_insert_only"}, | ||
| }) | ||
| n2 := spockCfg("n2", types.SpockSubscription{ | ||
| SubName: "totally_different", ProviderNode: "n1", SubEnabled: true, | ||
| ReplicationSets: []string{"default_insert_only", "default"}, | ||
| }) | ||
|
|
||
| d := compareSubscriptions(n1, n2) | ||
|
|
||
| assert.Empty(t, d.MissingOnNode1, "n1 subscribes from n2, nothing missing") | ||
| assert.Empty(t, d.MissingOnNode2, "n2 subscribes from n1, nothing missing") | ||
| assert.Empty(t, d.Different, "replication sets match (order-insensitive)") | ||
| } | ||
|
|
||
| // n1 doesn't subscribe from n2 (one direction missing); n2 does subscribe from n1. | ||
| func TestCompareSubscriptions_MissingOneDirection(t *testing.T) { | ||
| n1 := spockCfg("n1") // no subscriptions at all | ||
| n2 := spockCfg("n2", types.SpockSubscription{ | ||
| SubName: "s", ProviderNode: "n1", SubEnabled: true, | ||
| ReplicationSets: []string{"default"}, | ||
| }) | ||
|
|
||
| d := compareSubscriptions(n1, n2) | ||
|
|
||
| assert.Equal(t, []string{"n2"}, d.MissingOnNode1, | ||
| "n1 should be flagged as not subscribing from n2") | ||
| assert.Empty(t, d.MissingOnNode2, | ||
| "n2 correctly subscribes from n1") | ||
| } | ||
|
|
||
| // Both directions exist but replication sets differ: reported under Different. | ||
| func TestCompareSubscriptions_DifferentReplicationSets(t *testing.T) { | ||
| n1 := spockCfg("n1", types.SpockSubscription{ | ||
| SubName: "a", ProviderNode: "n2", SubEnabled: true, | ||
| ReplicationSets: []string{"default"}, | ||
| }) | ||
| n2 := spockCfg("n2", types.SpockSubscription{ | ||
| SubName: "b", ProviderNode: "n1", SubEnabled: true, | ||
| ReplicationSets: []string{"default", "extra"}, | ||
| }) | ||
|
|
||
| d := compareSubscriptions(n1, n2) | ||
|
|
||
| assert.Empty(t, d.MissingOnNode1) | ||
| assert.Empty(t, d.MissingOnNode2) | ||
| assert.Len(t, d.Different, 1, "replication set difference should be reported") | ||
| } | ||
|
|
||
| // compareSubscriptions must not reorder the caller's ReplicationSets: the slices | ||
| // are shared with the SpockConfigs section of the written JSON, which should | ||
| // preserve database-returned order. | ||
| func TestCompareSubscriptions_DoesNotMutateReplicationSets(t *testing.T) { | ||
| n1Sets := []string{"default_insert_only", "default"} | ||
| n2Sets := []string{"default", "default_insert_only"} | ||
| n1 := spockCfg("n1", types.SpockSubscription{ | ||
| SubName: "a", ProviderNode: "n2", SubEnabled: true, ReplicationSets: n1Sets, | ||
| }) | ||
| n2 := spockCfg("n2", types.SpockSubscription{ | ||
| SubName: "b", ProviderNode: "n1", SubEnabled: true, ReplicationSets: n2Sets, | ||
| }) | ||
|
|
||
| compareSubscriptions(n1, n2) | ||
|
|
||
| assert.Equal(t, []string{"default_insert_only", "default"}, n1Sets, | ||
| "n1 replication set order must be preserved") | ||
| assert.Equal(t, []string{"default", "default_insert_only"}, n2Sets, | ||
| "n2 replication set order must be preserved") | ||
| } | ||
|
|
||
| // In a 3-node mesh, comparing n1 and n2 ignores their subscriptions with n3. | ||
| func TestCompareSubscriptions_IgnoresUnrelatedPeers(t *testing.T) { | ||
| n1 := spockCfg("n1", | ||
| types.SpockSubscription{SubName: "a", ProviderNode: "n2", SubEnabled: true, ReplicationSets: []string{"default"}}, | ||
| types.SpockSubscription{SubName: "c", ProviderNode: "n3", SubEnabled: true, ReplicationSets: []string{"default"}}, | ||
| ) | ||
| n2 := spockCfg("n2", | ||
| types.SpockSubscription{SubName: "b", ProviderNode: "n1", SubEnabled: true, ReplicationSets: []string{"default"}}, | ||
| types.SpockSubscription{SubName: "d", ProviderNode: "n3", SubEnabled: true, ReplicationSets: []string{"default"}}, | ||
| ) | ||
|
|
||
| d := compareSubscriptions(n1, n2) | ||
|
|
||
| assert.Empty(t, d.MissingOnNode1) | ||
| assert.Empty(t, d.MissingOnNode2) | ||
| assert.Empty(t, d.Different) | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
ni.SubOriginName == ""the code emits a hint saying the subscription is "excluded from comparison" and setssub.ProviderNode = "". However,config.Subscriptions = append(config.Subscriptions, sub)still runs unconditionally (it's outside theif ni.SubName != ""block).subscriptionsByProvidercorrectly skips entries with emptyProviderNode, so this node's lookup for the peer returns false, andMissingOnNode1gets the peer name — a false-positive mismatch. The hint and the diff report are inconsistent: the user is told the subscription is excluded, then immediately shown a mismatch caused by its exclusion. Fix: addcontinue(skip the append) whenSubOriginName == "".There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SubscriptionsByProvider already skips empty-ProviderNode entries, so
MissingOnNode1 still gets the peer name regardless of the append; it'd only drop the subscription from
the printed config (and if it's the node's only sub, the config would then print "No subscriptions
found" while the hint names it).
With an unresolved origin we can't tell which peer the subscription belongs to, so the "missing" entry
is unavoidable. I reworded the hint to match the diff instead:
▎ Subscription '' has an unresolved origin node; its reciprocal peer cannot be determined and it
▎ may be reported below as a missing subscription.