libsql icon indicating copy to clipboard operation
libsql copied to clipboard

Conflict detection in WAL API

Open penberg opened this issue 1 year ago • 1 comments

We currently allow arbitrary frames to be inserted to the WAL. Let's check the salt and the checksum to verify that a new frame matches the existing WAL. The tricky bit here is that the WAL we insert to needs to have the same salt as the origin WAL because salt is part of the cumulative checksum.

penberg avatar Dec 10 '24 09:12 penberg

We could augment the libsql_wal_frame_insert() to force the WAL to have the same salt and checksum as the first frame. However, this seems a bit intrusive to SQLite itself, so perhaps a better approach is to use external checksumming.

penberg avatar Dec 12 '24 09:12 penberg

There is a simple solution here: make the libsql_wal_insert_frame simply check if a frame already exists in the WAL. If it does not, append it; otherwise compare the existing and the new frame and only accept it if the frames have the same contents.

penberg avatar Jan 30 '25 16:01 penberg

Fixed by https://github.com/tursodatabase/libsql/commit/f1d2eea349e46107a8676324ffb0b5b5223e3929

penberg avatar Mar 19 '25 14:03 penberg