diff options
author | Hari Khalsa <hkhalsa@10gen.com> | 2014-05-15 13:26:48 -0400 |
---|---|---|
committer | Hari Khalsa <hkhalsa@10gen.com> | 2014-05-15 13:56:05 -0400 |
commit | 4de88387eec6c0bb08b10d0ba1574a656f56232d (patch) | |
tree | 7fdc9a0acd251b5b8b0a8f3de45ce1c2ecf7e94c /src/mongo/db/storage | |
parent | 71cbb04eb8262b0bdf255056f26101466c11b43d (diff) | |
download | mongo-4de88387eec6c0bb08b10d0ba1574a656f56232d.tar.gz |
SERVER-13641 rename TransactionExperiment to OperationContext
Diffstat (limited to 'src/mongo/db/storage')
-rw-r--r-- | src/mongo/db/storage/data_file.cpp | 12 | ||||
-rw-r--r-- | src/mongo/db/storage/data_file.h | 12 | ||||
-rw-r--r-- | src/mongo/db/storage/extent_manager.h | 10 | ||||
-rw-r--r-- | src/mongo/db/storage/mmap_v1/dur_transaction.cpp | 69 | ||||
-rw-r--r-- | src/mongo/db/storage/mmap_v1/dur_transaction.h | 67 | ||||
-rw-r--r-- | src/mongo/db/storage/mmap_v1/mmap_v1_extent_manager.cpp | 24 | ||||
-rw-r--r-- | src/mongo/db/storage/mmap_v1/mmap_v1_extent_manager.h | 24 | ||||
-rw-r--r-- | src/mongo/db/storage/transaction.h | 136 |
8 files changed, 41 insertions, 313 deletions
diff --git a/src/mongo/db/storage/data_file.cpp b/src/mongo/db/storage/data_file.cpp index adeaf34b129..b6466fd5b71 100644 --- a/src/mongo/db/storage/data_file.cpp +++ b/src/mongo/db/storage/data_file.cpp @@ -37,7 +37,7 @@ #include "mongo/db/d_concurrency.h" #include "mongo/db/storage/mmap_v1/dur.h" #include "mongo/db/lockstate.h" -#include "mongo/db/storage/transaction.h" +#include "mongo/db/operation_context.h" #include "mongo/util/file_allocator.h" namespace mongo { @@ -88,7 +88,7 @@ namespace mongo { } /** @return true if found and opened. if uninitialized (prealloc only) does not open. */ - Status DataFile::openExisting( TransactionExperiment* txn, const char *filename ) { + Status DataFile::openExisting( OperationContext* txn, const char *filename ) { verify( _mb == 0 ); if( !boost::filesystem::exists(filename) ) return Status( ErrorCodes::InvalidPath, "DataFile::openExisting - file does not exist" ); @@ -118,7 +118,7 @@ namespace mongo { return Status::OK(); } - void DataFile::open( TransactionExperiment* txn, + void DataFile::open( OperationContext* txn, const char *filename, int minSize, bool preallocateOnly ) { @@ -160,7 +160,7 @@ namespace mongo { mmf.flush( sync ); } - DiskLoc DataFile::allocExtentArea( TransactionExperiment* txn, int size ) { + DiskLoc DataFile::allocExtentArea( OperationContext* txn, int size ) { massert( 10357, "shutdown in progress", !inShutdown() ); massert( 10359, "header==0 on new extent: 32 bit mmap space exceeded?", header() ); // null if file open failed @@ -178,7 +178,7 @@ namespace mongo { // ------------------------------------------------------------------------------- - void DataFileHeader::init(TransactionExperiment* txn, int fileno, int filelength, const char* filename) { + void DataFileHeader::init(OperationContext* txn, int fileno, int filelength, const char* filename) { if ( uninitialized() ) { DEV log() << "datafileheader::init initializing " << filename << " n:" << fileno << endl; if( !(filelength > 32768 ) ) { @@ -217,7 +217,7 @@ namespace mongo { } } - void DataFileHeader::checkUpgrade(TransactionExperiment* txn) { + void DataFileHeader::checkUpgrade(OperationContext* txn) { if ( freeListStart == minDiskLoc ) { // we are upgrading from 2.4 to 2.6 invariant( freeListEnd == minDiskLoc ); // both start and end should be (0,0) or real diff --git a/src/mongo/db/storage/data_file.h b/src/mongo/db/storage/data_file.h index d96d20dffd7..f83e9f8f08f 100644 --- a/src/mongo/db/storage/data_file.h +++ b/src/mongo/db/storage/data_file.h @@ -37,7 +37,7 @@ namespace mongo { class ExtentManager; - class TransactionExperiment; + class OperationContext; /* a datafile - i.e. the "dbname.<#>" files : @@ -77,9 +77,9 @@ namespace mongo { bool uninitialized() const { return version == 0; } - void init(TransactionExperiment* txn, int fileno, int filelength, const char* filename); + void init(OperationContext* txn, int fileno, int filelength, const char* filename); - void checkUpgrade(TransactionExperiment* txn); + void checkUpgrade(OperationContext* txn); bool isEmpty() const { return uninitialized() || ( unusedLength == fileLength - HeaderSize - 16 ); @@ -95,15 +95,15 @@ namespace mongo { DataFile(int fn) : _mb(0), fileNo(fn) { } /** @return true if found and opened. if uninitialized (prealloc only) does not open. */ - Status openExisting( TransactionExperiment* txn, const char *filename ); + Status openExisting( OperationContext* txn, const char *filename ); /** creates if DNE */ - void open(TransactionExperiment* txn, + void open(OperationContext* txn, const char *filename, int requestedDataSize = 0, bool preallocateOnly = false); - DiskLoc allocExtentArea( TransactionExperiment* txn, int size ); + DiskLoc allocExtentArea( OperationContext* txn, int size ); DataFileHeader* getHeader() { return header(); } const DataFileHeader* getHeader() const { return header(); } diff --git a/src/mongo/db/storage/extent_manager.h b/src/mongo/db/storage/extent_manager.h index 7ebb7b199c4..671f4271698 100644 --- a/src/mongo/db/storage/extent_manager.h +++ b/src/mongo/db/storage/extent_manager.h @@ -41,7 +41,7 @@ namespace mongo { class DataFile; class Record; - class TransactionExperiment; + class OperationContext; struct Extent; @@ -68,7 +68,7 @@ namespace mongo { /** * opens all current files */ - virtual Status init(TransactionExperiment* txn) = 0; + virtual Status init(OperationContext* txn) = 0; virtual size_t numFiles() const = 0; virtual long long fileSize() const = 0; @@ -76,7 +76,7 @@ namespace mongo { virtual void flushFiles( bool sync ) = 0; // must call Extent::reuse on the returned extent - virtual DiskLoc allocateExtent( TransactionExperiment* txn, + virtual DiskLoc allocateExtent( OperationContext* txn, bool capped, int size, int quotaMax ) = 0; @@ -84,14 +84,14 @@ namespace mongo { /** * firstExt has to be == lastExt or a chain */ - virtual void freeExtents( TransactionExperiment* txn, + virtual void freeExtents( OperationContext* txn, DiskLoc firstExt, DiskLoc lastExt ) = 0; /** * frees a single extent * ignores all fields in the Extent except: magic, myLoc, length */ - virtual void freeExtent( TransactionExperiment* txn, DiskLoc extent ) = 0; + virtual void freeExtent( OperationContext* txn, DiskLoc extent ) = 0; virtual void freeListStats( int* numExtents, int64_t* totalFreeSize ) const = 0; diff --git a/src/mongo/db/storage/mmap_v1/dur_transaction.cpp b/src/mongo/db/storage/mmap_v1/dur_transaction.cpp deleted file mode 100644 index 8dbf008d5d3..00000000000 --- a/src/mongo/db/storage/mmap_v1/dur_transaction.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Copyright (C) 2014 MongoDB Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the GNU Affero General Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#include "mongo/db/storage/mmap_v1/dur_transaction.h" - -#include "mongo/db/client.h" -#include "mongo/db/curop.h" -#include "mongo/db/kill_current_op.h" -#include "mongo/db/storage/mmap_v1/dur_recovery_unit.h" - -namespace mongo { - - DurTransaction::DurTransaction() { - _recovery.reset(new DurRecoveryUnit()); - } - - RecoveryUnit* DurTransaction::recoveryUnit() const { - return _recovery.get(); - } - - ProgressMeter* DurTransaction::setMessage(const char* msg, - const std::string& name, - unsigned long long progressMeterTotal, - int secondsBetween) { - return &cc().curop()->setMessage( msg, name, progressMeterTotal, secondsBetween ); - } - - void DurTransaction::checkForInterrupt(bool heedMutex) const { - killCurrentOp.checkForInterrupt(heedMutex); - } - - Status DurTransaction::checkForInterruptNoAssert() const { - const char* killed = killCurrentOp.checkForInterruptNoAssert(); - if ( !killed || !killed[0] ) - return Status::OK(); - - return Status( ErrorCodes::Interrupted, killed ); - } - - TransactionExperiment* DurTransaction::factory() { - return new DurTransaction(); - } - -} // namespace mongo diff --git a/src/mongo/db/storage/mmap_v1/dur_transaction.h b/src/mongo/db/storage/mmap_v1/dur_transaction.h deleted file mode 100644 index a0dc1029e6a..00000000000 --- a/src/mongo/db/storage/mmap_v1/dur_transaction.h +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Copyright (C) 2014 MongoDB Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the GNU Affero General Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#include <boost/scoped_ptr.hpp> -#include <string> - -#include "mongo/db/storage/transaction.h" - -#pragma once - -namespace mongo { - - /** - * TODO(hk): Move to db/ and rename to OperationContextMongoDImpl or something better? - */ - class DurTransaction : public TransactionExperiment { - public: - DurTransaction(); - - virtual ~DurTransaction() { } - - virtual RecoveryUnit* recoveryUnit() const; - - virtual ProgressMeter* setMessage(const char* msg, - const std::string& name , - unsigned long long progressMeterTotal, - int secondsBetween); - - virtual void checkForInterrupt(bool heedMutex = true) const; - - virtual Status checkForInterruptNoAssert() const; - - /** - * Returns a DurTransaction. Caller takes ownership. - */ - static TransactionExperiment* factory(); - - private: - boost::scoped_ptr<RecoveryUnit> _recovery; - }; - -} // namespace mongo diff --git a/src/mongo/db/storage/mmap_v1/mmap_v1_extent_manager.cpp b/src/mongo/db/storage/mmap_v1/mmap_v1_extent_manager.cpp index 84bfae056e7..85ad027b39b 100644 --- a/src/mongo/db/storage/mmap_v1/mmap_v1_extent_manager.cpp +++ b/src/mongo/db/storage/mmap_v1/mmap_v1_extent_manager.cpp @@ -40,7 +40,7 @@ #include "mongo/db/storage/extent.h" #include "mongo/db/storage/extent_manager.h" #include "mongo/db/storage/record.h" -#include "mongo/db/storage/transaction.h" +#include "mongo/db/operation_context.h" namespace mongo { @@ -74,7 +74,7 @@ namespace mongo { } - Status MmapV1ExtentManager::init(TransactionExperiment* txn) { + Status MmapV1ExtentManager::init(OperationContext* txn) { verify( _files.size() == 0 ); for ( int n = 0; n < DiskLoc::MaxFiles; n++ ) { @@ -113,7 +113,7 @@ namespace mongo { // todo: this is called a lot. streamline the common case - DataFile* MmapV1ExtentManager::getFile( TransactionExperiment* txn, + DataFile* MmapV1ExtentManager::getFile( OperationContext* txn, int n, int sizeNeeded , bool preallocateOnly) { @@ -174,7 +174,7 @@ namespace mongo { return preallocateOnly ? 0 : p; } - DataFile* MmapV1ExtentManager::_addAFile( TransactionExperiment* txn, + DataFile* MmapV1ExtentManager::_addAFile( OperationContext* txn, int sizeNeeded, bool preallocateNextFile ) { DEV Lock::assertWriteLocked( _dbname ); @@ -243,7 +243,7 @@ namespace mongo { return DataFile::maxSize() - DataFileHeader::HeaderSize - 16; } - DiskLoc MmapV1ExtentManager::_createExtentInFile( TransactionExperiment* txn, + DiskLoc MmapV1ExtentManager::_createExtentInFile( OperationContext* txn, int fileNo, DataFile* f, int size, @@ -276,7 +276,7 @@ namespace mongo { } - DiskLoc MmapV1ExtentManager::_createExtent( TransactionExperiment* txn, + DiskLoc MmapV1ExtentManager::_createExtent( OperationContext* txn, int size, int maxFileNoForQuota ) { size = quantizeExtentSize( size ); @@ -315,7 +315,7 @@ namespace mongo { msgasserted(14810, "couldn't allocate space for a new extent" ); } - DiskLoc MmapV1ExtentManager::_allocFromFreeList( TransactionExperiment* txn, + DiskLoc MmapV1ExtentManager::_allocFromFreeList( OperationContext* txn, int approxSize, bool capped ) { // setup extent constraints @@ -400,7 +400,7 @@ namespace mongo { return best->myLoc; } - DiskLoc MmapV1ExtentManager::allocateExtent( TransactionExperiment* txn, + DiskLoc MmapV1ExtentManager::allocateExtent( OperationContext* txn, bool capped, int size, int quotaMax ) { @@ -423,7 +423,7 @@ namespace mongo { return eloc; } - void MmapV1ExtentManager::freeExtent(TransactionExperiment* txn, DiskLoc firstExt ) { + void MmapV1ExtentManager::freeExtent(OperationContext* txn, DiskLoc firstExt ) { Extent* e = getExtent( firstExt ); txn->writing( &e->xnext )->Null(); txn->writing( &e->xprev )->Null(); @@ -445,7 +445,7 @@ namespace mongo { } - void MmapV1ExtentManager::freeExtents(TransactionExperiment* txn, DiskLoc firstExt, DiskLoc lastExt) { + void MmapV1ExtentManager::freeExtents(OperationContext* txn, DiskLoc firstExt, DiskLoc lastExt) { if ( firstExt.isNull() && lastExt.isNull() ) return; @@ -488,13 +488,13 @@ namespace mongo { return file->header()->freeListEnd; } - void MmapV1ExtentManager::_setFreeListStart( TransactionExperiment* txn, DiskLoc loc ) { + void MmapV1ExtentManager::_setFreeListStart( OperationContext* txn, DiskLoc loc ) { invariant( !_files.empty() ); DataFile* file = _files[0]; *txn->writing( &file->header()->freeListStart ) = loc; } - void MmapV1ExtentManager::_setFreeListEnd( TransactionExperiment* txn, DiskLoc loc ) { + void MmapV1ExtentManager::_setFreeListEnd( OperationContext* txn, DiskLoc loc ) { invariant( !_files.empty() ); DataFile* file = _files[0]; *txn->writing( &file->header()->freeListEnd ) = loc; diff --git a/src/mongo/db/storage/mmap_v1/mmap_v1_extent_manager.h b/src/mongo/db/storage/mmap_v1/mmap_v1_extent_manager.h index c045a075df4..47a35d3eb91 100644 --- a/src/mongo/db/storage/mmap_v1/mmap_v1_extent_manager.h +++ b/src/mongo/db/storage/mmap_v1/mmap_v1_extent_manager.h @@ -44,7 +44,7 @@ namespace mongo { class DataFile; class Record; - class TransactionExperiment; + class OperationContext; struct Extent; @@ -83,13 +83,13 @@ namespace mongo { /** * opens all current files */ - Status init(TransactionExperiment* txn); + Status init(OperationContext* txn); size_t numFiles() const; long long fileSize() const; // TODO: make private - DataFile* getFile( TransactionExperiment* txn, + DataFile* getFile( OperationContext* txn, int n, int sizeNeeded = 0, bool preallocateOnly = false ); @@ -97,7 +97,7 @@ namespace mongo { void flushFiles( bool sync ); // must call Extent::reuse on the returned extent - DiskLoc allocateExtent( TransactionExperiment* txn, + DiskLoc allocateExtent( OperationContext* txn, bool capped, int size, int quotaMax ); @@ -105,13 +105,13 @@ namespace mongo { /** * firstExt has to be == lastExt or a chain */ - void freeExtents( TransactionExperiment* txn, DiskLoc firstExt, DiskLoc lastExt ); + void freeExtents( OperationContext* txn, DiskLoc firstExt, DiskLoc lastExt ); /** * frees a single extent * ignores all fields in the Extent except: magic, myLoc, length */ - void freeExtent( TransactionExperiment* txn, DiskLoc extent ); + void freeExtent( OperationContext* txn, DiskLoc extent ); void printFreeList() const; @@ -153,23 +153,23 @@ namespace mongo { /** * will return NULL if nothing suitable in free list */ - DiskLoc _allocFromFreeList( TransactionExperiment* txn, int approxSize, bool capped ); + DiskLoc _allocFromFreeList( OperationContext* txn, int approxSize, bool capped ); /* allocate a new Extent, does not check free list * @param maxFileNoForQuota - 0 for unlimited */ - DiskLoc _createExtent( TransactionExperiment* txn, int approxSize, int maxFileNoForQuota ); + DiskLoc _createExtent( OperationContext* txn, int approxSize, int maxFileNoForQuota ); - DataFile* _addAFile( TransactionExperiment* txn, int sizeNeeded, bool preallocateNextFile ); + DataFile* _addAFile( OperationContext* txn, int sizeNeeded, bool preallocateNextFile ); DiskLoc _getFreeListStart() const; DiskLoc _getFreeListEnd() const; - void _setFreeListStart( TransactionExperiment* txn, DiskLoc loc ); - void _setFreeListEnd( TransactionExperiment* txn, DiskLoc loc ); + void _setFreeListStart( OperationContext* txn, DiskLoc loc ); + void _setFreeListEnd( OperationContext* txn, DiskLoc loc ); const DataFile* _getOpenFile( int n ) const; - DiskLoc _createExtentInFile( TransactionExperiment* txn, + DiskLoc _createExtentInFile( OperationContext* txn, int fileNo, DataFile* f, int size, diff --git a/src/mongo/db/storage/transaction.h b/src/mongo/db/storage/transaction.h deleted file mode 100644 index e76e1ab49ca..00000000000 --- a/src/mongo/db/storage/transaction.h +++ /dev/null @@ -1,136 +0,0 @@ -/** - * Copyright (C) 2014 MongoDB Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the GNU Affero General Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#pragma once - -#include <stdlib.h> - -#include "mongo/base/disallow_copying.h" -#include "mongo/base/status.h" -#include "mongo/db/storage/recovery_unit.h" - -namespace mongo { - - class ProgressMeter; - - /** - * This name and this class are both a work in progress. - * - * TODO(hk): move up a level, rename to OperationContext (or OpCtx if you're into the whole - * brevity thing) - */ - class TransactionExperiment { - MONGO_DISALLOW_COPYING(TransactionExperiment); - public: - virtual ~TransactionExperiment() { } - - /** - * Interface for durability. Caller DOES NOT own pointer. - * - * XXX: what's a better name for this - */ - virtual RecoveryUnit* recoveryUnit() const = 0; - - // XXX: migrate callers use the recoveryUnit() directly - template <typename T> - T* writing(T* x) { - return recoveryUnit()->writing(x); - } - - int& writingInt(int& d) { - return recoveryUnit()->writingInt(d); - } - - void syncDataAndTruncateJournal() { - recoveryUnit()->syncDataAndTruncateJournal(); - } - - void createdFile(const std::string& filename, unsigned long long len) { - recoveryUnit()->createdFile(filename, len); - } - - void* writingPtr(void* data, size_t len) { - return recoveryUnit()->writingPtr(data, len); - } - - bool isCommitNeeded() const { - return recoveryUnit()->isCommitNeeded(); - } - - bool commitIfNeeded(bool force = false) { - return recoveryUnit()->commitIfNeeded(force); - } - // XXX: migrate callers use the recoveryUnit() directly - - - // --- operation level info? --- - - /** - * TODO: Get rid of this and just have one interrupt func? - * throws an exception if the operation is interrupted - * @param heedMutex if true and have a write lock, won't kill op since it might be unsafe - */ - virtual void checkForInterrupt(bool heedMutex = true) const = 0; - - /** - * TODO: Where do I go - * @return Status::OK() if not interrupted - * otherwise returns reasons - */ - virtual Status checkForInterruptNoAssert() const = 0; - - /** - * TODO(ERH): this should move to some CurOp like context. - */ - virtual ProgressMeter* setMessage(const char* msg, - const std::string& name = "Progress", - unsigned long long progressMeterTotal = 0, - int secondsBetween = 3) = 0; - - /** - * Returns a TransactionExperiment. Caller takes ownership. - * - * This interface is used for functions that need to create transactions (aka OpCtx), but - * don't know which implementation they should create. It allows the calling code to make - * that decision for them. - * - * TODO come up with a better Factory API once we split this class up (SERVER-13931). - */ - typedef TransactionExperiment* (*Factory)(); - - /** - * A TransactionExperiment::Factory that always returns NULL. For things that shouldn't be - * touching their txns such as mongos or some unittests. - */ - static TransactionExperiment* factoryNULL() { return NULL; } - - protected: - TransactionExperiment() {} - }; - -} // namespace mongo |