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-30 16:38:42 -0400
commit356c1a17b36b165704183e8696fcac3b2d32deb0 (patch)
tree400a71d89bc259f382d523bcdfa5abe5a9c6d187 /src
parent3f3ff0050caf0b008b1b665348e4183c1d180f66 (diff)
downloadmongo-356c1a17b36b165704183e8696fcac3b2d32deb0.tar.gz
SERVER-28022 Invalidate old IDs for moved system.namespaces records
(cherry picked from commit b21ff4b1a89bf90a3cceee6961c75f8d10c733e6) Conflicts: src/mongo/db/storage/mmap_v1/catalog/namespace_details_collection_entry.cpp src/mongo/db/storage/mmap_v1/mmap_v1_database_catalog_entry.h
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.cpp24
-rw-r--r--src/mongo/db/storage/mmap_v1/mmap_v1_database_catalog_entry.cpp36
-rw-r--r--src/mongo/db/storage/mmap_v1/mmap_v1_database_catalog_entry.h9
5 files changed, 55 insertions, 24 deletions
diff --git a/src/mongo/db/catalog/collection.cpp b/src/mongo/db/catalog/collection.cpp
index 533f0d428d0..928548101c7 100644
--- a/src/mongo/db/catalog/collection.cpp
+++ b/src/mongo/db/catalog/collection.cpp
@@ -632,4 +632,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 d64dd95aef8..2b2fd73c065 100644
--- a/src/mongo/db/catalog/collection.h
+++ b/src/mongo/db/catalog/collection.h
@@ -296,6 +296,12 @@ public:
// --- end suspect things
+ /**
+ * This function is necessary for a 3.2 and 3.0 backport. We have a better fix for the
+ * underlying issue in later versions.
+ */
+ UpdateNotifier* getUpdateNotifier();
+
private:
Status recordStoreGoingToMove(OperationContext* txn,
const RecordId& oldLocation,
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 d8b32fbe47c..092312a97b4 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,9 @@
#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"
#include "mongo/db/ops/update.h"
#include "mongo/db/record_id.h"
@@ -252,6 +255,11 @@ Status NamespaceDetailsCollectionCatalogEntry::removeIndex(OperationContext* txn
d->idx(getTotalIndexCount(txn)) = IndexDetails();
}
+ // 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);
@@ -361,8 +369,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 f6e0e6c185c..b46a632fd5c 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
@@ -311,12 +311,7 @@ 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"), loc);
systemIndexRecordStore->deleteRecord(txn, loc);
}
@@ -384,13 +379,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);
@@ -404,6 +394,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 {
@@ -822,13 +823,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 250d8084b00..1f0ee7dfa38 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
@@ -123,11 +123,16 @@ public:
CollectionOptions getCollectionOptions(OperationContext* txn, RecordId nsRid) const;
/**
- * Creates a CollectionCatalogEntry in the for an index rather than a collection. MMAPv1
- * puts both indexes and collections into CCEs. A namespace named 'name' must not exist.
+ * Creates a CollectionCatalogEntry in the form of an index rather than a collection.
+ * MMAPv1 puts both indexes and collections into CCEs. A namespace named 'name' must not
+ * exist.
*/
void createNamespaceForIndex(OperationContext* txn, const StringData& name);
+ static void invalidateSystemCollectionRecord(OperationContext* txn,
+ NamespaceString systemCollectionNamespace,
+ RecordId record);
+
private:
class EntryInsertion;
class EntryRemoval;