Skip to content

Conversation

@rkistner
Copy link
Contributor

The issue

The main replication loop periodically checks whether there are new replication jobs that should be started, old ones to be stopped, or data to be cleared.

The issue is that the data clearing was a "blocking" operation, and would prevent the loop from running again until it completed. In most cases it's fine - the actual replication jobs would already be running, and continue fine in the background.

However, there is an edge case: If a replication job was not immediately due to a competing sync rules lock, but the clearing was started, then the replication job would not be retried until the clearing has completed. This could result in significant replication lag building up.

The fix

This removes the blocking behavior of the clearing jobs, resolving the issue.

@changeset-bot
Copy link

changeset-bot bot commented Jun 20, 2025

🦋 Changeset detected

Latest commit: 3e7c1fc

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

This PR includes changesets to release 11 packages
Name Type
@powersync/service-core Patch
@powersync/service-image Patch
@powersync/service-core-tests Patch
@powersync/service-module-core Patch
@powersync/service-module-mongodb-storage Patch
@powersync/service-module-mongodb Patch
@powersync/service-module-mysql Patch
@powersync/service-module-postgres-storage Patch
@powersync/service-module-postgres Patch
test-client Patch
@powersync/service-schema 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 requested review from Rentacookie and Copilot June 20, 2025 08:36
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the replication clearing process to remove blocking behavior that was causing replication lag.

  • Introduces a new asynchronous clearingJobs map for tracking non-blocking data clearing tasks.
  • Modifies the main replication loop to schedule clearing jobs asynchronously.
  • Updates termination logic with additional logging and comments explaining the process.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/service-core/src/replication/AbstractReplicator.ts Refactors sync rule clearing to run asynchronously and removes blocking behavior.
.changeset/orange-comics-buy.md Documents the patch for non-blocking sync rule clearing.

Co-authored-by: Copilot <[email protected]>
@rkistner rkistner merged commit c002948 into main Jun 20, 2025
21 checks passed
@rkistner rkistner deleted the background-clearing branch June 20, 2025 09:44
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