Skip to content

Conversation

@rkistner
Copy link
Contributor

@rkistner rkistner commented Dec 4, 2025

This modifies the APIs and implementation of BucketStorageBatch to allow using multiple batches concurrently without introducing consistency issues. The first goal of this is to allow reading the replication stream while snapshotting - see #426 for a Postgres implementation.

The actual writes to the database still rely on exclusive database locks to a large extent, so there isn't true concurrency yet. But it does allow running a replication stream concurrently with replication snapshots without breaking.

Specifically, this changes:

  1. Rely less on local variables in the batch, using the database state instead.
  2. Remove the distinction between commit() and keepalive(). The only remaining difference is that keepalive is essentially commit({allowEmptyCommit: true}).
  3. snapshot_done is now explicitly set after completing a snapshot, rather than setting it automatically on commit. No commit will go through until snapshot_done is set.
  4. current_data deletes are now soft-deletes (storing an empty document/row instead of deleting the document/row), converted into hard deletes on the next commit. We need this to consistently handle snapshots while streaming.
  5. Fix concurrency issues for flushing and committing batches, especially in Postgres storage (previously not an issue since we wouldn't ever do this concurrently).
  6. Change SourceTable.id to be strongly typed, specifically checking for string in Postgres storage and ObjectId in MongoDB storage. This unfortunately had a big knock-on effect in tests, including now having different checksums in postgres storage vs mongodb storage.

Other more minor changes:

  1. Reduce migration logs in tests.
  2. Rely less on a split between initial snapshot and streaming replication in Postgres tests.
  3. Add a cause to ReplicationAbortedError.

@changeset-bot
Copy link

changeset-bot bot commented Dec 4, 2025

🦋 Changeset detected

Latest commit: 5c18559

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

This PR includes changesets to release 17 packages
Name Type
@powersync/service-module-postgres-storage Minor
@powersync/service-module-mongodb-storage Minor
@powersync/service-core-tests Minor
@powersync/service-module-postgres Minor
@powersync/service-errors Minor
@powersync/service-module-mongodb Minor
@powersync/service-core Minor
@powersync/service-module-mysql Minor
@powersync/lib-services-framework Minor
@powersync/service-schema Minor
@powersync/service-module-mssql Patch
@powersync/service-image Minor
@powersync/service-module-core Patch
test-client Patch
@powersync/service-rsocket-router Patch
@powersync/lib-service-mongodb Patch
@powersync/lib-service-postgres 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

@rkistner rkistner changed the title [WIP] Concurrent storage write batch support Concurrent storage write batch support Dec 4, 2025
@rkistner rkistner force-pushed the concurrent-storage-batches branch from 6522374 to 841273e Compare December 4, 2025 13:08
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