Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
qingyang-hu committed Sep 28, 2023
1 parent 3ce688d commit d7c9ff7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 37 deletions.
21 changes: 3 additions & 18 deletions benchmark/operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,10 @@ func BenchmarkClientWrite(b *testing.B) {
}
for _, bm := range benchmarks {
b.Run(bm.name, func(b *testing.B) {
client, err := mongo.NewClient(bm.opt)
client, err := mongo.Connect(context.Background(), bm.opt)
if err != nil {
b.Fatalf("error creating client: %v", err)
}
ctx := context.Background()
err = client.Connect(ctx)
if err != nil {
b.Fatalf("error connecting: %v", err)
}
defer client.Disconnect(context.Background())
coll := client.Database("test").Collection("test")
_, err = coll.DeleteMany(context.Background(), bson.D{})
Expand Down Expand Up @@ -76,15 +71,10 @@ func BenchmarkClientBulkWrite(b *testing.B) {
}
for _, bm := range benchmarks {
b.Run(bm.name, func(b *testing.B) {
client, err := mongo.NewClient(bm.opt)
client, err := mongo.Connect(context.Background(), bm.opt)
if err != nil {
b.Fatalf("error creating client: %v", err)
}
ctx := context.Background()
err = client.Connect(ctx)
if err != nil {
b.Fatalf("error connecting: %v", err)
}
defer client.Disconnect(context.Background())
coll := client.Database("test").Collection("test")
_, err = coll.DeleteMany(context.Background(), bson.D{})
Expand Down Expand Up @@ -125,15 +115,10 @@ func BenchmarkClientRead(b *testing.B) {
}
for _, bm := range benchmarks {
b.Run(bm.name, func(b *testing.B) {
client, err := mongo.NewClient(bm.opt)
client, err := mongo.Connect(context.Background(), bm.opt)
if err != nil {
b.Fatalf("error creating client: %v", err)
}
ctx := context.Background()
err = client.Connect(ctx)
if err != nil {
b.Fatalf("error connecting: %v", err)
}
defer client.Disconnect(context.Background())
coll := client.Database("test").Collection("test")
_, err = coll.DeleteMany(context.Background(), bson.D{})
Expand Down
5 changes: 1 addition & 4 deletions benchmark/single.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,10 @@ func getClientDB(ctx context.Context) (*mongo.Database, error) {
if err != nil {
return nil, err
}
client, err := mongo.NewClient(options.Client().ApplyURI(cs.String()))
client, err := mongo.Connect(ctx, options.Client().ApplyURI(cs.String()))
if err != nil {
return nil, err
}
if err = client.Connect(ctx); err != nil {
return nil, err
}

db := client.Database(integtest.GetDBName(cs))
return db, nil
Expand Down
4 changes: 1 addition & 3 deletions mongo/integration/client_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ func TestClientOptions_CustomDialer(t *testing.T) {
cs := integtest.ConnString(t)
opts := options.Client().ApplyURI(cs.String()).SetDialer(td)
integtest.AddTestServerAPIVersion(opts)
client, err := mongo.NewClient(opts)
require.NoError(t, err)
err = client.Connect(context.Background())
client, err := mongo.Connect(context.Background(), opts)
require.NoError(t, err)
_, err = client.ListDatabases(context.Background(), bson.D{})
require.NoError(t, err)
Expand Down
9 changes: 3 additions & 6 deletions mongo/integration/mtest/mongotest.go
Original file line number Diff line number Diff line change
Expand Up @@ -692,13 +692,13 @@ func (t *T) createTestClient() {
// pin to first mongos
pinnedHostList := []string{testContext.connString.Hosts[0]}
uriOpts := options.Client().ApplyURI(testContext.connString.Original).SetHosts(pinnedHostList)
t.Client, err = mongo.NewClient(uriOpts, clientOpts)
t.Client, err = mongo.Connect(context.Background(), uriOpts, clientOpts)
case Mock:
// clear pool monitor to avoid configuration error
clientOpts.PoolMonitor = nil
t.mockDeployment = newMockDeployment()
clientOpts.Deployment = t.mockDeployment
t.Client, err = mongo.NewClient(clientOpts)
t.Client, err = mongo.Connect(context.Background(), clientOpts)
case Proxy:
t.proxyDialer = newProxyDialer()
clientOpts.SetDialer(t.proxyDialer)
Expand All @@ -716,14 +716,11 @@ func (t *T) createTestClient() {
}

// Pass in uriOpts first so clientOpts wins if there are any conflicting settings.
t.Client, err = mongo.NewClient(uriOpts, clientOpts)
t.Client, err = mongo.Connect(context.Background(), uriOpts, clientOpts)
}
if err != nil {
t.Fatalf("error creating client: %v", err)
}
if err := t.Client.Connect(context.Background()); err != nil {
t.Fatalf("error connecting client: %v", err)
}
}

func (t *T) createTestCollection() {
Expand Down
16 changes: 10 additions & 6 deletions x/mongo/driver/session/client_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,13 +465,17 @@ func (c *Client) CommitTransaction() error {
// w timeout of 10 seconds. This should be called after a commit transaction operation fails with a
// retryable error or after a successful commit transaction operation.
func (c *Client) UpdateCommitTransactionWriteConcern() {
if c.CurrentWc == nil {
c.CurrentWc = &writeconcern.WriteConcern{}
}
c.CurrentWc.W = "majority"
if c.CurrentWc.WTimeout == 0 {
c.CurrentWc.WTimeout = 10 * time.Second
wc := &writeconcern.WriteConcern{}
timeout := 10 * time.Second
if c.CurrentWc != nil {
*wc = *c.CurrentWc
if c.CurrentWc.WTimeout != 0 {
timeout = c.CurrentWc.WTimeout
}
}
wc.W = "majority"
wc.WTimeout = timeout
c.CurrentWc = wc
}

// CheckAbortTransaction checks to see if allowed to abort transaction and returns
Expand Down

0 comments on commit d7c9ff7

Please sign in to comment.