-
Notifications
You must be signed in to change notification settings - Fork 918
GODRIVER-3668 Add bypassEmptyTsReplacement option. #2219
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
Conversation
🧪 Performance ResultsCommit SHA: ef7d27cThe following benchmark tests for version 68e67f32b878170007586c17 had statistically significant changes (i.e., |z-score| > 1.96):
For a comprehensive view of all microbenchmark results for this PR's commit, please check out the Evergreen perf task for this patch. |
API Change Report./v2/x/mongo/driver/operationcompatible changes(*FindAndModify).AdditionalCmd: added |
f42d087
to
446c2e1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds the bypassEmptyTsReplacement option to various MongoDB write operations by implementing an "addCommandFields" mechanism that allows arbitrary command fields to be added to operations.
- Adds support for bypassEmptyTsReplacement option across insert, update, replace, findOneAndUpdate, findOneAndReplace, and bulk write operations
- Implements addCommandFields functionality in internal options handling to support additional command parameters
- Adds comprehensive test coverage to verify the option is properly passed through to MongoDB commands
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
x/mongo/driver/xoptions/options.go | Adds "addCommandFields" case handling to all internal option setters |
x/mongo/driver/operation/update.go | Adds additionalCmd field and AdditionalCmd method to Update operation |
x/mongo/driver/operation/insert.go | Adds additionalCmd field and AdditionalCmd method to Insert operation |
x/mongo/driver/operation/find_and_modify.go | Adds additionalCmd field and AdditionalCmd method to FindAndModify operation |
mongo/collection.go | Integrates addCommandFields option handling into collection methods |
mongo/client_bulk_write.go | Adds additionalCmd field to clientBulkWrite struct |
mongo/client.go | Integrates addCommandFields option handling into Client.BulkWrite |
mongo/bulk_write.go | Adds additionalCmd field and integrates it into bulk write operations |
internal/integration/collection_test.go | Adds comprehensive tests for bypassEmptyTsReplacement option |
internal/integration/client_test.go | Adds tests for client bulk write with bypassEmptyTsReplacement and fixes test assertions |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
internal/integration/client_test.go
Outdated
}) | ||
} | ||
}) | ||
mt.RunOpts("bulk write with bypassEmptyTsReplacement", mtBulkWriteOpts, func(mt *mtest.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: Subtests in subtests are difficult to read. Consider splitting this subtest out into a separate test function.
internal/integration/client_test.go
Outdated
t.Helper() | ||
|
||
valType, data, err := bson.MarshalValue(val) | ||
require.Nil(t, err, "MarshalValue error: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use mt
and require.NoError
.
t.Helper() | |
valType, data, err := bson.MarshalValue(val) | |
require.Nil(t, err, "MarshalValue error: %v", err) | |
mt.Helper() | |
valType, data, err := bson.MarshalValue(val) | |
require.NoError(mt, err, "MarshalValue error") |
internal/integration/client_test.go
Outdated
{ | ||
"insert one", | ||
mongo.NewClientInsertOneModel().SetDocument(bson.D{{"x", 1}}), | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: Keyed struct literals are easier to use. Consider including the key names.
internal/integration/client_test.go
Outdated
{ | ||
"empty", | ||
options.ClientBulkWrite(), | ||
bson.RawValue{}, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: Keyed struct literals are easier to use. Consider including the key names.
internal/integration/client_test.go
Outdated
return opts | ||
} | ||
|
||
marshalValue := func(val interface{}) bson.RawValue { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: Consider factoring marshalValue
into a separate function since an identical function is also used in TestBypassEmptyTsReplacement
.
mongo/client.go
Outdated
if additionalCmd := optionsutil.Value(bwo.Internal, "addCommandFields"); additionalCmd != nil { | ||
if ac, ok := additionalCmd.(bson.D); ok { | ||
op.additionalCmd = ac | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Combine these conditions into one. This suggestion applies to all instances of this block in this PR.
if additionalCmd := optionsutil.Value(bwo.Internal, "addCommandFields"); additionalCmd != nil { | |
if ac, ok := additionalCmd.(bson.D); ok { | |
op.additionalCmd = ac | |
} | |
} | |
if ac, ok := optionsutil.Value(bwo.Internal, "addCommandFields").(bson.D); ok { | |
op.additionalCmd = ac | |
} |
mongo/collection.go
Outdated
if rawDataOpt := optionsutil.Value(args.Internal, "addCommandFields"); rawDataOpt != nil { | ||
imOpts.Opts = append(imOpts.Opts, func(opts *options.InsertManyOptions) error { | ||
opts.Internal = optionsutil.WithValue(opts.Internal, "addCommandFields", rawDataOpt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rawDataOpt
is confusingly named because we're copying the "addCommandFields" option here. Rename to something like ac
or acOpt
.
if rawDataOpt := optionsutil.Value(args.Internal, "addCommandFields"); rawDataOpt != nil { | |
imOpts.Opts = append(imOpts.Opts, func(opts *options.InsertManyOptions) error { | |
opts.Internal = optionsutil.WithValue(opts.Internal, "addCommandFields", rawDataOpt) | |
if ac := optionsutil.Value(args.Internal, "addCommandFields"); ac != nil { | |
imOpts.Opts = append(imOpts.Opts, func(opts *options.InsertManyOptions) error { | |
opts.Internal = optionsutil.WithValue(opts.Internal, "addCommandFields", ac) |
843e33f
to
ef7d27c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! 👍
GODRIVER-3668
GODRIVER-3582
Summary
Add bypassEmptyTsReplacement option to:
Background & Motivation