Skip to content

Commit 0a38408

Browse files
committed
revert #393
1 parent e8def14 commit 0a38408

File tree

5 files changed

+36
-174
lines changed

5 files changed

+36
-174
lines changed

core/rs/core/src/changes_vtab_write.rs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,11 @@ use crate::util::slab_rowid;
2727
*/
2828
fn did_cid_win(
2929
db: *mut sqlite3,
30-
ext_data: *mut crsql_ExtData,
3130
insert_tbl: &str,
3231
tbl_info: &TableInfo,
3332
unpacked_pks: &Vec<ColumnValue>,
3433
key: sqlite::int64,
3534
insert_val: *mut sqlite::value,
36-
insert_site_id: &[u8],
3735
col_name: &str,
3836
col_version: sqlite::int64,
3937
errmsg: *mut *mut c_char,
@@ -77,19 +75,7 @@ fn did_cid_win(
7775
}
7876

7977
// versions are equal
80-
// need to compare site ids
81-
let ret = unsafe {
82-
let my_site_id = core::slice::from_raw_parts((*ext_data).siteId, 16);
83-
insert_site_id.cmp(my_site_id) as c_int
84-
};
85-
86-
// site id lost.
87-
if ret <= 0 {
88-
return Ok(false);
89-
}
90-
91-
// site id won
92-
// last thing, compare values to ensure we're not changing state on equal values
78+
// need to compare values
9379
let col_val_stmt_ref = tbl_info.get_col_value_stmt(db, col_name)?;
9480
let col_val_stmt = col_val_stmt_ref.as_ref().ok_or(ResultCode::ERROR)?;
9581

@@ -105,9 +91,9 @@ fn did_cid_win(
10591
let local_value = col_val_stmt.column_value(0)?;
10692
let ret = crsql_compare_sqlite_values(insert_val, local_value);
10793
reset_cached_stmt(col_val_stmt.stmt)?;
108-
// insert site id won and values differ. We should take the update.
94+
// value won, take value
10995
// if values are the same (ret == 0) then we return false and do not take the update
110-
return Ok(ret != 0);
96+
return Ok(ret > 0);
11197
}
11298
_ => {
11399
// ResultCode::DONE would happen if clock values exist but actual values are missing.
@@ -600,13 +586,11 @@ unsafe fn merge_insert(
600586
|| !row_exists_locally
601587
|| did_cid_win(
602588
db,
603-
(*tab).pExtData,
604589
insert_tbl,
605590
&tbl_info,
606591
&unpacked_pks,
607592
key,
608593
insert_val,
609-
insert_site_id,
610594
insert_col,
611595
insert_col_vrsn,
612596
errmsg,

core/src/crsqlite.test.c

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -440,20 +440,6 @@ static sqlite3_int64 getDbVersion(sqlite3 *db) {
440440
return db2v;
441441
}
442442

443-
static void *getSiteId(sqlite3 *db) {
444-
sqlite3_stmt *pStmt = 0;
445-
int rc = sqlite3_prepare_v2(db, "SELECT crsql_site_id()", -1, &pStmt, 0);
446-
if (rc != SQLITE_OK) {
447-
return 0;
448-
}
449-
450-
sqlite3_step(pStmt);
451-
void *site = sqlite3_column_blob(pStmt, 0);
452-
sqlite3_finalize(pStmt);
453-
454-
return site;
455-
}
456-
457443
static void testLamportCondition() {
458444
printf("LamportCondition\n");
459445
// syncing from A -> B, while no changes happen on B, moves up
@@ -525,15 +511,6 @@ static void noopsDoNotMoveClocks() {
525511
rc += sqlite3_open(":memory:", &db1);
526512
rc += sqlite3_open(":memory:", &db2);
527513

528-
void *db1SiteId = getSiteId(db1);
529-
void *db2SiteId = getSiteId(db2);
530-
int cmp = memcmp(db1SiteId, db2SiteId, 16);
531-
if (cmp > 0) {
532-
sqlite3 *temp = db1;
533-
db1 = db2;
534-
db2 = temp;
535-
}
536-
537514
// swap dbs based on site id compare to make it a noop.
538515

539516
rc += sqlite3_exec(
@@ -570,10 +547,6 @@ static void noopsDoNotMoveClocks() {
570547
sqlite3_int64 db1vPost = getDbVersion(db1);
571548
sqlite3_int64 db2vPost = getDbVersion(db2);
572549

573-
// TODO: we still need to compare values so as not to bump the db_version
574-
// forward on a no-difference
575-
// this fails sometimes because site id winning.
576-
printf("db1 pre: %lld db2 post: %lld", db1vPre, db2vPost);
577550
assert(db1vPre == db2vPost);
578551
assert(db1vPre == db1vPost);
579552

core/src/rows-impacted.test.c

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ static void testCreateThatDoesNotChangeAnything() {
314314
printf("\t\e[0;32mSuccess\e[0m\n");
315315
}
316316

317-
static void testValueWouldWinButSiteIdLoses() {
317+
static void testValueWin() {
318318
printf("ValueWin\n");
319319
int rc = SQLITE_OK;
320320
char *err = 0;
@@ -330,33 +330,6 @@ static void testValueWouldWinButSiteIdLoses() {
330330
0, 0, &err);
331331
sqlite3_prepare_v2(db, "SELECT crsql_rows_impacted()", -1, &pStmt, 0);
332332
sqlite3_step(pStmt);
333-
// value is greater but site id lower, a loss and now rows changed.
334-
assert(sqlite3_column_int(pStmt, 0) == 0);
335-
sqlite3_finalize(pStmt);
336-
rc += sqlite3_exec(db, "COMMIT", 0, 0, 0);
337-
assert(rc == SQLITE_OK);
338-
339-
crsql_close(db);
340-
printf("\t\e[0;32mSuccess\e[0m\n");
341-
}
342-
343-
static void testSiteIdWin() {
344-
printf("SiteIdWin\n");
345-
int rc = SQLITE_OK;
346-
char *err = 0;
347-
sqlite3 *db = createDb();
348-
sqlite3_stmt *pStmt = 0;
349-
350-
rc = sqlite3_exec(db, "INSERT INTO foo VALUES (1, 2)", 0, 0, 0);
351-
352-
rc = sqlite3_exec(db, "BEGIN", 0, 0, 0);
353-
rc += sqlite3_exec(db,
354-
"INSERT INTO crsql_changes VALUES ('foo', X'010901', 'b', "
355-
"3, 1, 1, X'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF', 1, 1)",
356-
0, 0, &err);
357-
sqlite3_prepare_v2(db, "SELECT crsql_rows_impacted()", -1, &pStmt, 0);
358-
sqlite3_step(pStmt);
359-
// site id is larger, a win
360333
assert(sqlite3_column_int(pStmt, 0) == 1);
361334
sqlite3_finalize(pStmt);
362335
rc += sqlite3_exec(db, "COMMIT", 0, 0, 0);
@@ -401,8 +374,7 @@ void rowsImpactedTestSuite() {
401374
testUpdateThatDoesNotChangeAnything();
402375
testDeleteThatDoesNotChangeAnything();
403376
testCreateThatDoesNotChangeAnything();
404-
testValueWouldWinButSiteIdLoses();
405-
testSiteIdWin();
377+
testValueWin();
406378
testClockWin();
407379
testDelete();
408380
}

py/correctness/tests/test_cl_merging.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ def make_simple_schema():
2828
return c
2929

3030

31-
def get_site_id(c):
32-
return c.execute("SELECT crsql_site_id()").fetchone()[0]
33-
34-
3531
def make_pko_schema():
3632
c = connect(":memory:")
3733
c.execute("CREATE TABLE foo (a INTEGER PRIMARY KEY NOT NULL) STRICT;")
@@ -841,32 +837,17 @@ def test_larger_col_version_same_cl():
841837
close(c2)
842838

843839

844-
# should be a no-op.
845-
# values do not break ties.
846-
# site id loses on the merge
847840
def test_larger_col_value_same_cl_and_col_version():
848841
c1 = make_simple_schema()
849842
c2 = make_simple_schema()
850843

851-
# greater site id wins so we need to swap
852-
if get_site_id(c1) > get_site_id(c2):
853-
temp = c1
854-
c1 = c2
855-
c2 = temp
856-
857844
c1.execute("INSERT INTO foo VALUES (1, 4)")
858845
c1.commit()
859846
c2.execute("INSERT INTO foo VALUES (1, 1)")
860847
c2.commit()
861848

862849
sync_left_to_right(c1, c2, 0)
863850

864-
assert (c1.execute("SELECT * FROM foo").fetchall() !=
865-
c2.execute("SELECT * FROM foo").fetchall())
866-
867-
sync_left_to_right(c2, c1, 0)
868-
869-
# swapping direcitons it'll merge because the other guy had the bigger site id
870851
assert (c1.execute("SELECT * FROM foo").fetchall() ==
871852
c2.execute("SELECT * FROM foo").fetchall())
872853

0 commit comments

Comments
 (0)