Skip to content

Fix deleteMany for bucket_parameters to use an index #244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/gentle-coins-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@powersync/service-module-mongodb-storage': patch
'@powersync/service-core': patch
'@powersync/service-image': patch
---

Fix slow clearing of bucket_parameters collection.
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ export class MongoSyncBucketStorage
);
await this.db.bucket_parameters.deleteMany(
{
key: idPrefixFilter<SourceKey>({ g: this.group_id }, ['t', 'k'])
'key.g': this.group_id
Copy link
Contributor

@Rentacookie Rentacookie Apr 22, 2025

Choose a reason for hiding this comment

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

Would a simpler filter + index like this not perhaps help with the clearing of the bucket_data collection?
I had a look and even though the index there is being used it still looked to be rather slow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding another index on bucket_data can significantly affect the performance for all writes there, and even make deletes slower because of that. The current filter is slightly complex, but it does efficiently use the _id index. I suspect the performance bottleneck is to a large extend just an overall write throughput bottleneck (although I haven't tested that properly).

},
{ maxTimeMS: lib_mongo.db.MONGO_CLEAR_OPERATION_TIMEOUT_MS }
);
Expand Down