Skip to content
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

GODRIVER-2617 Remove deprecated code #1398

Merged
merged 20 commits into from
Oct 13, 2023

Conversation

qingyang-hu
Copy link
Collaborator

@qingyang-hu qingyang-hu commented Sep 20, 2023

GODRIVER-2617
GODRIVER-2885

Summary

Remove or un-export deprecated code in Go Driver 2.0.

Background & Motivation

options.MergeClientOptions will be removed in GODRIVER-3001.
GODRIVER-2862 and GODRIVER-2927 are not covered in this PR.

@qingyang-hu qingyang-hu force-pushed the godriver2617 branch 2 times, most recently from d1127f2 to 3ef44aa Compare September 25, 2023 22:26
@qingyang-hu qingyang-hu force-pushed the godriver2617 branch 2 times, most recently from f050dc0 to f3fea53 Compare September 27, 2023 22:00
@qingyang-hu qingyang-hu force-pushed the godriver2617 branch 9 times, most recently from 628a603 to 5b1da45 Compare September 28, 2023 19:08
@qingyang-hu qingyang-hu force-pushed the godriver2617 branch 10 times, most recently from e261dc3 to 23df976 Compare October 2, 2023 17:27
Comment on lines +251 to +258
bwo := options.BulkWrite()
for _, opt := range opts {
if opt == nil {
continue
}
if opt.Comment != nil {
bwo.Comment = opt.Comment
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

The intent of removing the Merge...Options functions is also to remove the bug-prone logic of merging options structs together. Instead, we want to only allow a single options struct and return an error if the user passes more than one.

E.g.

if len(opts) > 1 {
	return errors.New("only one BulkWriteOptions can be provided")
}
bwo := options.BulkWrite()
if len(opts) == 1 {
	bwo = opts[0]
}
...

Copy link
Collaborator

Choose a reason for hiding this comment

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

That change will be handled in GODRIVER-2696, so it's fine to keep the options struct merging here. Consider this comment resolved.

Passive bool
Primary address.Address
ReadOnly bool
ServiceID *primitive.ObjectID // Only set for servers that are deployed behind a load balancer.
SessionTimeoutMinutesPtr *int64
Copy link
Collaborator

Choose a reason for hiding this comment

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

Optional: It's a little awkward to leave a field named ...Ptr. Consider renaming SessionTimeoutMinutesPtr to SessionTimeoutMinutes.

@@ -1971,7 +1971,10 @@ func WithTransactionExample(ctx context.Context) error {
defer func() { _ = client.Disconnect(ctx) }()

// Prereq: Create collections.
wcMajority := writeconcern.New(writeconcern.WMajority(), writeconcern.WTimeout(1*time.Second))
wcMajority := &writeconcern.WriteConcern{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we use the convenience function in the example, instead of using the "majority" magic string?

wcMajority := writeconcern.Majority()
wcMajority.WTimeout = 1 * time.Second

@@ -2552,7 +2555,11 @@ func CausalConsistencyExamples(client *mongo.Client) error {

// Use a causally-consistent session to run some operations
opts := options.Session().SetDefaultReadConcern(readconcern.Majority()).SetDefaultWriteConcern(
writeconcern.New(writeconcern.WMajority(), writeconcern.WTimeout(1000)))
&writeconcern.WriteConcern{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we use the convenience function in the example, instead of using the "majority" magic string?

wcMajority := writeconcern.Majority()
wcMajority.WTimeout = 1000

readconcern.Majority()).SetDefaultWriteConcern(writeconcern.New(writeconcern.WMajority(),
writeconcern.WTimeout(1000)))
readconcern.Majority()).SetDefaultWriteConcern(
&writeconcern.WriteConcern{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we use the convenience function in the example, instead of using the "majority" magic string?

wcMajority := writeconcern.Majority()
wcMajority.WTimeout = 1000

mongo/change_stream.go Outdated Show resolved Hide resolved
description: "empty",
input: []*options.ChangeStreamOptions{},
want: &options.ChangeStreamOptions{},
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we include a nil case as well?

wcAck := writeconcern.New(writeconcern.WMajority())
wcUnack := writeconcern.New(writeconcern.W(0))
wcAck := writeconcern.Majority()
wcUnack := &writeconcern.WriteConcern{W: 0}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
wcUnack := &writeconcern.WriteConcern{W: 0}
wcUnack := writeconcern.Unacknowledged()

@@ -1688,7 +1685,7 @@ func TestCollection(t *testing.T) {
assert.Equal(mt, res.UpsertedIDs[3].(string), id3, "expected UpsertedIDs[3] to be %v, got %v", id3, res.UpsertedIDs[3])
})
unackClientOpts := options.Client().
SetWriteConcern(writeconcern.New(writeconcern.W(0)))
SetWriteConcern(&writeconcern.WriteConcern{W: 0})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
SetWriteConcern(&writeconcern.WriteConcern{W: 0})
SetWriteConcern(writeconcern.Unacknowledged())

@@ -264,7 +263,7 @@ func TestIndexView(t *testing.T) {
}
})
unackClientOpts := options.Client().
SetWriteConcern(writeconcern.New(writeconcern.W(0)))
SetWriteConcern(&writeconcern.WriteConcern{W: 0})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
SetWriteConcern(&writeconcern.WriteConcern{W: 0})
SetWriteConcern(writeconcern.Unacknowledged())

@@ -345,7 +344,7 @@ func TestIndexView(t *testing.T) {
Name: indexNames[1],
})
})
wc := writeconcern.New(writeconcern.W(1))
wc := &writeconcern.WriteConcern{W: 1}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
wc := &writeconcern.WriteConcern{W: 1}
wc := writeconcern.W1()

@@ -107,7 +107,7 @@ func TestSessions(t *testing.T) {
})
})

unackWcOpts := options.Collection().SetWriteConcern(writeconcern.New(writeconcern.W(0)))
unackWcOpts := options.Collection().SetWriteConcern(&writeconcern.WriteConcern{W: 0})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
unackWcOpts := options.Collection().SetWriteConcern(&writeconcern.WriteConcern{W: 0})
unackWcOpts := options.Collection().SetWriteConcern(writeconcern.Unacknowledged())

Copy link
Collaborator

@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.

Looks good 👍

Comment on lines +251 to +258
bwo := options.BulkWrite()
for _, opt := range opts {
if opt == nil {
continue
}
if opt.Comment != nil {
bwo.Comment = opt.Comment
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

That change will be handled in GODRIVER-2696, so it's fine to keep the options struct merging here. Consider this comment resolved.

Copy link
Collaborator

@prestonvasquez prestonvasquez left a comment

Choose a reason for hiding this comment

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

LGTM

@qingyang-hu qingyang-hu merged commit 71f65e3 into mongodb:master Oct 13, 2023
36 of 37 checks passed
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.

3 participants