Skip to content

Background, resumable migrations for big caches #89

Closed

Description

@neoromantic

One-time migrations run in one BEGIN IMMEDIATE transaction on the first open of a cache. The last one (filling NULL senders) takes several seconds per 100,000 messages while it holds the write lock, and the daemon waits only 5 seconds for a write. Any change that rewrites every message (re-encoding raw_json byte fields, #86; filling attachment metadata from raw_json for #22; a search index rebuild with another tokenizer) would hold the lock for minutes on a cache with millions of messages.

Proposed:

  • A background migration runs in small batches, each its own short write, and records its progress in the cache, so it resumes after a stop and never holds the write lock for long.
  • The daemon runs pending ones; a command that needs one finished says so instead of waiting. tg status shows each pending migration and its progress.
  • Reads stay correct while a migration is half done (rows in the old and the new form both work).
  • First users: re-encode raw_json byte fields of existing rows (raw_json: store byte arrays as base64 #86), attachment metadata from raw_json (Send and download media #22), and later index rebuilds.

Done when the re-encode of existing raw_json rows runs this way on a made-up cache, a stop in the middle resumes, a daemon write never waits more than a short batch, and docs/database-schema.md describes the mechanism. Related: #80.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions