summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/cloner.cpp128
-rw-r--r--src/mongo/db/cloner.h33
-rw-r--r--src/mongo/db/commands/clone.cpp1
-rw-r--r--src/mongo/db/commands/clone_collection.cpp2
-rw-r--r--src/mongo/db/commands/copydb.cpp2
-rw-r--r--src/mongo/db/repl/master_slave.cpp2
-rw-r--r--src/mongo/db/repl/rollback_source_impl.cpp10
-rw-r--r--src/mongo/db/repl/rs_initialsync.cpp2
8 files changed, 49 insertions, 131 deletions
diff --git a/src/mongo/db/cloner.cpp b/src/mongo/db/cloner.cpp
index b3b128b89ab..eec4a83e1db 100644
--- a/src/mongo/db/cloner.cpp
+++ b/src/mongo/db/cloner.cpp
@@ -141,9 +141,7 @@ struct Cloner::Fun {
<< "]",
!createdCollection);
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
- if (_mayBeInterrupted) {
- txn->checkForInterrupt();
- }
+ txn->checkForInterrupt();
WriteUnitOfWork wunit(txn);
Status s = userCreateNS(txn, db, to_collection.toString(), from_options, false);
@@ -163,41 +161,36 @@ struct Cloner::Fun {
log() << "clone " << to_collection << ' ' << numSeen << endl;
lastLog = now;
}
+ txn->checkForInterrupt();
- if (_mayBeInterrupted) {
- txn->checkForInterrupt();
- }
+ scopedXact.reset();
+ globalWriteLock.reset();
- if (_mayYield) {
- scopedXact.reset();
- globalWriteLock.reset();
+ CurOp::get(txn)->yielded();
- CurOp::get(txn)->yielded();
+ scopedXact.reset(new ScopedTransaction(txn, MODE_X));
+ globalWriteLock.reset(new Lock::GlobalWrite(txn->lockState()));
- scopedXact.reset(new ScopedTransaction(txn, MODE_X));
- globalWriteLock.reset(new Lock::GlobalWrite(txn->lockState()));
+ // Check if everything is still all right.
+ if (txn->writesAreReplicated()) {
+ uassert(
+ 28592,
+ str::stream() << "Cannot write to ns: " << to_collection.ns()
+ << " after yielding",
+ repl::getGlobalReplicationCoordinator()->canAcceptWritesFor(to_collection));
+ }
- // Check if everything is still all right.
- if (txn->writesAreReplicated()) {
- uassert(28592,
- str::stream() << "Cannot write to ns: " << to_collection.ns()
- << " after yielding",
- repl::getGlobalReplicationCoordinator()->canAcceptWritesFor(
- to_collection));
- }
+ // TODO: SERVER-16598 abort if original db or collection is gone.
+ db = dbHolder().get(txn, _dbName);
+ uassert(28593,
+ str::stream() << "Database " << _dbName << " dropped while cloning",
+ db != NULL);
- // TODO: SERVER-16598 abort if original db or collection is gone.
- db = dbHolder().get(txn, _dbName);
- uassert(28593,
- str::stream() << "Database " << _dbName << " dropped while cloning",
- db != NULL);
-
- collection = db->getCollection(to_collection);
- uassert(28594,
- str::stream() << "Collection " << to_collection.ns()
- << " dropped while cloning",
- collection != NULL);
- }
+ collection = db->getCollection(to_collection);
+ uassert(28594,
+ str::stream() << "Collection " << to_collection.ns()
+ << " dropped while cloning",
+ collection != NULL);
}
BSONObj tmp = i.nextSafe();
@@ -218,9 +211,7 @@ struct Cloner::Fun {
verify(collection);
++numSeen;
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
- if (_mayBeInterrupted) {
- txn->checkForInterrupt();
- }
+ txn->checkForInterrupt();
WriteUnitOfWork wunit(txn);
@@ -250,8 +241,6 @@ struct Cloner::Fun {
BSONObj from_options;
NamespaceString to_collection;
time_t saveLast;
- bool _mayYield;
- bool _mayBeInterrupted;
};
/* copy the specified collection
@@ -263,8 +252,6 @@ void Cloner::copy(OperationContext* txn,
const NamespaceString& to_collection,
bool masterSameProcess,
bool slaveOk,
- bool mayYield,
- bool mayBeInterrupted,
Query query) {
LOG(2) << "\t\tcloning collection " << from_collection << " to " << to_collection << " on "
<< _conn->getServerAddress() << " with filter " << query.toString() << endl;
@@ -275,8 +262,6 @@ void Cloner::copy(OperationContext* txn,
f.from_options = from_opts;
f.to_collection = to_collection;
f.saveLast = time(0);
- f._mayYield = mayYield;
- f._mayBeInterrupted = mayBeInterrupted;
int options = QueryOption_NoCursorTimeout | (slaveOk ? QueryOption_SlaveOk : 0);
{
@@ -301,9 +286,7 @@ void Cloner::copyIndexes(OperationContext* txn,
const BSONObj& from_opts,
const NamespaceString& to_collection,
bool masterSameProcess,
- bool slaveOk,
- bool mayYield,
- bool mayBeInterrupted) {
+ bool slaveOk) {
LOG(2) << "\t\t copyIndexes " << from_collection << " to " << to_collection << " on "
<< _conn->getServerAddress();
@@ -336,9 +319,7 @@ void Cloner::copyIndexes(OperationContext* txn,
Collection* collection = db->getCollection(to_collection);
if (!collection) {
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
- if (mayBeInterrupted) {
- txn->checkForInterrupt();
- }
+ txn->checkForInterrupt();
WriteUnitOfWork wunit(txn);
Status s = userCreateNS(txn, db, to_collection.toString(), from_opts, false);
@@ -356,8 +337,7 @@ void Cloner::copyIndexes(OperationContext* txn,
// matches. It also wouldn't work on non-empty collections so we would need both
// implementations anyway as long as that is supported.
MultiIndexBlock indexer(txn, collection);
- if (mayBeInterrupted)
- indexer.allowInterruption();
+ indexer.allowInterruption();
indexer.removeExistingIndexes(&indexesToBuild);
if (indexesToBuild.empty())
@@ -384,8 +364,6 @@ bool Cloner::copyCollection(OperationContext* txn,
const string& ns,
const BSONObj& query,
string& errmsg,
- bool mayYield,
- bool mayBeInterrupted,
bool shouldCopyIndexes) {
const NamespaceString nss(ns);
const string dbname = nss.db().toString();
@@ -411,8 +389,7 @@ bool Cloner::copyCollection(OperationContext* txn,
options = col["options"].Obj();
}
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
- if (mayBeInterrupted)
- txn->checkForInterrupt();
+ txn->checkForInterrupt();
WriteUnitOfWork wunit(txn);
Status status = userCreateNS(txn, db, ns, options, false);
@@ -430,16 +407,7 @@ bool Cloner::copyCollection(OperationContext* txn,
}
// main data
- copy(txn,
- dbname,
- nss,
- options,
- nss,
- false,
- true,
- mayYield,
- mayBeInterrupted,
- Query(query).snapshot());
+ copy(txn, dbname, nss, options, nss, false, true, Query(query).snapshot());
/* TODO : copyIndexes bool does not seem to be implemented! */
if (!shouldCopyIndexes) {
@@ -447,15 +415,7 @@ bool Cloner::copyCollection(OperationContext* txn,
}
// indexes
- copyIndexes(txn,
- dbname,
- NamespaceString(ns),
- options,
- NamespaceString(ns),
- false,
- true,
- mayYield,
- mayBeInterrupted);
+ copyIndexes(txn, dbname, NamespaceString(ns), options, NamespaceString(ns), false, true);
return true;
}
@@ -600,10 +560,7 @@ Status Cloner::copyDb(OperationContext* txn,
{
MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN {
- if (opts.mayBeInterrupted) {
- txn->checkForInterrupt();
- }
-
+ txn->checkForInterrupt();
WriteUnitOfWork wunit(txn);
// we defer building id index for performance - building it in batch is much
@@ -623,16 +580,7 @@ Status Cloner::copyDb(OperationContext* txn,
if (opts.snapshot)
q.snapshot();
- copy(txn,
- toDBName,
- from_name,
- options,
- to_name,
- masterSameProcess,
- opts.slaveOk,
- opts.mayYield,
- opts.mayBeInterrupted,
- q);
+ copy(txn, toDBName, from_name, options, to_name, masterSameProcess, opts.slaveOk, q);
// Copy releases the lock, so we need to re-load the database. This should
// probably throw if the database has changed in between, but for now preserve
@@ -648,9 +596,7 @@ Status Cloner::copyDb(OperationContext* txn,
set<RecordId> dups;
MultiIndexBlock indexer(txn, c);
- if (opts.mayBeInterrupted) {
- indexer.allowInterruption();
- }
+ indexer.allowInterruption();
uassertStatusOK(indexer.init(c->getIndexCatalog()->getDefaultIdIndexSpec()));
uassertStatusOK(indexer.insertAllDocumentsInCollection(&dups));
@@ -697,9 +643,7 @@ Status Cloner::copyDb(OperationContext* txn,
collection.getObjectField("options"),
to_name,
masterSameProcess,
- opts.slaveOk,
- opts.mayYield,
- opts.mayBeInterrupted);
+ opts.slaveOk);
}
}
diff --git a/src/mongo/db/cloner.h b/src/mongo/db/cloner.h
index 64f2a1477ed..5a89f191dd1 100644
--- a/src/mongo/db/cloner.h
+++ b/src/mongo/db/cloner.h
@@ -64,9 +64,7 @@ public:
const std::string& ns,
const BSONObj& query,
std::string& errmsg,
- bool mayYield,
- bool mayBeInterrupted,
- bool copyIndexes = true);
+ bool copyIndexes);
private:
void copy(OperationContext* txn,
@@ -76,8 +74,6 @@ private:
const NamespaceString& to_ns,
bool masterSameProcess,
bool slaveOk,
- bool mayYield,
- bool mayBeInterrupted,
Query q);
void copyIndexes(OperationContext* txn,
@@ -86,9 +82,7 @@ private:
const BSONObj& from_opts,
const NamespaceString& to_ns,
bool masterSameProcess,
- bool slaveOk,
- bool mayYield,
- bool mayBeInterrupted);
+ bool slaveOk);
struct Fun;
std::unique_ptr<DBClientBase> _conn;
@@ -102,28 +96,15 @@ private:
* repairDatabase need not use it.
*/
struct CloneOptions {
- CloneOptions() {
- slaveOk = false;
- useReplAuth = false;
- snapshot = true;
- mayYield = true;
- mayBeInterrupted = false;
-
- syncData = true;
- syncIndexes = true;
- }
-
std::string fromDB;
std::set<std::string> collsToIgnore;
- bool slaveOk;
- bool useReplAuth;
- bool snapshot;
- bool mayYield;
- bool mayBeInterrupted;
+ bool slaveOk = false;
+ bool useReplAuth = false;
+ bool snapshot = true;
- bool syncData;
- bool syncIndexes;
+ bool syncData = true;
+ bool syncIndexes = true;
};
} // namespace mongo
diff --git a/src/mongo/db/commands/clone.cpp b/src/mongo/db/commands/clone.cpp
index 4cee4a3beef..0e6c7fbf1e7 100644
--- a/src/mongo/db/commands/clone.cpp
+++ b/src/mongo/db/commands/clone.cpp
@@ -102,7 +102,6 @@ public:
CloneOptions opts;
opts.fromDB = dbname;
opts.slaveOk = cmdObj["slaveOk"].trueValue();
- opts.mayBeInterrupted = true;
// See if there's any collections we should ignore
if (cmdObj["collsToIgnore"].type() == Array) {
diff --git a/src/mongo/db/commands/clone_collection.cpp b/src/mongo/db/commands/clone_collection.cpp
index a60fd0b7212..5f3e21008e2 100644
--- a/src/mongo/db/commands/clone_collection.cpp
+++ b/src/mongo/db/commands/clone_collection.cpp
@@ -155,7 +155,7 @@ public:
cloner.setConnection(myconn.release());
return cloner.copyCollection(
- txn, collection, query, errmsg, true, true /* interruptable */, copyIndexes);
+ txn, collection, query, errmsg, copyIndexes);
}
} cmdCloneCollection;
diff --git a/src/mongo/db/commands/copydb.cpp b/src/mongo/db/commands/copydb.cpp
index f3c7ff83d27..c53dd86f8f9 100644
--- a/src/mongo/db/commands/copydb.cpp
+++ b/src/mongo/db/commands/copydb.cpp
@@ -138,8 +138,6 @@ public:
cloneOptions.slaveOk = cmdObj["slaveOk"].trueValue();
cloneOptions.useReplAuth = false;
cloneOptions.snapshot = true;
- cloneOptions.mayYield = true;
- cloneOptions.mayBeInterrupted = true;
string todb = cmdObj.getStringField("todb");
if (fromhost.empty() || todb.empty() || cloneOptions.fromDB.empty()) {
diff --git a/src/mongo/db/repl/master_slave.cpp b/src/mongo/db/repl/master_slave.cpp
index 0b662ce66dd..d4de89ef581 100644
--- a/src/mongo/db/repl/master_slave.cpp
+++ b/src/mongo/db/repl/master_slave.cpp
@@ -479,8 +479,6 @@ void ReplSource::resync(OperationContext* txn, const std::string& dbName) {
cloneOptions.slaveOk = true;
cloneOptions.useReplAuth = true;
cloneOptions.snapshot = true;
- cloneOptions.mayYield = true;
- cloneOptions.mayBeInterrupted = true;
Cloner cloner;
Status status = cloner.copyDb(txn, db, hostName.c_str(), cloneOptions, NULL);
diff --git a/src/mongo/db/repl/rollback_source_impl.cpp b/src/mongo/db/repl/rollback_source_impl.cpp
index 65f0c8e60ad..0e1256a8d7a 100644
--- a/src/mongo/db/repl/rollback_source_impl.cpp
+++ b/src/mongo/db/repl/rollback_source_impl.cpp
@@ -77,11 +77,11 @@ void RollbackSourceImpl::copyCollectionFromRemote(OperationContext* txn,
// cloner owns _conn in unique_ptr
Cloner cloner;
cloner.setConnection(tmpConn.release());
- uassert(15909,
- str::stream() << "replSet rollback error resyncing collection " << nss.ns() << ' '
- << errmsg,
- cloner.copyCollection(
- txn, nss.ns(), BSONObj(), errmsg, true, true /* interruptable */, true));
+ uassert(
+ 15909,
+ str::stream() << "replSet rollback error resyncing collection " << nss.ns() << ' '
+ << errmsg,
+ cloner.copyCollection(txn, nss.ns(), BSONObj(), errmsg, true));
}
StatusWith<BSONObj> RollbackSourceImpl::getCollectionInfo(const NamespaceString& nss) const {
diff --git a/src/mongo/db/repl/rs_initialsync.cpp b/src/mongo/db/repl/rs_initialsync.cpp
index 57224dca3bc..569480452d1 100644
--- a/src/mongo/db/repl/rs_initialsync.cpp
+++ b/src/mongo/db/repl/rs_initialsync.cpp
@@ -184,8 +184,6 @@ bool _initialSyncClone(OperationContext* txn,
options.slaveOk = true;
options.useReplAuth = true;
options.snapshot = false;
- options.mayYield = true;
- options.mayBeInterrupted = true;
options.syncData = dataPass;
options.syncIndexes = !dataPass;