summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSpencer T Brody <spencer@mongodb.com>2014-04-09 20:07:16 -0400
committerMatt Kangas <matt.kangas@mongodb.com>2014-04-14 13:40:51 -0400
commit279163e3802cf5b538b22eac9302419f0f7bb6f8 (patch)
treec4113473761a2b1688b18a50753b73de3bf3ac8f
parent52da235706ca1713ae91475009348a0ceded5307 (diff)
downloadmongo-279163e3802cf5b538b22eac9302419f0f7bb6f8.tar.gz
SERVER-9358 Prevent logRotate twice in the same second from losing log data
(cherry picked from commit d53521c9534d579d44582bb06cb37d73ffeab931)
-rw-r--r--src/mongo/logger/rotatable_file_writer.cpp14
-rw-r--r--src/mongo/util/log.cpp5
2 files changed, 19 insertions, 0 deletions
diff --git a/src/mongo/logger/rotatable_file_writer.cpp b/src/mongo/logger/rotatable_file_writer.cpp
index 74c38247c2d..dd1a62a789c 100644
--- a/src/mongo/logger/rotatable_file_writer.cpp
+++ b/src/mongo/logger/rotatable_file_writer.cpp
@@ -17,6 +17,7 @@
#include "mongo/logger/rotatable_file_writer.h"
+#include <boost/filesystem/operations.hpp>
#include <boost/scoped_array.hpp>
#include <cstdio>
#include <fstream>
@@ -211,6 +212,19 @@ namespace {
Status RotatableFileWriter::Use::rotate(const std::string& renameTarget) {
if (_writer->_stream) {
_writer->_stream->flush();
+ try {
+ if (boost::filesystem::exists(renameTarget)) {
+ return Status(ErrorCodes::FileRenameFailed, mongoutils::str::stream() <<
+ "Renaming file " << _writer->_fileName << " to " <<
+ renameTarget << " failed; destination already exists");
+ }
+ } catch (const std::exception& e) {
+ return Status(ErrorCodes::FileRenameFailed, mongoutils::str::stream() <<
+ "Renaming file " << _writer->_fileName << " to " <<
+ renameTarget << " failed; Cannot verify whether destination "
+ "already exists: " << e.what());
+ }
+
if (0 != renameFile(_writer->_fileName, renameTarget)) {
return Status(ErrorCodes::FileRenameFailed, mongoutils::str::stream() <<
"Failed to rename \"" << _writer->_fileName << "\" to \"" <<
diff --git a/src/mongo/util/log.cpp b/src/mongo/util/log.cpp
index 52fba9ae070..84fc1399c21 100644
--- a/src/mongo/util/log.cpp
+++ b/src/mongo/util/log.cpp
@@ -64,6 +64,11 @@ namespace mongo {
RotatableFileManager* manager = logger::globalRotatableFileManager();
RotatableFileManager::FileNameStatusPairVector result(
manager->rotateAll("." + terseCurrentTime(false)));
+ for (RotatableFileManager::FileNameStatusPairVector::iterator it = result.begin();
+ it != result.end(); it++) {
+ warning() << "Rotating log file " << it->first << " failed: " << it->second.toString()
+ << endl;
+ }
return result.empty();
}