Skip to content

fix(sqlite-storage): open v1 migration stages#4805

Closed
NathanFlurry wants to merge 1 commit intoengine-stabilize/actor2-validation-lifecyclefrom
engine-stabilize/sqlite-v1-migration-open
Closed

fix(sqlite-storage): open v1 migration stages#4805
NathanFlurry wants to merge 1 commit intoengine-stabilize/actor2-validation-lifecyclefrom
engine-stabilize/sqlite-v1-migration-open

Conversation

@NathanFlurry
Copy link
Copy Markdown
Member

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Copy link
Copy Markdown
Member Author

NathanFlurry commented Apr 27, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@claude
Copy link
Copy Markdown

claude Bot commented Apr 27, 2026

Review: fix(sqlite-storage): open v1 migration stages

The core logic is sound. prepare_v1_migration now correctly mirrors the open pattern (insert into open_dbs first, update generation on success, remove on error), and the ConcurrentTakeover error is the right signal for callers to disconnect the actor.

A few things worth looking at before merging:


Potential open_dbs leak in invalidate_v1_migration

prepare_v1_migration inserts a generation-0 sentinel into open_dbs and updates it on success. When concurrent takeover is later detected inside invalidate_v1_migration (origin not MigratingFromV1 with require_stage_in_progress=true), reset_v1_migration returns Ok(None) and invalidate_v1_migration does not remove the entry:

if reset.is_some() {
    self.open_dbs.remove_async(&actor_id.to_string()).await;
}

This leaves a stale open_dbs entry. Future calls to open or prepare_v1_migration for the same actor will hit the "sqlite db already open for actor" guard. Whether this is safe depends on whether the caller reliably invokes force_close on all non-Some returns. If Ok(None) always means "close the migration", unconditional cleanup is safer:

let reset = self.reset_v1_migration(actor_id, now_ms, true).await?;
self.open_dbs.remove_async(actor_id).await;
Ok(reset.is_some())

Unusual None.context(...) idiom

The Ok(None) arm in prepare_v1_migration uses None.context(...) to produce an error. It works, but is visually surprising. Minor nit.


Unnecessary allocations

In the cleanup arms of prepare_v1_migration, actor_id is &str. The .to_string() calls create needless String allocations. scc::HashMap accepts Q where K: Borrow<Q>, so actor_id works directly.


Missing test coverage

No tests cover the new error path. Two cases worth adding:

  1. prepare_v1_migration on an actor whose origin is no longer MigratingFromV1 should return ConcurrentTakeover and leave open_dbs clean so a subsequent open succeeds.
  2. invalidate_v1_migration when concurrent takeover is detected should return Ok(false) without leaving a stale open_dbs entry.

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.

1 participant