Skip to content

Conversation

@rkistner
Copy link
Contributor

@rkistner rkistner commented Feb 24, 2025

There are some scenarios that trigger a restart of replication:

  1. On Postgres, when the logical replication slot is invalid or deleted.
  2. On MongoDB, when the resumeToken is not valid anymore.

In those cases, replication is restarted by creating a new sync-rules copy. The issue is that the active storage was immediately stopped, which could result in an unexpected [PSYNC_S2302] No sync rules available error.

This change instead keeps the current sync-rules storage active, which will be stopped automatically once the new storage has finished initial replication. This means clients can still continue syncing the (stale) data while re-replicating.

To implement this, a new ERRORED state is introduced for sync rules. This is the same as ACTIVE in terms of serving sync requests, but is not replicated.

This fixes some other issues:

  1. For Postgres source db, when a replication slot is removed completely, handle it the same as an invalid slot. Previously, it would clear storage and re-create the same slot, which causes issues if that is the active sync rules storage.
  2. When clearing storage for old sync rules, don't fire storageCreated hooks. Those caused issues in some cases if the sync rules had a parse error.

@changeset-bot
Copy link

changeset-bot bot commented Feb 24, 2025

🦋 Changeset detected

Latest commit: 827da3e

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

This PR includes changesets to release 9 packages
Name Type
@powersync/service-module-postgres-storage Patch
@powersync/service-module-mongodb-storage Patch
@powersync/service-module-postgres Patch
@powersync/service-module-mongodb Patch
@powersync/service-core Patch
@powersync/service-module-mysql Patch
@powersync/service-image Patch
@powersync/service-core-tests Patch
test-client 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 marked this pull request as ready for review February 25, 2025 10:25
@rkistner rkistner changed the title Keep current sync rules active when restarting replication Keep current sync rule storage active when restarting replication due to errors Feb 25, 2025
@rkistner rkistner merged commit 88ab679 into main Feb 26, 2025
20 checks passed
@rkistner rkistner deleted the fix-restarting-replication branch February 26, 2025 11:22
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