Skip to content

fix(android): checkpoint old database before legacy migration - #1371

Open
stereodenis wants to merge 1 commit into
react-native-async-storage:mainfrom
stereodenis:fix/android-legacy-migration-wal
Open

stereodenis wants to merge 1 commit into
react-native-async-storage:mainfrom
stereodenis:fix/android-legacy-migration-wal

Conversation

@stereodenis

Copy link
Copy Markdown

Summary

On the first launch after upgrading from v2 (default storage), the legacy storage is created with createFromFile(RKStorage). Room copies only the main database file. If RKStorage uses write-ahead logging, recent writes may still be in RKStorage-wal, so they are lost. With a small database that has never been checkpointed, everything is lost.

v2 handled this with verifyAndForceSqliteCheckpoint (#582) for the Next storage migration. That step is missing in v3, where the migration runs for everyone who used the default v2 storage. Compatibility WAL is enabled by default on Android 9.

This PR checkpoints the old database before Room copies it. It runs only while the new database does not exist yet.

Test Plan

  1. On an emulator, force compatibility WAL (I used API 35):
    adb shell settings put global sqlite_compatibility_wal_flags legacy_compatibility_wal_enabled=true
  2. Install an app with v2.2.0, write some values, force stop it. databases/ has a 4 KB RKStorage and a non-empty RKStorage-wal.
  3. Install the same app with v3 over it and read the keys.
3.1.1 this PR
WAL on 0 of 6 keys 6 of 6
WAL off 6 of 6 6 of 6

The values included a 300 KB string, Cyrillic and emoji, and the last write before the force stop. I also checked a second launch and a clean install. Tested in a React Native 0.88.1 app with the change applied to the published 3.1.1 package, not on a physical Android 9 device.

@changeset-bot

changeset-bot Bot commented Nov 24, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: dd03bf8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@react-native-async-storage/async-storage Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@krizzu krizzu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good catch, thanks

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants