4 ms·
Well the issue I ran into was that I wanted a SQLite db to have one writer and many readers. However, what I was seeing was that queries were failing because th
by umvi 7y ago
Well the issue I ran into was that I wanted a SQLite db to have one writer and many readers. However, what I was seeing was that queries were failing because the DB was locked at the time of reading. The solution is to switch journaling mode to WAL[1].
However the particular platform I was developing for was an embedded system using the JFFS2 filesystem. JFFS2 doesn't support shared mmap, which is a feature SQLite needs for WAL.
So basically, it was big pain - I had to setup a tmpfs mount point where the WAL-enabled DB resided and then periodically sync it to flash.
[1] https://www.sqlite.org/wal.html https://www.sqlite.org/wal.html
- BubRoss 7y agoWhy didn't you just do more granular writes and let the different processes lock the file? SQLite is impressively fast, it can handle a lot before you need a full database.
- umvi 7y agoI don't know how to do that. Basically there is one process periodically dumping stats into a sqlitedb. There is an HTTP API that can retrieve said stats. How do I make it so the HTTP API doesn't occasionally fail when trying to read from the DB?
- BubRoss 7y agoRetry until it gets the lock and don't hold the lock longer than you need to to write to the db. Really though if you are trying to read and write to a db concurrently and over the network, it sounds much more clear cut for something like postgres.
- umvi 7y agoI don't really like the idea of a retry loop. Why doesn't sqlite have an API to just block until the DB is available?
- BubRoss 7y agoYou asked the question and now you don't like the 'idea' of the answer. Use real numbers instead of feels, and again if you need real concurrency, use a real database.
- umvi 7y ago"Retry" is not a solution; it's a workaround. Imagine if that's how opening files worked: "Oh yeah, if the file fails to open just retry a few times until it works." There's a small chance even retrying 3 times you could fail all 3 times in a row. WAL journaling is a solution.