cr-sqlite
cr-sqlite copied to clipboard
option to "win on equal values"
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
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