[SERVER-31049] View with collation doesn't work as expected in sharded cluster Created: 12/Sep/17  Updated: 30/Oct/23  Resolved: 21/Sep/17

Status: Closed
Project: Core Server
Component/s: Querying, Sharding
Affects Version/s: 3.4.9
Fix Version/s: 3.4.10, 3.6.0-rc0

Type: Bug Priority: Critical - P2
Reporter: adrien petel Assignee: David Storch
Resolution: Fixed Votes: 0
Labels: read-only-views
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Mongodb 3.4.9, Ubuntu 16.04, sharded cluster


Issue Links:
Backports
Depends
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v3.4
Steps To Reproduce:

In single mongod instance:

> db.test.insertMany([{"nm": "case"}, {"nm": "CaSe"}, {"nm": "câse"}])
{
	"acknowledged" : true,
	"insertedIds" : [
		ObjectId("59b7887b90afeae466d0cdcb"),
		ObjectId("59b7887b90afeae466d0cdcc"),
		ObjectId("59b7887b90afeae466d0cdcd")
	]
}
> db.createView("view", "test", [{$match: {"nm": "case"}}], {"collation": {"locale": "en", strength: 1}})
{ "ok" : 1 }
> db.view.find()
{ "_id" : ObjectId("59b7887b90afeae466d0cdcb"), "nm" : "case" }
{ "_id" : ObjectId("59b7887b90afeae466d0cdcc"), "nm" : "CaSe" }
{ "_id" : ObjectId("59b7887b90afeae466d0cdcd"), "nm" : "câse" }

In sharded cluster (2 shards, 3 config server started as replicaSet). Collection is not sharded

Cluster info :

mongos> sh.status()
--- Sharding Status --- 
  sharding version: {
	"_id" : 1,
	"minCompatibleVersion" : 5,
	"currentVersion" : 6,
	"clusterId" : ObjectId("59b7860fbc018363095e4c79")
}
  shards:
	{  "_id" : "shard0000",  "host" : "localhost:27021",  "state" : 1 }
	{  "_id" : "shard0001",  "host" : "localhost:27022",  "state" : 1 }
  active mongoses:
	"3.4.9" : 1
 autosplit:
	Currently enabled: yes
  balancer:
	Currently enabled:  yes
	Currently running:  no
		Balancer lock taken at Tue Sep 12 2017 11:00:35 GMT+0400 (RET) by ConfigServer:Balancer
	Failed balancer rounds in last 5 attempts:  0
	Migration Results for the last 24 hours: 
		No recent migrations
  databases:
	{  "_id" : "test",  "primary" : "shard0000",  "partitioned" : false }

mongos> db.test.insertMany([{"nm": "case"}, {"nm": "CaSe"}, {"nm": "câse"}])
{
	"acknowledged" : true,
	"insertedIds" : [
		ObjectId("59b7890412b88ce4ce4ccf30"),
		ObjectId("59b7890412b88ce4ce4ccf31"),
		ObjectId("59b7890412b88ce4ce4ccf32")
	]
}
mongos> db.createView("view", "test", [{$match: {"nm": "case"}}], {"collation": {"locale": "en", strength: 1}})
{ "ok" : 1 }
mongos> db.view.find()
{ "_id" : ObjectId("59b7890412b88ce4ce4ccf30"), "nm" : "case" }

Sprint: Query 2017-10-02
Participants:
Linked BF Score: 0

 Description   

Creating a view with a collation in a sharded cluster does not work as expected, whereas it works fine in a single mongod instance



 Comments   
Comment by Githook User [ 26/Sep/17 ]

Author:

{'email': 'david.storch@10gen.com', 'name': 'David Storch', 'username': 'dstorch'}

Message: SERVER-31049 Fix resolution of a view's default collation on mongos.

(cherry picked from commit 5f8d84b1792839a4b372e8479d0eccba6fd64357)

Conflicts:
buildscripts/resmokeconfig/suites/causally_consistent_jscore_passthrough.yml
buildscripts/resmokeconfig/suites/causally_consistent_jscore_passthrough_auth.yml
jstests/core/views/views_collation.js
src/mongo/db/commands/run_aggregate.cpp
src/mongo/db/views/resolved_view.cpp
src/mongo/db/views/resolved_view_test.cpp
Branch: v3.4
https://github.com/mongodb/mongo/commit/3a262ee4002375ed7f2e4cdf6cac60b712d42685

Comment by Githook User [ 21/Sep/17 ]

Author:

{'email': 'david.storch@10gen.com', 'name': 'David Storch', 'username': 'dstorch'}

Message: SERVER-31049 Fix resolution of a view's default collation on mongos.
Branch: master
https://github.com/mongodb/mongo/commit/5f8d84b1792839a4b372e8479d0eccba6fd64357

Comment by David Storch [ 12/Sep/17 ]

Hi felix2626,

I've tracked this down as an issue with how mongos handles the view catalog metadata returned to it by the primary shard. Specifically, the query does not correctly inherit the view's default collation when mongos rewrites the view query as a query over the base collection. The code with the defect is here:

https://github.com/mongodb/mongo/blob/33cb4a950c5de3c1c783b25ecf0fd4454cce844a/src/mongo/s/commands/cluster_find_cmd.cpp#L185-L214

We plan to work on a fix within the next few weeks. Thanks again for the report and please let me know if you have any further questions or concerns.

Best,
Dave

Comment by David Storch [ 12/Sep/17 ]

Hi felix2626,

Thanks for reporting this issue. I can reproduce this as you describe and am currently looking into the root cause.

Best,
Dave

Generated at Thu Feb 08 04:25:50 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.