37
37
#include " mongo/db/commands/shutdown.h"
38
38
#include " mongo/db/commands/test_commands_enabled.h"
39
39
#include " mongo/db/log_process_details.h"
40
+ #include " mongo/logv2/ramlog.h"
40
41
#include " mongo/scripting/engine.h"
41
42
#include " mongo/util/exit.h"
42
43
#include " mongo/util/fail_point.h"
52
53
namespace mongo {
53
54
namespace {
54
55
55
- using std::string;
56
- using std::vector;
57
-
58
56
class FeaturesCmd : public BasicCommand {
59
57
public:
60
58
FeaturesCmd () : BasicCommand(" features" ) {}
@@ -71,7 +69,7 @@ class FeaturesCmd : public BasicCommand {
71
69
const BSONObj& cmdObj,
72
70
std::vector<Privilege>* out) const {} // No auth required
73
71
virtual bool run (OperationContext* opCtx,
74
- const string& ns,
72
+ const std:: string& ns,
75
73
const BSONObj& cmdObj,
76
74
BSONObjBuilder& result) {
77
75
if (getGlobalScriptEngine ()) {
@@ -112,7 +110,7 @@ class HostInfoCmd : public BasicCommand {
112
110
out->push_back (Privilege (ResourcePattern::forClusterResource (), actions));
113
111
}
114
112
bool run (OperationContext* opCtx,
115
- const string& dbname,
113
+ const std:: string& dbname,
116
114
const BSONObj& cmdObj,
117
115
BSONObjBuilder& result) {
118
116
ProcessInfo p;
@@ -165,7 +163,7 @@ class CmdGetCmdLineOpts : public BasicCommand {
165
163
out->push_back (Privilege (ResourcePattern::forClusterResource (), actions));
166
164
}
167
165
virtual bool run (OperationContext* opCtx,
168
- const string&,
166
+ const std:: string&,
169
167
const BSONObj& cmdObj,
170
168
BSONObjBuilder& result) {
171
169
result.append (" argv" , serverGlobalParams.argvArray );
@@ -195,7 +193,7 @@ class LogRotateCmd : public BasicCommand {
195
193
out->push_back (Privilege (ResourcePattern::forClusterResource (), actions));
196
194
}
197
195
virtual bool run (OperationContext* opCtx,
198
- const string& ns,
196
+ const std:: string& ns,
199
197
const BSONObj& cmdObj,
200
198
BSONObjBuilder& result) {
201
199
bool didRotate = rotateLogs (serverGlobalParams.logRenameOnRotate , serverGlobalParams.logV2 );
@@ -230,22 +228,34 @@ class GetLogCmd : public ErrmsgCommandDeprecated {
230
228
return " { getLog : '*' } OR { getLog : 'global' }" ;
231
229
}
232
230
233
- virtual bool errmsgRun (OperationContext* opCtx,
234
- const string& dbname,
235
- const BSONObj& cmdObj,
236
- string& errmsg,
237
- BSONObjBuilder& result) {
231
+ bool errmsgRun (OperationContext* opCtx,
232
+ const std::string& dbname,
233
+ const BSONObj& cmdObj,
234
+ std::string& errmsg,
235
+ BSONObjBuilder& result) override {
236
+ if (serverGlobalParams.logV2 ) {
237
+ return errmsgRunImpl<logv2::RamLog>(opCtx, dbname, cmdObj, errmsg, result);
238
+ }
239
+ return errmsgRunImpl<RamLog>(opCtx, dbname, cmdObj, errmsg, result);
240
+ }
241
+
242
+ template <typename RamLogType>
243
+ bool errmsgRunImpl (OperationContext* opCtx,
244
+ const std::string& dbname,
245
+ const BSONObj& cmdObj,
246
+ std::string& errmsg,
247
+ BSONObjBuilder& result) {
238
248
BSONElement val = cmdObj.firstElement ();
239
249
if (val.type () != String) {
240
250
uasserted (ErrorCodes::TypeMismatch,
241
251
str::stream () << " Argument to getLog must be of type String; found "
242
252
<< val.toString (false ) << " of type " << typeName (val.type ()));
243
253
}
244
254
245
- string p = val.String ();
255
+ std:: string p = val.String ();
246
256
if (p == " *" ) {
247
- vector<string> names;
248
- RamLog ::getNames (names);
257
+ std:: vector<std:: string> names;
258
+ RamLogType ::getNames (names);
249
259
250
260
BSONArrayBuilder arr;
251
261
for (unsigned i = 0 ; i < names.size (); i++) {
@@ -254,12 +264,12 @@ class GetLogCmd : public ErrmsgCommandDeprecated {
254
264
255
265
result.appendArray (" names" , arr.arr ());
256
266
} else {
257
- RamLog * ramlog = RamLog ::getIfExists (p);
267
+ RamLogType * ramlog = RamLogType ::getIfExists (p);
258
268
if (!ramlog) {
259
269
errmsg = str::stream () << " no RamLog named: " << p;
260
270
return false ;
261
271
}
262
- RamLog ::LineIterator rl (ramlog);
272
+ typename RamLogType ::LineIterator rl (ramlog);
263
273
264
274
result.appendNumber (" totalLinesWritten" , rl.getTotalLinesWritten ());
265
275
@@ -298,7 +308,7 @@ class ClearLogCmd : public BasicCommand {
298
308
}
299
309
300
310
virtual bool run (OperationContext* opCtx,
301
- const string& dbname,
311
+ const std:: string& dbname,
302
312
const BSONObj& cmdObj,
303
313
BSONObjBuilder& result) {
304
314
std::string logName;
@@ -308,9 +318,15 @@ class ClearLogCmd : public BasicCommand {
308
318
if (logName != " global" ) {
309
319
uasserted (ErrorCodes::InvalidOptions, " Only the 'global' log can be cleared" );
310
320
}
311
- RamLog* ramlog = RamLog::getIfExists (logName);
312
- invariant (ramlog);
313
- ramlog->clear ();
321
+ auto clearRamlog = [&](auto * ramlog) {
322
+ invariant (ramlog);
323
+ ramlog->clear ();
324
+ };
325
+ if (serverGlobalParams.logV2 ) {
326
+ clearRamlog (logv2::RamLog::getIfExists (logName));
327
+ } else {
328
+ clearRamlog (RamLog::getIfExists (logName));
329
+ }
314
330
return true ;
315
331
}
316
332
};
0 commit comments