summaryrefslogtreecommitdiff
path: root/db/cloner.cpp
diff options
context:
space:
mode:
authorAaron Staple <aaron@10gen.com>2009-07-30 03:22:18 -0400
committerAaron Staple <aaron@10gen.com>2009-07-30 03:22:18 -0400
commit7fd282b98989ac84562549d77a5d2c4f1fbb960b (patch)
treeb2bf2859c69b875573daaad38adb583482bb46ee /db/cloner.cpp
parent3a337ff121656c47ff665a5c18f9a9de349d505e (diff)
parentce2640bfae3ca4e90dd705da768350a6adfc7552 (diff)
downloadmongo-7fd282b98989ac84562549d77a5d2c4f1fbb960b.tar.gz
Merge branch 'master' of git@github.com:mongodb/mongo
Diffstat (limited to 'db/cloner.cpp')
-rw-r--r--db/cloner.cpp109
1 files changed, 60 insertions, 49 deletions
diff --git a/db/cloner.cpp b/db/cloner.cpp
index 0f86c2e7e50..b7279acc3e4 100644
--- a/db/cloner.cpp
+++ b/db/cloner.cpp
@@ -91,7 +91,7 @@ namespace mongo {
auto_ptr<DBClientCursor> c;
{
dbtemprelease r;
- c = conn->query( from_collection, query, 0, 0, 0, slaveOk ? Option_SlaveOk : 0 );
+ c = conn->query( from_collection, query, 0, 0, 0, Option_NoCursorTimeout | ( slaveOk ? Option_SlaveOk : 0 ) );
}
assert( c.get() );
long long n = 0;
@@ -155,61 +155,71 @@ namespace mongo {
or just wait until we get rid of global lock anyway.
*/
string ns = fromdb + ".system.namespaces";
- auto_ptr<DBClientCursor> c;
- {
+ list<BSONObj> toClone;
+ {
dbtemprelease r;
- if ( !masterSameProcess ) {
- auto_ptr< DBClientConnection > c( new DBClientConnection() );
- if ( !c->connect( masterHost, errmsg ) )
- return false;
- if( !replAuthenticate(c.get()) )
- return false;
-
- conn = c;
- } else {
- conn.reset( new DBDirectClient() );
- }
- c = conn->query( ns.c_str(), BSONObj(), 0, 0, 0, slaveOk ? Option_SlaveOk : 0 );
- }
- if ( c.get() == 0 ) {
- errmsg = "query failed " + ns;
- return false;
+
+ auto_ptr<DBClientCursor> c;
+ {
+ if ( !masterSameProcess ) {
+ auto_ptr< DBClientConnection > c( new DBClientConnection() );
+ if ( !c->connect( masterHost, errmsg ) )
+ return false;
+ if( !replAuthenticate(c.get()) )
+ return false;
+
+ conn = c;
+ } else {
+ conn.reset( new DBDirectClient() );
+ }
+ c = conn->query( ns.c_str(), BSONObj(), 0, 0, 0, slaveOk ? Option_SlaveOk : 0 );
+ }
+
+ if ( c.get() == 0 ) {
+ errmsg = "query failed " + ns;
+ return false;
+ }
+
+ while ( c->more() ){
+ BSONObj collection = c->next();
+
+ log(2) << "\t cloner got " << collection << endl;
+
+ BSONElement e = collection.findElement("name");
+ if ( e.eoo() ) {
+ string s = "bad system.namespaces object " + collection.toString();
+ massert(s.c_str(), false);
+ }
+ assert( !e.eoo() );
+ assert( e.type() == String );
+ const char *from_name = e.valuestr();
+
+ if( strstr(from_name, ".system.") ) {
+ /* system.users is cloned -- but nothing else from system. */
+ if( strstr(from_name, ".system.users") == 0 ){
+ log(2) << "\t\t not cloning because system collection" << endl;
+ continue;
+ }
+ }
+ else if( strchr(from_name, '$') ) {
+ // don't clone index namespaces -- we take care of those separately below.
+ log(2) << "\t\t not cloning because has $ " << endl;
+ continue;
+ }
+
+ toClone.push_back( collection.getOwned() );
+ }
}
- while ( 1 ) {
+ for ( list<BSONObj>::iterator i=toClone.begin(); i != toClone.end(); i++ ){
{
dbtemprelease r;
- if ( !c->more() )
- break;
- }
- BSONObj collection = c->next();
- BSONElement e = collection.findElement("name");
- if ( e.eoo() ) {
- string s = "bad system.namespaces object " + collection.toString();
-
- /* temp
- out() << masterHost << endl;
- out() << ns << endl;
- out() << e.toString() << endl;
- exit(1);*/
-
- massert(s.c_str(), false);
- }
- assert( !e.eoo() );
- assert( e.type() == String );
- const char *from_name = e.valuestr();
-
- if( strstr(from_name, ".system.") ) {
- /* system.users is cloned -- but nothing else from system. */
- if( strstr(from_name, ".system.users") == 0 )
- continue;
- }
- else if( strchr(from_name, '$') ) {
- // don't clone index namespaces -- we take care of those separately below.
- continue;
}
+ BSONObj collection = *i;
+ log(2) << " really will clone: " << collection << endl;
+ const char * from_name = collection["name"].valuestr();
BSONObj options = collection.getObjectField("options");
-
+
/* change name "<fromdb>.collection" -> <todb>.collection */
const char *p = strchr(from_name, '.');
assert(p);
@@ -229,6 +239,7 @@ namespace mongo {
if ( strstr(toname, "._chunks") )
ensureHaveIdIndex(toname);
}
+ log(1) << "\t\t cloning " << from_name << " -> " << to_name << endl;
copy(from_name, to_name.c_str(), false, logForRepl, masterSameProcess, slaveOk);
}