summaryrefslogtreecommitdiff
path: root/src/mongo/s/config.cpp
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2015-04-13 15:47:20 -0400
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2015-04-21 14:31:46 -0400
commit4777fb87f36dc4c1f808570490eab01a1c12095f (patch)
tree34e6d877daf775d3d1a4d6006b82a2b6eabe61e2 /src/mongo/s/config.cpp
parent1e0624eb98e4c5609ddf86c8f14bdea68bce9f3b (diff)
downloadmongo-4777fb87f36dc4c1f808570490eab01a1c12095f.tar.gz
SERVER-18024 Move collection metadata loading under the catalog manager
Cleans up the CollectionType parsing code and moves all the collection metadata retrieval logic under the catalog manager. Also moves type_collection.* under the catalog manager library.
Diffstat (limited to 'src/mongo/s/config.cpp')
-rw-r--r--src/mongo/s/config.cpp87
1 files changed, 28 insertions, 59 deletions
diff --git a/src/mongo/s/config.cpp b/src/mongo/s/config.cpp
index 501012e6375..66444be1d10 100644
--- a/src/mongo/s/config.cpp
+++ b/src/mongo/s/config.cpp
@@ -43,6 +43,7 @@
#include "mongo/db/write_concern.h"
#include "mongo/s/catalog/catalog_cache.h"
#include "mongo/s/catalog/catalog_manager.h"
+#include "mongo/s/catalog/type_collection.h"
#include "mongo/s/catalog/type_chunk.h"
#include "mongo/s/catalog/type_shard.h"
#include "mongo/s/chunk_manager.h"
@@ -51,7 +52,6 @@
#include "mongo/s/cluster_write.h"
#include "mongo/s/grid.h"
#include "mongo/s/server.h"
-#include "mongo/s/type_collection.h"
#include "mongo/s/type_database.h"
#include "mongo/s/type_locks.h"
#include "mongo/s/type_lockpings.h"
@@ -76,14 +76,10 @@ namespace mongo {
Shard Shard::EMPTY;
- CollectionInfo::CollectionInfo(const BSONObj& in) {
- _dirty = false;
- _dropped = in[CollectionType::dropped()].trueValue();
-
- if (in[CollectionType::keyPattern()].isABSONObj()) {
- shard(new ChunkManager(in));
- }
+ CollectionInfo::CollectionInfo(const CollectionType& coll) {
+ _dropped = coll.getDropped();
+ shard(new ChunkManager(coll));
_dirty = false;
}
@@ -133,33 +129,24 @@ namespace mongo {
}
void CollectionInfo::save(const string& ns) {
- BSONObj key = BSON( "_id" << ns );
-
- BSONObjBuilder val;
- val.append(CollectionType::ns(), ns);
- val.appendDate(CollectionType::DEPRECATED_lastmod(), jsTime());
- val.appendBool(CollectionType::dropped(), _dropped);
- if ( _cm ) {
- // This also appends the lastmodEpoch.
- _cm->getInfo( val );
+ CollectionType coll;
+ coll.setNs(ns);
+
+ if (_cm) {
+ invariant(!_dropped);
+ coll.setEpoch(_cm->getVersion().epoch());
+ coll.setUpdatedAt(_cm->getVersion().toLong());
+ coll.setKeyPattern(_cm->getShardKeyPattern().toBSON());
+ coll.setUnique(_cm->isUnique());
}
else {
- // lastmodEpoch is a required field so we also need to do it here.
- val.append(CollectionType::DEPRECATED_lastmodEpoch(), ChunkVersion::DROPPED().epoch());
- }
-
- Status result = grid.catalogManager()->update(CollectionType::ConfigNS,
- key,
- val.obj(),
- true, // upsert
- false, // multi
- NULL);
- if (!result.isOK()) {
- uasserted(13473,
- str::stream() << "failed to save collection (" << ns << "): "
- << result.reason());
+ invariant(_dropped);
+ coll.setDropped(true);
+ coll.setEpoch(ChunkVersion::DROPPED().epoch());
+ coll.setUpdatedAt(jsTime());
}
+ uassertStatusOK(grid.catalogManager()->updateCollection(ns, coll));
_dirty = false;
}
@@ -471,43 +458,25 @@ namespace mongo {
_shardingEnabled = dbt.getSharded();
// Load all collections
- BSONObjBuilder b;
- b.appendRegex(CollectionType::ns(),
- (string)"^" + pcrecpp::RE::QuoteMeta( _name ) + "\\." );
+ vector<CollectionType> collections;
+ uassertStatusOK(grid.catalogManager()->getCollections(&_name, &collections));
int numCollsErased = 0;
int numCollsSharded = 0;
- ScopedDbConnection conn(configServer.modelServer(), 30.0);
- auto_ptr<DBClientCursor> cursor = conn->query(CollectionType::ConfigNS, b.obj());
- verify( cursor.get() );
- while ( cursor->more() ) {
-
- BSONObj collObj = cursor->next();
- string collName = collObj[CollectionType::ns()].String();
-
- if( collObj[CollectionType::dropped()].trueValue() ){
- _collections.erase( collName );
- numCollsErased++;
- }
- else if( !collObj[CollectionType::primary()].eoo() ){
- // For future compatibility, explicitly ignore any collection with the
- // "primary" field set.
-
- // Erased in case it was previously sharded, dropped, then init'd as unsharded
- _collections.erase( collName );
+ for (const auto& coll : collections) {
+ if (coll.getDropped()) {
+ _collections.erase(coll.getNs());
numCollsErased++;
}
- else{
- _collections[ collName ] = CollectionInfo( collObj );
- if( _collections[ collName ].isSharded() ) numCollsSharded++;
+ else {
+ _collections[coll.getNs()] = CollectionInfo(coll);
+ numCollsSharded++;
}
}
- LOG(2) << "found " << numCollsErased << " dropped collections and "
- << numCollsSharded << " sharded collections for database " << _name << endl;
-
- conn.done();
+ LOG(2) << "found " << numCollsSharded << " collections left and "
+ << numCollsErased << " collections dropped for database " << _name;
return true;
}