[SERVER-54507] Can't execute $merge if sharding catalog cache is empty Created: 12/Feb/21  Updated: 29/Oct/23  Resolved: 07/May/21

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 4.4.4
Fix Version/s: 5.0.0-rc0

Type: Bug Priority: Major - P3
Reporter: Tommaso Tocci Assignee: Eric Cox (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File merge_cache_bug.patch    
Issue Links:
Backports
Depends
Problem/Incident
Related
related to SERVER-56815 Complete TODO listed in SERVER-54507 Closed
is related to SERVER-56763 Validate collection epoch when not ho... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v4.9, v4.4, v4.2, v4.0
Steps To Reproduce:

Even though it can be reproduced by a far more easy test case, I've been able to reproduce consistently this bug by just flushing the cache for the target collection in jstests/sharding/query/merge_write_concern.js before to execute the $merge aggregation command.

merge_cache_bug.patch

Sprint: Query Execution 2021-03-08, Query Execution 2021-03-22, Query Execution 2021-04-05, Query Execution 2021-04-19, Query Execution 2021-05-03, Query Execution 2021-05-17
Participants:
Linked BF Score: 145

 Description   

Manifestation of the bug: The impossibility to execute the $merge pipeline stage

Consider the case in which the $merge pipeline stage is executed in a shard that:

  • Has the CollectionShardingState correctly updated with the latest shard version of the target collection.
  • Doesn't currently hold any entry in the cache for the target collection.

(This is possible because the sharding catalog cache is a LRU cache in which not frequently used entries can be evicted.)

The shard executes DocumentSourceMerge::createFromBson() that triggers a call to MongoProcessInterface::ensureFieldsUniqueOrResolveDocumentKey().  This function in the end throws a StaleConfigInfo because the target collection is not present in the cache. The error is correctly handled by the shard that will execute the onShardVersionMismatch() procedure.

Since the CollectionShardingState already contains the latest shard version for the target collection no action will be taken and no refresh of the catalog cache will be triggered.

In other words if the CollectionShardingState is up to date, the StaleConfigInfo won't guarantee that the catalog cache will be refreshed.



 Comments   
Comment by Githook User [ 01/Jul/21 ]

Author:

{'name': 'Eric Cox', 'email': 'eric.cox@mongodb.com', 'username': 'ericox'}

Message: SERVER-56815 Complete TODO listed in SERVER-54507
Branch: master
https://github.com/mongodb/mongo/commit/620a4c060e7cf06d340a81b01cad62f5812852f3

Comment by Githook User [ 07/May/21 ]

Author:

{'name': 'Eric Cox', 'email': 'eric.cox@mongodb.com', 'username': 'ericox'}

Message: SERVER-54507 Can't execute merge if sharding catalog cache is empty
Branch: master
https://github.com/mongodb/mongo/commit/32fe49396dec58836033bca67ad1360b1a80f03c

Generated at Thu Feb 08 05:33:44 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.