-
-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move away from sqlite #307
Comments
I've rebased the work from the less-sql branch, and updated it to the point where all of the tests are at least passing. I've pushed that work to the event-log branch. It wasn't a clean rebase, given that the less-sql branch was a couple of years old, and lot has changed since then. So even though the tests are passing, my current confidence in this branch is low. |
Other options:
|
This forces all updates/inserts to the db to go through a single-threaded executor, which prevents concurrent db access and the resulting lock exceptions. This is hopefully a stopgap measure until we get rid of sqlite entirely.
That commit serializes db writes through a single thread, and 7fa5980 moves the admin script functionality to the |
Why can't we use just a normal RDBMS as postgres? I find that more straightforward and extensible. |
Postgres would be nice, but there are costs associated with moving to it:
The serialized-writes solution that we have currently is a bit gross, |
…ojars#307] This forces all updates/inserts to the db to go through a single-threaded executor, which prevents concurrent db access and the resulting lock exceptions. This is hopefully a stopgap measure until we get rid of sqlite entirely.
@tobias what do you think about using datomic free (with h2 as store)? |
Thanks for the suggestion, but our data isn't something that we need to maintain history of, generally, and I don't want to add the complexity of running a transactor. |
PR: #443 |
You could at least turn on SQLite's WAL mode so readers aren't blocked by writers and vice versa: https://www.sqlite.org/wal.html. The timeout handling is configurable: https://sqlite.org/faq.html#q5. SQLite isn't going to be fast with more than one concurrent writer but there's no reason to be hacking around it: it does work fine, just perhaps not how you want it to by default. |
@thestinger - we'd happily take a pull request that enables WAL via the java SQLite driver. |
Just a followup on this, I think there were (at least!) two more reasons why we were getting concurrency errors: 1: jdbc-sqlite was compiled without HAVE_USLEEP up until xerial/sqlite-jdbc@4b2b2c3 (xerial/sqlite-jdbc#104). Running
I get
This looks like the same issue as http://beets.io/blog/sqlite-nightmare.html, where the sqlite driver is sleeping for 1 second at a time before retrying, meaning that concurrent writes could stack up, especially combined with: 2: There is also xerial/sqlite-jdbc#59 which would allow us to use sqlite with two different threading options: multi-threaded, or single threaded. Both of these would probably be faster than the default serialised option. There hasn't been a release of jdbc-sqlite for a while, but we should look at upgrading and taking advantage of these features when there is. |
We've moved to postgres (see #736), which has been released as part of Clojars 79. |
This is to track moving away from sqlite to something we can access
concurrently. We've had quite a few bugs related to concurrency issues
with sqlite (#266, #115, #105), and we can't do automatic promotion
with it. It's also possible to lock the database from outside of the
app when doing maintenance (as touched on in #226).
@technomancy and @xeqi have done quite a bit of work on using a
log-based event stream system. The event logging is already happening
in production, and there is work on the less-sql branch to use the log
instead of sqlite for queries. You can read about that work on
the mailing list. If we want to continue with the event log approach,
at least the following things need to happen:
current shell scripts only alter the sqlite db, so no deletion
events get written to the log. It may be worthwhile to have lein
aliases to write these deletion events to the log.
logs, we'll need to move to file-based locking instead of using
clojure's locking macro to prevent log corruption
processes can write to them (a file watcher perhaps?)
We don't currently have the backup instance running, but if we do plan
to bring that back, we need to take that in to consideration (file
locking may be enough here if both instances share the same log file
set.
An alternative approach would be to move to a different database that
better handles concurrency (postgres, etc). That delegates locking and
corruption issues to the db, but adds infrastructure complexity.
The text was updated successfully, but these errors were encountered: