Skip to content

Commit 6c86667

Browse files
committed
libsql: Fail sync_db_if_needed() if database exists but metadata is missing
This is an inconsistent state because there is no way for us to know what generation the database file is tracking. For all we know, it could be a totally unrelated database file than the one we have remotely. Therefore, return an error.
1 parent 70c9bbc commit 6c86667

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

libsql/src/sync.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -658,16 +658,14 @@ impl SyncContext {
658658
self.sync_db(generation).await
659659
}
660660
(false, true) => {
661-
// kinda inconsistent state: DB exists but metadata missing
662-
// however, this generally not an issue. For a fresh db, a user might do writes
663-
// locally and then try to do sync later. So in this case, we will not
664-
// bootstrap the db file and let the user proceed. If it is not a fresh db, the
665-
// push will fail anyways later.
666-
// if metadata file does not exist, then generation should be zero
667-
assert_eq!(self.durable_generation, 0);
668-
// lets initialise it to first generation
669-
self.durable_generation = 1;
670-
Ok(())
661+
// inconsistent state: DB exists but metadata missing
662+
tracing::error!(
663+
"local state is incorrect, db file exists but metadata file does not"
664+
);
665+
Err(SyncError::InvalidLocalState(
666+
"db file exists but metadata file does not".to_string(),
667+
)
668+
.into())
671669
}
672670
(true, false) => {
673671
// inconsistent state: Metadata exists but DB missing

0 commit comments

Comments
 (0)