[DOCS-10842] Docs for SERVER-30344: prevent shards from implicitly creating a collection on createIndexes Created: 27/Sep/17  Updated: 15/Oct/19  Resolved: 23/Oct/17

Status: Closed
Project: Documentation
Component/s: None
Affects Version/s: None
Fix Version/s: 3.6.0-rc0

Type: Task Priority: Major - P3
Reporter: Kay Kim (Inactive) Assignee: Kevin Albertson
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Documented
documents SERVER-30344 prevent shards from implicitly creati... Closed
Participants:
Days since reply: 6 years, 16 weeks, 2 days ago
Epic Link: DOCS: 3.6 Server

 Description   

Documentation Request Summary:

This ticket makes createIndexes, reIndex, dropIndex, and collMod only actually execute on shards that currently know about the namespace. (A shard may not currently own any chunks for the namespace, but have previously owned chunks).

For unsharded collections, these commands only target the primary shard.

For sharded collections, these commands are broadcast to all shards, but shards that do not know about the namespace return NamespaceNotFound (reIndex, dropIndex, collMod) or CannotImplicitlyCreateCollection (createIndexes).

Mongos treats these errors as success (the overall command will report success if shards return a mix of ok:1 and these errors), but these error codes are shown in the raw responses from shards in the 'raw' field of the response object.

Engineering Ticket Description:

createIndexes on mongos is currently broadcast to all shards rather than only targeting shards which own data for the collection, since listIndexes expects the primary shard to have all the indexes for the collection (and the primary shard might not own any chunks for the collection at some particular time) (SERVER-16273).

However, this means the collection is implicitly created on shards which don't own chunks for the collection AND don't have an entry for the collection in their storage engine (e.g., any shard that has never owned chunks for the collection). The collection is implicitly created on these shards without the collection options, including the collection's UUID.

To prevent this,

1) mongods running as --shardsvr should fail createIndexes with NamespaceNotFound rather than implicitly create the collection with the wrong options
2) for createIndexes on a sharded collection, mongos should ignore NamespaceNotFound errors from shards
3) for createIndexes on an unsharded collection, mongos should check if the collection exists on the primary shard, and explicitly create it if not before sending createIndexes to the primary shard



 Comments   
Comment by Kevin Albertson [ 23/Oct/17 ]

Discussed with Esha. Since we don't mention the "raw" field in the command responses we don't need to make any documentation changes.

Comment by Kevin Albertson [ 16/Oct/17 ]

I'm not sure what is the best way to document this change. We don't currently discuss the raw part of a response from a command issued to a sharded cluster.

I could add a snippet to the createIndex page like so:

If the collection is sharded, the :dbcommand:`createIndexes` command will be
sent to every shard. Shards that know the collection definition will create
the index. Shards that do not know the collection definition will return
individual errors, but the entire command will still succeed.

But then again, the behavior should be pretty transparent to the user. If they create an index, it won't be created on shards unaware of that collection until chunks are moved to it. OTOH, the errors from the raw error document may be confusing. E.g.

"raw": {
    "localhost:27019" : {
        "ok" : 0,
        "errmsg" : "request doesn't allow collection to be created implicitly",
        "code" : 227,
        "codeName" : "CannotImplicitlyCreateCollection"
    },
    "localhost:27020" : {
        "ok" : 0,
        "errmsg" : "request doesn't allow collection to be created implicitly",
        "code" : 227,
        "codeName" : "CannotImplicitlyCreateCollection"
    },
    "localhost:27018" : {
        "createdCollectionAutomatically" : false,
        "numIndexesBefore" : 2,
        "numIndexesAfter" : 3,
        "ok" : 1
    }
}

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