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

Incrementally purge oldest revisions in SQLite databases #1165

Closed
snej opened this issue Mar 12, 2016 · 1 comment
Closed

Incrementally purge oldest revisions in SQLite databases #1165

snej opened this issue Mar 12, 2016 · 1 comment

Comments

@snej
Copy link
Contributor

snej commented Mar 12, 2016

The SQLite storage engine only prunes documents — deletes metadata of old revisions that are deeper down than the maxRevTreeDepth — when the database's Compact method is called by the app. This means that a doc that's frequently updated will accumulate more and more entries in the revs table.

We have evidence from the field that this eventually slows down database operations on that document to an unacceptable degree (albeit in an extreme scenario where a doc is updated several times a minute for hours, while multiple replications are running.)

We can fix this by pruning the revision tree periodically (the way the ForestDB storage does) as new revisions are added. -[CBLSQLiteStorage forceInsert:...] (called by pull replications) looks like it could be extended to prune old revisions, since it already loads the metadata of every revision of the document. The -addDocID:... method (called by local puts) is a bit harder to fix since it doesn’t have the whole document history available. It might be sufficient to check if the new revision’s generation # is a multiple of the maxRevTreeDepth, and if so trigger a prune operation on that document.

@snej
Copy link
Contributor Author

snej commented Apr 1, 2016

Merged to dev branch; closing.

@snej snej closed this as completed Apr 1, 2016
@snej snej changed the title Docs in SQLite dbs never get pruned until entire db is compacted Incrementally purge oldest revisions in SQLite databases Jul 3, 2016
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