summaryrefslogtreecommitdiff
path: root/src/mongo/db/storage/mmap_v1/catalog/namespace_details_collection_entry.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/storage/mmap_v1/catalog/namespace_details_collection_entry.cpp')
-rw-r--r--src/mongo/db/storage/mmap_v1/catalog/namespace_details_collection_entry.cpp165
1 files changed, 83 insertions, 82 deletions
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 7d92f431db8..ee2031d4a7e 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
@@ -65,8 +65,8 @@ NamespaceDetailsCollectionCatalogEntry::NamespaceDetailsCollectionCatalogEntry(
}
CollectionOptions NamespaceDetailsCollectionCatalogEntry::getCollectionOptions(
- OperationContext* txn) const {
- CollectionOptions options = _db->getCollectionOptions(txn, _namespacesRecordId);
+ OperationContext* opCtx) const {
+ CollectionOptions options = _db->getCollectionOptions(opCtx, _namespacesRecordId);
if (options.flagsSet) {
if (options.flags != _details->userFlags) {
@@ -84,11 +84,11 @@ CollectionOptions NamespaceDetailsCollectionCatalogEntry::getCollectionOptions(
return options;
}
-int NamespaceDetailsCollectionCatalogEntry::getTotalIndexCount(OperationContext* txn) const {
+int NamespaceDetailsCollectionCatalogEntry::getTotalIndexCount(OperationContext* opCtx) const {
return _details->nIndexes + _details->indexBuildsInProgress;
}
-int NamespaceDetailsCollectionCatalogEntry::getCompletedIndexCount(OperationContext* txn) const {
+int NamespaceDetailsCollectionCatalogEntry::getCompletedIndexCount(OperationContext* opCtx) const {
return _details->nIndexes;
}
@@ -96,22 +96,22 @@ int NamespaceDetailsCollectionCatalogEntry::getMaxAllowedIndexes() const {
return NamespaceDetails::NIndexesMax;
}
-void NamespaceDetailsCollectionCatalogEntry::getAllIndexes(OperationContext* txn,
+void NamespaceDetailsCollectionCatalogEntry::getAllIndexes(OperationContext* opCtx,
std::vector<std::string>* names) const {
NamespaceDetails::IndexIterator i = _details->ii(true);
while (i.more()) {
const IndexDetails& id = i.next();
- const BSONObj obj = _indexRecordStore->dataFor(txn, id.info.toRecordId()).toBson();
+ const BSONObj obj = _indexRecordStore->dataFor(opCtx, id.info.toRecordId()).toBson();
names->push_back(obj.getStringField("name"));
}
}
-bool NamespaceDetailsCollectionCatalogEntry::isIndexMultikey(OperationContext* txn,
+bool NamespaceDetailsCollectionCatalogEntry::isIndexMultikey(OperationContext* opCtx,
StringData idxName,
MultikeyPaths* multikeyPaths) const {
// TODO SERVER-22727: Populate 'multikeyPaths' with path components that cause 'idxName' to be
// multikey.
- int idxNo = _findIndexNumber(txn, idxName);
+ int idxNo = _findIndexNumber(opCtx, idxName);
invariant(idxNo >= 0);
return isIndexMultikey(idxNo);
}
@@ -121,16 +121,16 @@ bool NamespaceDetailsCollectionCatalogEntry::isIndexMultikey(int idxNo) const {
}
bool NamespaceDetailsCollectionCatalogEntry::setIndexIsMultikey(
- OperationContext* txn, StringData indexName, const MultikeyPaths& multikeyPaths) {
+ OperationContext* opCtx, StringData indexName, const MultikeyPaths& multikeyPaths) {
// TODO SERVER-22727: Store new path components from 'multikeyPaths' that cause 'indexName' to
// be multikey.
- int idxNo = _findIndexNumber(txn, indexName);
+ int idxNo = _findIndexNumber(opCtx, indexName);
invariant(idxNo >= 0);
const bool multikey = true;
- return setIndexIsMultikey(txn, idxNo, multikey);
+ return setIndexIsMultikey(opCtx, idxNo, multikey);
}
-bool NamespaceDetailsCollectionCatalogEntry::setIndexIsMultikey(OperationContext* txn,
+bool NamespaceDetailsCollectionCatalogEntry::setIndexIsMultikey(OperationContext* opCtx,
int idxNo,
bool multikey) {
unsigned long long mask = 1ULL << idxNo;
@@ -141,7 +141,7 @@ bool NamespaceDetailsCollectionCatalogEntry::setIndexIsMultikey(OperationContext
return false;
}
- *txn->recoveryUnit()->writing(&_details->multiKeyIndexBits) |= mask;
+ *opCtx->recoveryUnit()->writing(&_details->multiKeyIndexBits) |= mask;
} else {
// Shortcut if the bit is already set correctly
if (!(_details->multiKeyIndexBits & mask)) {
@@ -150,49 +150,49 @@ bool NamespaceDetailsCollectionCatalogEntry::setIndexIsMultikey(OperationContext
// Invert mask: all 1's except a 0 at the ith bit
mask = ~mask;
- *txn->recoveryUnit()->writing(&_details->multiKeyIndexBits) &= mask;
+ *opCtx->recoveryUnit()->writing(&_details->multiKeyIndexBits) &= mask;
}
return true;
}
-RecordId NamespaceDetailsCollectionCatalogEntry::getIndexHead(OperationContext* txn,
+RecordId NamespaceDetailsCollectionCatalogEntry::getIndexHead(OperationContext* opCtx,
StringData idxName) const {
- int idxNo = _findIndexNumber(txn, idxName);
+ int idxNo = _findIndexNumber(opCtx, idxName);
invariant(idxNo >= 0);
return _details->idx(idxNo).head.toRecordId();
}
-BSONObj NamespaceDetailsCollectionCatalogEntry::getIndexSpec(OperationContext* txn,
+BSONObj NamespaceDetailsCollectionCatalogEntry::getIndexSpec(OperationContext* opCtx,
StringData idxName) const {
- int idxNo = _findIndexNumber(txn, idxName);
+ int idxNo = _findIndexNumber(opCtx, idxName);
invariant(idxNo >= 0);
const IndexDetails& id = _details->idx(idxNo);
- return _indexRecordStore->dataFor(txn, id.info.toRecordId()).toBson();
+ return _indexRecordStore->dataFor(opCtx, id.info.toRecordId()).toBson();
}
-void NamespaceDetailsCollectionCatalogEntry::setIndexHead(OperationContext* txn,
+void NamespaceDetailsCollectionCatalogEntry::setIndexHead(OperationContext* opCtx,
StringData idxName,
const RecordId& newHead) {
- int idxNo = _findIndexNumber(txn, idxName);
+ int idxNo = _findIndexNumber(opCtx, idxName);
invariant(idxNo >= 0);
- *txn->recoveryUnit()->writing(&_details->idx(idxNo).head) = DiskLoc::fromRecordId(newHead);
+ *opCtx->recoveryUnit()->writing(&_details->idx(idxNo).head) = DiskLoc::fromRecordId(newHead);
}
-bool NamespaceDetailsCollectionCatalogEntry::isIndexReady(OperationContext* txn,
+bool NamespaceDetailsCollectionCatalogEntry::isIndexReady(OperationContext* opCtx,
StringData idxName) const {
- int idxNo = _findIndexNumber(txn, idxName);
+ int idxNo = _findIndexNumber(opCtx, idxName);
invariant(idxNo >= 0);
- return idxNo < getCompletedIndexCount(txn);
+ return idxNo < getCompletedIndexCount(opCtx);
}
-int NamespaceDetailsCollectionCatalogEntry::_findIndexNumber(OperationContext* txn,
+int NamespaceDetailsCollectionCatalogEntry::_findIndexNumber(OperationContext* opCtx,
StringData idxName) const {
NamespaceDetails::IndexIterator i = _details->ii(true);
while (i.more()) {
const IndexDetails& id = i.next();
int idxNo = i.pos() - 1;
- const BSONObj obj = _indexRecordStore->dataFor(txn, id.info.toRecordId()).toBson();
+ const BSONObj obj = _indexRecordStore->dataFor(opCtx, id.info.toRecordId()).toBson();
if (idxName == obj.getStringField("name"))
return idxNo;
}
@@ -221,29 +221,29 @@ public:
}
} iu_unittest;
-Status NamespaceDetailsCollectionCatalogEntry::removeIndex(OperationContext* txn,
+Status NamespaceDetailsCollectionCatalogEntry::removeIndex(OperationContext* opCtx,
StringData indexName) {
- int idxNo = _findIndexNumber(txn, indexName);
+ int idxNo = _findIndexNumber(opCtx, indexName);
if (idxNo < 0)
return Status(ErrorCodes::NamespaceNotFound, "index not found to remove");
RecordId infoLocation = _details->idx(idxNo).info.toRecordId();
{ // sanity check
- BSONObj info = _indexRecordStore->dataFor(txn, infoLocation).toBson();
+ BSONObj info = _indexRecordStore->dataFor(opCtx, infoLocation).toBson();
invariant(info["name"].String() == indexName);
}
{ // drop the namespace
string indexNamespace = IndexDescriptor::makeIndexNamespace(ns().ns(), indexName);
- Status status = _db->dropCollection(txn, indexNamespace);
+ Status status = _db->dropCollection(opCtx, indexNamespace);
if (!status.isOK()) {
return status;
}
}
{ // all info in the .ns file
- NamespaceDetails* d = _details->writingWithExtra(txn);
+ NamespaceDetails* d = _details->writingWithExtra(opCtx);
// fix the _multiKeyIndexBits, by moving all bits above me down one
d->multiKeyIndexBits = removeAndSlideBit(d->multiKeyIndexBits, idxNo);
@@ -253,100 +253,100 @@ Status NamespaceDetailsCollectionCatalogEntry::removeIndex(OperationContext* txn
else
d->nIndexes--;
- for (int i = idxNo; i < getTotalIndexCount(txn); i++)
+ for (int i = idxNo; i < getTotalIndexCount(opCtx); i++)
d->idx(i) = d->idx(i + 1);
- d->idx(getTotalIndexCount(txn)) = IndexDetails();
+ d->idx(getTotalIndexCount(opCtx)) = 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);
+ opCtx, NamespaceString(_db->name(), "system.indexes"), infoLocation);
// remove from system.indexes
- _indexRecordStore->deleteRecord(txn, infoLocation);
+ _indexRecordStore->deleteRecord(opCtx, infoLocation);
return Status::OK();
}
-Status NamespaceDetailsCollectionCatalogEntry::prepareForIndexBuild(OperationContext* txn,
+Status NamespaceDetailsCollectionCatalogEntry::prepareForIndexBuild(OperationContext* opCtx,
const IndexDescriptor* desc) {
BSONObj spec = desc->infoObj();
// 1) entry in system.indexs
StatusWith<RecordId> systemIndexesEntry =
- _indexRecordStore->insertRecord(txn, spec.objdata(), spec.objsize(), false);
+ _indexRecordStore->insertRecord(opCtx, spec.objdata(), spec.objsize(), false);
if (!systemIndexesEntry.isOK())
return systemIndexesEntry.getStatus();
// 2) NamespaceDetails mods
IndexDetails* id;
try {
- id = &_details->idx(getTotalIndexCount(txn), true);
+ id = &_details->idx(getTotalIndexCount(opCtx), true);
} catch (DBException&) {
- _details->allocExtra(txn, ns().ns(), _db->_namespaceIndex, getTotalIndexCount(txn));
- id = &_details->idx(getTotalIndexCount(txn), false);
+ _details->allocExtra(opCtx, ns().ns(), _db->_namespaceIndex, getTotalIndexCount(opCtx));
+ id = &_details->idx(getTotalIndexCount(opCtx), false);
}
const DiskLoc infoLoc = DiskLoc::fromRecordId(systemIndexesEntry.getValue());
- *txn->recoveryUnit()->writing(&id->info) = infoLoc;
- *txn->recoveryUnit()->writing(&id->head) = DiskLoc();
+ *opCtx->recoveryUnit()->writing(&id->info) = infoLoc;
+ *opCtx->recoveryUnit()->writing(&id->head) = DiskLoc();
- txn->recoveryUnit()->writingInt(_details->indexBuildsInProgress) += 1;
+ opCtx->recoveryUnit()->writingInt(_details->indexBuildsInProgress) += 1;
// 3) indexes entry in .ns file and system.namespaces
- _db->createNamespaceForIndex(txn, desc->indexNamespace());
+ _db->createNamespaceForIndex(opCtx, desc->indexNamespace());
// TODO SERVER-22727: Create an entry for path-level multikey info when creating the new index.
// Mark the collation feature as in use if the index has a non-simple collation.
if (spec["collation"]) {
- _db->markCollationFeatureAsInUse(txn);
+ _db->markCollationFeatureAsInUse(opCtx);
}
return Status::OK();
}
-void NamespaceDetailsCollectionCatalogEntry::indexBuildSuccess(OperationContext* txn,
+void NamespaceDetailsCollectionCatalogEntry::indexBuildSuccess(OperationContext* opCtx,
StringData indexName) {
- int idxNo = _findIndexNumber(txn, indexName);
+ int idxNo = _findIndexNumber(opCtx, indexName);
fassert(17202, idxNo >= 0);
// Make sure the newly created index is relocated to nIndexes, if it isn't already there
- if (idxNo != getCompletedIndexCount(txn)) {
- int toIdxNo = getCompletedIndexCount(txn);
+ if (idxNo != getCompletedIndexCount(opCtx)) {
+ int toIdxNo = getCompletedIndexCount(opCtx);
- //_details->swapIndex( txn, idxNo, toIdxNo );
+ //_details->swapIndex( opCtx, idxNo, toIdxNo );
// flip main meta data
IndexDetails temp = _details->idx(idxNo);
- *txn->recoveryUnit()->writing(&_details->idx(idxNo)) = _details->idx(toIdxNo);
- *txn->recoveryUnit()->writing(&_details->idx(toIdxNo)) = temp;
+ *opCtx->recoveryUnit()->writing(&_details->idx(idxNo)) = _details->idx(toIdxNo);
+ *opCtx->recoveryUnit()->writing(&_details->idx(toIdxNo)) = temp;
// flip multi key bits
bool tempMultikey = isIndexMultikey(idxNo);
- setIndexIsMultikey(txn, idxNo, isIndexMultikey(toIdxNo));
- setIndexIsMultikey(txn, toIdxNo, tempMultikey);
+ setIndexIsMultikey(opCtx, idxNo, isIndexMultikey(toIdxNo));
+ setIndexIsMultikey(opCtx, toIdxNo, tempMultikey);
idxNo = toIdxNo;
- invariant((idxNo = _findIndexNumber(txn, indexName)));
+ invariant((idxNo = _findIndexNumber(opCtx, indexName)));
}
- txn->recoveryUnit()->writingInt(_details->indexBuildsInProgress) -= 1;
- txn->recoveryUnit()->writingInt(_details->nIndexes) += 1;
+ opCtx->recoveryUnit()->writingInt(_details->indexBuildsInProgress) -= 1;
+ opCtx->recoveryUnit()->writingInt(_details->nIndexes) += 1;
- invariant(isIndexReady(txn, indexName));
+ invariant(isIndexReady(opCtx, indexName));
}
-void NamespaceDetailsCollectionCatalogEntry::updateTTLSetting(OperationContext* txn,
+void NamespaceDetailsCollectionCatalogEntry::updateTTLSetting(OperationContext* opCtx,
StringData idxName,
long long newExpireSeconds) {
- int idx = _findIndexNumber(txn, idxName);
+ int idx = _findIndexNumber(opCtx, idxName);
invariant(idx >= 0);
IndexDetails& indexDetails = _details->idx(idx);
- BSONObj obj = _indexRecordStore->dataFor(txn, indexDetails.info.toRecordId()).toBson();
+ BSONObj obj = _indexRecordStore->dataFor(opCtx, indexDetails.info.toRecordId()).toBson();
const BSONElement oldExpireSecs = obj.getField("expireAfterSeconds");
// Important that we set the new value in-place. We are writing directly to the
@@ -358,14 +358,14 @@ void NamespaceDetailsCollectionCatalogEntry::updateTTLSetting(OperationContext*
massert(16631, "index does not have an 'expireAfterSeconds' field", false);
break;
case NumberInt:
- *txn->recoveryUnit()->writing(reinterpret_cast<int*>(nonConstPtr)) = newExpireSeconds;
+ *opCtx->recoveryUnit()->writing(reinterpret_cast<int*>(nonConstPtr)) = newExpireSeconds;
break;
case NumberDouble:
- *txn->recoveryUnit()->writing(reinterpret_cast<double*>(nonConstPtr)) =
+ *opCtx->recoveryUnit()->writing(reinterpret_cast<double*>(nonConstPtr)) =
newExpireSeconds;
break;
case NumberLong:
- *txn->recoveryUnit()->writing(reinterpret_cast<long long*>(nonConstPtr)) =
+ *opCtx->recoveryUnit()->writing(reinterpret_cast<long long*>(nonConstPtr)) =
newExpireSeconds;
break;
default:
@@ -373,65 +373,66 @@ void NamespaceDetailsCollectionCatalogEntry::updateTTLSetting(OperationContext*
}
}
-void NamespaceDetailsCollectionCatalogEntry::_updateSystemNamespaces(OperationContext* txn,
+void NamespaceDetailsCollectionCatalogEntry::_updateSystemNamespaces(OperationContext* opCtx,
const BSONObj& update) {
if (!_namespacesRecordStore)
return;
- RecordData entry = _namespacesRecordStore->dataFor(txn, _namespacesRecordId);
+ RecordData entry = _namespacesRecordStore->dataFor(opCtx, _namespacesRecordId);
const BSONObj newEntry = applyUpdateOperators(entry.releaseToBson(), update);
Status result = _namespacesRecordStore->updateRecord(
- txn, _namespacesRecordId, newEntry.objdata(), newEntry.objsize(), false, NULL);
+ opCtx, _namespacesRecordId, newEntry.objdata(), newEntry.objsize(), false, NULL);
if (ErrorCodes::NeedsDocumentMove == result) {
StatusWith<RecordId> newLocation = _namespacesRecordStore->insertRecord(
- txn, newEntry.objdata(), newEntry.objsize(), false);
+ opCtx, newEntry.objdata(), newEntry.objsize(), false);
fassert(40074, newLocation.getStatus().isOK());
// Invalidate old namespace record
MMAPV1DatabaseCatalogEntry::invalidateSystemCollectionRecord(
- txn, NamespaceString(_db->name(), "system.namespaces"), _namespacesRecordId);
+ opCtx, NamespaceString(_db->name(), "system.namespaces"), _namespacesRecordId);
- _namespacesRecordStore->deleteRecord(txn, _namespacesRecordId);
+ _namespacesRecordStore->deleteRecord(opCtx, _namespacesRecordId);
- setNamespacesRecordId(txn, newLocation.getValue());
+ setNamespacesRecordId(opCtx, newLocation.getValue());
} else {
fassert(17486, result.isOK());
}
}
-void NamespaceDetailsCollectionCatalogEntry::updateFlags(OperationContext* txn, int newValue) {
+void NamespaceDetailsCollectionCatalogEntry::updateFlags(OperationContext* opCtx, int newValue) {
NamespaceDetailsRSV1MetaData md(ns().ns(), _details);
- md.replaceUserFlags(txn, newValue);
- _updateSystemNamespaces(txn, BSON("$set" << BSON("options.flags" << newValue)));
+ md.replaceUserFlags(opCtx, newValue);
+ _updateSystemNamespaces(opCtx, BSON("$set" << BSON("options.flags" << newValue)));
}
-void NamespaceDetailsCollectionCatalogEntry::updateValidator(OperationContext* txn,
+void NamespaceDetailsCollectionCatalogEntry::updateValidator(OperationContext* opCtx,
const BSONObj& validator,
StringData validationLevel,
StringData validationAction) {
_updateSystemNamespaces(
- txn,
+ opCtx,
BSON("$set" << BSON("options.validator" << validator << "options.validationLevel"
<< validationLevel
<< "options.validationAction"
<< validationAction)));
}
-void NamespaceDetailsCollectionCatalogEntry::setNamespacesRecordId(OperationContext* txn,
+void NamespaceDetailsCollectionCatalogEntry::setNamespacesRecordId(OperationContext* opCtx,
RecordId newId) {
if (newId.isNull()) {
invariant(ns().coll() == "system.namespaces" || ns().coll() == "system.indexes");
} else {
- // 'txn' is allowed to be null, but we don't need an OperationContext in MMAP, so that's OK.
- auto namespaceEntry = _namespacesRecordStore->dataFor(txn, newId).releaseToBson();
+ // 'opCtx' is allowed to be null, but we don't need an OperationContext in MMAP, so that's
+ // OK.
+ auto namespaceEntry = _namespacesRecordStore->dataFor(opCtx, newId).releaseToBson();
invariant(namespaceEntry["name"].String() == ns().ns());
// Register RecordId change for rollback if we're not initializing.
- if (txn && !_namespacesRecordId.isNull()) {
+ if (opCtx && !_namespacesRecordId.isNull()) {
auto oldNamespacesRecordId = _namespacesRecordId;
- txn->recoveryUnit()->onRollback([=] { _namespacesRecordId = oldNamespacesRecordId; });
+ opCtx->recoveryUnit()->onRollback([=] { _namespacesRecordId = oldNamespacesRecordId; });
}
_namespacesRecordId = newId;
}