Skip to content
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

option to "win on equal values" #413

Open
tantaman opened this issue Dec 13, 2023 · 1 comment
Open

option to "win on equal values" #413

tantaman opened this issue Dec 13, 2023 · 1 comment

Comments

@tantaman
Copy link
Collaborator

ok I'm pretty sure i know what's up!
node A writes ID 1
node B writes ID 1
node A receives ID 1 from node B -> no rows impacted, declares that changeset as a no-op
node B receives ID 1 from node A -> no rows impacted, declares that changeset as a no-op
node C receives B:1 from node A -> stores it as a no-op
node C receives A:1 from node B -> stores it as a no-op
node C does not know about ID 1, but thinks it knows about all changes

@jeromegn
Copy link
Contributor

jeromegn commented Dec 13, 2023

Perhaps a clearer rundown:

  • node A writes ID 1 -> produces version A:1
  • node B writes ID 1 -> produces version B:1
  • node A receives B:1 -> no rows impacted, declares that changeset as a no-op
  • node B receives A:1 -> no rows impacted, declares that changeset as a no-op
  • node C receives B:1 from node A -> the changeset it got was empty, this is a no-op and it stores it as such
  • node C receives A:1 from node B -> the changeset it got was empty, this is a no-op and it stores it as such
  • node C does not know about the row from A:1 and B:1, but thinks it knows about all changes

And explained with SQLite...

Node A:

sqlite> create table foo (a integer primary key not null, b integer);
sqlite> select crsql_as_crr('foo');
sqlite> insert into foo values (1, 2);
sqlite> .mode quote
sqlite> select "table", pk, cid, val, col_version, db_version, coalesce(site_id, crsql_site_id()) as site_id, cl, seq from crsql_changes;
'foo',X'010901','b',2,1,1,X'067757d8c09546078d5284126042a0bb',1,0
sqlite> begin;
sqlite> insert into crsql_changes ("table", pk, cid, val, col_version, db_version, site_id, cl, seq) values ('foo',X'010901','b',2,1,1,X'9b0f66ec412b45f38ede4ae4c8103467',1,0);
sqlite> select crsql_rows_impacted();
0

Node B:

sqlite> create table foo (a integer primary key not null, b integer);
sqlite> select crsql_as_crr('foo');
sqlite> insert into foo values (1, 2);
sqlite> .mode quote
sqlite> select "table", pk, cid, val, col_version, db_version, coalesce(site_id, crsql_site_id()) as site_id, cl, seq from crsql_changes;
'foo',X'010901','b',2,1,1,X'9b0f66ec412b45f38ede4ae4c8103467',1,0
sqlite> begin;
sqlite> insert into crsql_changes ("table", pk, cid, val, col_version, db_version, site_id, cl, seq) values ('foo',X'010901','b',2,1,1,X'067757d8c09546078d5284126042a0bb',1,0);
sqlite> select crsql_rows_impacted();
0

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

No branches or pull requests

2 participants