summaryrefslogtreecommitdiff
path: root/src/mongo/s
diff options
context:
space:
mode:
authorShaun Verch <shaun.verch@10gen.com>2012-11-30 17:08:14 -0800
committerShaun Verch <shaun.verch@10gen.com>2012-12-18 11:39:20 -0500
commit9c07a059fedfe534c890a59d13e0fc6536fd8ee8 (patch)
tree43f8e2dec2bc4741719a2d7fcc47340cabe58c97 /src/mongo/s
parent6cd748eccdcea47c6413a144f921cd8ec9dfcff4 (diff)
downloadmongo-9c07a059fedfe534c890a59d13e0fc6536fd8ee8.tar.gz
SERVER-939 Changed CollectionFields to CollectionType
Diffstat (limited to 'src/mongo/s')
-rw-r--r--src/mongo/s/balance.cpp13
-rw-r--r--src/mongo/s/chunk.cpp22
-rw-r--r--src/mongo/s/chunk.h6
-rw-r--r--src/mongo/s/cluster_constants.cpp10
-rw-r--r--src/mongo/s/cluster_constants.h17
-rw-r--r--src/mongo/s/config.cpp21
-rw-r--r--src/mongo/s/d_chunk_manager.cpp5
-rw-r--r--src/mongo/s/grid.cpp5
8 files changed, 40 insertions, 59 deletions
diff --git a/src/mongo/s/balance.cpp b/src/mongo/s/balance.cpp
index 3eaabd26c0c..de576734da7 100644
--- a/src/mongo/s/balance.cpp
+++ b/src/mongo/s/balance.cpp
@@ -28,6 +28,7 @@
#include "mongo/s/server.h"
#include "mongo/s/shard.h"
#include "mongo/s/type_chunk.h"
+#include "mongo/s/type_collection.h"
namespace mongo {
@@ -155,18 +156,18 @@ namespace mongo {
// the ShardsNS::collections collection
//
- auto_ptr<DBClientCursor> cursor = conn.query(ConfigNS::collection, BSONObj());
+ auto_ptr<DBClientCursor> cursor = conn.query(CollectionType::ConfigNS, BSONObj());
vector< string > collections;
while ( cursor->more() ) {
BSONObj col = cursor->nextSafe();
// sharded collections will have a shard "key".
- if ( ! col[CollectionFields::key()].eoo() &&
- ! col[CollectionFields::noBalance()].trueValue() ){
- collections.push_back( col[CollectionFields::name()].String() );
+ if ( ! col[CollectionType::keyPattern()].eoo() &&
+ ! col[CollectionType::noBalance()].trueValue() ){
+ collections.push_back( col[CollectionType::ns()].String() );
}
- else if( col[CollectionFields::noBalance()].trueValue() ){
- LOG(1) << "not balancing collection " << col[CollectionFields::name()].String()
+ else if( col[CollectionType::noBalance()].trueValue() ){
+ LOG(1) << "not balancing collection " << col[CollectionType::ns()].String()
<< ", explicitly disabled" << endl;
}
diff --git a/src/mongo/s/chunk.cpp b/src/mongo/s/chunk.cpp
index 8ae0e4b6db7..57cce2d3611 100644
--- a/src/mongo/s/chunk.cpp
+++ b/src/mongo/s/chunk.cpp
@@ -18,18 +18,20 @@
#include "pch.h"
+#include "mongo/s/chunk.h"
+
#include "mongo/client/connpool.h"
#include "mongo/client/dbclientcursor.h"
#include "mongo/db/queryutil.h"
#include "mongo/platform/random.h"
-#include "mongo/s/chunk.h"
#include "mongo/s/chunk_diff.h"
#include "mongo/s/client_info.h"
#include "mongo/s/config.h"
#include "mongo/s/cursors.h"
#include "mongo/s/grid.h"
-#include "mongo/util/concurrency/ticketholder.h"
#include "mongo/s/strategy.h"
+#include "mongo/s/type_collection.h"
+#include "mongo/util/concurrency/ticketholder.h"
#include "mongo/util/startup_test.h"
#include "mongo/util/timer.h"
@@ -596,13 +598,13 @@ namespace mongo {
ChunkManager::ChunkManager( const BSONObj& collDoc ) :
// Need the ns early, to construct the lock
// TODO: Construct lock on demand? Not sure why we need to keep it around
- _ns(collDoc[CollectionFields::name()].type() == String ?
- collDoc[CollectionFields::name()].String() :
+ _ns(collDoc[CollectionType::ns()].type() == String ?
+ collDoc[CollectionType::ns()].String() :
""),
- _key(collDoc[CollectionFields::key()].type() == Object ?
- collDoc[CollectionFields::key()].Obj().getOwned() :
+ _key(collDoc[CollectionType::keyPattern()].type() == Object ?
+ collDoc[CollectionType::keyPattern()].Obj().getOwned() :
BSONObj()),
- _unique(collDoc[CollectionFields::unique()].trueValue()),
+ _unique(collDoc[CollectionType::unique()].trueValue()),
_chunkRanges(),
_mutex("ChunkManager"),
// The shard versioning mechanism hinges on keeping track of the number of times we reloaded ChunkManager's.
@@ -1292,6 +1294,12 @@ namespace mongo {
return _version;
}
+ void ChunkManager::getInfo( BSONObjBuilder& b ) const {
+ b.append(CollectionType::keyPattern(), _key.key());
+ b.appendBool(CollectionType::unique(), _unique);
+ _version.addEpochToBSON(b, CollectionType::DEPRECATED_lastmod());
+ }
+
string ChunkManager::toString() const {
stringstream ss;
ss << "ChunkManager: " << _ns << " key:" << _key.toString() << '\n';
diff --git a/src/mongo/s/chunk.h b/src/mongo/s/chunk.h
index 45a5d5db5b3..2dc604df431 100644
--- a/src/mongo/s/chunk.h
+++ b/src/mongo/s/chunk.h
@@ -414,11 +414,7 @@ namespace mongo {
ShardChunkVersion getVersion( const Shard& shard ) const;
ShardChunkVersion getVersion() const;
- void getInfo( BSONObjBuilder& b ) const {
- b.append(CollectionFields::key(), _key.key());
- b.appendBool(CollectionFields::unique(), _unique);
- _version.addEpochToBSON(b, CollectionFields::lastmod());
- }
+ void getInfo( BSONObjBuilder& b ) const;
/**
* @param me - so i don't get deleted before i'm done
diff --git a/src/mongo/s/cluster_constants.cpp b/src/mongo/s/cluster_constants.cpp
index 28a09ed06b7..7f1b0e40f47 100644
--- a/src/mongo/s/cluster_constants.cpp
+++ b/src/mongo/s/cluster_constants.cpp
@@ -28,16 +28,6 @@ namespace mongo {
BSONField<bool> DatabaseFields::NEW_draining("draining");
BSONField<bool> DatabaseFields::NEW_scatterCollections("scatterCollections");
- const string ConfigNS::collection = "config.collections";
- BSONField<string> CollectionFields::name("_id");
- BSONField<string> CollectionFields::shard("shard");
- BSONField<BSONObj> CollectionFields::key("key");
- BSONField<bool> CollectionFields::unique("unique");
- BSONField<Date_t> CollectionFields::lastmod("lastmod");
- BSONField<bool> CollectionFields::dropped("dropped");
- BSONField<bool> CollectionFields::noBalance("noBalance");
- BSONField<OID> CollectionFields::epoch("lastmodEpoch");
-
const string ConfigNS::tag = "config.tags";
BSONField<string> TagFields::ns("ns");
BSONField<string> TagFields::tag("tag");
diff --git a/src/mongo/s/cluster_constants.h b/src/mongo/s/cluster_constants.h
index aaccb5bb675..bafe4534b1b 100644
--- a/src/mongo/s/cluster_constants.h
+++ b/src/mongo/s/cluster_constants.h
@@ -29,10 +29,7 @@ namespace mongo {
* ConfigNS holds the names for all the metadata collections stored in a config server.
*/
struct ConfigNS {
- static const string shard;
static const string database;
- static const string collection;
- static const string chunk;
static const string tag;
static const string mongos;
static const string settings;
@@ -61,20 +58,6 @@ namespace mongo {
};
/**
- * CollectionFields holds all the field names and types for the collections collection.
- */
- struct CollectionFields {
- static BSONField<string> name; // collection's name
- static BSONField<string> shard; // primary, if not sharded
- static BSONField<BSONObj> key; // sharding key, if sharded
- static BSONField<bool> unique; // sharding key unique?
- static BSONField<Date_t> lastmod; // when collecation was created
- static BSONField<bool> dropped; // logical deletion
- static BSONField<bool> noBalance; // true if balancing is disabled
- static BSONField<OID> epoch; // Epoch of collection
- };
-
- /**
* TagFields holds all the field names and types for the tags collection.
*/
struct TagFields {
diff --git a/src/mongo/s/config.cpp b/src/mongo/s/config.cpp
index bc6d627ce44..b593b34454b 100644
--- a/src/mongo/s/config.cpp
+++ b/src/mongo/s/config.cpp
@@ -30,6 +30,7 @@
#include "mongo/s/grid.h"
#include "mongo/s/server.h"
#include "mongo/s/type_chunk.h"
+#include "mongo/s/type_collection.h"
#include "mongo/s/type_shard.h"
#include "mongo/util/net/message.h"
#include "mongo/util/stringutils.h"
@@ -45,9 +46,9 @@ namespace mongo {
DBConfig::CollectionInfo::CollectionInfo( const BSONObj& in ) {
_dirty = false;
- _dropped = in[CollectionFields::dropped()].trueValue();
+ _dropped = in[CollectionType::dropped()].trueValue();
- if ( in[CollectionFields::key()].isABSONObj() ) {
+ if ( in[CollectionType::keyPattern()].isABSONObj() ) {
shard( new ChunkManager( in ) );
}
@@ -89,13 +90,13 @@ namespace mongo {
BSONObj key = BSON( "_id" << ns );
BSONObjBuilder val;
- val.append(CollectionFields::name(), ns);
- val.appendDate(CollectionFields::lastmod(), time(0));
- val.appendBool(CollectionFields::dropped(), _dropped);
+ val.append(CollectionType::ns(), ns);
+ val.appendDate(CollectionType::DEPRECATED_lastmod(), time(0));
+ val.appendBool(CollectionType::dropped(), _dropped);
if ( _cm )
_cm->getInfo( val );
- conn->update(ConfigNS::collection, key, val.obj(), true);
+ conn->update(CollectionType::ConfigNS, key, val.obj(), true);
string err = conn->getLastError();
uassert( 13473 , (string)"failed to save collection (" + ns + "): " + err , err.size() == 0 );
@@ -464,20 +465,20 @@ namespace mongo {
unserialize( dbObj );
BSONObjBuilder b;
- b.appendRegex(CollectionFields::name(),
+ b.appendRegex(CollectionType::ns(),
(string)"^" + pcrecpp::RE::QuoteMeta( _name ) + "\\." );
int numCollsErased = 0;
int numCollsSharded = 0;
- auto_ptr<DBClientCursor> cursor = conn->get()->query(ConfigNS::collection, b.obj());
+ auto_ptr<DBClientCursor> cursor = conn->get()->query(CollectionType::ConfigNS, b.obj());
verify( cursor.get() );
while ( cursor->more() ) {
BSONObj collObj = cursor->next();
- string collName = collObj[CollectionFields::name()].String();
+ string collName = collObj[CollectionType::ns()].String();
- if( collObj[CollectionFields::dropped()].trueValue() ){
+ if( collObj[CollectionType::dropped()].trueValue() ){
_collections.erase( collName );
numCollsErased++;
}
diff --git a/src/mongo/s/d_chunk_manager.cpp b/src/mongo/s/d_chunk_manager.cpp
index c30c16632cf..abf267f19cb 100644
--- a/src/mongo/s/d_chunk_manager.cpp
+++ b/src/mongo/s/d_chunk_manager.cpp
@@ -26,6 +26,7 @@
#include "mongo/db/instance.h"
#include "mongo/s/chunk_diff.h"
#include "mongo/s/type_chunk.h"
+#include "mongo/s/type_collection.h"
namespace mongo {
@@ -88,14 +89,14 @@ namespace mongo {
}
// get this collection's sharding key
- BSONObj collectionDoc = conn->findOne(ConfigNS::collection, BSON(CollectionFields::name(ns)));
+ BSONObj collectionDoc = conn->findOne(CollectionType::ConfigNS, BSON(CollectionType::ns(ns)));
if( collectionDoc.isEmpty() ){
warning() << ns << " does not exist as a sharded collection" << endl;
return;
}
- if( collectionDoc[CollectionFields::dropped()].Bool() ){
+ if( collectionDoc[CollectionType::dropped()].Bool() ){
warning() << ns << " was dropped. Re-shard collection first." << endl;
return;
}
diff --git a/src/mongo/s/grid.cpp b/src/mongo/s/grid.cpp
index d4b98cc4fc0..49b7a3f52f6 100644
--- a/src/mongo/s/grid.cpp
+++ b/src/mongo/s/grid.cpp
@@ -27,6 +27,7 @@
#include "mongo/s/cluster_constants.h"
#include "mongo/s/grid.h"
#include "mongo/s/shard.h"
+#include "mongo/s/type_collection.h"
#include "mongo/s/type_shard.h"
#include "mongo/util/startup_test.h"
#include "mongo/util/stringutils.h"
@@ -466,8 +467,8 @@ namespace mongo {
// look for the stop balancer marker
balancerDoc = conn->get()->findOne( ConfigNS::settings,
BSON( SettingsFields::key("balancer") ) );
- if( ns.size() > 0 ) collDoc = conn->get()->findOne(ConfigNS::collection,
- BSON( CollectionFields::name(ns)));
+ if( ns.size() > 0 ) collDoc = conn->get()->findOne(CollectionType::ConfigNS,
+ BSON( CollectionType::ns(ns)));
conn->done();
}
catch( DBException& e ){