From b5378e3b57fec7cca6ded55f4af07119c532edc9 Mon Sep 17 00:00:00 2001 From: Gregory Noma Date: Fri, 25 Sep 2020 09:33:56 -0400 Subject: SERVER-51107 Suffix index build external sort files with a random number generated at startup --- src/mongo/db/index/index_access_method.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/mongo/db') diff --git a/src/mongo/db/index/index_access_method.cpp b/src/mongo/db/index/index_access_method.cpp index 5ae6e0be6d3..dd9c8b22863 100644 --- a/src/mongo/db/index/index_access_method.cpp +++ b/src/mongo/db/index/index_access_method.cpp @@ -847,7 +847,8 @@ std::shared_ptr AbstractIndexAccessMethod::getSharedIdent() const { /** * Generates a new file name on each call using a static, atomic and monotonically increasing - * number. + * number. Each name is suffixed with a random number generated at startup, to prevent name + * collisions when the index build external sort files are preserved across restarts. * * Each user of the Sorter must implement this function to ensure that all temporary files that the * Sorter instances produce are uniquely identified using a unique file name extension with separate @@ -856,7 +857,9 @@ std::shared_ptr AbstractIndexAccessMethod::getSharedIdent() const { */ std::string nextFileName() { static AtomicWord indexAccessMethodFileCounter; - return "extsort-index." + std::to_string(indexAccessMethodFileCounter.fetchAndAdd(1)); + static const int64_t randomSuffix = SecureRandom().nextInt64(); + return str::stream() << "extsort-index." << indexAccessMethodFileCounter.fetchAndAdd(1) << '-' + << randomSuffix; } Status AbstractIndexAccessMethod::_handleDuplicateKey(OperationContext* opCtx, -- cgit v1.2.1