diff options
author | Sara Golemon <sara.golemon@mongodb.com> | 2020-09-11 20:04:06 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-09-14 17:16:39 +0000 |
commit | ec929e17993ade6e0258aab73fd8024d1cb6180f (patch) | |
tree | d6491b868115e9b4714e2f13731076dfd7048017 | |
parent | aa1d8cc685874e6530c589ab10c6260c2533c5b0 (diff) | |
download | mongo-ec929e17993ade6e0258aab73fd8024d1cb6180f.tar.gz |
SERVER-20359 Rename terse(UTC)CurrentTime to terseCurrentTimeForFilename()
-rw-r--r-- | src/mongo/db/ftdc/file_manager.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/initialize_server_global_state.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/storage/remove_saver.cpp | 2 | ||||
-rw-r--r-- | src/mongo/logv2/log_util.cpp | 2 | ||||
-rw-r--r-- | src/mongo/util/exception_filter_win32.cpp | 4 | ||||
-rw-r--r-- | src/mongo/util/time_support.cpp | 17 | ||||
-rw-r--r-- | src/mongo/util/time_support.h | 11 |
7 files changed, 17 insertions, 25 deletions
diff --git a/src/mongo/db/ftdc/file_manager.cpp b/src/mongo/db/ftdc/file_manager.cpp index fc1c2a9a025..9316a89dcfc 100644 --- a/src/mongo/db/ftdc/file_manager.cpp +++ b/src/mongo/db/ftdc/file_manager.cpp @@ -91,7 +91,7 @@ StatusWith<std::unique_ptr<FTDCFileManager>> FTDCFileManager::create( auto interimDocs = mgr->recoverInterimFile(); // Open the archive file for writing - auto swFile = mgr->generateArchiveFileName(path, terseUTCCurrentTime()); + auto swFile = mgr->generateArchiveFileName(path, terseCurrentTimeForFilename(true)); if (!swFile.isOK()) { return swFile.getStatus(); } @@ -315,7 +315,7 @@ Status FTDCFileManager::rotate(Client* client) { return s; } - auto swFile = generateArchiveFileName(_path, terseUTCCurrentTime()); + auto swFile = generateArchiveFileName(_path, terseCurrentTimeForFilename(true)); if (!swFile.isOK()) { return swFile.getStatus(); } diff --git a/src/mongo/db/initialize_server_global_state.cpp b/src/mongo/db/initialize_server_global_state.cpp index 0ecacf78018..aef5a665d4f 100644 --- a/src/mongo/db/initialize_server_global_state.cpp +++ b/src/mongo/db/initialize_server_global_state.cpp @@ -329,7 +329,7 @@ MONGO_INITIALIZER_GENERAL(ServerLogRedirection, } if (!serverGlobalParams.logAppend && boost::filesystem::is_regular(absoluteLogpath)) { - std::string renameTarget = absoluteLogpath + "." + terseCurrentTime(false); + std::string renameTarget = absoluteLogpath + "." + terseCurrentTimeForFilename(); boost::system::error_code ec; boost::filesystem::rename(absoluteLogpath, renameTarget, ec); if (!ec) { diff --git a/src/mongo/db/storage/remove_saver.cpp b/src/mongo/db/storage/remove_saver.cpp index 0e56f22ba38..950d390d63e 100644 --- a/src/mongo/db/storage/remove_saver.cpp +++ b/src/mongo/db/storage/remove_saver.cpp @@ -68,7 +68,7 @@ RemoveSaver::RemoveSaver(const string& a, _file = _root; stringstream ss; - ss << why << "." << terseCurrentTime(false) << "." << NUM++ << ".bson"; + ss << why << "." << terseCurrentTimeForFilename() << "." << NUM++ << ".bson"; _file /= ss.str(); auto encryptionHooks = EncryptionHooks::get(getGlobalServiceContext()); diff --git a/src/mongo/logv2/log_util.cpp b/src/mongo/logv2/log_util.cpp index 0e7a6526a80..b37e98b6bed 100644 --- a/src/mongo/logv2/log_util.cpp +++ b/src/mongo/logv2/log_util.cpp @@ -50,7 +50,7 @@ void addLogRotator(LogRotateCallback cb) { bool rotateLogs(bool renameFiles) { // Rotate on both logv1 and logv2 so all files that need rotation gets rotated - std::string suffix = "." + terseCurrentTime(false); + std::string suffix = "." + terseCurrentTimeForFilename(); LOGV2(23166, "Log rotation initiated", "suffix"_attr = suffix); bool success = true; diff --git a/src/mongo/util/exception_filter_win32.cpp b/src/mongo/util/exception_filter_win32.cpp index d15c5545838..ce8e30ebbdb 100644 --- a/src/mongo/util/exception_filter_win32.cpp +++ b/src/mongo/util/exception_filter_win32.cpp @@ -79,11 +79,9 @@ void doMinidumpWithException(struct _EXCEPTION_POINTERS* exceptionInfo) { std::wstring dumpName(moduleFileName); - std::string currentTime = terseCurrentTime(false); - dumpName += L"."; - dumpName += toWideString(currentTime.c_str()); + dumpName += toWideStringFromStringData(terseCurrentTimeForFilename()); dumpName += L".mdmp"; diff --git a/src/mongo/util/time_support.cpp b/src/mongo/util/time_support.cpp index 4de71bcc251..e022d0b4cd0 100644 --- a/src/mongo/util/time_support.cpp +++ b/src/mongo/util/time_support.cpp @@ -142,23 +142,22 @@ std::string time_t_to_String_short(time_t t) { return buf; } +constexpr auto kUTCFilenameFormat = "%Y-%m-%dT%H-%M-%S"_sd; +constexpr auto kUTCFilenameFormatZ = "%Y-%m-%dT%H-%M-%SZ"_sd; -// uses ISO 8601 dates without trailing Z -// colonsOk should be false when creating filenames -std::string terseCurrentTime(bool colonsOk) { +// Produces a UTC datetime string suitable for use in filenames. +std::string terseCurrentTimeForFilename(bool appendZed) { struct tm t; time_t_to_Struct(time(nullptr), &t); - const char* fmt = (colonsOk ? "%Y-%m-%dT%H:%M:%S" : "%Y-%m-%dT%H-%M-%S"); + const auto fmt = appendZed ? kUTCFilenameFormatZ : kUTCFilenameFormat; + const std::size_t expLen = appendZed ? 20 : 19; + char buf[32]; - fassert(16226, strftime(buf, sizeof(buf), fmt, &t) == 19); + fassert(16226, strftime(buf, sizeof(buf), fmt.rawData(), &t) == expLen); return buf; } -std::string terseUTCCurrentTime() { - return terseCurrentTime(false) + "Z"; -} - DateStringBuffer& DateStringBuffer::iso8601(Date_t date, bool local) { invariant(date.isFormattable()); diff --git a/src/mongo/util/time_support.h b/src/mongo/util/time_support.h index f7ba73ca26d..c5d4481e06d 100644 --- a/src/mongo/util/time_support.h +++ b/src/mongo/util/time_support.h @@ -288,15 +288,10 @@ private: }; /** - * uses ISO 8601 dates without trailing "Z". - * `colonsOk` should be false when creating filenames. + * Uses a format similar to, but incompatable with ISO 8601 + * to produce UTC based datetimes suitable for use in filenames. */ -std::string terseCurrentTime(bool colonsOk = true); - -/** - * Produces a short UTC date + time approriate for file names with Z appended. - */ -std::string terseUTCCurrentTime(); +std::string terseCurrentTimeForFilename(bool appendZed = false); /** @{ */ /** |