8000 browser: BrowserDb.open() does not write migrated pages back to IndexedDB · Issue #411 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content

browser: BrowserDb.open() does not write migrated pages back to IndexedDB #411

Closed

Description

@adityamukho

Problem

BrowserDb.open() loads all pages from IndexedDB into a BrowserBufferBackend. Then it calls PersistentFactStorage::new(buffer, 0), which runs the normal load path. If the stored data is in an older file format, that load path upgrades it (migrate_v1_to_v2, migrate_v5_to_v6, and the one-per-page repack in load()). The upgrade writes new pages to the buffer and marks them dirty.

open() never sends those dirty pages to IndexedDB. So the upgraded pages only exist in memory. The IndexedDB copy stays in the old format until one of these happens:

  • a transact or retract through execute()
  • a call to checkpoint()

import_graph() does not have this problem. It takes the dirty set and writes it right after PersistentFactStorage::new.

Impact

Today this is a latent issue. IndexedDB support shipped in v0.20.0 with format v7, and the format has not changed since. So no existing IndexedDB database needs an upgrade yet.

It will matter when the format changes again (for example #388, format v8):

  • A read-only session upgrades the data in memory on every open. The work is repeated each time and the stored copy never changes.
  • If the upgrade also fixes a problem in the stored data, such as an index rebuild after a checksum mismatch, that fix is also not saved.

Proposed fix

In BrowserDb::open() (src/browser/mod.rs), after PersistentFactStorage::new(...), do the same thing import_graph() does:

  1. Call pfs.with_backend_mut(|b| b.take_dirty()).
  2. Read those pages with read_page_raw.
  3. If the set is not empty, call idb.write_pages(...) before returning.

On a normal open with no upgrade, the dirty set is empty, so this adds no IndexedDB write.

Test idea

Add a wasm_bindgen_test that:

  1. Writes the pages of an older-format fixture (for example a v5 file from test: golden-file compatibility corpus for every file format version #391) straight into an IndexedDB store with IndexedDbBackend::write_pages.
  2. Opens it with BrowserDb::open() and runs only a query.
  3. Reads page 0 back from IndexedDB with load_all_pages() and checks that the header version is FORMAT_VERSION.

Activity

  1. added this to the v3.0.0 milestone on Sep 27, 2026
  2. added a commit that references this issue on Oct 7, 2026
  3. adityamukho commented on Oct 7, 2026

    @adityamukho
    CollaboratorAuthor

    Fixed on v3 by #474 (merge deb82a4); ships in v3.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingmigrationMigration related issue

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0