diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2015-03-20 15:48:49 -0400 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2015-03-24 15:04:58 -0400 |
commit | e23b1c0eba1aa58e22af068e8499c3b018693749 (patch) | |
tree | 8ffb36ee95083da4bd420d6579eaf12ef53422b6 /src/mongo/s/config.cpp | |
parent | 6d33c3637e073c83138919a5472b181c65a48d08 (diff) | |
download | mongo-e23b1c0eba1aa58e22af068e8499c3b018693749.tar.gz |
SERVER-17690 Move sharding change logging operations to catalog manager
So they can be abstracted behind the interface and not go through a config
server connection directly.
Diffstat (limited to 'src/mongo/s/config.cpp')
-rw-r--r-- | src/mongo/s/config.cpp | 68 |
1 files changed, 10 insertions, 58 deletions
diff --git a/src/mongo/s/config.cpp b/src/mongo/s/config.cpp index 89c6a60a362..04493ad098d 100644 --- a/src/mongo/s/config.cpp +++ b/src/mongo/s/config.cpp @@ -50,7 +50,6 @@ #include "mongo/s/cluster_write.h" #include "mongo/s/grid.h" #include "mongo/s/server.h" -#include "mongo/s/type_changelog.h" #include "mongo/s/type_chunk.h" #include "mongo/s/type_collection.h" #include "mongo/s/type_database.h" @@ -266,7 +265,10 @@ namespace mongo { collectionDetail.append("initShards", initialShards); collectionDetail.append("numChunks", (int)(initPoints->size() + 1)); - configServer.logChange("shardCollection.start", ns, collectionDetail.obj()); + grid.catalogManager()->logChange(NULL, + "shardCollection.start", + ns, + collectionDetail.obj()); ChunkManager* cm = new ChunkManager( ns, fieldsAndOrder, unique ); cm->createFirstChunks(configServer.getPrimary().getConnString(), @@ -306,7 +308,8 @@ namespace mongo { // Record finish in changelog BSONObjBuilder finishDetail; finishDetail.append("version", manager->getVersion().toString()); - configServer.logChange("shardCollection", ns, finishDetail.obj()); + + grid.catalogManager()->logChange(NULL, "shardCollection", ns, finishDetail.obj()); return manager; } @@ -646,7 +649,7 @@ namespace mongo { return _load(); } - bool DBConfig::dropDatabase( string& errmsg ) { + bool DBConfig::dropDatabase(string& errmsg) { /** * 1) make sure everything is up * 2) update config server @@ -656,7 +659,7 @@ namespace mongo { */ log() << "DBConfig::dropDatabase: " << _name << endl; - configServer.logChange( "dropDatabase.start" , _name , BSONObj() ); + grid.catalogManager()->logChange(NULL, "dropDatabase.start", _name, BSONObj()); // 1 if (!configServer.allUp(false, errmsg)) { @@ -725,7 +728,8 @@ namespace mongo { LOG(1) << "\t dropped primary db for: " << _name << endl; - configServer.logChange( "dropDatabase" , _name , BSONObj() ); + grid.catalogManager()->logChange(NULL, "dropDatabase", _name, BSONObj()); + return true; } @@ -1223,58 +1227,6 @@ namespace mongo { return name; } - /* must never throw */ - void ConfigServer::logChange( const string& what , const string& ns , const BSONObj& detail ) { - string changeID; - - try { - // get this entry's ID so we can use on the exception code path too - stringstream id; - id << getHostNameCached() << "-" << terseCurrentTime() << "-" << OID::gen(); - changeID = id.str(); - - // send a copy of the message to the log in case it doesn't manage to reach config.changelog - Client* c = currentClient.get(); - BSONObj msg = BSON( ChangelogType::changeID(changeID) << - ChangelogType::server(getHostNameCached()) << - ChangelogType::clientAddr((c ? c->clientAddress(true) : "N/A")) << - ChangelogType::time(jsTime()) << - ChangelogType::what(what) << - ChangelogType::ns(ns) << - ChangelogType::details(detail) ); - log() << "about to log metadata event: " << msg << endl; - - verify( _primary.ok() ); - - ScopedDbConnection conn(_primary.getConnString(), 30.0); - - static bool createdCapped = false; - if ( ! createdCapped ) { - try { - conn->createCollection( ChangelogType::ConfigNS , 1024 * 1024 * 10 , true ); - } - catch ( UserException& e ) { - LOG(1) << "couldn't create changelog (like race condition): " << e << endl; - // don't care - } - createdCapped = true; - } - - conn.done(); - - Status result = grid.catalogManager()->insert(ChangelogType::ConfigNS, msg, NULL); - if (!result.isOK()) { - log() << "Error encountered while logging config change with ID: " << changeID - << result.reason(); - } - } - - catch ( std::exception& e ) { - // if we got here, it means the config change is only in the log; it didn't make it to config.changelog - log() << "not logging config change: " << changeID << " " << e.what() << endl; - } - } - void ConfigServer::replicaSetChange(const string& setName, const string& newConnectionString) { // This is run in it's own thread. Exceptions escaping would result in a call to terminate. Client::initThread("replSetChange"); |