Skip to content

Clear expired upload cache entries in one transaction - #941

Open
caglarpir wants to merge 1 commit into
mapillary:mainfrom
caglarpir:clear-upload-cache-in-one-transaction
Open

caglarpir wants to merge 1 commit into
mapillary:mainfrom
caglarpir:clear-upload-cache-in-one-transaction

Conversation

@caglarpir

Copy link
Copy Markdown
Contributor

Before it uploads images, upload deletes the expired entries of its file handle cache (entries expire 2 days after their image is uploaded). Each entry was deleted in its own transaction, so SQLite synced the database to disk once per entry. With full syncs (PRAGMA fullfsync on macOS), that is about 5 ms per entry: 100,000 expired entries took about 8 minutes, and upload showed nothing after ==> Uploading... until it uploaded or skipped the first sequence. The first upload after a large batch paid for all of it.

  • KeyValueStore.delete_matching() reads the entries and deletes the expired ones in one BEGIN IMMEDIATE transaction: 200,000 expired entries now take under a second.
  • The cache is cleared once per upload, not twice: ImageSequenceUploader cleared it, then created a CachedImageUploader, which cleared it again.

Tests: unit tests for delete_matching (deletes in one transaction; deletes nothing if the predicate fails), and the existing cache tests on Python 3.9, 3.11 and 3.13, which differ in how sqlite3 handles transactions.

Before it uploads images, upload deletes the expired entries of its
file handle cache. Each entry was deleted in its own transaction, so
SQLite synced the database to disk once per entry. With full syncs
(PRAGMA fullfsync on macOS) that took about 5 ms per entry, so 100,000
expired entries took about 8 minutes before upload uploaded or skipped
anything. Entries expire 2 days after their image is uploaded, so the
first upload after a large batch paid for all of them.

Delete them in one transaction: 200,000 expired entries now take under
a second. Also clear the cache once per upload, not twice:
ImageSequenceUploader cleared it, then created a CachedImageUploader,
which cleared it again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant