Skip to content

[MongoDB Storage] Compact using secondaries#570

Draft
rkistner wants to merge 1 commit intomainfrom
compact-using-secondaries
Draft

[MongoDB Storage] Compact using secondaries#570
rkistner wants to merge 1 commit intomainfrom
compact-using-secondaries

Conversation

@rkistner
Copy link
Copy Markdown
Contributor

@rkistner rkistner commented Mar 17, 2026

This changes the compact process to read from secondaries (readPreference: 'secondaryPreferred').

The main goal here is to reduce load on primary MongoDB nodes, by shifting these bulk reads to secondaries.

In general, reading stale data is not an issue for compacting. There are cases where we want to read our own writes, so we use a session with causal consistency for this. This specifically means setting the readConcern: { level: 'majority' } and writeConcern: { w: 'majority' } as well, to get all the guarantees we need.

We may be able to relax some of the guarantees later to improve throughput, for example by using a separate session for reads vs writes. That gets more complex though, so leaving that for another project.

We can also consider making the read preference configurable in the future, for example to allow allow these reads on secondaries, and rather fail if a secondary isn't available.

TODO:

  • Test on actual replicaset with replication lag.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 17, 2026

⚠️ No Changeset found

Latest commit: e15bb9b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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