summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2014-09-02 19:07:42 -0400
committerMathias Stearn <redbeard0531@gmail.com>2014-09-17 14:14:32 -0400
commit299b86caf30bae2c88cd51ae189a37bd9cdeea73 (patch)
tree08a2acce4a604c9f4d43494e8d277f6f8b6bd858
parentd024587b174d1328361d78b3220794c4b941258b (diff)
downloadmongo-299b86caf30bae2c88cd51ae189a37bd9cdeea73.tar.gz
SERVER-15087 check for dropped collection in MR
(cherry picked from commit aa5c0a136c9ab37023d89908c8b02d6d687ed070)
-rw-r--r--src/mongo/db/commands/mr.cpp22
-rw-r--r--src/mongo/db/commands/mr.h5
2 files changed, 15 insertions, 12 deletions
diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp
index 493997d84dc..c409bdda3ca 100644
--- a/src/mongo/db/commands/mr.cpp
+++ b/src/mongo/db/commands/mr.cpp
@@ -623,11 +623,7 @@ namespace mongo {
Client::WriteContext ctx( ns );
uassert(10004, "no longer master", isMasterNs(ns.c_str()));
- Collection* coll = ctx.ctx().db()->getCollection( ns );
- if ( !coll )
- uasserted(13630, str::stream() << "attempted to insert into nonexistent" <<
- " collection during a mr operation." <<
- " collection expected: " << ns );
+ Collection* coll = getCollectionOrUassert(ctx.ctx().db(), ns);
class BSONObjBuilder b;
if ( !o.hasField( "_id" ) ) {
@@ -649,12 +645,7 @@ namespace mongo {
verify( _onDisk );
Client::WriteContext ctx( _config.incLong );
- Collection* coll = ctx.ctx().db()->getCollection( _config.incLong );
- if ( !coll )
- uasserted(13631, str::stream() << "attempted to insert into nonexistent"
- " collection during a mr operation." <<
- " collection expected: " << _config.incLong );
-
+ Collection* coll = getCollectionOrUassert(ctx.ctx().db(), _config.incLong);
coll->insertDocument( o, true );
getDur().commitIfNeeded();
}
@@ -850,6 +841,13 @@ namespace mongo {
_config.reducer->numReduces = _scope->getNumberInt("_redCt");
}
+ Collection* State::getCollectionOrUassert(Database* db, const StringData& ns) {
+ Collection* out = db ? db->getCollection(ns) : NULL;
+ uassert(18697, "Collection unexpectedly disappeared: " + ns.toString(),
+ out);
+ return out;
+ }
+
/**
* Applies last reduce and finalize on a list of tuples (key, val)
* Inserts single result {_id: key, value: val} into temp collection
@@ -924,7 +922,7 @@ namespace mongo {
{
Client::WriteContext incCtx( _config.incLong );
- Collection* incColl = incCtx.ctx().db()->getCollection( _config.incLong );
+ Collection* incColl = getCollectionOrUassert(incCtx.ctx().db(), _config.incLong );
bool foundIndex = false;
IndexCatalog::IndexIterator ii =
diff --git a/src/mongo/db/commands/mr.h b/src/mongo/db/commands/mr.h
index f32924c4bf5..5c3a550cbfe 100644
--- a/src/mongo/db/commands/mr.h
+++ b/src/mongo/db/commands/mr.h
@@ -42,6 +42,9 @@
namespace mongo {
+ class Collection;
+ class Database;
+
namespace mr {
typedef vector<BSONObj> BSONList;
@@ -324,6 +327,8 @@ namespace mongo {
void switchMode(bool jsMode);
void bailFromJS();
+ Collection* getCollectionOrUassert(Database* db, const StringData& ns);
+
const Config& _config;
DBDirectClient _db;
bool _useIncremental; // use an incremental collection