[SERVER-29057] Unreplicated temporary collection creations should use unique names Created: 03/May/17  Updated: 30/Oct/23  Resolved: 28/Jul/17

Status: Closed
Project: Core Server
Component/s: Replication
Affects Version/s: None
Fix Version/s: 3.5.11

Type: Improvement Priority: Major - P3
Reporter: Judah Schvimer Assignee: Benety Goh
Resolution: Fixed Votes: 1
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Related
related to SERVER-65711 Use 'regular expression' in database_... Closed
related to SERVER-31749 Clarify the reason temporary unique c... Closed
is related to SERVER-28382 convertToCapped should use a unique n... Closed
Backwards Compatibility: Fully Compatible
Sprint: Repl 2017-07-31
Participants:
Linked BF Score: 15

 Description   

In multiple places we create temporary collections and use in-memory counters to make the names unique. If the node shuts down and starts back up, these names may no longer be unique. We can use a UUID to be more unique.

Here are two examples:
https://github.com/mongodb/mongo/blob/fa2dcc33303dd6a2080c108e121da6984d08a9d6/src/mongo/db/pipeline/document_source_out.cpp#L95-L96
https://github.com/mongodb/mongo/blob/fa2dcc33303dd6a2080c108e121da6984d08a9d6/src/mongo/db/commands/mr.cpp#L310-L314



 Comments   
Comment by Githook User [ 28/Jul/17 ]

Author:

{'email': 'benety@mongodb.com', 'username': 'benety', 'name': 'Benety Goh'}

Message: SERVER-29057 createCollectionForApplyOps uses randomly generated temporary collection name

This applies to rare oplog replay scenarios where the collection to create already exists.
Branch: master
https://github.com/mongodb/mongo/commit/9a46831201e17c6b2aa281888eea1f1c13869698

Comment by Githook User [ 28/Jul/17 ]

Author:

{'email': 'benety@mongodb.com', 'username': 'benety', 'name': 'Benety Goh'}

Message: SERVER-29057 renameCollection() uses randomly generated temporary collection name
Branch: master
https://github.com/mongodb/mongo/commit/702e4b28e4808a0c895b7e97ce66accee31c8a4b

Comment by Githook User [ 28/Jul/17 ]

Author:

{'email': 'benety@mongodb.com', 'username': 'benety', 'name': 'Benety Goh'}

Message: SERVER-29057 convertToCapped uses randomly generated temporary collection name
Branch: master
https://github.com/mongodb/mongo/commit/8f61a856fc7add0eed9f1572c18b0e4b996ff177

Comment by Githook User [ 28/Jul/17 ]

Author:

{'email': 'benety@mongodb.com', 'username': 'benety', 'name': 'Benety Goh'}

Message: SERVER-29057 add Database::makeUniqueCollectionNamespace()

This function generates a unique collection name suitable for temporary
collections in the same database using a mkstemp-like template.
Branch: master
https://github.com/mongodb/mongo/commit/8bdcd3ac5fe7f3ba0bc0ddaa70ea6731ef775918

Comment by Githook User [ 27/Jul/17 ]

Author:

{'email': 'benety@mongodb.com', 'username': 'benety', 'name': 'Benety Goh'}

Message: SERVER-29057 cloneCollectionAsCapped() includes collection name in error message when destination exists
Branch: master
https://github.com/mongodb/mongo/commit/9d2ce39c3bb7cd2f5cd3763cf8f1941543c26bc4

Comment by Githook User [ 27/Jul/17 ]

Author:

{'email': 'benety@mongodb.com', 'username': 'benety', 'name': 'Benety Goh'}

Message: SERVER-29057 include collection name in message for assertion 17399
Branch: master
https://github.com/mongodb/mongo/commit/6015c85de33727a5b5e01eb5cc6a52e9059ad3e6

Comment by Judah Schvimer [ 04/May/17 ]

renameCollection looks like another example of this:
https://github.com/mongodb/mongo/blob/fa2dcc33303dd6a2080c108e121da6984d08a9d6/src/mongo/db/catalog/rename_collection.cpp#L189-L191

Comment by Eric Milkie [ 04/May/17 ]

After discussion, it's more clear what this ticket work represents. The examples listed in the description are not in fact the ones we should be changing. Instead, we only need to change the temp table name generation logic for temporary tables that are NOT replicated. One example is the convertToCapped temporary table.

Comment by Eric Milkie [ 04/May/17 ]

I thought temporary collections did not live across startups (they are dropped because that's what makes them temporary).

Comment by Matthew Russotto [ 03/May/17 ]

Yes, some of our current code includes the existing collection name which wouldn't leave much. But I guess we don't need that.

Comment by Geert Bosch [ 03/May/17 ]

We have 120 - 63 - 1 == 56 characters for the collection part of the namespace name. The UUID is 36 bytes in ASCII representation, so that leaves some space for a prefix like tmp_ or whatever indicating to humans this is a temporary collection.

Comment by Matthew Russotto [ 03/May/17 ]

We also probably want to ensure our temporary names don't exceed namespace length limits.

Comment by Geert Bosch [ 03/May/17 ]

We probably should make a single method that creates a new temp collection with a unique name. Once we enable collection UUIDs we can change them to use the actual UUID of the collection. Until then we can just generate a new one.

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