Skip to content

GODRIVER-1953 Remove bsonx from production code paths. #893

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

Merged
merged 3 commits into from
Apr 7, 2022

Conversation

matthewdale
Copy link
Collaborator

GODRIVER-1953

Stop using types and functions from the bsonx package in "production" code paths. Leave references in (most) tests and non-production code (e.g. benchmarks) to make reviewing easier and ensure backward compatibility of the changes. We can remove those additional bsonx references (and maybe the bsonx package) in a later change.

Based on #692 by RammasEchor

Copy link
Contributor

@benjirewis benjirewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Can you clarify where bsonx is still in use? I still see it in a couple tests and the benchmark package. Removing the bsonx package entirely would be great, but is that even an option?

doc, err := bsonx.ReadDoc(raw)
if err != nil {
return nil, err
doc := &bson.D{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[opt] Usually I see var doc bson.D and then &doc in the call to UnmarshalWithRegistry. Then you could avoid the dereference with upload.metadata = doc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion, will update.

Copy link
Contributor

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this looks like a good step towards removing the unused bsonx types. And removing the convertFileID is nice.

LGTM

RammasEchor and others added 2 commits April 6, 2022 17:12
Removed the cases where it checks/creates a bsonx.Doc, and replaced
them with bson.D type if necessary. Removed functions that seemed only
to transform bsonx to another type. Removed a test for an specific
function for the same reason.

The bsonx package is largely replaced by bson and bsoncore. bsonx
was a proof of concept, and it should be completely replaced.

There is still various places that use bsonx:

	- benchmark directory
	- mongo/gridfs/bucket.go
	- mongo/gridfs/upload_stream.go
	- mongo/integration/collection_test.go
	- mongo/integration/gridfs_spec_test.go

And a file inside the same bsonx package uses bsonx package:
	- x/bsonx/array.go
Copy link
Collaborator Author

@matthewdale matthewdale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benjirewis here are where the remaining bsonx package references are:

❯ grep -Rl "bsonx\." ./* | sort | uniq
./benchmark/bson.go
./benchmark/bson_document.go
./benchmark/multi.go
./benchmark/single.go
./mongo/cursor.go
./mongo/integration/collection_test.go
./mongo/integration/gridfs_spec_test.go
./mongo/mongo.go
./x/bsonx/document.go

The only remaining references in "production" driver paths are mongo/mongo.go (see here) and mongo/cursor.go (see here). Both of those are in switch statements to support bsonx.Doc input parameters. For example:

func transformAndEnsureID(...) {
	// ...
	switch tt := val.(type) {
	// ...
	case bsonx.Doc:
		val = tt.Copy()
	// ...
}

And you're correct, removing the bsonx package would break our compatibility guarantee, so we still need to keep the bsonx package and keep support in the driver for bsonx types.

doc, err := bsonx.ReadDoc(raw)
if err != nil {
return nil, err
doc := &bson.D{}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion, will update.

@matthewdale matthewdale force-pushed the godriver1953-reduce-bsonx branch from 8fa14fd to 6386fb9 Compare April 7, 2022 01:07
@matthewdale matthewdale merged commit 5083299 into mongodb:master Apr 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants