vlcn-io / cr-sqlite

Convergent, Replicated SQLite. Multi-writer and CRDT support for SQLite
https://vlcn.io
MIT License
2.61k stars 69 forks source link

option to "win on equal values" #413

Open tantaman opened 6 months ago

tantaman commented 6 months ago

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 commented 6 months ago

Perhaps a clearer rundown:

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