summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl/drop_pending_collection_reaper.cpp
diff options
context:
space:
mode:
authorJudah Schvimer <judah@mongodb.com>2017-06-20 13:39:07 -0400
committerJudah Schvimer <judah@mongodb.com>2017-06-20 13:48:54 -0400
commitda2e51bd03fd4e6a519eb170e301af36c8b8e420 (patch)
tree67c4b0fb2d4cad19db7efe4f18b185930aede39f /src/mongo/db/repl/drop_pending_collection_reaper.cpp
parent50623596fb62da49a2b1495d5e0cd852faf91f9f (diff)
downloadmongo-da2e51bd03fd4e6a519eb170e301af36c8b8e420.tar.gz
SERVER-29276 adds functions to DropPendingCollectionReaper for rollback
Diffstat (limited to 'src/mongo/db/repl/drop_pending_collection_reaper.cpp')
-rw-r--r--src/mongo/db/repl/drop_pending_collection_reaper.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/mongo/db/repl/drop_pending_collection_reaper.cpp b/src/mongo/db/repl/drop_pending_collection_reaper.cpp
index d2aec5aaaae..63da089f28c 100644
--- a/src/mongo/db/repl/drop_pending_collection_reaper.cpp
+++ b/src/mongo/db/repl/drop_pending_collection_reaper.cpp
@@ -97,6 +97,71 @@ boost::optional<OpTime> DropPendingCollectionReaper::getEarliestDropOpTime() {
return it->first;
}
+bool DropPendingCollectionReaper::dropCollectionAtOpTime(OperationContext* opCtx,
+ const OpTime& opTime) {
+ // Every node cleans up its own drop-pending collections. We should never replicate these drops
+ // because these are internal operations.
+ UnreplicatedWritesBlock uwb(opCtx);
+
+ NamespaceString pendingNss;
+ {
+ stdx::lock_guard<stdx::mutex> lock(_mutex);
+ auto pendingNssIt = _dropPendingNamespaces.find(opTime);
+ if (pendingNssIt == _dropPendingNamespaces.end()) {
+ warning() << "Cannot find drop-pending namespace at OpTime " << opTime << " to drop.";
+ return false;
+ }
+
+ pendingNss = pendingNssIt->second;
+ _dropPendingNamespaces.erase(opTime);
+ }
+
+ log() << "Completing collection drop for " << pendingNss << " with drop OpTime " << opTime;
+
+ auto status = _storageInterface->dropCollection(opCtx, pendingNss);
+ if (!status.isOK()) {
+ warning() << "Failed to remove drop-pending collection " << pendingNss
+ << " with drop OpTime " << opTime << ": " << status;
+ }
+
+ return true;
+}
+
+bool DropPendingCollectionReaper::rollBackDropPendingCollection(OperationContext* opCtx,
+ const OpTime& opTime,
+ StringData collName) {
+ // Every node cleans up its own drop-pending collections. We should never replicate these
+ // renames because these are internal operations.
+ UnreplicatedWritesBlock uwb(opCtx);
+
+ NamespaceString pendingNss;
+ {
+ stdx::lock_guard<stdx::mutex> lock(_mutex);
+ auto pendingNssIt = _dropPendingNamespaces.find(opTime);
+ if (pendingNssIt == _dropPendingNamespaces.end()) {
+ warning() << "Cannot find drop-pending namespace at OpTime " << opTime
+ << " for collection " << collName << " to roll back.";
+ return false;
+ }
+
+ pendingNss = pendingNssIt->second;
+ _dropPendingNamespaces.erase(opTime);
+ }
+
+ NamespaceString newNss(pendingNss.db(), collName);
+ log() << "Rolling back collection drop for " << pendingNss << " with drop OpTime " << opTime
+ << " to namespace " << newNss;
+
+ auto status = _storageInterface->renameCollection(opCtx, pendingNss, newNss, true);
+ if (!status.isOK()) {
+ warning() << "Failed to roll back drop-pending collection " << pendingNss
+ << " with drop OpTime " << opTime << " and rename it to namespace " << newNss
+ << ": " << status;
+ }
+
+ return true;
+}
+
void DropPendingCollectionReaper::dropCollectionsOlderThan(OperationContext* opCtx,
const OpTime& opTime) {
DropPendingNamespaces toDrop;