diff options
author | Evgeni Dobranov <evgeni.dobranov@mongodb.com> | 2019-09-09 21:25:21 +0000 |
---|---|---|
committer | evergreen <evergreen@mongodb.com> | 2019-09-09 21:25:21 +0000 |
commit | 857c21aec7011c9b8858bdd032e9c0c24970faef (patch) | |
tree | 728fe1f4967eace5b4c39d6e49e277f1a9c46e26 | |
parent | 35211e5167fb9a3de774dfcc866ef05d6dd4755f (diff) | |
download | mongo-857c21aec7011c9b8858bdd032e9c0c24970faef.tar.gz |
SERVER-41896 Take a unique_ptr as an argument to RecoveryUnit::registerChange()
23 files changed, 83 insertions, 72 deletions
diff --git a/src/mongo/db/auth/authorization_manager_test.cpp b/src/mongo/db/auth/authorization_manager_test.cpp index 46c6da88230..54f99db1aa7 100644 --- a/src/mongo/db/auth/authorization_manager_test.cpp +++ b/src/mongo/db/auth/authorization_manager_test.cpp @@ -335,9 +335,9 @@ public: public: MockRecoveryUnit(size_t* registeredChanges) : _registeredChanges(registeredChanges) {} - virtual void registerChange(Change* change) final { + virtual void registerChange(std::unique_ptr<Change> change) final { // RecoveryUnitNoop takes ownership of the Change - RecoveryUnitNoop::registerChange(change); + RecoveryUnitNoop::registerChange(std::move(change)); ++(*_registeredChanges); } diff --git a/src/mongo/db/auth/authz_manager_external_state_local.cpp b/src/mongo/db/auth/authz_manager_external_state_local.cpp index e87a9880e73..311e68ad533 100644 --- a/src/mongo/db/auth/authz_manager_external_state_local.cpp +++ b/src/mongo/db/auth/authz_manager_external_state_local.cpp @@ -645,12 +645,13 @@ void AuthzManagerExternalStateLocal::logOp(OperationContext* opCtx, nss == AuthorizationManager::usersCollectionNamespace || nss == AuthorizationManager::adminCommandNamespace) { - auto change = new AuthzManagerLogOpHandler(opCtx, authzManager, this, op, nss, o, o2); + auto change = + std::make_unique<AuthzManagerLogOpHandler>(opCtx, authzManager, this, op, nss, o, o2); // AuthzManagerExternalState's logOp method registers a RecoveryUnit::Change // and to do so we need to have begun a UnitOfWork WriteUnitOfWork wuow(opCtx); - opCtx->recoveryUnit()->registerChange(change); + opCtx->recoveryUnit()->registerChange(std::move(change)); wuow.commit(); } diff --git a/src/mongo/db/catalog/coll_mod.cpp b/src/mongo/db/catalog/coll_mod.cpp index 99a65c73471..a1f87acd21e 100644 --- a/src/mongo/db/catalog/coll_mod.cpp +++ b/src/mongo/db/catalog/coll_mod.cpp @@ -368,7 +368,7 @@ Status _collModInternal(OperationContext* opCtx, // in cmrNew will be invalidated and the idx pointer in cmrOld will be valid again. cmrNew.idx = coll->getIndexCatalog()->refreshEntry(opCtx, cmrOld.idx); opCtx->recoveryUnit()->registerChange( - new CollModResultChange(oldExpireSecs, newExpireSecs, result)); + std::make_unique<CollModResultChange>(oldExpireSecs, newExpireSecs, result)); if (MONGO_FAIL_POINT(assertAfterIndexUpdate)) { log() << "collMod - assertAfterIndexUpdate fail point enabled."; diff --git a/src/mongo/db/catalog/collection_catalog.cpp b/src/mongo/db/catalog/collection_catalog.cpp index 42e5d1986cc..0513e37b9cb 100644 --- a/src/mongo/db/catalog/collection_catalog.cpp +++ b/src/mongo/db/catalog/collection_catalog.cpp @@ -420,9 +420,9 @@ std::unique_ptr<Collection> CollectionCatalog::deregisterCollection(CollectionUU return coll; } -RecoveryUnit::Change* CollectionCatalog::makeFinishDropCollectionChange( +std::unique_ptr<RecoveryUnit::Change> CollectionCatalog::makeFinishDropCollectionChange( std::unique_ptr<Collection> coll, CollectionUUID uuid) { - return new FinishDropCollectionChange(this, std::move(coll), uuid); + return std::make_unique<FinishDropCollectionChange>(this, std::move(coll), uuid); } void CollectionCatalog::deregisterAllCollections() { diff --git a/src/mongo/db/catalog/collection_catalog.h b/src/mongo/db/catalog/collection_catalog.h index f3886c3fea0..e54c6141a13 100644 --- a/src/mongo/db/catalog/collection_catalog.h +++ b/src/mongo/db/catalog/collection_catalog.h @@ -126,8 +126,8 @@ public: /** * Returns the RecoveryUnit's Change for dropping the collection */ - RecoveryUnit::Change* makeFinishDropCollectionChange(std::unique_ptr<Collection>, - CollectionUUID uuid); + std::unique_ptr<RecoveryUnit::Change> makeFinishDropCollectionChange( + std::unique_ptr<Collection>, CollectionUUID uuid); /** * Deregister all the collection objects. diff --git a/src/mongo/db/catalog/index_catalog_impl.cpp b/src/mongo/db/catalog/index_catalog_impl.cpp index 00617fbb514..04066249e50 100644 --- a/src/mongo/db/catalog/index_catalog_impl.cpp +++ b/src/mongo/db/catalog/index_catalog_impl.cpp @@ -914,13 +914,13 @@ Status IndexCatalogImpl::dropIndexEntry(OperationContext* opCtx, IndexCatalogEnt auto released = _readyIndexes.release(entry->descriptor()); if (released) { invariant(released.get() == entry); - opCtx->recoveryUnit()->registerChange( - new IndexRemoveChange(opCtx, _collection, &_readyIndexes, std::move(released))); + opCtx->recoveryUnit()->registerChange(std::make_unique<IndexRemoveChange>( + opCtx, _collection, &_readyIndexes, std::move(released))); } else { released = _buildingIndexes.release(entry->descriptor()); invariant(released.get() == entry); - opCtx->recoveryUnit()->registerChange( - new IndexRemoveChange(opCtx, _collection, &_buildingIndexes, std::move(released))); + opCtx->recoveryUnit()->registerChange(std::make_unique<IndexRemoveChange>( + opCtx, _collection, &_buildingIndexes, std::move(released))); } CollectionQueryInfo::get(_collection).droppedIndex(opCtx, indexName); @@ -1165,8 +1165,8 @@ const IndexDescriptor* IndexCatalogImpl::refreshEntry(OperationContext* opCtx, // CollectionQueryInfo. auto oldEntry = _readyIndexes.release(oldDesc); invariant(oldEntry); - opCtx->recoveryUnit()->registerChange( - new IndexRemoveChange(opCtx, _collection, &_readyIndexes, std::move(oldEntry))); + opCtx->recoveryUnit()->registerChange(std::make_unique<IndexRemoveChange>( + opCtx, _collection, &_readyIndexes, std::move(oldEntry))); CollectionQueryInfo::get(_collection).droppedIndex(opCtx, indexName); // Ask the CollectionCatalogEntry for the new index spec. diff --git a/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp b/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp index 8a01dc92912..b2d8544b21a 100644 --- a/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp +++ b/src/mongo/db/s/migration_chunk_cloner_source_legacy.cpp @@ -461,11 +461,11 @@ void MigrationChunkClonerSourceLegacy::onInsertOp(OperationContext* opCtx, } if (opCtx->getTxnNumber()) { - opCtx->recoveryUnit()->registerChange( - new LogOpForShardingHandler(this, idElement.wrap(), 'i', opTime, {})); + opCtx->recoveryUnit()->registerChange(std::make_unique<LogOpForShardingHandler>( + this, idElement.wrap(), 'i', opTime, repl::OpTime())); } else { - opCtx->recoveryUnit()->registerChange( - new LogOpForShardingHandler(this, idElement.wrap(), 'i', {}, {})); + opCtx->recoveryUnit()->registerChange(std::make_unique<LogOpForShardingHandler>( + this, idElement.wrap(), 'i', repl::OpTime(), repl::OpTime())); } } @@ -500,11 +500,11 @@ void MigrationChunkClonerSourceLegacy::onUpdateOp(OperationContext* opCtx, } if (opCtx->getTxnNumber()) { - opCtx->recoveryUnit()->registerChange( - new LogOpForShardingHandler(this, idElement.wrap(), 'u', opTime, prePostImageOpTime)); + opCtx->recoveryUnit()->registerChange(std::make_unique<LogOpForShardingHandler>( + this, idElement.wrap(), 'u', opTime, prePostImageOpTime)); } else { - opCtx->recoveryUnit()->registerChange( - new LogOpForShardingHandler(this, idElement.wrap(), 'u', {}, {})); + opCtx->recoveryUnit()->registerChange(std::make_unique<LogOpForShardingHandler>( + this, idElement.wrap(), 'u', repl::OpTime(), repl::OpTime())); } } @@ -526,11 +526,11 @@ void MigrationChunkClonerSourceLegacy::onDeleteOp(OperationContext* opCtx, } if (opCtx->getTxnNumber()) { - opCtx->recoveryUnit()->registerChange( - new LogOpForShardingHandler(this, idElement.wrap(), 'd', opTime, preImageOpTime)); + opCtx->recoveryUnit()->registerChange(std::make_unique<LogOpForShardingHandler>( + this, idElement.wrap(), 'd', opTime, preImageOpTime)); } else { - opCtx->recoveryUnit()->registerChange( - new LogOpForShardingHandler(this, idElement.wrap(), 'd', {}, {})); + opCtx->recoveryUnit()->registerChange(std::make_unique<LogOpForShardingHandler>( + this, idElement.wrap(), 'd', repl::OpTime(), repl::OpTime())); } } diff --git a/src/mongo/db/s/op_observer_sharding_impl.cpp b/src/mongo/db/s/op_observer_sharding_impl.cpp index 4ede2a0f03d..ab0022dd860 100644 --- a/src/mongo/db/s/op_observer_sharding_impl.cpp +++ b/src/mongo/db/s/op_observer_sharding_impl.cpp @@ -170,8 +170,9 @@ void OpObserverShardingImpl::shardObserveTransactionPrepareOrUnpreparedCommit( const std::vector<repl::ReplOperation>& stmts, const repl::OpTime& prepareOrCommitOptime) { - opCtx->recoveryUnit()->registerChange(new LogTransactionOperationsForShardingHandler( - opCtx->getServiceContext(), stmts, prepareOrCommitOptime)); + opCtx->recoveryUnit()->registerChange( + std::make_unique<LogTransactionOperationsForShardingHandler>( + opCtx->getServiceContext(), stmts, prepareOrCommitOptime)); } } // namespace mongo diff --git a/src/mongo/db/s/shard_server_op_observer.cpp b/src/mongo/db/s/shard_server_op_observer.cpp index 9c58f262692..ed74cf027e7 100644 --- a/src/mongo/db/s/shard_server_op_observer.cpp +++ b/src/mongo/db/s/shard_server_op_observer.cpp @@ -140,7 +140,8 @@ void onConfigDeleteInvalidateCachedCollectionMetadataAndNotify(OperationContext* // Need the WUOW to retain the lock for CollectionVersionLogOpHandler::commit(). AutoGetCollection autoColl(opCtx, deletedNss, MODE_IX); - opCtx->recoveryUnit()->registerChange(new CollectionVersionLogOpHandler(opCtx, deletedNss)); + opCtx->recoveryUnit()->registerChange( + std::make_unique<CollectionVersionLogOpHandler>(opCtx, deletedNss)); } /** @@ -219,7 +220,8 @@ void ShardServerOpObserver::onInserts(OperationContext* opCtx, uassertStatusOK(ShardIdentityType::fromShardIdentityDocument(insertedDoc)); uassertStatusOK(shardIdentityDoc.validate()); opCtx->recoveryUnit()->registerChange( - new ShardIdentityLogOpHandler(opCtx, std::move(shardIdentityDoc))); + std::make_unique<ShardIdentityLogOpHandler>(opCtx, + std::move(shardIdentityDoc))); } } } @@ -281,7 +283,7 @@ void ShardServerOpObserver::onUpdate(OperationContext* opCtx, const OplogUpdateE if (setField.hasField(ShardCollectionType::kLastRefreshedCollectionVersionFieldName) && !setField.getBoolField("refreshing")) { opCtx->recoveryUnit()->registerChange( - new CollectionVersionLogOpHandler(opCtx, updatedNss)); + std::make_unique<CollectionVersionLogOpHandler>(opCtx, updatedNss)); } if (setField.hasField(ShardCollectionType::kEnterCriticalSectionCounterFieldName)) { diff --git a/src/mongo/db/session_catalog_mongod.cpp b/src/mongo/db/session_catalog_mongod.cpp index a4200433a24..1a336e5c730 100644 --- a/src/mongo/db/session_catalog_mongod.cpp +++ b/src/mongo/db/session_catalog_mongod.cpp @@ -307,7 +307,8 @@ void MongoDSessionCatalog::observeDirectWriteToConfigTransactions(OperationConte << " because it is in the prepared state", !participant.transactionIsPrepared()); - opCtx->recoveryUnit()->registerChange(new KillSessionTokenOnCommit(opCtx, session.kill())); + opCtx->recoveryUnit()->registerChange( + std::make_unique<KillSessionTokenOnCommit>(opCtx, session.kill())); }); } diff --git a/src/mongo/db/storage/biggie/biggie_visibility_manager.cpp b/src/mongo/db/storage/biggie/biggie_visibility_manager.cpp index e638638aa4d..d9921bc6472 100644 --- a/src/mongo/db/storage/biggie/biggie_visibility_manager.cpp +++ b/src/mongo/db/storage/biggie/biggie_visibility_manager.cpp @@ -78,7 +78,7 @@ void VisibilityManager::addUncommittedRecord(OperationContext* opCtx, RecordId rid) { stdx::lock_guard<stdx::mutex> lock(_stateLock); _uncommittedRecords.insert(rid); - opCtx->recoveryUnit()->registerChange(new VisibilityManagerChange(this, rs, rid)); + opCtx->recoveryUnit()->registerChange(std::make_unique<VisibilityManagerChange>(this, rs, rid)); if (rid > _highestSeen) _highestSeen = rid; diff --git a/src/mongo/db/storage/durable_catalog_impl.cpp b/src/mongo/db/storage/durable_catalog_impl.cpp index faf49552f34..fc88ca957ff 100644 --- a/src/mongo/db/storage/durable_catalog_impl.cpp +++ b/src/mongo/db/storage/durable_catalog_impl.cpp @@ -493,7 +493,7 @@ Status DurableCatalogImpl::_addEntry(OperationContext* opCtx, return Status(ErrorCodes::NamespaceExists, "collection already exists"); } - opCtx->recoveryUnit()->registerChange(new AddIdentChange(this, nss.ns())); + opCtx->recoveryUnit()->registerChange(std::make_unique<AddIdentChange>(this, nss.ns())); BSONObj obj; { @@ -657,8 +657,8 @@ Status DurableCatalogImpl::_replaceEntry(OperationContext* opCtx, invariant(fromIt != _idents.end()); opCtx->recoveryUnit()->registerChange( - new RemoveIdentChange(this, fromNss.ns(), fromIt->second)); - opCtx->recoveryUnit()->registerChange(new AddIdentChange(this, toNss.ns())); + std::make_unique<RemoveIdentChange>(this, fromNss.ns(), fromIt->second)); + opCtx->recoveryUnit()->registerChange(std::make_unique<AddIdentChange>(this, toNss.ns())); _idents.erase(fromIt); _idents[toNss.toString()] = Entry(old["ident"].String(), loc); @@ -679,7 +679,8 @@ Status DurableCatalogImpl::_removeEntry(OperationContext* opCtx, const Namespace return Status(ErrorCodes::NamespaceNotFound, "collection not found"); } - opCtx->recoveryUnit()->registerChange(new RemoveIdentChange(this, nss.ns(), it->second)); + opCtx->recoveryUnit()->registerChange( + std::make_unique<RemoveIdentChange>(this, nss.ns(), it->second)); LOG(1) << "deleting metadata for " << nss << " @ " << it->second.storedLoc; _rs->deleteRecord(opCtx, it->second.storedLoc); @@ -766,7 +767,7 @@ StatusWith<std::string> DurableCatalogImpl::newOrphanedIdent(OperationContext* o return Status(ErrorCodes::NamespaceExists, str::stream() << ns << " already exists in the catalog"); } - opCtx->recoveryUnit()->registerChange(new AddIdentChange(this, ns)); + opCtx->recoveryUnit()->registerChange(std::make_unique<AddIdentChange>(this, ns)); // Generate a new UUID for the orphaned collection. CollectionOptions optionsWithUUID; @@ -982,7 +983,7 @@ Status DurableCatalogImpl::removeIndex(OperationContext* opCtx, // Lazily remove to isolate underlying engine from rollback. opCtx->recoveryUnit()->registerChange( - new RemoveIndexChange(opCtx, _engine, md.options.uuid, ns, indexName, ident)); + std::make_unique<RemoveIndexChange>(opCtx, _engine, md.options.uuid, ns, indexName, ident)); return Status::OK(); } @@ -1027,7 +1028,8 @@ Status DurableCatalogImpl::prepareForIndexBuild(OperationContext* opCtx, const Status status = kvEngine->createGroupedSortedDataInterface( opCtx, getCollectionOptions(opCtx, ns), ident, spec, prefix); if (status.isOK()) { - opCtx->recoveryUnit()->registerChange(new AddIndexChange(opCtx, _engine, ident)); + opCtx->recoveryUnit()->registerChange( + std::make_unique<AddIndexChange>(opCtx, _engine, ident)); } return status; diff --git a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl.cpp b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl.cpp index 7053db41a66..79222964c48 100644 --- a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl.cpp +++ b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_btree_impl.cpp @@ -177,7 +177,8 @@ public: IndexKeyEntry entry(key.getOwned(), loc); if (_data->insert(entry).second) { _currentKeySize += key.objsize(); - opCtx->recoveryUnit()->registerChange(new IndexChange(_data, entry, true)); + opCtx->recoveryUnit()->registerChange( + std::make_unique<IndexChange>(_data, entry, true)); } return Status::OK(); } @@ -204,7 +205,8 @@ public: invariant(numDeleted <= 1); if (numDeleted == 1) { _currentKeySize -= key.objsize(); - opCtx->recoveryUnit()->registerChange(new IndexChange(_data, entry, false)); + opCtx->recoveryUnit()->registerChange( + std::make_unique<IndexChange>(_data, entry, false)); } } diff --git a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_record_store.cpp b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_record_store.cpp index dc41fab864c..cc49ab9fbd0 100644 --- a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_record_store.cpp +++ b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_record_store.cpp @@ -345,7 +345,7 @@ void EphemeralForTestRecordStore::deleteRecord(WithLock lk, OperationContext* opCtx, const RecordId& loc) { EphemeralForTestRecord* rec = recordFor(lk, loc); - opCtx->recoveryUnit()->registerChange(new RemoveChange(opCtx, _data, loc, *rec)); + opCtx->recoveryUnit()->registerChange(std::make_unique<RemoveChange>(opCtx, _data, loc, *rec)); _data->dataSize -= rec->size; invariant(_data->records.erase(loc) == 1); } @@ -426,7 +426,7 @@ Status EphemeralForTestRecordStore::insertRecords(OperationContext* opCtx, _data->records[loc] = rec; record->id = loc; - opCtx->recoveryUnit()->registerChange(new InsertChange(opCtx, _data, loc)); + opCtx->recoveryUnit()->registerChange(std::make_unique<InsertChange>(opCtx, _data, loc)); cappedDeleteAsNeeded(lock, opCtx); return Status::OK(); @@ -455,7 +455,8 @@ Status EphemeralForTestRecordStore::updateRecord(OperationContext* opCtx, EphemeralForTestRecord newRecord(len); memcpy(newRecord.data.get(), data, len); - opCtx->recoveryUnit()->registerChange(new RemoveChange(opCtx, _data, loc, *oldRecord)); + opCtx->recoveryUnit()->registerChange( + std::make_unique<RemoveChange>(opCtx, _data, loc, *oldRecord)); _data->dataSize += len - oldLen; *oldRecord = newRecord; @@ -482,7 +483,8 @@ StatusWith<RecordData> EphemeralForTestRecordStore::updateWithDamages( EphemeralForTestRecord newRecord(len); memcpy(newRecord.data.get(), oldRecord->data.get(), len); - opCtx->recoveryUnit()->registerChange(new RemoveChange(opCtx, _data, loc, *oldRecord)); + opCtx->recoveryUnit()->registerChange( + std::make_unique<RemoveChange>(opCtx, _data, loc, *oldRecord)); *oldRecord = newRecord; cappedDeleteAsNeeded(lock, opCtx); @@ -511,7 +513,7 @@ std::unique_ptr<SeekableRecordCursor> EphemeralForTestRecordStore::getCursor( Status EphemeralForTestRecordStore::truncate(OperationContext* opCtx) { // Unlike other changes, TruncateChange mutates _data on construction to perform the // truncate - opCtx->recoveryUnit()->registerChange(new TruncateChange(opCtx, _data)); + opCtx->recoveryUnit()->registerChange(std::make_unique<TruncateChange>(opCtx, _data)); return Status::OK(); } @@ -529,7 +531,8 @@ void EphemeralForTestRecordStore::cappedTruncateAfter(OperationContext* opCtx, uassertStatusOK(_cappedCallback->aboutToDeleteCapped(opCtx, id, record.toRecordData())); } - opCtx->recoveryUnit()->registerChange(new RemoveChange(opCtx, _data, id, record)); + opCtx->recoveryUnit()->registerChange( + std::make_unique<RemoveChange>(opCtx, _data, id, record)); _data->dataSize -= record.size; _data->records.erase(it++); } diff --git a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.cpp b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.cpp index c99194a4406..dd819c9ad48 100644 --- a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.cpp +++ b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.cpp @@ -77,7 +77,7 @@ void EphemeralForTestRecoveryUnit::abortUnitOfWork() { try { for (Changes::reverse_iterator it = _changes.rbegin(), end = _changes.rend(); it != end; ++it) { - ChangePtr change = *it; + auto change = *it; LOG(2) << "CUSTOM ROLLBACK " << demangleName(typeid(*change)); change->rollback(); } @@ -108,7 +108,7 @@ Status EphemeralForTestRecoveryUnit::obtainMajorityCommittedSnapshot() { return Status::OK(); } -void EphemeralForTestRecoveryUnit::registerChange(Change* change) { - _changes.push_back(ChangePtr(change)); +void EphemeralForTestRecoveryUnit::registerChange(std::unique_ptr<Change> change) { + _changes.push_back(std::move(change)); } } // namespace mongo diff --git a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.h b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.h index ab368f45bf5..02e1727c44c 100644 --- a/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.h +++ b/src/mongo/db/storage/ephemeral_for_test/ephemeral_for_test_recovery_unit.h @@ -58,7 +58,7 @@ public: Status obtainMajorityCommittedSnapshot() final; - virtual void registerChange(Change* change); + virtual void registerChange(std::unique_ptr<Change> change); virtual SnapshotId getSnapshotId() const { return SnapshotId(); @@ -89,8 +89,7 @@ public: } private: - typedef std::shared_ptr<Change> ChangePtr; - typedef std::vector<ChangePtr> Changes; + typedef std::vector<std::shared_ptr<Change>> Changes; Changes _changes; std::function<void()> _waitUntilDurableCallback; diff --git a/src/mongo/db/storage/mobile/mobile_record_store.cpp b/src/mongo/db/storage/mobile/mobile_record_store.cpp index 49741ea5f93..7543fcb1617 100644 --- a/src/mongo/db/storage/mobile/mobile_record_store.cpp +++ b/src/mongo/db/storage/mobile/mobile_record_store.cpp @@ -431,7 +431,7 @@ private: void MobileRecordStore::_changeNumRecs(OperationContext* opCtx, int64_t diff) { stdx::lock_guard<stdx::mutex> lock(_numRecsMutex); - opCtx->recoveryUnit()->registerChange(new NumRecsChange(this, diff)); + opCtx->recoveryUnit()->registerChange(std::make_unique<NumRecsChange>(this, diff)); _initNumRecsIfNeeded_inlock(opCtx); _numRecs += diff; } @@ -468,7 +468,7 @@ private: void MobileRecordStore::_changeDataSize(OperationContext* opCtx, int64_t diff) { stdx::lock_guard<stdx::mutex> lock(_dataSizeMutex); - opCtx->recoveryUnit()->registerChange(new DataSizeChange(this, diff)); + opCtx->recoveryUnit()->registerChange(std::make_unique<DataSizeChange>(this, diff)); _initDataSizeIfNeeded_inlock(opCtx); _dataSize += diff; } diff --git a/src/mongo/db/storage/recovery_unit.cpp b/src/mongo/db/storage/recovery_unit.cpp index eb389eaf8b5..27f433d0c5f 100644 --- a/src/mongo/db/storage/recovery_unit.cpp +++ b/src/mongo/db/storage/recovery_unit.cpp @@ -35,9 +35,9 @@ #include "mongo/util/log.h" namespace mongo { -void RecoveryUnit::registerChange(Change* change) { +void RecoveryUnit::registerChange(std::unique_ptr<Change> change) { invariant(_inUnitOfWork(), toString(_getState())); - _changes.push_back(std::unique_ptr<Change>{change}); + _changes.push_back(std::move(change)); } void RecoveryUnit::commitRegisteredChanges(boost::optional<Timestamp> commitTimestamp) { diff --git a/src/mongo/db/storage/recovery_unit.h b/src/mongo/db/storage/recovery_unit.h index b04caa40921..4a03a9a71a7 100644 --- a/src/mongo/db/storage/recovery_unit.h +++ b/src/mongo/db/storage/recovery_unit.h @@ -451,7 +451,7 @@ public: * The registerChange() method may only be called when a WriteUnitOfWork is active, and * may not be called during commit or rollback. */ - virtual void registerChange(Change* change); + virtual void registerChange(std::unique_ptr<Change> change); /** * Registers a callback to be called if the current WriteUnitOfWork rolls back. @@ -472,7 +472,7 @@ public: Callback _callback; }; - registerChange(new OnRollbackChange(std::move(callback))); + registerChange(std::make_unique<OnRollbackChange>(std::move(callback))); } /** @@ -494,7 +494,7 @@ public: Callback _callback; }; - registerChange(new OnCommitChange(std::move(callback))); + registerChange(std::make_unique<OnCommitChange>(std::move(callback))); } virtual void setOrderedCommit(bool orderedCommit) = 0; diff --git a/src/mongo/db/storage/recovery_unit_noop.h b/src/mongo/db/storage/recovery_unit_noop.h index 740cd6f8d1c..c9fee6ca4b2 100644 --- a/src/mongo/db/storage/recovery_unit_noop.h +++ b/src/mongo/db/storage/recovery_unit_noop.h @@ -68,8 +68,8 @@ public: return true; } - virtual void registerChange(Change* change) { - _changes.push_back(std::unique_ptr<Change>(change)); + virtual void registerChange(std::unique_ptr<Change> change) { + _changes.push_back(std::move(change)); } virtual SnapshotId getSnapshotId() const { diff --git a/src/mongo/db/storage/recovery_unit_test_harness.cpp b/src/mongo/db/storage/recovery_unit_test_harness.cpp index 4a6e6df8981..fd1fe3bab35 100644 --- a/src/mongo/db/storage/recovery_unit_test_harness.cpp +++ b/src/mongo/db/storage/recovery_unit_test_harness.cpp @@ -93,13 +93,13 @@ TEST_F(RecoveryUnitTestHarness, CommitAndRollbackChanges) { const auto rs = harnessHelper->createRecordStore(opCtx.get(), "table1"); ru->beginUnitOfWork(opCtx.get()); - ru->registerChange(new TestChange(&count)); + ru->registerChange(std::make_unique<TestChange>(&count)); ASSERT_EQUALS(count, 0); ru->commitUnitOfWork(); ASSERT_EQUALS(count, 1); ru->beginUnitOfWork(opCtx.get()); - ru->registerChange(new TestChange(&count)); + ru->registerChange(std::make_unique<TestChange>(&count)); ASSERT_EQUALS(count, 1); ru->abortUnitOfWork(); ASSERT_EQUALS(count, 0); @@ -125,7 +125,7 @@ TEST_F(RecoveryUnitTestHarness, CheckInActiveTxnWithAbort) { DEATH_TEST_F(RecoveryUnitTestHarness, RegisterChangeMustBeInUnitOfWork, "invariant") { int count = 0; - opCtx->recoveryUnit()->registerChange(new TestChange(&count)); + opCtx->recoveryUnit()->registerChange(std::make_unique<TestChange>(&count)); } DEATH_TEST_F(RecoveryUnitTestHarness, CommitMustBeInUnitOfWork, "invariant") { diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp index 78f31cb4981..f0a12735423 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp @@ -266,11 +266,11 @@ void WiredTigerRecordStore::OplogStones::updateCurrentStoneAfterInsertOnCommit( RecordId highestInserted, int64_t countInserted) { opCtx->recoveryUnit()->registerChange( - new InsertChange(this, bytesInserted, highestInserted, countInserted)); + std::make_unique<InsertChange>(this, bytesInserted, highestInserted, countInserted)); } void WiredTigerRecordStore::OplogStones::clearStonesOnCommit(OperationContext* opCtx) { - opCtx->recoveryUnit()->registerChange(new TruncateChange(this)); + opCtx->recoveryUnit()->registerChange(std::make_unique<TruncateChange>(this)); } void WiredTigerRecordStore::OplogStones::updateStonesAfterCappedTruncateAfter( @@ -1674,7 +1674,7 @@ void WiredTigerRecordStore::_changeNumRecords(OperationContext* opCtx, int64_t d return; } - opCtx->recoveryUnit()->registerChange(new NumRecordsChange(this, diff)); + opCtx->recoveryUnit()->registerChange(std::make_unique<NumRecordsChange>(this, diff)); if (_sizeInfo->numRecords.fetchAndAdd(diff) < 0) _sizeInfo->numRecords.store(std::max(diff, int64_t(0))); } @@ -1702,7 +1702,7 @@ void WiredTigerRecordStore::_increaseDataSize(OperationContext* opCtx, int64_t a } if (opCtx) - opCtx->recoveryUnit()->registerChange(new DataSizeChange(this, amount)); + opCtx->recoveryUnit()->registerChange(std::make_unique<DataSizeChange>(this, amount)); if (_sizeInfo->dataSize.fetchAndAdd(amount) < 0) _sizeInfo->dataSize.store(std::max(amount, int64_t(0))); diff --git a/src/mongo/scripting/engine.cpp b/src/mongo/scripting/engine.cpp index d1a97725786..0c477a24c11 100644 --- a/src/mongo/scripting/engine.cpp +++ b/src/mongo/scripting/engine.cpp @@ -199,7 +199,7 @@ public: }; void Scope::storedFuncMod(OperationContext* opCtx) { - opCtx->recoveryUnit()->registerChange(new StoredFuncModLogOpHandler()); + opCtx->recoveryUnit()->registerChange(std::make_unique<StoredFuncModLogOpHandler>()); } void Scope::validateObjectIdString(const string& str) { |