[GODRIVER-484] Read preference doesn't work Created: 07/Jul/18  Updated: 27/Oct/23  Resolved: 08/Oct/18

Status: Closed
Project: Go Driver
Component/s: CRUD
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Hailin Hu Assignee: Kristofer Brandow (Inactive)
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

mongodb:
    read_preference: "secondary"
    read_preference_tags:
      - storage: "SSD"

Our configuration looks like this. It works with mgo.
We switched to mongo-go-driver and found all the queries went to the primary.
But the driver threw exception if we intended to use a non-existed read preference tags.

Topology:
go client -> mongos -> a 3.2 sharded cluster



 Comments   
Comment by Hailin Hu [ 10/Sep/18 ]

Sorry for the late reply. I failed to find a way to make a simple test case.
My colleague borrowed codes of connection management from yours and made some customization of mgo, which solved our biggest issue in production env.
It just works and we paused the replacement of mongodb driver.

Comment by Jeffrey Yemin [ 31/Aug/18 ]

h@bulbit.jp any luck with a simple test case?

Comment by Kristofer Brandow (Inactive) [ 19/Jul/18 ]

Hi,

There isn't any default way to know from the driver.

Comment by Hailin Hu [ 19/Jul/18 ]

Hi,

We verified the issue with cloud manager.
Let me see if I can give out a simple test case.

BTW., is there any way to know that the result comes from a secondary node or not?

Comment by Kristofer Brandow (Inactive) [ 18/Jul/18 ]

Hi h@bulbit.jp,

I've attempted to reproduce this locally and haven't been able to. How are you verifying that the reads are going to the secondaries?

Comment by Hailin Hu [ 18/Jul/18 ]

Hi,

We mainly use FindOne() like this

db := client.Database("myDb")
coll := db.Collection("myCollection")
res := coll.FindOne(context.Background(), bson.NewDocument(bson.EC.String("_id", "myId")))

Although the driver doesn't work with proper tag sets, it will complain no valid host if we use wrong tag sets.

Comment by Kristofer Brandow (Inactive) [ 17/Jul/18 ]

Hi h@bulbit.jp,

Which CRUD methods are you calling that you expect to be going to a secondary but are going to a primary? Are you using db.RunComamnd at all?

Comment by Hailin Hu [ 10/Jul/18 ]

Hi,

Go driver version: bb548a5e4d4cabb086e6425b113b07270e40bbb8

clientOptions := mongo.ClientOpt.
  AppName("myapp").
  SocketTimeout(1 * time.Second).
  MaxConnsPerHost(16).
  MaxIdleConnsPerHost(16).
  ConnectTimeout(1 * time.Second).
  ReadPreference("secondary").
  ReadPreferenceTagSets([]map[string]string{{"storage": "SSD"}})
client, err := mongo.Connect(context.Background(), FormatUrl("/var/run/mongodb/mongodb-27017.sock"), clientOptions)

Thanks.

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

Hi h@bulbit.jp,

Thanks for the report. Can you provide some more information, e.g. the version of the Go driver you're using, the connection string being used, etc?

Thanks,

Kris

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