[GODRIVER-633] commands meant for local node are directed to primary Created: 09/Nov/18  Updated: 11/Sep/19  Resolved: 29/Nov/18

Status: Closed
Project: Go Driver
Component/s: Options & Configuration
Affects Version/s: 0.0.17
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: prashant deva Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Go 1.11
Linux 64 bit


Issue Links:
Related
related to GODRIVER-665 Support only "automatic" and "direct"... Closed

 Description   

We have our custom monitoring agent we run on each mongo instance, which call `serverStatus` like this:

 

 

connectStr := fmt.Sprintf("mongodb://%s:%s@%s:%d/%s", h.Username, h.Password, "localhost", h.Port, h.Database)
client, e := mongo.NewClient(connectStr)
ctx, _ := context.WithTimeout(context.Background(), 3*time.Second)
client.Connect(ctx)
db := client.Database(h.Database)
rdr, e := db.RunCommand(ctx, bson.NewDocument(bson.EC.Int32("serverStatus", 1))) 

 

However, it seems the commands are always routed to the primary, since even when run on the secondaries, we get the exact same stats as the primary for metrics like connections, opcounters, opcountersRepl, etc.

This seems to be a bug in the driver, where a query being run on 'localhost' is being directed to the primary

 



 Comments   
Comment by Jeffrey Yemin [ 29/Nov/18 ]

pdeva Thanks for asking about this.  We opened GODRIVER-665 to address the issue.

Comment by Jeffrey Yemin [ 29/Nov/18 ]

Opened GODRIVER-665.

Comment by Ian Whalen (Inactive) [ 26/Nov/18 ]

We will be removing one of the two prior to GA of 1.0.

Comment by prashant deva [ 12/Nov/18 ]

does that mean there are plans to replace them with something else in the future?

any kind of documentation on this would be good to have

Comment by Kristofer Brandow (Inactive) [ 12/Nov/18 ]

pdeva There is no difference. You can use either, they both exist for historical purposes.

Comment by prashant deva [ 10/Nov/18 ]

Whats the difference between connect=direct or connect=single? 

This does not seem to be documented anywhere

Comment by Kristofer Brandow (Inactive) [ 09/Nov/18 ]

Hi pdeva,

The Go driver will do automatic cluster discovery unless you specify it shouldn't. If you want to connect directly to a secondary and run commands against that secondary you need to add either connect=direct or connect=single to the connection string.

--Kris

Generated at Thu Feb 08 08:34:37 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.