mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-29 14:04:22 +01:00
When `struct Database` is constructed, store `is_empty` as an `Arc<AtomicBool>` - the value is true if: 1. DB size is zero 2. WAL has no frames When `struct Pager` is constructed, this `Arc` is simply cloned. When any connection runs a transaction it will first check `is_empty`, and if the DB is empty, it will lock `init_lock` and then check `is_empty` again, and if it's still true, it allocates page1 and stores `false` in the `is_empty` `AtomicBool` and drops the lock. --- Note that Limbo can currently have a zero DB and a WAL with frames, as we have no special logic for folding page1 to the main DB file during initialization. Page 1 allocation currently happens on the first transaction (read or write, due to having to support `select * from sqlite_schema` on an empty DB; we should really check how SQLite actually does this.).