summaryrefslogtreecommitdiff
path: root/db/cloner.cpp
diff options
context:
space:
mode:
authorDwight <dwight@10gen.com>2010-06-30 17:28:57 -0400
committerDwight <dwight@10gen.com>2010-06-30 17:28:57 -0400
commit12663be3f934feaf4443708188f6c8f2aef37f36 (patch)
treefcce0258659dd3b9bc19fc89e009ce3ee4b1637c /db/cloner.cpp
parent6aaa45ae24008f269b6b35a38dbbcaea068569ea (diff)
downloadmongo-12663be3f934feaf4443708188f6c8f2aef37f36.tar.gz
defer creating the id index on a clone until we first insert all the data
Diffstat (limited to 'db/cloner.cpp')
-rw-r--r--db/cloner.cpp23
1 files changed, 22 insertions, 1 deletions
diff --git a/db/cloner.cpp b/db/cloner.cpp
index c23a3d5f32b..a84b238fee5 100644
--- a/db/cloner.cpp
+++ b/db/cloner.cpp
@@ -165,6 +165,9 @@ namespace mongo {
}
}
+ extern bool inDBRepair;
+ void ensureIdIndexForNewNs(const char *ns);
+
bool Cloner::go(const char *masterHost, string& errmsg, const string& fromdb, bool logForRepl, bool slaveOk, bool useReplAuth, bool snapshot) {
massert( 10289 , "useReplAuth is not written to replication log", !useReplAuth || !logForRepl );
@@ -256,19 +259,37 @@ namespace mongo {
assert(p);
string to_name = todb + p;
+ bool wantIdIndex = false;
{
string err;
const char *toname = to_name.c_str();
- userCreateNS(toname, options, err, logForRepl);
+ /* we defer building id index for performance - building it in batch is much faster */
+ userCreateNS(toname, options, err, logForRepl, &wantIdIndex);
}
log(1) << "\t\t cloning " << from_name << " -> " << to_name << endl;
Query q;
if( snapshot )
q.snapshot();
copy(from_name, to_name.c_str(), false, logForRepl, masterSameProcess, slaveOk, q);
+
+ if( wantIdIndex ) {
+ /* we need dropDups to be true as we didn't do a true snapshot and this is before applying oplog operations
+ that occur during the initial sync. inDBRepair makes dropDups be true.
+ */
+ bool old = inDBRepair;
+ try {
+ inDBRepair = true;
+ ensureIdIndexForNewNs(to_name.c_str());
+ }
+ catch(...) {
+ inDBRepair = old;
+ throw;
+ }
+ }
}
// now build the indexes
+
string system_indexes_from = fromdb + ".system.indexes";
string system_indexes_to = todb + ".system.indexes";
/* [dm]: is the ID index sometimes not called "_id_"? There is other code in the system that looks for a "_id" prefix