Repository navigation
fix(storage): concurrent migrate() runs converge instead of throwing (#309) - #310
Merged
Merged
Conversation
…309) Instances of a fresh installation that start together on one store all read `_migrations` before any of them applies a migration. The loser's batch fails (duplicate column, or the bookkeeping row's primary key), rolls back as a whole and was thrown, although the migration was now applied: the first request on that instance failed with `StorageError: migration "0004_audit_actor_name" failed`. When a migration's batch fails, migrate() now reads its `_migrations` row again. If a peer applied it, the run moves on (the name is not in `applied`); otherwise it throws as before. At most once still rests on the primary-key row inside the same atomic batch: no interactive transaction, no lock (hard rule 4). - test/migrate-concurrent.test.ts: three and four runs gated to read the same empty state converge, on better-sqlite3 and Miniflare D1; each migration applies once (a non-idempotent INSERT is not doubled); a migration that fails on its own still throws. - admin-worker: the retry-once wrappers in ensureMigrated and SchedulerClock are gone. - helm-smoke.sh: fails when any instance logs a migration error, with two instances and after scaling to three (Parallel pod management). Closes #309 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Madraka <8898640+Madraka@users.noreply.github.com>
…n error (#309) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Madraka <8898640+Madraka@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #309
What
Instances of a fresh installation that start together on one store all read
_migrationsbefore any of them applies a migration. The loser's batch fails (a duplicate column, or the bookkeeping row's primary key), rolls back as a whole and was thrown, even though the migration had just been applied. That made the first request on the losing instance fail withStorageError: migration "0004_audit_actor_name" failed(run 46188727714).packages/storage/src/migrate.ts: when a migration'sbatch()fails,migrate()reads that migration's_migrationsrow again.applied).packages/cloudflare/src/admin-worker.ts: the retry-once wrappers inensureMigratedandSchedulerClockare removed.SiteGraphStore.init()and the other callers get the fix throughmigrate().Tests
packages/storage/test/migrate-concurrent.test.ts(better-sqlite3 and Miniflare D1). The runs are gated so they all read the same empty_migrationsbefore any batch, the worst case.CREATE TABLE,INSERT,ALTER TABLE ADD COLUMN) leave exactly one row, so nothing was re-run.scripts/swarm-smoke.shfails if either instance's log contains a migration error.scripts/helm-smoke.shdoes the same with two instances and again after scaling to three (the StatefulSet usespodManagementPolicy: Parallel).Changeset:
@cloudhal/storage,@cloudhal/cloudflare(patch). Size baseline updated (createAdminWorkershrank).🤖 Generated with Claude Code