diff options
author | Dianna Hohensee <dianna.hohensee@10gen.com> | 2015-12-23 10:54:50 -0500 |
---|---|---|
committer | Dianna Hohensee <dianna.hohensee@10gen.com> | 2016-01-27 13:46:31 -0500 |
commit | d6c68c80f4c30adfe134dad232995151899195b8 (patch) | |
tree | 86f4faebe5412add0e8a45adac2f8a41d450d28d /src/mongo | |
parent | 43482c1e7ad1fd8c307460682a76368c80bb355d (diff) | |
download | mongo-d6c68c80f4c30adfe134dad232995151899195b8.tar.gz |
SERVER-21678 setting fromMigrate flag for deletes in oplog
(cherry picked from commit c28bf48e5d3cbe6c1aceed89adcdf8ed7cba5f42)
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/catalog/collection.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/catalog/collection.h | 12 | ||||
-rw-r--r-- | src/mongo/db/cloner.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/dbhelpers.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/exec/delete.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/op_observer.h | 11 | ||||
-rw-r--r-- | src/mongo/db/s/migration_source_manager.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/s/migration_source_manager.h | 4 | ||||
-rw-r--r-- | src/mongo/s/d_migrate.cpp | 10 |
9 files changed, 44 insertions, 11 deletions
diff --git a/src/mongo/db/catalog/collection.cpp b/src/mongo/db/catalog/collection.cpp index daa74399995..9e41d643452 100644 --- a/src/mongo/db/catalog/collection.cpp +++ b/src/mongo/db/catalog/collection.cpp @@ -476,10 +476,8 @@ Status Collection::aboutToDeleteCapped(OperationContext* txn, return Status::OK(); } -void Collection::deleteDocument(OperationContext* txn, - const RecordId& loc, - bool cappedOK, - bool noWarn) { +void Collection::deleteDocument( + OperationContext* txn, const RecordId& loc, bool fromMigrate, bool cappedOK, bool noWarn) { if (isCapped() && !cappedOK) { log() << "failing remove on a capped ns " << _ns << endl; uasserted(10089, "cannot remove from a capped collection"); @@ -498,7 +496,7 @@ void Collection::deleteDocument(OperationContext* txn, _recordStore->deleteRecord(txn, loc); - opObserver->onDelete(txn, ns(), std::move(deleteState)); + opObserver->onDelete(txn, ns(), std::move(deleteState), fromMigrate); } Counter64 moveCounter; diff --git a/src/mongo/db/catalog/collection.h b/src/mongo/db/catalog/collection.h index 5db3fe09984..261ac42bf97 100644 --- a/src/mongo/db/catalog/collection.h +++ b/src/mongo/db/catalog/collection.h @@ -243,8 +243,20 @@ public: */ std::vector<std::unique_ptr<RecordCursor>> getManyCursors(OperationContext* txn) const; + /** + * Deletes the document with the given RecordId from the collection. + * + * 'fromMigrate' indicates whether the delete was induced by a chunk migration, and + * so should be ignored by the user as an internal maintenance operation and not a + * real delete. + * 'loc' key to uniquely identify a record in a collection. + * 'cappedOK' if true, allows deletes on capped collections (Cloner::copyDB uses this). + * 'noWarn' if unindexing the record causes an error, if noWarn is true the error + * will not be logged. + */ void deleteDocument(OperationContext* txn, const RecordId& loc, + bool fromMigrate = false, bool cappedOK = false, bool noWarn = false); diff --git a/src/mongo/db/cloner.cpp b/src/mongo/db/cloner.cpp index a5cf8451558..8fda1b0b17f 100644 --- a/src/mongo/db/cloner.cpp +++ b/src/mongo/db/cloner.cpp @@ -639,7 +639,7 @@ Status Cloner::copyDb(OperationContext* txn, // dupsAllowed in IndexCatalog::_unindexRecord and SERVER-17487. for (set<RecordId>::const_iterator it = dups.begin(); it != dups.end(); ++it) { WriteUnitOfWork wunit(txn); - c->deleteDocument(txn, *it, true, true); + c->deleteDocument(txn, *it, false, true, true); wunit.commit(); } diff --git a/src/mongo/db/dbhelpers.cpp b/src/mongo/db/dbhelpers.cpp index e42979d6649..6ea104b6faa 100644 --- a/src/mongo/db/dbhelpers.cpp +++ b/src/mongo/db/dbhelpers.cpp @@ -429,7 +429,7 @@ long long Helpers::removeRange(OperationContext* txn, if (callback) callback->goingToDelete(obj); - collection->deleteDocument(txn, rloc); + collection->deleteDocument(txn, rloc, fromMigrate); wuow.commit(); numDeleted++; } diff --git a/src/mongo/db/exec/delete.cpp b/src/mongo/db/exec/delete.cpp index c0708617b5a..9db64a9ea20 100644 --- a/src/mongo/db/exec/delete.cpp +++ b/src/mongo/db/exec/delete.cpp @@ -210,7 +210,7 @@ PlanStage::StageState DeleteStage::work(WorkingSetID* out) { // Do the write, unless this is an explain. if (!_params.isExplain) { WriteUnitOfWork wunit(getOpCtx()); - _collection->deleteDocument(getOpCtx(), rloc); + _collection->deleteDocument(getOpCtx(), rloc, _params.fromMigrate); wunit.commit(); } diff --git a/src/mongo/db/op_observer.h b/src/mongo/db/op_observer.h index e9c18f4bbe7..406402b093d 100644 --- a/src/mongo/db/op_observer.h +++ b/src/mongo/db/op_observer.h @@ -68,10 +68,19 @@ public: bool fromMigrate = false); void onUpdate(OperationContext* txn, oplogUpdateEntryArgs args); DeleteState aboutToDelete(OperationContext* txn, const NamespaceString& ns, const BSONObj& doc); + /** + * Handles logging before document is deleted. + * + * "ns" name of the collection from which deleteState.idDoc will be deleted. + * "deleteState" holds information about the deleted document. + * "fromMigrate" indicates whether the delete was induced by a chunk migration, and + * so should be ignored by the user as an internal maintenance operation and not a + * real delete. + */ void onDelete(OperationContext* txn, const NamespaceString& ns, DeleteState deleteState, - bool fromMigrate = false); + bool fromMigrate); void onOpMessage(OperationContext* txn, const BSONObj& msgObj); void onCreateCollection(OperationContext* txn, const NamespaceString& collectionName, diff --git a/src/mongo/db/s/migration_source_manager.cpp b/src/mongo/db/s/migration_source_manager.cpp index 59eb96222fb..09680bae2a3 100644 --- a/src/mongo/db/s/migration_source_manager.cpp +++ b/src/mongo/db/s/migration_source_manager.cpp @@ -234,8 +234,8 @@ void MigrationSourceManager::logOp(OperationContext* txn, // won't be transferred to the recipient shard. Also ignore ops from // _migrateClone and _transferMods since it is impossible to move a chunk // to self. - // Also ignore out of range deletes when migrating (notInActiveChunk is set in - // OpObserver::onDelete) + // Also ignore out of range deletes when migrating a chunk (is set + // in OpObserver::onDelete) return; } diff --git a/src/mongo/db/s/migration_source_manager.h b/src/mongo/db/s/migration_source_manager.h index 8c6251fe49b..076c14fa9f0 100644 --- a/src/mongo/db/s/migration_source_manager.h +++ b/src/mongo/db/s/migration_source_manager.h @@ -71,6 +71,10 @@ public: BSONObj* patt, bool notInActiveChunk); + /** + * Determines whether the given document 'doc' in namespace 'ns' is within the range + * of a currently migrating chunk. + */ bool isInMigratingChunk(const NamespaceString& ns, const BSONObj& doc); /** diff --git a/src/mongo/s/d_migrate.cpp b/src/mongo/s/d_migrate.cpp index 6a7abe7f723..9983ccd58df 100644 --- a/src/mongo/s/d_migrate.cpp +++ b/src/mongo/s/d_migrate.cpp @@ -430,6 +430,16 @@ public: } // namespace +/** + * If sharding is enabled, logs the operation for an active migration in the transfer mods log. + * + * 'ns' name of the collection in which the operation will occur. + * 'notInActiveChunk' a true value indicates that either: + * 1) the delete is coming from a donor shard in a current chunk migration, + * and so does not need to be entered in this shard's outgoing transfer log. + * 2) the document is not within this shard's outgoing chunk migration range, + * and so does not need to be forwarded to the migration recipient via the transfer log. + */ void logOpForSharding(OperationContext* txn, const char* opstr, const char* ns, |