Skip to content

Commit a885953

Browse files
committed
review nits
1 parent 3251fa1 commit a885953

File tree

3 files changed

+49
-12
lines changed

3 files changed

+49
-12
lines changed

components/places/sql/create_shared_triggers.sql

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ BEGIN
6262
AND NEW.parent IS NOT NULL;
6363

6464
SELECT throw(format(
65-
'update: nonexistent parent: old_parent=%d, new_parent=%d, operation=%q',
66-
OLD.parent,
67-
NEW.parent,
65+
'update: item without parent: operation=%q',
6866
CASE WHEN NEW.syncChangeCounter > 0 THEN 'sync' ELSE 'user' END
6967
))
7068
WHERE NEW.guid <> 'root________'

components/places/src/bookmark_sync/engine.rs

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,18 @@ fn update_local_items_in_places(
364364

365365
log::debug!("Changing GUIDs");
366366
scope.err_if_interrupted()?;
367-
db.execute_batch("DELETE FROM changeGuidOps")?;
367+
let result = db.execute_batch("DELETE FROM changeGuidOps");
368+
// Due to bug 1935797, guid collisions are happening in some step of bookmarks
369+
// but not clear if it's the "fixup" step, so we catch and log to sentry
370+
if let Err(rusqlite::Error::SqliteFailure(e, _)) = &result {
371+
if e.code == ErrorCode::ConstraintViolation {
372+
error_support::report_error!(
373+
"places-sync-bookmarks-guid-collision",
374+
"changeGuidOps ran into guid collision violation"
375+
);
376+
}
377+
}
378+
result?;
368379

369380
log::debug!("Applying remote items");
370381
apply_remote_items(db, scope, now)?;
@@ -374,6 +385,35 @@ fn update_local_items_in_places(
374385
scope.err_if_interrupted()?;
375386
db.execute_batch("DELETE FROM applyNewLocalStructureOps")?;
376387

388+
// Similar to the check in apply_remote_items, however we do a post check
389+
// to see if dogear was unable to fix up the issue
390+
let orphaned_count: i64 = db.query_row(
391+
"WITH RECURSIVE orphans(id) AS (
392+
SELECT b.id
393+
FROM moz_bookmarks b
394+
WHERE b.parent IS NOT NULL
395+
AND NOT EXISTS (
396+
SELECT 1 FROM moz_bookmarks p WHERE p.id = b.parent
397+
)
398+
UNION
399+
SELECT c.id
400+
FROM moz_bookmarks c
401+
JOIN orphans o ON c.parent = o.id
402+
)
403+
SELECT COUNT(*) FROM orphans;",
404+
[],
405+
|row| row.get(0),
406+
)?;
407+
408+
if orphaned_count > 0 {
409+
log::warn!("Found {} orphaned bookmarks after sync", orphaned_count);
410+
error_support::report_error!(
411+
"places-sync-bookmarks-orphaned",
412+
"found local orphaned bookmarks after we applied new local structure ops: {}",
413+
orphaned_count,
414+
);
415+
}
416+
377417
log::debug!("Resetting change counters for items that shouldn't be uploaded");
378418
sql_support::each_chunk_mapped(
379419
&ops.set_local_merged,
@@ -491,8 +531,8 @@ fn apply_remote_items(db: &PlacesDb, scope: &SqlInterruptScope, now: Timestamp)
491531
}
492532
).ok(); // We ignore the error because it's expected, users should not have entries with the same id that have different types
493533

494-
// Same as above but we check if any users have any undetected orphaned bookmarks and
495-
// report them appropiately
534+
// Due to bug 1935797, we need to check if any users have any
535+
// undetected orphaned bookmarks and report them
496536
let orphaned_count: i64 = db.query_row(
497537
"WITH RECURSIVE orphans(id) AS (
498538
SELECT b.id
@@ -513,9 +553,8 @@ fn apply_remote_items(db: &PlacesDb, scope: &SqlInterruptScope, now: Timestamp)
513553

514554
if orphaned_count > 0 {
515555
log::warn!("Found {} orphaned bookmarks during sync", orphaned_count);
516-
error_support::report_error!(
517-
"places-sync-bookmarks-orphaned",
518-
"found local orphaned bookmarks {}",
556+
error_support::breadcrumb!(
557+
"places-sync-bookmarks-orphaned: found local orphans before upsert {}",
519558
orphaned_count
520559
);
521560
}
@@ -559,7 +598,7 @@ fn apply_remote_items(db: &PlacesDb, scope: &SqlInterruptScope, now: Timestamp)
559598
let result = db.execute_batch(&upsert_sql);
560599

561600
// In trying to debug bug 1935797 - relaxing the trigger caused a spike on
562-
// guid collisions, we want to report on this error before the actual upsert to see
601+
// guid collisions, we want to report on this during the upsert to see
563602
// if we can discern any obvious signs
564603
if let Err(rusqlite::Error::SqliteFailure(e, _)) = &result {
565604
if e.code == ErrorCode::ConstraintViolation {

components/places/src/db/schema.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ mod tests {
555555
)
556556
.expect_err("should fail to update folder with NULL parent");
557557
assert!(
558-
e.to_string().contains("update: nonexistent parent"),
558+
e.to_string().contains("update: item without parent"),
559559
"Expected error, got: {:?}",
560560
e,
561561
);
@@ -571,7 +571,7 @@ mod tests {
571571
)
572572
.expect_err("should fail to update folder with nonexistent parent");
573573
assert!(
574-
e.to_string().contains("update: nonexistent parent"),
574+
e.to_string().contains("update: item without parent"),
575575
"Expected error, got: {:?}",
576576
e,
577577
);

0 commit comments

Comments
 (0)