summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSpencer T Brody <spencer@mongodb.com>2014-03-19 16:40:49 -0400
committerSpencer T Brody <spencer@mongodb.com>2014-03-19 17:13:45 -0400
commit21426b3b8109fafb7fae997021cbd0357c968111 (patch)
treeab98b2b9f644b3ed17fbb099fc633cbcf1013791
parent11e8a1d1b7d58b710a8a6f59e507dafcec01f247 (diff)
downloadmongo-21426b3b8109fafb7fae997021cbd0357c968111.tar.gz
SERVER-13265 Fix race condition in mongorestore startup
(cherry picked from commit 47ce3aebb48d9b9191584e3173774e29a0a3808c)
-rw-r--r--src/mongo/tools/restore.cpp18
-rw-r--r--src/mongo/tools/tool.cpp10
2 files changed, 19 insertions, 9 deletions
diff --git a/src/mongo/tools/restore.cpp b/src/mongo/tools/restore.cpp
index 16f1ae5694c..e1158292c95 100644
--- a/src/mongo/tools/restore.cpp
+++ b/src/mongo/tools/restore.cpp
@@ -36,6 +36,7 @@
#include <fstream>
#include <set>
+#include "mongo/base/init.h"
#include "mongo/bson/util/bson_extract.h"
#include "mongo/client/auth_helpers.h"
#include "mongo/client/dbclientcursor.h"
@@ -58,6 +59,17 @@ namespace {
const char* OPLOG_SENTINEL = "$oplog"; // compare by ptr not strcmp
}
+MONGO_INITIALIZER_WITH_PREREQUISITES(RestoreAuthExternalState, ("ToolAuthExternalState"))(
+ InitializerContext* context) {
+ // Give restore the mongod implementation of AuthorizationManager so that it can run
+ // the _mergeAuthzCollections command directly against the data files
+ clearGlobalAuthorizationManager();
+ setGlobalAuthorizationManager(new AuthorizationManager(
+ new AuthzManagerExternalStateMongod()));
+
+ return Status::OK();
+}
+
class Restore : public BSONTool {
public:
@@ -101,12 +113,6 @@ public:
virtual int doRun() {
- // Give restore the mongod implementation of AuthorizationManager so that it can run
- // the _mergeAuthzCollections command directly against the data files
- clearGlobalAuthorizationManager();
- setGlobalAuthorizationManager(new AuthorizationManager(
- new AuthzManagerExternalStateMongod()));
-
boost::filesystem::path root = mongoRestoreGlobalParams.restoreDirectory;
// check if we're actually talking to a machine that can write
diff --git a/src/mongo/tools/tool.cpp b/src/mongo/tools/tool.cpp
index 5fe4dde1735..c5e63723bf9 100644
--- a/src/mongo/tools/tool.cpp
+++ b/src/mongo/tools/tool.cpp
@@ -35,6 +35,7 @@
#include <iostream>
#include "mongo/base/initializer.h"
+#include "mongo/base/init.h"
#include "mongo/client/dbclient_rs.h"
#include "mongo/client/sasl_client_authenticate.h"
#include "mongo/db/auth/authorization_manager.h"
@@ -65,11 +66,14 @@ namespace mongo {
delete _conn;
}
- int Tool::main( int argc , char ** argv, char ** envp ) {
- static StaticObserver staticObserver;
-
+ MONGO_INITIALIZER(ToolAuthExternalState)(InitializerContext*) {
setGlobalAuthorizationManager(new AuthorizationManager(
new AuthzManagerExternalStateMock()));
+ return Status::OK();
+ }
+
+ int Tool::main( int argc , char ** argv, char ** envp ) {
+ static StaticObserver staticObserver;
mongo::runGlobalInitializersOrDie(argc, argv, envp);