[CDRIVER-413] Mongo C driver does not respect readPreferenceTags Created: 23/Aug/14  Updated: 26/Aug/14  Resolved: 26/Aug/14

Status: Closed
Project: C Driver
Component/s: None
Affects Version/s: 0.96.4
Fix Version/s: 1.0.0

Type: Bug Priority: Critical - P2
Reporter: Denis Gladkikh Assignee: Christian Hergert
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File example-client.c    
Issue Links:
Related

 Description   

I have a replica set with 3 nodes:

{
	"_id" : "replset",
	"version" : 3,
	"members" : [
		{
			"_id" : 0,
			"host" : "outcoldx:28001",
			"tags" : {
				"instance" : "11111111-1111-1111-1111-111111111111"
			}
		},
		{
			"_id" : 1,
			"host" : "outcoldx:28002",
			"tags" : {
				"instance" : "11111111-1111-1111-1111-111111111112"
			}
		},
		{
			"_id" : 2,
			"host" : "outcoldx:28003",
			"tags" : {
				"instance" : "11111111-1111-1111-1111-111111111113"
			}
		}
	]
}

1. It seems like having "readPreference=nearest" and "readPreferenceTags=instance:11111111-1111-1111-1111-111111111113" in connection strings does not change readPreference behavior, read preference needs to be explicitly set via one of the mongoc_client_set_read_prefs or mongoc_collection_set_read_prefs. Which is fine, not great, but fine.
2. I tried to explicitly set mongoc_client_set_read_prefs with tags, but it did not work, because it seems like mongoc driver never loads tags for server from replica set configuration, because private function "_score_tags" from mongoc-read-prefs.c always has empty tags for nodes.

Also I attached an example which I used to verify that. When I use mongoc_read_prefs_t with tags - this example fails because it cannot find node, which should be used for search.



 Comments   
Comment by Christian Hergert [ 26/Aug/14 ]

No thank you Denis! Fixing it is easy, finding the bug is the hard part!

Comment by Denis Gladkikh [ 26/Aug/14 ]

Hi Christian,

Thank you for fixing it. At the because we did not use readPreferenceTags (not intentionally) - we decided to just keep readPreference=nearest for this release. But for next release we will probably pick this change.

Thank you for fixing it!

Comment by Christian Hergert [ 25/Aug/14 ]

This commit will also be useful, to set a proper error response as found from your test case.

https://github.com/mongodb/mongo-c-driver/commit/979f1c1b99cf45f3fbcb4f68600080dd3a1077f6

Comment by Christian Hergert [ 25/Aug/14 ]

Hi Denis,

Would you mind applying this patch to your mongo-c-driver build and let me know how it goes?

https://github.com/mongodb/mongo-c-driver/commit/022bc04198fc2d0e2100895eefabe46328bf334e

Comment by Christian Hergert [ 25/Aug/14 ]

Thanks for reporting this Denis, I'll take a look Monday PDT and verify.

Generated at Wed Feb 07 21:09:25 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.