[SERVER-27207] Find on view with sort through mongos may incorrectly return empty result set Created: 29/Nov/16  Updated: 05/Apr/17  Resolved: 01/Dec/16

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: 3.4.1, 3.5.1

Type: Bug Priority: Major - P3
Reporter: Kyle Suarez Assignee: Kyle Suarez
Resolution: Done Votes: 0
Labels: 34errata, read-only-views
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-26765 Move views tests into jsCore Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Completed:
Sprint: Query 2016-12-12
Participants:

 Description   

A find() with a sort() on a mongos may return an empty result set:

mongos> db.c.insert({x:1})
WriteResult({ "nInserted" : 1 })
mongos> db.c.find()
{ "_id" : ObjectId("583dc54dade9d2265ce2b196"), "x" : 1 }
mongos> db.createView("cView", "c", [{$match : { x : {$gt : 0}}}])
{ "ok" : 1 }
mongos> db.cView.find()
{ "_id" : ObjectId("583dc54dade9d2265ce2b196"), "x" : 1 }
mongos> db.cView.find().sort({_id:1})

There's a simple workaround, which is to use the aggregation pipeline:

mongos> db.cView.aggregate([{ $sort: {_id:1}}])
{ "_id" : ObjectId("583dc54dade9d2265ce2b196"), "x" : 1 }



 Comments   
Comment by Githook User [ 01/Dec/16 ]

Author:

{u'username': u'ksuarz', u'name': u'Kyle Suarez', u'email': u'kyle.suarez@mongodb.com'}

Message: SERVER-27207 populate merge queue in AsyncResultsMerger when encountering ResolvedView

(cherry picked from commit 1db6b26bcfdc67992c52739f50deacd31edc4fc0)
Branch: v3.4
https://github.com/mongodb/mongo/commit/9e941332d0c15cf498298de32d843bd6f409ddf7

Comment by Githook User [ 01/Dec/16 ]

Author:

{u'username': u'ksuarz', u'name': u'Kyle Suarez', u'email': u'kyle.suarez@mongodb.com'}

Message: SERVER-27207 populate merge queue in AsyncResultsMerger when encountering ResolvedView
Branch: master
https://github.com/mongodb/mongo/commit/1db6b26bcfdc67992c52739f50deacd31edc4fc0

Comment by Kyle Suarez [ 30/Nov/16 ]

In AsyncResultsMerger::handleBatchResponse(), we detect the view kickback error code from the primary shard and fill out a ClusterQueryResult with the new resolved view. However, we only fill out the docBuffer of the remote. We don't touch the merge queue in any way, so it's left empty. If the query has a sort, we call AsyncResultsMerger::nextReadySorted(), which consults the top of the merge queue. Since it's empty, it returns an empty result.

There are a few ways we could fix this. Off the top of my head, we could also push remoteIndex to _mergeQueue when populating the result's view definition; or we could change the code to not go down the sorted codepath if a view's been discovered. I leave the strategy up to david.storch.

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