summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSpencer T Brody <spencer@mongodb.com>2017-03-17 13:57:23 -0400
committerSpencer T Brody <spencer@mongodb.com>2017-04-04 16:01:38 -0400
commit302d82c0d1e86db64ea411e464571608f2b66bad (patch)
tree953022a2cd8130ffaba82dc645baf7885aebdb30 /src
parent9818bae9a907ef224972470e461a590422149df8 (diff)
downloadmongo-302d82c0d1e86db64ea411e464571608f2b66bad.tar.gz
SERVER-28380 Clear ramlog before looking for stopReplProducer failpoint log message
(cherry picked from commit 07ddacf92a2c53bd5a02878917ab8ebb35874413)
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/commands/generic.cpp56
-rw-r--r--src/mongo/logger/ramlog.cpp13
-rw-r--r--src/mongo/logger/ramlog.h5
3 files changed, 72 insertions, 2 deletions
diff --git a/src/mongo/db/commands/generic.cpp b/src/mongo/db/commands/generic.cpp
index ae173c44942..be8f55b9fe5 100644
--- a/src/mongo/db/commands/generic.cpp
+++ b/src/mongo/db/commands/generic.cpp
@@ -32,6 +32,7 @@
#include <time.h>
+#include "mongo/bson/util/bson_extract.h"
#include "mongo/bson/util/builder.h"
#include "mongo/client/dbclient_rs.h"
#include "mongo/db/auth/action_set.h"
@@ -450,6 +451,61 @@ public:
} getLogCmd;
+class ClearLogCmd : public Command {
+public:
+ ClearLogCmd() : Command("clearLog") {}
+
+ virtual bool slaveOk() const {
+ return true;
+ }
+ virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
+ return false;
+ }
+ virtual bool adminOnly() const {
+ return true;
+ }
+ Status checkAuthForCommand(Client* client,
+ const std::string& dbname,
+ const BSONObj& cmdObj) override {
+ // No access control needed since this command is a testing-only command that must be
+ // enabled at the command line.
+ return Status::OK();
+ }
+ virtual void help(stringstream& help) const {
+ help << "{ clearLog : 'global' }";
+ }
+
+ virtual bool run(OperationContext* opCtx,
+ const string& dbname,
+ BSONObj& cmdObj,
+ int,
+ string& errmsg,
+ BSONObjBuilder& result) {
+ std::string logName;
+ Status status = bsonExtractStringField(cmdObj, "clearLog", &logName);
+ if (!status.isOK()) {
+ return appendCommandStatus(result, status);
+ }
+
+ if (logName != "global") {
+ return appendCommandStatus(
+ result, Status(ErrorCodes::InvalidOptions, "Only the 'global' log can be cleared"));
+ }
+ RamLog* ramlog = RamLog::getIfExists(logName);
+ invariant(ramlog);
+ ramlog->clear();
+ return true;
+ }
+};
+
+MONGO_INITIALIZER(RegisterClearLogCmd)(InitializerContext* context) {
+ if (Command::testCommandsEnabled) {
+ // Leaked intentionally: a Command registers itself when constructed.
+ new ClearLogCmd();
+ }
+ return Status::OK();
+}
+
class CmdGetCmdLineOpts : Command {
public:
CmdGetCmdLineOpts() : Command("getCmdLineOpts") {}
diff --git a/src/mongo/logger/ramlog.cpp b/src/mongo/logger/ramlog.cpp
index 42742f32bcc..e0190577f71 100644
--- a/src/mongo/logger/ramlog.cpp
+++ b/src/mongo/logger/ramlog.cpp
@@ -50,8 +50,7 @@ RM* _named = NULL;
} // namespace
RamLog::RamLog(const std::string& name) : _name(name), _totalLinesWritten(0), _lastWrite(0) {
- h = 0;
- n = 0;
+ clear();
for (int i = 0; i < N; i++)
lines[i][C - 1] = 0;
}
@@ -84,6 +83,16 @@ void RamLog::write(const std::string& str) {
h = (h + 1) % N;
}
+void RamLog::clear() {
+ stdx::lock_guard<stdx::mutex> lk(_mutex);
+ _totalLinesWritten = 0;
+ _lastWrite = 0;
+ h = 0;
+ n = 0;
+ for (int i = 0; i < N; i++)
+ lines[i][0] = 0;
+}
+
time_t RamLog::LineIterator::lastWrite() {
return _ramlog->_lastWrite;
}
diff --git a/src/mongo/logger/ramlog.h b/src/mongo/logger/ramlog.h
index 54901948f74..902471c4563 100644
--- a/src/mongo/logger/ramlog.h
+++ b/src/mongo/logger/ramlog.h
@@ -93,6 +93,11 @@ public:
*/
void write(const std::string& str);
+ /**
+ * Empties out the RamLog.
+ */
+ void clear();
+
/**
* Writes an HTML representation of the log to "s".