Skip to content
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

Mechanism for automatically picking up changes when on-disk .db file changes #271

Closed
simonw opened this issue May 17, 2018 · 4 comments
Closed

Comments

@simonw
Copy link
Owner

simonw commented May 17, 2018

It would be useful if Datasette could spot when a SQLite database file changes on disk and restart itself (hence re-running .inspect() and picking up the new content hash). Ideally this could happen in an atomic way so no requests get dropped during the switch-over.

This may not play well with SQLite opening databases in immutable mode. Research required.

@simonw simonw added the medium label May 17, 2018
@simonw
Copy link
Owner Author

simonw commented May 17, 2018

This is a departure from how Datasette has been designed so far, and it may turn out that it's not feasible or it requires too many philosophical changes to be worthwhile.

If we CAN do it though it would mean Datasette could stay running pointed at a directory on disk and new SQLite databases could be dropped into that directory by another process and served directly as they become available.

@simonw
Copy link
Owner Author

simonw commented May 17, 2018

From https://www.sqlite.org/c3ref/open.html

immutable: The immutable parameter is a boolean query parameter that indicates that the database file is stored on read-only media. When immutable is set, SQLite assumes that the database file cannot be changed, even by a process with higher privilege, and so the database is opened read-only and all locking and change detection is disabled. Caution: Setting the immutable property on a database file that does in fact change can result in incorrect query results and/or SQLITE_CORRUPT errors. See also: SQLITE_IOCAP_IMMUTABLE.

So this would probably have to be a new mode, datasette serve --detect-db-changes, which no longer opens in immutable mode. Or maybe current behavior becomes not-the-default and you opt into it with datasette serve --immutable

@simonw
Copy link
Owner Author

simonw commented Jun 18, 2018

As seen in #316 inspect is already taking a VERY long time to run against large (600GB) databases.

To get this working I may have to make inspect an optional optimization and run introspection for columns and primary keys in demand.

The one catch here is the count(*) queries - Datasette may need to learn not to return full table counts in circumstances where the count has not been pre-calculates and takes more than Xms to generate.

@simonw
Copy link
Owner Author

simonw commented Jan 10, 2019

It turns out this was much easier to support than I expected: eac08f0

@simonw simonw closed this as completed Jan 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant