feat(mongodb-to-mongodb]: Read/Write Performance and Reliability Improvements - #4079
feat(mongodb-to-mongodb]: Read/Write Performance and Reliability Improvements#4079michaeltle-goog wants to merge 20 commits into
Conversation
…atches shuffle barrier
…-throughput reads without splitVector
…ate stages with UriSanitizer
…ArgumentException
…iven read splits when numReadPrefixSplits > 1
…ed useBucketAuto and numSplits options
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the scalability and reliability of the MongoDB-to-MongoDB Dataflow template. By replacing brittle legacy splitting mechanisms with a robust, type-aware approach and introducing asynchronous, rate-limited write paths, the template is now better equipped to handle high-volume data migrations while maintaining stability and performance. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces parallel index-slice reading and linear write rate limiting to the MongoDB-to-MongoDB Dataflow template. Parallel reading is supported via a new ReadSplitGenerator utility that partitions collections based on key types, while write rate limiting is implemented in MongoDbTransforms using a linear ramp-up strategy. Additionally, a UriSanitizer utility is added to mask sensitive credentials in logs. Feedback was provided on ReadSplitGenerator to use a try-with-resources block when iterating over aggregate results to prevent potential MongoDB cursor leaks.
| List<BsonValue> sampledKeys = new ArrayList<>(); | ||
| for (BsonDocument doc : col.aggregate(pipeline)) { | ||
| if (doc.containsKey("_id")) { | ||
| sampledKeys.add(doc.get("_id")); | ||
| } | ||
| } |
There was a problem hiding this comment.
Iterating over col.aggregate(pipeline) directly with a for-each loop can leak the underlying MongoDB cursor if an exception is thrown during iteration. Using a try-with-resources block with MongoCursor ensures that the cursor is always closed properly.
List<BsonValue> sampledKeys = new ArrayList<>();
try (com.mongodb.client.MongoCursor<BsonDocument> cursor = col.aggregate(pipeline).iterator()) {
while (cursor.hasNext()) {
BsonDocument doc = cursor.next();
if (doc.containsKey("_id")) {
sampledKeys.add(doc.get("_id"));
}
}
}
Codecov Report❌ Patch coverage is ❌ Your patch check has failed because the patch coverage (57.62%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #4079 +/- ##
==========================================
Coverage 56.18% 56.19%
+ Complexity 7342 6932 -410
==========================================
Files 1126 1128 +2
Lines 68766 69197 +431
Branches 7785 7871 +86
==========================================
+ Hits 38637 38885 +248
- Misses 27635 27767 +132
- Partials 2494 2545 +51
🚀 New features to boost your workflow:
|
…eter order numbers
Overview
This PR refactors the mongodb-to-mongodb Dataflow template to improve read-phase scalability, write concurrency, and target cluster protection. It replaces legacy splitting operations with a dynamic, type-aware bounds generator and decouples read/write execution in high-throughput pipelines.
Performance: Migrated 2.5M documents in ~12 minutes.
Key Changes
1. Type-Aware Data-Driven Read Splitting (ReadSplitGenerator)
Replaced splitVector and autoBucket with a deterministic, data-driven splitting algorithm that safely handles single-type and mixed-type _id collections:
(Sample size scales dynamically as max(1000, numSplits * 64)).
2. Non-Blocking Asynchronous Writes (MongoDbTransforms)
3. Write-Path Rate Limiting
4. Logging