Repository navigation
Feat/mongodb data validator [DRAFT] - #4587
suryansh29 wants to merge 4 commits into
Conversation
…n template Adds the Mongodb_To_Firestore_Data_Validator batch Flex Template, which compares a source MongoDB database against a target Firestore with MongoDB compatibility database and reports the differences. - Diffs collections and index definitions before reading documents. - Splits each collection into _id ranges and compares source and target with ordered cursors, resuming a cursor from the last _id on transient errors or cursor expiry. - Re-reads candidate mismatches from the source primary and the target after a delay, so replication lag is not reported as a mismatch. - Writes a run summary, per-collection stats and mismatch rows to GCS, and optionally to BigQuery.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
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 introduces a new Dataflow Flex Template designed to validate data parity between a source MongoDB cluster and a target Cloud Firestore database. The solution leverages a high-performance, zero-shuffle merge-join architecture to compare document counts and BSON field values at scale. It includes robust features for handling replication lag via delayed rechecks, automatic cursor recovery, and comprehensive reporting to both Cloud Storage and BigQuery. 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 the mongodb-data-validator module, a Google Cloud Dataflow Flex Template designed to validate collection catalogs, secondary indexes, document counts, and deep BSON field-by-field parity between a source MongoDB cluster and a target Cloud Firestore database. Key components include zero-shuffle co-partitioned merge-joins, automatic cursor resumption, live-CDC lag tolerance via delayed rechecks, and strict BSON fidelity comparators. The code review feedback highlights three main improvement opportunities: reversing the configuration order in MongoClientManager to preserve user-specified UUID representations, using BigDecimal.valueOf(d) instead of new BigDecimal(d) in BsonOrderComparator to prevent floating-point precision issues, and removing a redundant JSON parsing step in BsonEncodingUtils to optimize performance.
| MongoClientSettings.Builder builder = | ||
| MongoClientSettings.builder() | ||
| .applyConnectionString(connString) | ||
| .uuidRepresentation(UuidRepresentation.STANDARD) |
There was a problem hiding this comment.
The current builder configuration applies the connection string first and then unconditionally sets the UUID representation to UuidRepresentation.STANDARD. This order of operations will overwrite any custom uuidRepresentation specified by the user in their connection URI (e.g., uuidRepresentation=javaLegacy or uuidRepresentation=cSharpLegacy), which is a common requirement for legacy MongoDB databases. Reversing the order allows the connection string configuration to correctly override the default standard representation.
| MongoClientSettings.Builder builder = | |
| MongoClientSettings.builder() | |
| .applyConnectionString(connString) | |
| .uuidRepresentation(UuidRepresentation.STANDARD) | |
| MongoClientSettings.Builder builder = | |
| MongoClientSettings.builder() | |
| .uuidRepresentation(UuidRepresentation.STANDARD) | |
| .applyConnectionString(connString) |
| case DOUBLE: | ||
| double d = v.asDouble().getValue(); | ||
| return d == 0.0d ? BigDecimal.ZERO : new BigDecimal(d); |
There was a problem hiding this comment.
Using new BigDecimal(d) for DOUBLE values introduces floating-point precision issues (for example, new BigDecimal(0.1) is not exactly 0.1). This can cause inconsistent comparisons and incorrect sorting order when comparing Double and Decimal128 values, leading to false mismatches or incorrect cursor advancement in the sorted merge-join. Using BigDecimal.valueOf(d) ensures the exact decimal representation is used, matching how BsonDocumentComparator handles double values.
| case DOUBLE: | |
| double d = v.asDouble().getValue(); | |
| return d == 0.0d ? BigDecimal.ZERO : new BigDecimal(d); | |
| case DOUBLE: | |
| double d = v.asDouble().getValue(); | |
| return d == 0.0d ? BigDecimal.ZERO : BigDecimal.valueOf(d); |
| /** Renders a {@link BsonValue} as canonical Extended JSON (e.g. {@code {"$oid": "..."}}). */ | ||
| public static String toExtendedJson(BsonValue idValue) { | ||
| if (idValue == null) { | ||
| return "null"; | ||
| } | ||
| BsonDocument wrapper = new BsonDocument("_id", idValue); | ||
| String fullJson = wrapper.toJson(EXTENDED_JSON); | ||
| BsonDocument parsed = BsonDocument.parse(fullJson); | ||
| // Extract just the canonical value representation when possible | ||
| int colonIdx = fullJson.indexOf(':'); | ||
| int endBrace = fullJson.lastIndexOf('}'); | ||
| if (colonIdx > 0 && endBrace > colonIdx && parsed.containsKey("_id")) { | ||
| return fullJson.substring(colonIdx + 1, endBrace).trim(); | ||
| } | ||
| return fullJson; |
There was a problem hiding this comment.
Parsing the generated JSON string back into a BsonDocument via BsonDocument.parse(fullJson) is highly redundant and inefficient. Since wrapper is explicitly created with _id as its only key, parsed.containsKey("_id") is guaranteed to be true. Removing this parsing step avoids significant CPU and memory overhead on a hot path.
public static String toExtendedJson(BsonValue idValue) {
if (idValue == null) {
return "null";
}
BsonDocument wrapper = new BsonDocument("_id", idValue);
String fullJson = wrapper.toJson(EXTENDED_JSON);
// Extract just the canonical value representation when possible
int colonIdx = fullJson.indexOf(':');
int endBrace = fullJson.lastIndexOf('}');
if (colonIdx > 0 && endBrace > colonIdx) {
return fullJson.substring(colonIdx + 1, endBrace).trim();
}
return fullJson;
}…l Pass-2 skip and $sample-first partitioning - Adopt $sample-first empirical quantile partitioning (omitting $type on single-type collections to avoid Ignite $type probe timeouts) - Add bounded concurrency slots via ValidationSlotTask (--maxConcurrentReads, default 128) - Default --comparisonStrategy to BATCH_LOOKUP (batched _id $in lookups, batchSize=1000) with ConditionalReverseOrphanFn skipping Pass 2 when targetCount == foundInTarget - Remove live-CDC RecheckMismatchesFn and resolved_on_recheck_count fields - Add unit tests covering $sample-first splitting and conditional Pass-2 skip/execution (16/16 passing, 0 Checkstyle violations)
No description provided.