Skip to content

Commit eeb9924

Browse files
committed
Move compareOneDocument() closer to where it’s called.
1 parent d40fca4 commit eeb9924

File tree

2 files changed

+33
-33
lines changed

2 files changed

+33
-33
lines changed

internal/verifier/compare.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,3 +512,36 @@ func (verifier *Verifier) getDocumentsCursor(ctx mongo.SessionContext, collectio
512512

513513
return collection.Database().RunCommandCursor(ctx, findCmd, runCommandOptions)
514514
}
515+
516+
func (verifier *Verifier) compareOneDocument(srcClientDoc, dstClientDoc bson.Raw, namespace string) ([]VerificationResult, error) {
517+
match := bytes.Equal(srcClientDoc, dstClientDoc)
518+
if match {
519+
return nil, nil
520+
}
521+
//verifier.logger.Info().Msg("Byte comparison failed for id %s, falling back to field comparison", id)
522+
523+
mismatch, err := BsonUnorderedCompareRawDocumentWithDetails(srcClientDoc, dstClientDoc)
524+
if err != nil {
525+
return nil, err
526+
}
527+
if mismatch == nil {
528+
if verifier.ignoreBSONFieldOrder {
529+
return nil, nil
530+
}
531+
dataSize := len(srcClientDoc)
532+
if dataSize < len(dstClientDoc) {
533+
dataSize = len(dstClientDoc)
534+
}
535+
536+
// If we're respecting field order we have just done a binary compare so we have fields in different order.
537+
return []VerificationResult{{
538+
ID: srcClientDoc.Lookup("_id"),
539+
Details: Mismatch + fmt.Sprintf(" : Document %s has fields in different order", srcClientDoc.Lookup("_id")),
540+
Cluster: ClusterTarget,
541+
NameSpace: namespace,
542+
dataSize: dataSize,
543+
}}, nil
544+
}
545+
results := mismatchResultsToVerificationResults(mismatch, srcClientDoc, dstClientDoc, namespace, srcClientDoc.Lookup("_id"), "" /* fieldPrefix */)
546+
return results, nil
547+
}

internal/verifier/migration_verifier.go

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -511,39 +511,6 @@ func mismatchResultsToVerificationResults(mismatch *MismatchDetails, srcClientDo
511511
return
512512
}
513513

514-
func (verifier *Verifier) compareOneDocument(srcClientDoc, dstClientDoc bson.Raw, namespace string) ([]VerificationResult, error) {
515-
match := bytes.Equal(srcClientDoc, dstClientDoc)
516-
if match {
517-
return nil, nil
518-
}
519-
//verifier.logger.Info().Msg("Byte comparison failed for id %s, falling back to field comparison", id)
520-
521-
mismatch, err := BsonUnorderedCompareRawDocumentWithDetails(srcClientDoc, dstClientDoc)
522-
if err != nil {
523-
return nil, err
524-
}
525-
if mismatch == nil {
526-
if verifier.ignoreBSONFieldOrder {
527-
return nil, nil
528-
}
529-
dataSize := len(srcClientDoc)
530-
if dataSize < len(dstClientDoc) {
531-
dataSize = len(dstClientDoc)
532-
}
533-
534-
// If we're respecting field order we have just done a binary compare so we have fields in different order.
535-
return []VerificationResult{{
536-
ID: srcClientDoc.Lookup("_id"),
537-
Details: Mismatch + fmt.Sprintf(" : Document %s has fields in different order", srcClientDoc.Lookup("_id")),
538-
Cluster: ClusterTarget,
539-
NameSpace: namespace,
540-
dataSize: dataSize,
541-
}}, nil
542-
}
543-
results := mismatchResultsToVerificationResults(mismatch, srcClientDoc, dstClientDoc, namespace, srcClientDoc.Lookup("_id"), "" /* fieldPrefix */)
544-
return results, nil
545-
}
546-
547514
func (verifier *Verifier) ProcessVerifyTask(ctx context.Context, workerNum int, task *VerificationTask) error {
548515
start := time.Now()
549516

0 commit comments

Comments
 (0)