summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaria van Keulen <maria@mongodb.com>2017-02-15 15:52:46 -0500
committerMaria van Keulen <maria@mongodb.com>2017-03-10 11:56:19 -0500
commitb21ff4b1a89bf90a3cceee6961c75f8d10c733e6 (patch)
tree0935f5bddbbd413ccec9eb768e7cd9fe87a88516 /src
parentc8afd7bba3aec74e49ce3467cce386f1d3f9b92f (diff)
downloadmongo-b21ff4b1a89bf90a3cceee6961c75f8d10c733e6.tar.gz
SERVER-28022 Invalidate old IDs for moved system.namespaces records
(cherry picked from commit 22ec4be075233d425f21349854b5ceac6baa5289) Conflicts: src/mongo/db/storage/mmap_v1/catalog/namespace_details_collection_entry.cpp
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/catalog/collection.cpp4
-rw-r--r--src/mongo/db/catalog/collection.h6
-rw-r--r--src/mongo/db/storage/mmap_v1/catalog/namespace_details_collection_entry.cpp30
-rw-r--r--src/mongo/db/storage/mmap_v1/mmap_v1_database_catalog_entry.cpp37
-rw-r--r--src/mongo/db/storage/mmap_v1/mmap_v1_database_catalog_entry.h3
5 files changed, 49 insertions, 31 deletions
diff --git a/src/mongo/db/catalog/collection.cpp b/src/mongo/db/catalog/collection.cpp
index 42fc0ea7fee..04e94eab47d 100644
--- a/src/mongo/db/catalog/collection.cpp
+++ b/src/mongo/db/catalog/collection.cpp
@@ -1047,4 +1047,8 @@ Status Collection::touch(OperationContext* txn,
return Status::OK();
}
+
+UpdateNotifier* Collection::getUpdateNotifier() {
+ return this;
+}
}
diff --git a/src/mongo/db/catalog/collection.h b/src/mongo/db/catalog/collection.h
index becfe366ab3..8f516f72bbd 100644
--- a/src/mongo/db/catalog/collection.h
+++ b/src/mongo/db/catalog/collection.h
@@ -433,6 +433,12 @@ public:
*/
void notifyCappedWaitersIfNeeded();
+ /**
+ * This function is necessary for a 3.2 backport. We have a better fix for the
+ * underlying issue in later versions.
+ */
+ UpdateNotifier* getUpdateNotifier();
+
private:
/**
* Returns a non-ok Status if document does not pass this collection's validator.
diff --git a/src/mongo/db/storage/mmap_v1/catalog/namespace_details_collection_entry.cpp b/src/mongo/db/storage/mmap_v1/catalog/namespace_details_collection_entry.cpp
index 2d9a2138542..e24b668ac3e 100644
--- a/src/mongo/db/storage/mmap_v1/catalog/namespace_details_collection_entry.cpp
+++ b/src/mongo/db/storage/mmap_v1/catalog/namespace_details_collection_entry.cpp
@@ -32,6 +32,7 @@
#include "mongo/db/storage/mmap_v1/catalog/namespace_details_collection_entry.h"
+#include "mongo/db/catalog/collection.h"
#include "mongo/db/catalog/database.h"
#include "mongo/db/catalog/database_holder.h"
#include "mongo/db/index/index_descriptor.h"
@@ -253,15 +254,10 @@ Status NamespaceDetailsCollectionCatalogEntry::removeIndex(OperationContext* txn
d->idx(getTotalIndexCount(txn)) = IndexDetails();
}
- // Soneone may be querying the system.indexes namespace directly, so we need to invalidate
- // its cursors. Having to go back up through the DatabaseHolder is a bit of a layering
- // violation, but at this point we're not going to add more MMAPv1 specific interfaces.
- // We can find the name of the database through the first entries of the CollectionMap.
- StringData dbName(nsToDatabaseSubstring(_db->_collections.begin()->first));
- invariant(txn->lockState()->isDbLockedForMode(dbName, MODE_X));
- Database* db = dbHolder().get(txn, dbName);
- Collection* systemIndexes = db->getCollection(db->getSystemIndexesName());
- systemIndexes->getCursorManager()->invalidateDocument(txn, infoLocation, INVALIDATION_DELETION);
+ // Someone may be querying the system.indexes namespace directly, so we need to invalidate
+ // its cursors.
+ MMAPV1DatabaseCatalogEntry::invalidateSystemCollectionRecord(
+ txn, NamespaceString(_db->name(), "system.indexes"), infoLocation);
// remove from system.indexes
_indexRecordStore->deleteRecord(txn, infoLocation);
@@ -372,8 +368,20 @@ void NamespaceDetailsCollectionCatalogEntry::_updateSystemNamespaces(OperationCo
RecordData entry = _namespacesRecordStore->dataFor(txn, _namespacesRecordId);
const BSONObj newEntry = applyUpdateOperators(entry.releaseToBson(), update);
- StatusWith<RecordId> result = _namespacesRecordStore->updateRecord(
- txn, _namespacesRecordId, newEntry.objdata(), newEntry.objsize(), false, NULL);
+
+ // Get update notifier
+ invariant(txn->lockState()->isDbLockedForMode(_db->name(), MODE_X));
+ Database* db = dbHolder().get(txn, _db->name());
+ Collection* systemCollection =
+ db->getCollection(NamespaceString(_db->name(), "system.namespaces"));
+ UpdateNotifier* namespacesNotifier = systemCollection->getUpdateNotifier();
+
+ StatusWith<RecordId> result = _namespacesRecordStore->updateRecord(txn,
+ _namespacesRecordId,
+ newEntry.objdata(),
+ newEntry.objsize(),
+ false,
+ namespacesNotifier);
fassert(17486, result.getStatus());
setNamespacesRecordId(txn, result.getValue());
}
diff --git a/src/mongo/db/storage/mmap_v1/mmap_v1_database_catalog_entry.cpp b/src/mongo/db/storage/mmap_v1/mmap_v1_database_catalog_entry.cpp
index fd7a3c267a5..c29d7507c9b 100644
--- a/src/mongo/db/storage/mmap_v1/mmap_v1_database_catalog_entry.cpp
+++ b/src/mongo/db/storage/mmap_v1/mmap_v1_database_catalog_entry.cpp
@@ -303,12 +303,8 @@ Status MMAPV1DatabaseCatalogEntry::renameCollection(OperationContext* txn,
return s;
}
// Invalidate index record for the old collection.
- StringData dbName(nsToDatabaseSubstring(_collections.begin()->first));
- invariant(txn->lockState()->isDbLockedForMode(dbName, MODE_X));
- Database* db = dbHolder().get(txn, dbName);
- Collection* systemIndexes = db->getCollection(db->getSystemIndexesName());
- systemIndexes->getCursorManager()->invalidateDocument(
- txn, record->id, INVALIDATION_DELETION);
+ invalidateSystemCollectionRecord(
+ txn, NamespaceString(name(), "system.indexes"), record->id);
systemIndexRecordStore->deleteRecord(txn, record->id);
}
@@ -376,13 +372,8 @@ Status MMAPV1DatabaseCatalogEntry::_renameSingleNamespace(OperationContext* txn,
RecordId rid = _addNamespaceToNamespaceCollection(txn, toNS, newSpec.isEmpty() ? 0 : &newSpec);
// Invalidate old namespace record
- const NamespaceString nsn(name(), "system.namespaces");
- StringData dbName(name());
- invariant(txn->lockState()->isDbLockedForMode(dbName, MODE_X));
- Database* db = dbHolder().get(txn, dbName);
- Collection* systemNamespaces = db->getCollection(nsn);
- systemNamespaces->getCursorManager()->invalidateDocument(
- txn, oldSpecLocation, INVALIDATION_DELETION);
+ invalidateSystemCollectionRecord(
+ txn, NamespaceString(name(), "system.namespaces"), oldSpecLocation);
_getNamespaceRecordStore()->deleteRecord(txn, oldSpecLocation);
@@ -396,6 +387,17 @@ Status MMAPV1DatabaseCatalogEntry::_renameSingleNamespace(OperationContext* txn,
return Status::OK();
}
+void MMAPV1DatabaseCatalogEntry::invalidateSystemCollectionRecord(
+ OperationContext* txn, NamespaceString systemCollectionNamespace, RecordId record) {
+ // Having to go back up through the DatabaseHolder is a bit of a layering
+ // violation, but at this point we're not going to add more MMAPv1 specific interfaces.
+ StringData dbName = systemCollectionNamespace.db();
+ invariant(txn->lockState()->isDbLockedForMode(dbName, MODE_X));
+ Database* db = dbHolder().get(txn, dbName);
+ Collection* systemCollection = db->getCollection(systemCollectionNamespace);
+ systemCollection->getCursorManager()->invalidateDocument(txn, record, INVALIDATION_DELETION);
+}
+
void MMAPV1DatabaseCatalogEntry::appendExtraStats(OperationContext* opCtx,
BSONObjBuilder* output,
double scale) const {
@@ -809,13 +811,8 @@ void MMAPV1DatabaseCatalogEntry::_removeNamespaceFromNamespaceCollection(Operati
// Invalidate old namespace record
RecordId oldSpecLocation = entry->second->catalogEntry->getNamespacesRecordId();
- const NamespaceString nsn(name(), "system.namespaces");
- StringData dbName(name());
- invariant(txn->lockState()->isDbLockedForMode(dbName, MODE_X));
- Database* db = dbHolder().get(txn, dbName);
- Collection* systemNamespaces = db->getCollection(nsn);
- systemNamespaces->getCursorManager()->invalidateDocument(
- txn, oldSpecLocation, INVALIDATION_DELETION);
+ invalidateSystemCollectionRecord(
+ txn, NamespaceString(name(), "system.namespaces"), oldSpecLocation);
rs->deleteRecord(txn, oldSpecLocation);
}
diff --git a/src/mongo/db/storage/mmap_v1/mmap_v1_database_catalog_entry.h b/src/mongo/db/storage/mmap_v1/mmap_v1_database_catalog_entry.h
index e127eece268..bc1229db016 100644
--- a/src/mongo/db/storage/mmap_v1/mmap_v1_database_catalog_entry.h
+++ b/src/mongo/db/storage/mmap_v1/mmap_v1_database_catalog_entry.h
@@ -127,6 +127,9 @@ public:
* exist.
*/
void createNamespaceForIndex(OperationContext* txn, StringData name);
+ static void invalidateSystemCollectionRecord(OperationContext* txn,
+ NamespaceString systemCollectionNamespace,
+ RecordId record);
/**
* Ensures data files are compatible, in case we are downgrading from a newer version. Returns