Skip to content

Commit

Permalink
Use WAL by default.
Browse files Browse the repository at this point in the history
For #169 / #175.
  • Loading branch information
lemon24 committed Jun 29, 2020
1 parent 6dff30f commit df58732
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
27 changes: 27 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,30 @@ Version 1.4

Unreleased

* Use SQLite's `write-ahead logging`_ by default,
to increase concurrency and prevent "database is locked" errors.
(:issue:`169`, :issue:`175`)

This changes how the database appears on disk and how it can be used;
most importantly:

* There are additional quasi-persistent ``-wal`` and ``-shm`` files
associated with the database.
Backing up the database by simply copying it may not be enough
(this was also true before this change, to a lesser extent).
To make a backup of the database, use the SQLite CLI::

sqlite3 src.sqlite ".backup 'dst.sqlite'"

* All processes using the database must be on the same host computer;
WAL does not work over a network filesystem.

*reader* will enable WAL exactly once: at creation for new databases,
and when migrating to reader 1.4 for existing databases.
After this, it can be disabled again from the SQLite CLI::

sqlite3 db.sqlite "pragma journal_mode = delete;"

* Do not fail for feeds with incorrectly-declared media types,
if feedparser can parse the feed;
this is similar to the current behavior for incorrectly-declared encodings.
Expand All @@ -23,6 +47,9 @@ Unreleased
* Other minor web application improvements.


.. _write-ahead logging: https://www.sqlite.org/wal.html


Version 1.3
-----------

Expand Down
11 changes: 10 additions & 1 deletion src/reader/_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ def create_db(db: sqlite3.Connection) -> None:
create_feeds(db)
create_entries(db)
create_feed_metadata(db)
# https://github.com/lemon24/reader/issues/169
# https://github.com/lemon24/reader/issues/175
db.execute("PRAGMA journal_mode = WAL;")


def create_feeds(db: sqlite3.Connection, name: str = 'feeds') -> None:
Expand Down Expand Up @@ -142,16 +145,22 @@ def update_from_18_to_19(db: sqlite3.Connection) -> None: # pragma: no cover
db.execute("ALTER TABLE feeds ADD COLUMN last_exception TEXT;")


def update_from_19_to_20(db: sqlite3.Connection) -> None: # pragma: no cover
# for https://github.com/lemon24/reader/issues/169
db.execute("PRAGMA journal_mode = WAL;")


def setup_db(db: sqlite3.Connection) -> None:
return setup_sqlite_db(
db,
create=create_db,
version=19,
version=20,
migrations={
# 1-9 removed before 0.1 (last in e4769d8ba77c61ec1fe2fbe99839e1826c17ace7)
# 10-16 removed before 1.0 (last in 618f158ebc0034eefb724a55a84937d21c93c1a7)
17: update_from_17_to_18,
18: update_from_18_to_19,
19: update_from_19_to_20,
},
# Row value support was added in 3.15.
minimum_sqlite_version=(3, 15),
Expand Down

0 comments on commit df58732

Please sign in to comment.