diff --git a/.github/workflows/all.yml b/.github/workflows/all.yml index ced7c10d..d5bd8701 100644 --- a/.github/workflows/all.yml +++ b/.github/workflows/all.yml @@ -7,20 +7,26 @@ on: pull_request: workflow_dispatch: +env: + replsetSrcConnStr: mongodb://localhost:27020,localhost:27021,localhost:27022 + replsetDstConnStr: mongodb://localhost:27030,localhost:27031,localhost:27032 + shardedSrcConnStr: mongodb://localhost:27020 + shardedDstConnStr: mongodb://localhost:27030 + jobs: basics: strategy: fail-fast: false matrix: include: + # NB: This is the only setup we’re supporting with 4.0. + - mongodb_versions: [ '4.0', '8.0' ] + topology: replset # Testing fallback when `hello` isn’t implemented # (but appendOplogNote is). - mongodb_versions: [ '4.2.5', '6.0' ] - topology: - name: replset - srcConnStr: mongodb://localhost:27020,localhost:27021,localhost:27022 - dstConnStr: mongodb://localhost:27030,localhost:27031,localhost:27032 + topology: replset exclude: - mongodb_versions: [ '4.2', '4.2' ] @@ -31,6 +37,8 @@ jobs: toHashedIndexKey: true - mongodb_versions: [ '4.2', '6.0' ] toHashedIndexKey: true + - mongodb_versions: [ '4.2', '8.0' ] + toHashedIndexKey: true # versions are: source, destination mongodb_versions: @@ -38,6 +46,7 @@ jobs: - [ '4.2', '4.4' ] - [ '4.2', '5.0' ] - [ '4.2', '6.0' ] + - [ '4.2', '8.0' ] - [ '4.4', '4.4' ] - [ '4.4', '5.0' ] @@ -61,26 +70,15 @@ jobs: toHashedIndexKey: [true, false] topology: - - name: replset - srcConnStr: mongodb://localhost:27020,localhost:27021,localhost:27022 - dstConnStr: mongodb://localhost:27030,localhost:27031,localhost:27032 - - - name: replset-to-sharded - dstArgs: --sharded 2 - srcConnStr: mongodb://localhost:27020,localhost:27021,localhost:27022 - dstConnStr: mongodb://localhost:27030 - - - name: sharded - srcArgs: --sharded 2 - dstArgs: --sharded 2 - srcConnStr: mongodb://localhost:27020 - dstConnStr: mongodb://localhost:27030 + - replset + - replset-to-sharded + - sharded # Ubuntu 24 lacks OpenSSL 1.1.1’s libcrypto, which pre-v6 MongoDB # versions need. runs-on: ubuntu-22.04 - name: ${{ matrix.mongodb_versions[0] }} to ${{ matrix.mongodb_versions[1] }}, ${{ matrix.topology.name }}${{ matrix.toHashedIndexKey && ', hashed doc compare' || '' }} + name: ${{ matrix.mongodb_versions[0] }} to ${{ matrix.mongodb_versions[1] }}, ${{ matrix.topology }}${{ matrix.toHashedIndexKey && ', hashed doc compare' || '' }} steps: - run: uname -a @@ -95,11 +93,12 @@ jobs: with: go-version: stable + # Use an old pymongo so we can install MongoDB 4.0. - name: Install m and mtools run: |- { echo npm install -g m - echo pipx install 'mtools[all]' + echo pip install pymongo==4.10.1 'mtools[all]' } | parallel - name: Install MongoDB ${{ matrix.mongodb_versions[0] }} (source) @@ -115,8 +114,8 @@ jobs: run: |- { echo ./build.sh - echo mlaunch init --binarypath $(cat .srcpath) --port 27020 --dir src --replicaset ${{ matrix.topology.srcArgs }} - echo mlaunch init --binarypath $(cat .dstpath) --port 27030 --dir dst --replicaset ${{ matrix.topology.dstArgs }} + echo mlaunch init --binarypath $(cat .srcpath) --port 27020 --dir src --replicaset ${{ (matrix.topology == 'sharded') && '--sharded 2' || '' }} + echo mlaunch init --binarypath $(cat .dstpath) --port 27030 --dir dst --replicaset ${{ (matrix.topology == 'sharded' || matrix.topology == 'replset-to-sharded') && '--sharded 2' || '' }} echo mlaunch init --binarypath $(cat .metapath) --port 27040 --dir meta --replicaset --nodes 1 } | parallel @@ -124,6 +123,8 @@ jobs: run: go test -v ./... -race env: MVTEST_DOC_COMPARE_METHOD: ${{matrix.toHashedIndexKey && 'toHashedIndexKey' || ''}} - MVTEST_SRC: ${{matrix.topology.srcConnStr}} - MVTEST_DST: ${{matrix.topology.dstConnStr}} + + MVTEST_SRC: ${{ (matrix.topology == 'sharded') && env.shardedSrcConnStr || env.replsetSrcConnStr }} + MVTEST_DST: ${{ (matrix.topology == 'sharded' || matrix.topology == 'replset-to-sharded') && env.shardedDstConnStr || env.replsetDstConnStr }} + MVTEST_META: mongodb://localhost:27040 diff --git a/go.mod b/go.mod index 7c452914..850f163d 100644 --- a/go.mod +++ b/go.mod @@ -8,8 +8,10 @@ require ( github.com/dustin/go-humanize v1.0.1 github.com/gin-contrib/pprof v1.5.3 github.com/gin-gonic/gin v1.10.0 + github.com/goaux/timer v1.1.0 github.com/google/uuid v1.3.0 github.com/huandu/go-clone/generic v1.7.2 + github.com/libp2p/go-buffer-pool v0.1.0 github.com/olekukonko/tablewriter v0.0.5 github.com/pkg/errors v0.9.1 github.com/quasilyte/go-ruleguard/dsl v0.3.22 @@ -18,7 +20,9 @@ require ( github.com/samber/mo v1.13.0 github.com/stretchr/testify v1.10.0 github.com/urfave/cli v1.22.9 - go.mongodb.org/mongo-driver/v2 v2.4.0 + + // NB: This is the last driver version that supported 4.0. + go.mongodb.org/mongo-driver/v2 v2.3.1 golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 golang.org/x/sync v0.13.0 gopkg.in/natefinch/lumberjack.v2 v2.0.0 @@ -36,7 +40,6 @@ require ( github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.26.0 // indirect - github.com/goaux/timer v1.1.0 // indirect github.com/goccy/go-json v0.10.5 // indirect github.com/golang/snappy v1.0.0 // indirect github.com/huandu/go-clone v1.6.0 // indirect @@ -44,7 +47,6 @@ require ( github.com/klauspost/compress v1.16.7 // indirect github.com/klauspost/cpuid/v2 v2.2.10 // indirect github.com/leodido/go-urn v1.4.0 // indirect - github.com/libp2p/go-buffer-pool v0.1.0 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.9 // indirect diff --git a/go.sum b/go.sum index 698a8a02..e4cfaa08 100644 --- a/go.sum +++ b/go.sum @@ -129,8 +129,8 @@ github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gi github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 h1:ilQV1hzziu+LLM3zUTJ0trRztfwgjqKnBWNtSRkbmwM= github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfSfmXjznFBSZNN13rSJjlIOI1fUNAtF7rmI= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -go.mongodb.org/mongo-driver/v2 v2.4.0 h1:Oq6BmUAAFTzMeh6AonuDlgZMuAuEiUxoAD1koK5MuFo= -go.mongodb.org/mongo-driver/v2 v2.4.0/go.mod h1:jHeEDJHJq7tm6ZF45Issun9dbogjfnPySb1vXA7EeAI= +go.mongodb.org/mongo-driver/v2 v2.3.1 h1:WrCgSzO7dh1/FrePud9dK5fKNZOE97q5EQimGkos7Wo= +go.mongodb.org/mongo-driver/v2 v2.3.1/go.mod h1:jHeEDJHJq7tm6ZF45Issun9dbogjfnPySb1vXA7EeAI= golang.org/x/arch v0.16.0 h1:foMtLTdyOmIniqWCHjY6+JxuC54XP1fDwx4N0ASyW+U= golang.org/x/arch v0.16.0/go.mod h1:JmwW7aLIoRUKgaTzhkiEFxvcEiQGyOg9BMonBJUS7EE= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= diff --git a/internal/testutil/testutil.go b/internal/testutil/testutil.go index 6b57dbd3..e0a680df 100644 --- a/internal/testutil/testutil.go +++ b/internal/testutil/testutil.go @@ -7,6 +7,7 @@ import ( "log" "testing" + "github.com/10gen/migration-verifier/internal/util" "github.com/pkg/errors" "github.com/samber/lo" "go.mongodb.org/mongo-driver/v2/bson" @@ -93,8 +94,18 @@ func KillApplicationChangeStreams( ctx context.Context, t *testing.T, client *mongo.Client, + versionArray []int, appName string, ) error { + currentOpArg := bson.D{} + + if util.ClusterHasCurrentOpIdleCursors([2]int(versionArray)) { + currentOpArg = append( + currentOpArg, + bson.E{"idleCursors", true}, + ) + } + // Kill verifier’s change stream. cursor, err := client.Database( "admin", @@ -103,9 +114,7 @@ func KillApplicationChangeStreams( ctx, mongo.Pipeline{ { - {"$currentOp", bson.D{ - {"idleCursors", true}, - }}, + {"$currentOp", currentOpArg}, }, { {"$match", bson.D{ diff --git a/internal/util/clusterinfo.go b/internal/util/clusterinfo.go index b2354e96..f08608ac 100644 --- a/internal/util/clusterinfo.go +++ b/internal/util/clusterinfo.go @@ -31,6 +31,18 @@ func ClusterHasBSONSize(va [2]int) bool { return major > 4 } +func ClusterHasCurrentOpIdleCursors(va [2]int) bool { + major := va[0] + + if major == 4 { + return va[1] >= 2 + } + + return major > 4 +} + +var ClusterHasChangeStreamStartAfter = ClusterHasCurrentOpIdleCursors + const ( TopologySharded ClusterTopology = "sharded" TopologyReplset ClusterTopology = "replset" diff --git a/internal/verifier/change_stream.go b/internal/verifier/change_stream.go index 4a91a3c3..76529256 100644 --- a/internal/verifier/change_stream.go +++ b/internal/verifier/change_stream.go @@ -374,7 +374,11 @@ func (csr *ChangeStreamReader) createChangeStream( logEvent.Msg("Starting change stream from persisted resume token.") - opts = opts.SetStartAfter(token) + if util.ClusterHasChangeStreamStartAfter([2]int(csr.clusterInfo.VersionArray)) { + opts = opts.SetStartAfter(token) + } else { + opts = opts.SetResumeAfter(token) + } } else { csStartLogEvent.Msgf("Starting change stream from current %s cluster time.", csr.readerType) } @@ -386,7 +390,7 @@ func (csr *ChangeStreamReader) createChangeStream( sctx := mongo.NewSessionContext(ctx, sess) changeStream, err := csr.watcherClient.Watch(sctx, pipeline, opts) if err != nil { - return nil, nil, bson.Timestamp{}, errors.Wrap(err, "failed to open change stream") + return nil, nil, bson.Timestamp{}, errors.Wrap(err, "opening change stream") } err = csr.persistResumeToken(ctx, changeStream.ResumeToken()) diff --git a/internal/verifier/change_stream_test.go b/internal/verifier/change_stream_test.go index 5f746f14..5f8e8395 100644 --- a/internal/verifier/change_stream_test.go +++ b/internal/verifier/change_stream_test.go @@ -803,6 +803,7 @@ func (suite *IntegrationTestSuite) TestWritesOffCursorKilledResilience() { suite.Context(), suite.T(), suite.srcMongoClient, + verifier.srcClusterInfo.VersionArray, clientAppName, ), ) @@ -831,6 +832,7 @@ func (suite *IntegrationTestSuite) TestCursorKilledResilience() { suite.Context(), suite.T(), suite.srcMongoClient, + verifier.srcClusterInfo.VersionArray, clientAppName, ), ) diff --git a/internal/verifier/dockey_agg_test.go b/internal/verifier/dockey_agg_test.go index 94417b08..9141920e 100644 --- a/internal/verifier/dockey_agg_test.go +++ b/internal/verifier/dockey_agg_test.go @@ -66,7 +66,7 @@ func (suite *IntegrationTestSuite) testExtractTrueDocKeyAgg(reverseYN bool) { cursor, err := coll.Aggregate( ctx, mongo.Pipeline{ - {{"$replaceWith", computedDocKeyAgg}}, + {{"$replaceRoot", bson.D{{"newRoot", computedDocKeyAgg}}}}, }, ) require.NoError(err, "should open cursor to agg") diff --git a/internal/verifier/uri.go b/internal/verifier/uri.go index c5ed2cb8..f1c9ebe0 100644 --- a/internal/verifier/uri.go +++ b/internal/verifier/uri.go @@ -79,14 +79,7 @@ func (verifier *Verifier) maybeSuggestHashedComparisonOptimization() { } func isVersionSupported(version []int) bool { - if version[0] >= 5 { - return true - } - if version[0] < 4 { - return false - } - - return version[1] >= 2 + return version[0] >= 4 } func (verifier *Verifier) SetDstURI(ctx context.Context, uri string) error { diff --git a/vendor/go.mongodb.org/mongo-driver/v2/internal/decimal128/decimal128.go b/vendor/go.mongodb.org/mongo-driver/v2/internal/decimal128/decinal128.go similarity index 100% rename from vendor/go.mongodb.org/mongo-driver/v2/internal/decimal128/decimal128.go rename to vendor/go.mongodb.org/mongo-driver/v2/internal/decimal128/decinal128.go diff --git a/vendor/go.mongodb.org/mongo-driver/v2/internal/driverutil/description.go b/vendor/go.mongodb.org/mongo-driver/v2/internal/driverutil/description.go index 926de0bd..89963799 100644 --- a/vendor/go.mongodb.org/mongo-driver/v2/internal/driverutil/description.go +++ b/vendor/go.mongodb.org/mongo-driver/v2/internal/driverutil/description.go @@ -21,7 +21,7 @@ import ( ) const ( - MinWireVersion = 8 + MinWireVersion = 7 MaxWireVersion = 25 ) diff --git a/vendor/go.mongodb.org/mongo-driver/v2/mongo/bulk_write.go b/vendor/go.mongodb.org/mongo-driver/v2/mongo/bulk_write.go index ca683c1d..036e3bad 100644 --- a/vendor/go.mongodb.org/mongo-driver/v2/mongo/bulk_write.go +++ b/vendor/go.mongodb.org/mongo-driver/v2/mongo/bulk_write.go @@ -40,7 +40,6 @@ type bulkWrite struct { result BulkWriteResult let any rawData *bool - additionalCmd bson.D } func (bw *bulkWrite) execute(ctx context.Context) error { @@ -214,9 +213,6 @@ func (bw *bulkWrite) runInsert(ctx context.Context, batch bulkWriteBatch) (opera if bw.rawData != nil { op.RawData(*bw.rawData) } - if len(bw.additionalCmd) > 0 { - op.AdditionalCmd(bw.additionalCmd) - } err := op.Execute(ctx) @@ -431,9 +427,6 @@ func (bw *bulkWrite) runUpdate(ctx context.Context, batch bulkWriteBatch) (opera if bw.rawData != nil { op.RawData(*bw.rawData) } - if len(bw.additionalCmd) > 0 { - op.AdditionalCmd(bw.additionalCmd) - } err := op.Execute(ctx) diff --git a/vendor/go.mongodb.org/mongo-driver/v2/mongo/client.go b/vendor/go.mongodb.org/mongo-driver/v2/mongo/client.go index 10182276..cb2e5494 100644 --- a/vendor/go.mongodb.org/mongo-driver/v2/mongo/client.go +++ b/vendor/go.mongodb.org/mongo-driver/v2/mongo/client.go @@ -11,8 +11,6 @@ import ( "errors" "fmt" "net/http" - "sync" - "sync/atomic" "time" "go.mongodb.org/mongo-driver/v2/bson" @@ -58,26 +56,24 @@ var ( // The Client type opens and closes connections automatically and maintains a pool of idle connections. For // connection pool configuration options, see documentation for the ClientOptions type in the mongo/options package. type Client struct { - id uuid.UUID - deployment driver.Deployment - localThreshold time.Duration - retryWrites bool - retryReads bool - clock *session.ClusterClock - readPreference *readpref.ReadPref - readConcern *readconcern.ReadConcern - writeConcern *writeconcern.WriteConcern - bsonOpts *options.BSONOptions - registry *bson.Registry - monitor *event.CommandMonitor - serverAPI *driver.ServerAPIOptions - serverMonitor *event.ServerMonitor - sessionPool *session.Pool - timeout *time.Duration - httpClient *http.Client - logger *logger.Logger - currentDriverInfo *atomic.Pointer[options.DriverInfo] - seenDriverInfo sync.Map + id uuid.UUID + deployment driver.Deployment + localThreshold time.Duration + retryWrites bool + retryReads bool + clock *session.ClusterClock + readPreference *readpref.ReadPref + readConcern *readconcern.ReadConcern + writeConcern *writeconcern.WriteConcern + bsonOpts *options.BSONOptions + registry *bson.Registry + monitor *event.CommandMonitor + serverAPI *driver.ServerAPIOptions + serverMonitor *event.ServerMonitor + sessionPool *session.Pool + timeout *time.Duration + httpClient *http.Client + logger *logger.Logger // in-use encryption fields isAutoEncryptionSet bool @@ -91,19 +87,27 @@ type Client struct { authenticator driver.Authenticator } -// Connect creates a new Client with the given configuration options. +// Connect creates a new Client and then initializes it using the Connect method. // -// Connect returns an error if the configuration options are invalid, but does -// not validate that the MongoDB deployment is reachable. To verify that the -// deployment is reachable, call [Client.Ping]. -// -// When creating an [options.ClientOptions], the order the methods are called -// matters. Later option setter calls overwrite the values from previous option -// setter calls, including the ApplyURI method. This allows callers to -// determine the order of precedence for setting options. For instance, if -// ApplyURI is called before SetAuth, the Credential from SetAuth will -// overwrite the values from the connection string. If ApplyURI is called +// When creating an options.ClientOptions, the order the methods are called matters. Later Set* +// methods will overwrite the values from previous Set* method invocations. This includes the +// ApplyURI method. This allows callers to determine the order of precedence for option +// application. For instance, if ApplyURI is called before SetAuth, the Credential from +// SetAuth will overwrite the values from the connection string. If ApplyURI is called // after SetAuth, then its values will overwrite those from SetAuth. +// +// The opts parameter is processed using options.MergeClientOptions, which will overwrite entire +// option fields of previous options, there is no partial overwriting. For example, if Username is +// set in the Auth field for the first option, and Password is set for the second but with no +// Username, after the merge the Username field will be empty. +// +// The NewClient function does not do any I/O and returns an error if the given options are invalid. +// The Client.Connect method starts background goroutines to monitor the state of the deployment and does not do +// any I/O in the main goroutine to prevent the main goroutine from blocking. Therefore, it will not error if the +// deployment is down. +// +// The Client.Ping method can be used to verify that the deployment is successfully connected and the +// Client was correctly configured. func Connect(opts ...*options.ClientOptions) (*Client, error) { c, err := newClient(opts...) if err != nil { @@ -136,11 +140,7 @@ func newClient(opts ...*options.ClientOptions) (*Client, error) { if err != nil { return nil, err } - - client := &Client{ - id: id, - currentDriverInfo: &atomic.Pointer[options.DriverInfo]{}, - } + client := &Client{id: id} // ClusterClock client.clock = new(session.ClusterClock) @@ -225,16 +225,7 @@ func newClient(opts ...*options.ClientOptions) (*Client, error) { } } - if clientOpts.DriverInfo != nil { - client.AppendDriverInfo(*clientOpts.DriverInfo) - } - - cfg, err := topology.NewAuthenticatorConfig(client.authenticator, - topology.WithAuthConfigClock(client.clock), - topology.WithAuthConfigClientOptions(clientOpts), - topology.WithAuthConfigDriverInfo(client.currentDriverInfo), - ) - + cfg, err := topology.NewConfigFromOptionsWithAuthenticator(clientOpts, client.clock, client.authenticator) if err != nil { return nil, err } @@ -311,45 +302,6 @@ func (c *Client) connect() error { return nil } -// AppendDriverInfo appends the provided [options.DriverInfo] to the metadata -// (e.g. name, version, platform) that will be sent to the server in handshake -// requests when establishing new connections. -// -// Repeated calls to AppendDriverInfo with equivalent DriverInfo is a no-op. -// -// Metadata is limited to 512 bytes; any excess will be truncated. -func (c *Client) AppendDriverInfo(info options.DriverInfo) { - if _, loaded := c.seenDriverInfo.LoadOrStore(info, struct{}{}); loaded { - return - } - - if old := c.currentDriverInfo.Load(); old != nil { - if old.Name != "" && info.Name != "" && old.Name != info.Name { - info.Name = old.Name + "|" + info.Name - } else if old.Name != "" { - info.Name = old.Name - } - - if old.Version != "" && info.Version != "" && old.Version != info.Version { - info.Version = old.Version + "|" + info.Version - } else if old.Version != "" { - info.Version = old.Version - } - - if old.Platform != "" && info.Platform != "" && old.Platform != info.Platform { - info.Platform = old.Platform + "|" + info.Platform - } else if old.Platform != "" { - info.Platform = old.Platform - } - } - - // Copy-on-write so that the info stored in the client is immutable. - infoCopy := new(options.DriverInfo) - *infoCopy = info - - c.currentDriverInfo.Store(infoCopy) -} - // Disconnect closes sockets to the topology referenced by this Client. It will // shut down any monitoring goroutines, close the idle connection pool, and will // wait until all the in use connections have been returned to the connection @@ -1006,11 +958,10 @@ func (c *Client) BulkWrite(ctx context.Context, writes []ClientBulkWrite, selector: selector, writeConcern: wc, } - if rawData, ok := optionsutil.Value(bwo.Internal, "rawData").(bool); ok { - op.rawData = &rawData - } - if additionalCmd, ok := optionsutil.Value(bwo.Internal, "addCommandFields").(bson.D); ok { - op.additionalCmd = additionalCmd + if rawDataOpt := optionsutil.Value(bwo.Internal, "rawData"); rawDataOpt != nil { + if rawData, ok := rawDataOpt.(bool); ok { + op.rawData = &rawData + } } if bwo.VerboseResults == nil || !(*bwo.VerboseResults) { op.errorsOnly = true diff --git a/vendor/go.mongodb.org/mongo-driver/v2/mongo/client_bulk_write.go b/vendor/go.mongodb.org/mongo-driver/v2/mongo/client_bulk_write.go index cb9d8cb4..27c3ad3c 100644 --- a/vendor/go.mongodb.org/mongo-driver/v2/mongo/client_bulk_write.go +++ b/vendor/go.mongodb.org/mongo-driver/v2/mongo/client_bulk_write.go @@ -45,7 +45,6 @@ type clientBulkWrite struct { selector description.ServerSelector writeConcern *writeconcern.WriteConcern rawData *bool - additionalCmd bson.D result ClientBulkWriteResult } @@ -149,13 +148,6 @@ func (bw *clientBulkWrite) newCommand() func([]byte, description.SelectedServer) if bw.rawData != nil && desc.WireVersion != nil && driverutil.VersionRangeIncludes(*desc.WireVersion, 27) { dst = bsoncore.AppendBooleanElement(dst, "rawData", *bw.rawData) } - if len(bw.additionalCmd) > 0 { - doc, err := bson.Marshal(bw.additionalCmd) - if err != nil { - return nil, err - } - dst = append(dst, doc[4:len(doc)-1]...) - } return dst, nil } } diff --git a/vendor/go.mongodb.org/mongo-driver/v2/mongo/collection.go b/vendor/go.mongodb.org/mongo-driver/v2/mongo/collection.go index af1960d9..ef4188d6 100644 --- a/vendor/go.mongodb.org/mongo-driver/v2/mongo/collection.go +++ b/vendor/go.mongodb.org/mongo-driver/v2/mongo/collection.go @@ -246,11 +246,10 @@ func (coll *Collection) BulkWrite(ctx context.Context, models []WriteModel, writeConcern: wc, let: args.Let, } - if rawData, ok := optionsutil.Value(args.Internal, "rawData").(bool); ok { - op.rawData = &rawData - } - if additionalCmd, ok := optionsutil.Value(args.Internal, "addCommandFields").(bson.D); ok { - op.additionalCmd = additionalCmd + if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil { + if rawData, ok := rawDataOpt.(bool); ok { + op.rawData = &rawData + } } err = op.execute(ctx) @@ -331,11 +330,10 @@ func (coll *Collection) insert( if args.Ordered != nil { op = op.Ordered(*args.Ordered) } - if rawData, ok := optionsutil.Value(args.Internal, "rawData").(bool); ok { - op = op.RawData(rawData) - } - if additionalCmd, ok := optionsutil.Value(args.Internal, "addCommandFields").(bson.D); ok { - op = op.AdditionalCmd(additionalCmd) + if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil { + if rawData, ok := rawDataOpt.(bool); ok { + op = op.RawData(rawData) + } } retry := driver.RetryNone if coll.client.retryWrites { @@ -390,14 +388,7 @@ func (coll *Collection) InsertOne(ctx context.Context, document any, } if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil { imOpts.Opts = append(imOpts.Opts, func(opts *options.InsertManyOptions) error { - opts.Internal = optionsutil.WithValue(opts.Internal, "rawData", rawDataOpt) - - return nil - }) - } - if additionalCmd := optionsutil.Value(args.Internal, "addCommandFields"); additionalCmd != nil { - imOpts.Opts = append(imOpts.Opts, func(opts *options.InsertManyOptions) error { - opts.Internal = optionsutil.WithValue(opts.Internal, "addCommandFields", additionalCmd) + optionsutil.WithValue(opts.Internal, "rawData", rawDataOpt) return nil }) @@ -561,8 +552,10 @@ func (coll *Collection) delete( } op = op.Let(let) } - if rawData, ok := optionsutil.Value(args.Internal, "rawData").(bool); ok { - op = op.RawData(rawData) + if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil { + if rawData, ok := rawDataOpt.(bool); ok { + op = op.RawData(rawData) + } } // deleteMany cannot be retried @@ -712,11 +705,10 @@ func (coll *Collection) updateOrReplace( } op = op.Comment(comment) } - if rawData, ok := optionsutil.Value(args.Internal, "rawData").(bool); ok { - op = op.RawData(rawData) - } - if additionalCmd, ok := optionsutil.Value(args.Internal, "addCommandFields").(bson.D); ok { - op = op.AdditionalCmd(additionalCmd) + if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil { + if rawData, ok := rawDataOpt.(bool); ok { + op = op.RawData(rawData) + } } retry := driver.RetryNone // retryable writes are only enabled updateOne/replaceOne operations @@ -1075,8 +1067,10 @@ func aggregate(a aggregateParams, opts ...options.Lister[options.AggregateOption } op.CustomOptions(customOptions) } - if rawData, ok := optionsutil.Value(args.Internal, "rawData").(bool); ok { - op = op.RawData(rawData) + if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil { + if rawData, ok := rawDataOpt.(bool); ok { + op = op.RawData(rawData) + } } retry := driver.RetryNone @@ -1172,8 +1166,10 @@ func (coll *Collection) CountDocuments(ctx context.Context, filter any, } op.Hint(hintVal) } - if rawData, ok := optionsutil.Value(args.Internal, "rawData").(bool); ok { - op = op.RawData(rawData) + if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil { + if rawData, ok := rawDataOpt.(bool); ok { + op = op.RawData(rawData) + } } retry := driver.RetryNone if coll.client.retryReads { @@ -1256,8 +1252,10 @@ func (coll *Collection) EstimatedDocumentCount( } op = op.Comment(comment) } - if rawData, ok := optionsutil.Value(args.Internal, "rawData").(bool); ok { - op = op.RawData(rawData) + if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil { + if rawData, ok := rawDataOpt.(bool); ok { + op = op.RawData(rawData) + } } retry := driver.RetryNone @@ -1348,8 +1346,10 @@ func (coll *Collection) Distinct( } op.Hint(hint) } - if rawData, ok := optionsutil.Value(args.Internal, "rawData").(bool); ok { - op = op.RawData(rawData) + if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil { + if rawData, ok := rawDataOpt.(bool); ok { + op = op.RawData(rawData) + } } retry := driver.RetryNone if coll.client.retryReads { @@ -1554,8 +1554,10 @@ func (coll *Collection) find( } op.Sort(sort) } - if rawData, ok := optionsutil.Value(args.Internal, "rawData").(bool); ok { - op = op.RawData(rawData) + if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil { + if rawData, ok := rawDataOpt.(bool); ok { + op = op.RawData(rawData) + } } retry := driver.RetryNone if coll.client.retryReads { @@ -1755,8 +1757,10 @@ func (coll *Collection) FindOneAndDelete( } op = op.Let(let) } - if rawData, ok := optionsutil.Value(args.Internal, "rawData").(bool); ok { - op = op.RawData(rawData) + if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil { + if rawData, ok := rawDataOpt.(bool); ok { + op = op.RawData(rawData) + } } return coll.findAndModify(ctx, op) @@ -1855,11 +1859,10 @@ func (coll *Collection) FindOneAndReplace( } op = op.Let(let) } - if rawData, ok := optionsutil.Value(args.Internal, "rawData").(bool); ok { - op = op.RawData(rawData) - } - if additionalCmd, ok := optionsutil.Value(args.Internal, "addCommandFields").(bson.D); ok { - op = op.AdditionalCmd(additionalCmd) + if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil { + if rawData, ok := rawDataOpt.(bool); ok { + op = op.RawData(rawData) + } } return coll.findAndModify(ctx, op) @@ -1970,11 +1973,10 @@ func (coll *Collection) FindOneAndUpdate( } op = op.Let(let) } - if rawData, ok := optionsutil.Value(args.Internal, "rawData").(bool); ok { - op = op.RawData(rawData) - } - if additionalCmd, ok := optionsutil.Value(args.Internal, "addCommandFields").(bson.D); ok { - op = op.AdditionalCmd(additionalCmd) + if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil { + if rawData, ok := rawDataOpt.(bool); ok { + op = op.RawData(rawData) + } } return coll.findAndModify(ctx, op) diff --git a/vendor/go.mongodb.org/mongo-driver/v2/mongo/database.go b/vendor/go.mongodb.org/mongo-driver/v2/mongo/database.go index 7064929e..e42097bb 100644 --- a/vendor/go.mongodb.org/mongo-driver/v2/mongo/database.go +++ b/vendor/go.mongodb.org/mongo-driver/v2/mongo/database.go @@ -489,8 +489,10 @@ func (db *Database) ListCollections( if args.AuthorizedCollections != nil { op = op.AuthorizedCollections(*args.AuthorizedCollections) } - if rawData, ok := optionsutil.Value(args.Internal, "rawData").(bool); ok { - op = op.RawData(rawData) + if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil { + if rawData, ok := rawDataOpt.(bool); ok { + op = op.RawData(rawData) + } } retry := driver.RetryNone diff --git a/vendor/go.mongodb.org/mongo-driver/v2/mongo/index_view.go b/vendor/go.mongodb.org/mongo-driver/v2/mongo/index_view.go index 147978d2..f8529c16 100644 --- a/vendor/go.mongodb.org/mongo-driver/v2/mongo/index_view.go +++ b/vendor/go.mongodb.org/mongo-driver/v2/mongo/index_view.go @@ -102,8 +102,10 @@ func (iv IndexView) List(ctx context.Context, opts ...options.Lister[options.Lis op = op.BatchSize(*args.BatchSize) cursorOpts.BatchSize = *args.BatchSize } - if rawData, ok := optionsutil.Value(args.Internal, "rawData").(bool); ok { - op = op.RawData(rawData) + if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil { + if rawData, ok := rawDataOpt.(bool); ok { + op = op.RawData(rawData) + } } retry := driver.RetryNone @@ -288,8 +290,10 @@ func (iv IndexView) CreateMany( op.CommitQuorum(commitQuorum) } - if rawData, ok := optionsutil.Value(args.Internal, "rawData").(bool); ok { - op = op.RawData(rawData) + if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil { + if rawData, ok := rawDataOpt.(bool); ok { + op = op.RawData(rawData) + } } _, err = processWriteError(op.Execute(ctx)) @@ -425,8 +429,10 @@ func (iv IndexView) drop(ctx context.Context, index any, opts ...options.Lister[ Deployment(iv.coll.client.deployment).ServerAPI(iv.coll.client.serverAPI). Timeout(iv.coll.client.timeout).Crypt(iv.coll.client.cryptFLE).Authenticator(iv.coll.client.authenticator) - if rawData, ok := optionsutil.Value(args.Internal, "rawData").(bool); ok { - op = op.RawData(rawData) + if rawDataOpt := optionsutil.Value(args.Internal, "rawData"); rawDataOpt != nil { + if rawData, ok := rawDataOpt.(bool); ok { + op = op.RawData(rawData) + } } err = op.Execute(ctx) diff --git a/vendor/go.mongodb.org/mongo-driver/v2/mongo/mongointernal.go b/vendor/go.mongodb.org/mongo-driver/v2/mongo/mongointernal.go deleted file mode 100644 index 31195d37..00000000 --- a/vendor/go.mongodb.org/mongo-driver/v2/mongo/mongointernal.go +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (C) MongoDB, Inc. 2025-present. -// -// Licensed under the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. You may obtain -// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 - -//go:build mongointernal - -package mongo - -import ( - "time" - - "go.mongodb.org/mongo-driver/v2/bson" - "go.mongodb.org/mongo-driver/v2/x/bsonx/bsoncore" - "go.mongodb.org/mongo-driver/v2/x/mongo/driver/session" -) - -// NewSessionWithLSID returns a Session with the given sessionID document. The -// sessionID is a BSON document with key "id" containing a 16-byte UUID (binary -// subtype 4). -// -// Sessions returned by NewSessionWithLSID are never added to the driver's -// session pool. Calling "EndSession" or "ClientSession.SetServer" on a Session -// returned by NewSessionWithLSID will panic. -// -// NewSessionWithLSID is intended only for internal use and may be changed or -// removed at any time. -func NewSessionWithLSID(client *Client, sessionID bson.Raw) *Session { - return &Session{ - clientSession: &session.Client{ - Server: &session.Server{ - SessionID: bsoncore.Document(sessionID), - LastUsed: time.Now(), - }, - ClientID: client.id, - }, - client: client, - deployment: client.deployment, - } -} diff --git a/vendor/go.mongodb.org/mongo-driver/v2/mongo/options/changestreamoptions.go b/vendor/go.mongodb.org/mongo-driver/v2/mongo/options/changestreamoptions.go index 92f19638..9e5bb93b 100644 --- a/vendor/go.mongodb.org/mongo-driver/v2/mongo/options/changestreamoptions.go +++ b/vendor/go.mongodb.org/mongo-driver/v2/mongo/options/changestreamoptions.go @@ -135,7 +135,7 @@ func (cso *ChangeStreamOptionsBuilder) SetShowExpandedEvents(see bool) *ChangeSt } // SetStartAtOperationTime sets the value for the StartAtOperationTime field. If specified, the change stream -// will only return changes that occurred at or after the given timestamp. +// will only return changes that occurred at or after the given timestamp. This MongoDB versions >= 4.0. // If this is specified, ResumeAfter and StartAfter must not be set. func (cso *ChangeStreamOptionsBuilder) SetStartAtOperationTime(t *bson.Timestamp) *ChangeStreamOptionsBuilder { cso.Opts = append(cso.Opts, func(opts *ChangeStreamOptions) error { diff --git a/vendor/go.mongodb.org/mongo-driver/v2/mongo/options/listcollectionsoptions.go b/vendor/go.mongodb.org/mongo-driver/v2/mongo/options/listcollectionsoptions.go index c69a6dc4..14f96cc6 100644 --- a/vendor/go.mongodb.org/mongo-driver/v2/mongo/options/listcollectionsoptions.go +++ b/vendor/go.mongodb.org/mongo-driver/v2/mongo/options/listcollectionsoptions.go @@ -65,7 +65,8 @@ func (lc *ListCollectionsOptionsBuilder) SetBatchSize(size int32) *ListCollectio // SetAuthorizedCollections sets the value for the AuthorizedCollections field. If true, and // NameOnly is true, limits the documents returned to only contain collections the user is -// authorized to use. The default value is false. +// authorized to use. The default value is false. This option is only valid for MongoDB server +// versions >= 4.0. Server versions < 4.0 ignore this option. func (lc *ListCollectionsOptionsBuilder) SetAuthorizedCollections(b bool) *ListCollectionsOptionsBuilder { lc.Opts = append(lc.Opts, func(opts *ListCollectionsOptions) error { opts.AuthorizedCollections = &b diff --git a/vendor/go.mongodb.org/mongo-driver/v2/version/version.go b/vendor/go.mongodb.org/mongo-driver/v2/version/version.go index ab026bd1..2b483845 100644 --- a/vendor/go.mongodb.org/mongo-driver/v2/version/version.go +++ b/vendor/go.mongodb.org/mongo-driver/v2/version/version.go @@ -11,4 +11,4 @@ package version // Driver is the current version of the driver. -var Driver = "2.4.0" +var Driver = "2.3.1" diff --git a/vendor/go.mongodb.org/mongo-driver/v2/x/mongo/driver/operation.go b/vendor/go.mongodb.org/mongo-driver/v2/x/mongo/driver/operation.go index 3e720eba..57ec762e 100644 --- a/vendor/go.mongodb.org/mongo-driver/v2/x/mongo/driver/operation.go +++ b/vendor/go.mongodb.org/mongo-driver/v2/x/mongo/driver/operation.go @@ -1133,11 +1133,9 @@ func (op Operation) readWireMessage(ctx context.Context, conn *mnet.Connection) // decode res, err := op.decodeResult(opcode, rem) - // When a cluster clock is given, update cluster/operation time and recovery tokens before handling the error - // to ensure we're properly updating everything. - if op.Clock != nil { - op.updateClusterTimes(res) - } + // Update cluster/operation time and recovery tokens before handling the error to ensure we're properly updating + // everything. + op.updateClusterTimes(res) op.updateOperationTime(res) op.Client.UpdateRecoveryToken(bson.Raw(res)) @@ -1731,10 +1729,7 @@ func (op Operation) addClusterTime(dst []byte, desc description.SelectedServer) if (clock == nil && client == nil) || !sessionsSupported(desc.WireVersion) { return dst } - var clusterTime bson.Raw - if clock != nil { - clusterTime = clock.GetClusterTime() - } + clusterTime := clock.GetClusterTime() if client != nil { clusterTime = session.MaxClusterTime(clusterTime, client.ClusterTime) } @@ -1746,6 +1741,7 @@ func (op Operation) addClusterTime(dst []byte, desc description.SelectedServer) return dst } return append(bsoncore.AppendHeader(dst, bsoncore.Type(val.Type), "$clusterTime"), val.Value...) + // return bsoncore.AppendDocumentElement(dst, "$clusterTime", clusterTime) } // calculateMaxTimeMS calculates the value of the 'maxTimeMS' field to potentially append diff --git a/vendor/go.mongodb.org/mongo-driver/v2/x/mongo/driver/operation/find_and_modify.go b/vendor/go.mongodb.org/mongo-driver/v2/x/mongo/driver/operation/find_and_modify.go index 0b3da9c4..09205681 100644 --- a/vendor/go.mongodb.org/mongo-driver/v2/x/mongo/driver/operation/find_and_modify.go +++ b/vendor/go.mongodb.org/mongo-driver/v2/x/mongo/driver/operation/find_and_modify.go @@ -51,7 +51,6 @@ type FindAndModify struct { let bsoncore.Document timeout *time.Duration rawData *bool - additionalCmd bson.D result FindAndModifyResult } @@ -217,13 +216,6 @@ func (fam *FindAndModify) command(dst []byte, desc description.SelectedServer) ( if fam.rawData != nil && desc.WireVersion != nil && driverutil.VersionRangeIncludes(*desc.WireVersion, 27) { dst = bsoncore.AppendBooleanElement(dst, "rawData", *fam.rawData) } - if len(fam.additionalCmd) > 0 { - doc, err := bson.Marshal(fam.additionalCmd) - if err != nil { - return nil, err - } - dst = append(dst, doc[4:len(doc)-1]...) - } return dst, nil } @@ -499,13 +491,3 @@ func (fam *FindAndModify) RawData(rawData bool) *FindAndModify { fam.rawData = &rawData return fam } - -// AdditionalCmd sets additional command fields to be attached. -func (fam *FindAndModify) AdditionalCmd(d bson.D) *FindAndModify { - if fam == nil { - fam = new(FindAndModify) - } - - fam.additionalCmd = d - return fam -} diff --git a/vendor/go.mongodb.org/mongo-driver/v2/x/mongo/driver/operation/insert.go b/vendor/go.mongodb.org/mongo-driver/v2/x/mongo/driver/operation/insert.go index d4f01e6b..57d461ae 100644 --- a/vendor/go.mongodb.org/mongo-driver/v2/x/mongo/driver/operation/insert.go +++ b/vendor/go.mongodb.org/mongo-driver/v2/x/mongo/driver/operation/insert.go @@ -12,7 +12,6 @@ import ( "fmt" "time" - "go.mongodb.org/mongo-driver/v2/bson" "go.mongodb.org/mongo-driver/v2/event" "go.mongodb.org/mongo-driver/v2/internal/driverutil" "go.mongodb.org/mongo-driver/v2/internal/logger" @@ -44,7 +43,6 @@ type Insert struct { serverAPI *driver.ServerAPIOptions timeout *time.Duration rawData *bool - additionalCmd bson.D logger *logger.Logger } @@ -139,13 +137,6 @@ func (i *Insert) command(dst []byte, desc description.SelectedServer) ([]byte, e if i.rawData != nil && desc.WireVersion != nil && driverutil.VersionRangeIncludes(*desc.WireVersion, 27) { dst = bsoncore.AppendBooleanElement(dst, "rawData", *i.rawData) } - if len(i.additionalCmd) > 0 { - doc, err := bson.Marshal(i.additionalCmd) - if err != nil { - return nil, err - } - dst = append(dst, doc[4:len(doc)-1]...) - } return dst, nil } @@ -342,13 +333,3 @@ func (i *Insert) RawData(rawData bool) *Insert { i.rawData = &rawData return i } - -// AdditionalCmd sets additional command fields to be attached. -func (i *Insert) AdditionalCmd(d bson.D) *Insert { - if i == nil { - i = new(Insert) - } - - i.additionalCmd = d - return i -} diff --git a/vendor/go.mongodb.org/mongo-driver/v2/x/mongo/driver/operation/update.go b/vendor/go.mongodb.org/mongo-driver/v2/x/mongo/driver/operation/update.go index 07848a54..00e193ef 100644 --- a/vendor/go.mongodb.org/mongo-driver/v2/x/mongo/driver/operation/update.go +++ b/vendor/go.mongodb.org/mongo-driver/v2/x/mongo/driver/operation/update.go @@ -47,7 +47,6 @@ type Update struct { let bsoncore.Document timeout *time.Duration rawData *bool - additionalCmd bson.D logger *logger.Logger } @@ -209,13 +208,6 @@ func (u *Update) command(dst []byte, desc description.SelectedServer) ([]byte, e if u.rawData != nil && desc.WireVersion != nil && driverutil.VersionRangeIncludes(*desc.WireVersion, 27) { dst = bsoncore.AppendBooleanElement(dst, "rawData", *u.rawData) } - if len(u.additionalCmd) > 0 { - doc, err := bson.Marshal(u.additionalCmd) - if err != nil { - return nil, err - } - dst = append(dst, doc[4:len(doc)-1]...) - } return dst, nil } @@ -445,13 +437,3 @@ func (u *Update) RawData(rawData bool) *Update { u.rawData = &rawData return u } - -// AdditionalCmd sets additional command fields to be attached. -func (u *Update) AdditionalCmd(d bson.D) *Update { - if u == nil { - u = new(Update) - } - - u.additionalCmd = d - return u -} diff --git a/vendor/go.mongodb.org/mongo-driver/v2/x/mongo/driver/topology/fsm.go b/vendor/go.mongodb.org/mongo-driver/v2/x/mongo/driver/topology/fsm.go index 26e2fc32..530b2169 100644 --- a/vendor/go.mongodb.org/mongo-driver/v2/x/mongo/driver/topology/fsm.go +++ b/vendor/go.mongodb.org/mongo-driver/v2/x/mongo/driver/topology/fsm.go @@ -20,7 +20,7 @@ import ( var ( // MinSupportedMongoDBVersion is the version string for the lowest MongoDB version supported by the driver. - MinSupportedMongoDBVersion = "4.2" + MinSupportedMongoDBVersion = "4.0" // SupportedWireVersions is the range of wire versions supported by the driver. SupportedWireVersions = driverutil.NewVersionRange(driverutil.MinWireVersion, driverutil.MaxWireVersion) diff --git a/vendor/go.mongodb.org/mongo-driver/v2/x/mongo/driver/topology/server.go b/vendor/go.mongodb.org/mongo-driver/v2/x/mongo/driver/topology/server.go index a408aee5..90cee89e 100644 --- a/vendor/go.mongodb.org/mongo-driver/v2/x/mongo/driver/topology/server.go +++ b/vendor/go.mongodb.org/mongo-driver/v2/x/mongo/driver/topology/server.go @@ -807,18 +807,9 @@ func (s *Server) createConnection() *connection { opts := copyConnectionOpts(s.cfg.connectionOpts) opts = append(opts, WithHandshaker(func(Handshaker) Handshaker { - handshaker := operation.NewHello().AppName(s.cfg.appname).Compressors(s.cfg.compressionOpts). - ServerAPI(s.cfg.serverAPI) - - if s.cfg.driverInfo != nil { - driverInfo := s.cfg.driverInfo.Load() - if driverInfo != nil { - handshaker = handshaker.OuterLibraryName(driverInfo.Name).OuterLibraryVersion(driverInfo.Version). - OuterLibraryPlatform(driverInfo.Platform) - } - } - - return handshaker + return operation.NewHello().AppName(s.cfg.appname).Compressors(s.cfg.compressionOpts). + ServerAPI(s.cfg.serverAPI).OuterLibraryName(s.cfg.outerLibraryName). + OuterLibraryVersion(s.cfg.outerLibraryVersion).OuterLibraryPlatform(s.cfg.outerLibraryPlatform) }), // Override any monitors specified in options with nil to avoid monitoring heartbeats. WithMonitor(func(*event.CommandMonitor) *event.CommandMonitor { return nil }), @@ -851,6 +842,7 @@ func (s *Server) setupHeartbeatConnection(ctx context.Context) error { func (s *Server) createBaseOperation(conn *mnet.Connection) *operation.Hello { return operation. NewHello(). + ClusterClock(s.cfg.clock). Deployment(driver.SingleConnectionDeployment{C: conn}). ServerAPI(s.cfg.serverAPI) } diff --git a/vendor/go.mongodb.org/mongo-driver/v2/x/mongo/driver/topology/server_options.go b/vendor/go.mongodb.org/mongo-driver/v2/x/mongo/driver/topology/server_options.go index 297cafc7..490834cb 100644 --- a/vendor/go.mongodb.org/mongo-driver/v2/x/mongo/driver/topology/server_options.go +++ b/vendor/go.mongodb.org/mongo-driver/v2/x/mongo/driver/topology/server_options.go @@ -7,13 +7,11 @@ package topology import ( - "sync/atomic" "time" "go.mongodb.org/mongo-driver/v2/bson" "go.mongodb.org/mongo-driver/v2/event" "go.mongodb.org/mongo-driver/v2/internal/logger" - "go.mongodb.org/mongo-driver/v2/mongo/options" "go.mongodb.org/mongo-driver/v2/x/mongo/driver" "go.mongodb.org/mongo-driver/v2/x/mongo/driver/connstring" "go.mongodb.org/mongo-driver/v2/x/mongo/driver/session" @@ -34,7 +32,6 @@ type serverConfig struct { monitoringDisabled bool serverAPI *driver.ServerAPIOptions loadBalanced bool - driverInfo *atomic.Pointer[options.DriverInfo] // Connection pool options. maxConns uint64 @@ -44,6 +41,11 @@ type serverConfig struct { logger *logger.Logger poolMaxIdleTime time.Duration poolMaintainInterval time.Duration + + // Fields provided by a library that wraps the Go Driver. + outerLibraryName string + outerLibraryVersion string + outerLibraryPlatform string } func newServerConfig(connectTimeout time.Duration, opts ...ServerOption) *serverConfig { @@ -99,12 +101,27 @@ func WithServerAppName(fn func(string) string) ServerOption { } } -// WithDriverInfo sets at atomic pointer to the server configuration, which will -// be used to create the "driver" section on handshake commands. An atomic -// pointer is used so that the driver info can be updated concurrently. -func WithDriverInfo(info *atomic.Pointer[options.DriverInfo]) ServerOption { +// WithOuterLibraryName configures the name for the outer library to include +// in the drivers section of the handshake metadata. +func WithOuterLibraryName(fn func(string) string) ServerOption { + return func(cfg *serverConfig) { + cfg.outerLibraryName = fn(cfg.outerLibraryName) + } +} + +// WithOuterLibraryVersion configures the version for the outer library to +// include in the drivers section of the handshake metadata. +func WithOuterLibraryVersion(fn func(string) string) ServerOption { + return func(cfg *serverConfig) { + cfg.outerLibraryVersion = fn(cfg.outerLibraryVersion) + } +} + +// WithOuterLibraryPlatform configures the platform for the outer library to +// include in the platform section of the handshake metadata. +func WithOuterLibraryPlatform(fn func(string) string) ServerOption { return func(cfg *serverConfig) { - cfg.driverInfo = info + cfg.outerLibraryPlatform = fn(cfg.outerLibraryPlatform) } } diff --git a/vendor/go.mongodb.org/mongo-driver/v2/x/mongo/driver/topology/topology_options.go b/vendor/go.mongodb.org/mongo-driver/v2/x/mongo/driver/topology/topology_options.go index 2d53805d..2ddc7434 100644 --- a/vendor/go.mongodb.org/mongo-driver/v2/x/mongo/driver/topology/topology_options.go +++ b/vendor/go.mongodb.org/mongo-driver/v2/x/mongo/driver/topology/topology_options.go @@ -11,7 +11,6 @@ import ( "crypto/tls" "fmt" "net/http" - "sync/atomic" "time" "go.mongodb.org/mongo-driver/v2/event" @@ -140,56 +139,14 @@ func NewConfig(opts *options.ClientOptions, clock *session.ClusterClock) (*Confi return nil, fmt.Errorf("error creating authenticator: %w", err) } } - return NewAuthenticatorConfig(authenticator, - WithAuthConfigClock(clock), - WithAuthConfigClientOptions(opts), - ) -} - -type authConfigOptions struct { - clock *session.ClusterClock - opts *options.ClientOptions - driverInfo *atomic.Pointer[options.DriverInfo] -} - -// AuthConfigOption is a function that configures authConfigOptions. -type AuthConfigOption func(*authConfigOptions) - -// WithAuthConfigClock sets the cluster clock in authConfigOptions. -func WithAuthConfigClock(clock *session.ClusterClock) AuthConfigOption { - return func(co *authConfigOptions) { - co.clock = clock - } -} - -// WithAuthConfigClientOptions sets the client options in authConfigOptions. -func WithAuthConfigClientOptions(opts *options.ClientOptions) AuthConfigOption { - return func(co *authConfigOptions) { - co.opts = opts - } + return NewConfigFromOptionsWithAuthenticator(opts, clock, authenticator) } -// WithAuthConfigDriverInfo sets the driver info in authConfigOptions. -func WithAuthConfigDriverInfo(driverInfo *atomic.Pointer[options.DriverInfo]) AuthConfigOption { - return func(co *authConfigOptions) { - co.driverInfo = driverInfo - } -} - -// NewAuthenticatorConfig will translate data from client options into a +// NewConfigFromOptionsWithAuthenticator will translate data from client options into a // topology config for building non-default deployments. Server and topology // options are not honored if a custom deployment is used. It uses a passed in // authenticator to authenticate the connection. -func NewAuthenticatorConfig(authenticator driver.Authenticator, clientOpts ...AuthConfigOption) (*Config, error) { - settings := authConfigOptions{} - for _, apply := range clientOpts { - apply(&settings) - } - - opts := settings.opts - clock := settings.clock - driverInfo := settings.driverInfo - +func NewConfigFromOptionsWithAuthenticator(opts *options.ClientOptions, clock *session.ClusterClock, authenticator driver.Authenticator) (*Config, error) { var serverAPI *driver.ServerAPIOptions if err := opts.Validate(); err != nil { @@ -243,8 +200,23 @@ func NewAuthenticatorConfig(authenticator driver.Authenticator, clientOpts ...Au })) } - if driverInfo != nil { - serverOpts = append(serverOpts, WithDriverInfo(driverInfo)) + var outerLibraryName, outerLibraryVersion, outerLibraryPlatform string + if opts.DriverInfo != nil { + outerLibraryName = opts.DriverInfo.Name + outerLibraryVersion = opts.DriverInfo.Version + outerLibraryPlatform = opts.DriverInfo.Platform + + serverOpts = append(serverOpts, WithOuterLibraryName(func(string) string { + return outerLibraryName + })) + + serverOpts = append(serverOpts, WithOuterLibraryVersion(func(string) string { + return outerLibraryVersion + })) + + serverOpts = append(serverOpts, WithOuterLibraryPlatform(func(string) string { + return outerLibraryPlatform + })) } // Compressors & ZlibLevel @@ -284,57 +256,46 @@ func NewAuthenticatorConfig(authenticator driver.Authenticator, clientOpts ...Au // Handshaker var handshaker func(driver.Handshaker) driver.Handshaker if authenticator != nil { - handshaker = func(driver.Handshaker) driver.Handshaker { - handshakeOpts := &auth.HandshakeOptions{ - AppName: appName, - Authenticator: authenticator, - Compressors: comps, - ServerAPI: serverAPI, - LoadBalanced: loadBalanced, - ClusterClock: clock, - } - - if opts.Auth.AuthMechanism == "" { - // Required for SASL mechanism negotiation during handshake - handshakeOpts.DBUser = opts.Auth.AuthSource + "." + opts.Auth.Username - } + handshakeOpts := &auth.HandshakeOptions{ + AppName: appName, + Authenticator: authenticator, + Compressors: comps, + ServerAPI: serverAPI, + LoadBalanced: loadBalanced, + ClusterClock: clock, + OuterLibraryName: outerLibraryName, + OuterLibraryVersion: outerLibraryVersion, + OuterLibraryPlatform: outerLibraryPlatform, + } - if auth, ok := optionsutil.Value(opts.Custom, "authenticateToAnything").(bool); ok && auth { + if opts.Auth.AuthMechanism == "" { + // Required for SASL mechanism negotiation during handshake + handshakeOpts.DBUser = opts.Auth.AuthSource + "." + opts.Auth.Username + } + if a := optionsutil.Value(opts.Custom, "authenticateToAnything"); a != nil { + if v, ok := a.(bool); ok && v { // Authenticate arbiters handshakeOpts.PerformAuthentication = func(_ description.Server) bool { return true } } + } - if driverInfo != nil { - if di := driverInfo.Load(); di != nil { - handshakeOpts.OuterLibraryName = di.Name - handshakeOpts.OuterLibraryVersion = di.Version - handshakeOpts.OuterLibraryPlatform = di.Platform - } - } - + handshaker = func(driver.Handshaker) driver.Handshaker { return auth.Handshaker(nil, handshakeOpts) } } else { handshaker = func(driver.Handshaker) driver.Handshaker { - op := operation.NewHello(). + return operation.NewHello(). AppName(appName). Compressors(comps). ClusterClock(clock). ServerAPI(serverAPI). - LoadBalanced(loadBalanced) - - if driverInfo != nil { - if di := driverInfo.Load(); di != nil { - op = op.OuterLibraryName(di.Name). - OuterLibraryVersion(di.Version). - OuterLibraryPlatform(di.Platform) - } - } - - return op + LoadBalanced(loadBalanced). + OuterLibraryName(outerLibraryName). + OuterLibraryVersion(outerLibraryVersion). + OuterLibraryPlatform(outerLibraryPlatform) } } diff --git a/vendor/modules.txt b/vendor/modules.txt index 7a0418d8..10f4b1d0 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -240,7 +240,7 @@ github.com/xdg-go/stringprep # github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 ## explicit; go 1.17 github.com/youmark/pkcs8 -# go.mongodb.org/mongo-driver/v2 v2.4.0 +# go.mongodb.org/mongo-driver/v2 v2.3.1 ## explicit; go 1.19 go.mongodb.org/mongo-driver/v2/bson go.mongodb.org/mongo-driver/v2/event