Storage Engine API
mongo::KVStorageEngine Class Referencefinal

#include <kv_storage_engine.h>

Inheritance diagram for mongo::KVStorageEngine:
mongo::StorageEngine

Classes

class  RemoveDBChange
 

Public Member Functions

 KVStorageEngine (KVEngine *engine, const KVStorageEngineOptions &options=KVStorageEngineOptions(), stdx::function< KVDatabaseCatalogEntryFactory > databaseCatalogEntryFactory=defaultDatabaseCatalogEntryFactory)
 
virtual ~KVStorageEngine ()
 
virtual void finishInit ()
 Called after the globalStorageEngine pointer has been set up, before any other methods are called. More...
 
virtual RecoveryUnitnewRecoveryUnit ()
 Returns a new interface to the storage engine's recovery unit. More...
 
virtual void listDatabases (std::vector< std::string > *out) const
 List the databases stored in this storage engine. More...
 
KVDatabaseCatalogEntryBasegetDatabaseCatalogEntry (OperationContext *opCtx, StringData db) override
 Return the DatabaseCatalogEntry that describes the database indicated by 'db'. More...
 
virtual bool supportsDocLocking () const
 Returns whether the storage engine supports its own locking locking below the collection level. More...
 
virtual bool supportsDBLocking () const
 Returns whether the storage engine supports locking at a database level. More...
 
virtual bool supportsCappedCollections () const
 Returns whether the storage engine supports capped collections. More...
 
virtual Status closeDatabase (OperationContext *opCtx, StringData db)
 Closes all file handles associated with a database. More...
 
virtual Status dropDatabase (OperationContext *opCtx, StringData db)
 Deletes all data and metadata for a database. More...
 
virtual int flushAllFiles (OperationContext *opCtx, bool sync)
 
virtual Status beginBackup (OperationContext *opCtx)
 Transitions the storage engine into backup mode. More...
 
virtual void endBackup (OperationContext *opCtx)
 Transitions the storage engine out of backup mode. More...
 
virtual bool isDurable () const
 Returns whether the engine supports a journalling concept or not. More...
 
virtual bool isEphemeral () const
 Returns true if the engine does not persist data to disk; false otherwise. More...
 
virtual Status repairRecordStore (OperationContext *opCtx, const std::string &ns)
 Recover as much data as possible from a potentially corrupt RecordStore. More...
 
virtual void cleanShutdown ()
 This method will be called before there is a clean shutdown. More...
 
virtual void setStableTimestamp (Timestamp stableTimestamp) override
 Sets the highest timestamp at which the storage engine is allowed to take a checkpoint. More...
 
virtual void setInitialDataTimestamp (Timestamp initialDataTimestamp) override
 Tells the storage engine the timestamp of the data at startup. More...
 
virtual void setOldestTimestampFromStable () override
 Uses the current stable timestamp to set the oldest timestamp for which the storage engine must maintain snapshot history through. More...
 
virtual void setOldestTimestamp (Timestamp newOldestTimestamp) override
 Sets the oldest timestamp for which the storage engine must maintain snapshot history through. More...
 
virtual bool isCacheUnderPressure (OperationContext *opCtx) const override
 Indicates whether the storage engine cache is under pressure. More...
 
virtual void setCachePressureForTest (int pressure) override
 For unit tests only. More...
 
virtual bool supportsRecoverToStableTimestamp () const override
 Returns whether the storage engine supports "recover to stable timestamp". More...
 
virtual StatusWith< Timestamp > recoverToStableTimestamp (OperationContext *opCtx) override
 Recovers the storage engine state to the last stable timestamp. More...
 
virtual boost::optional< Timestamp > getRecoveryTimestamp () const override
 Returns the stable timestamp that the storage engine recovered to on startup. More...
 
virtual boost::optional< Timestamp > getLastStableCheckpointTimestamp () const override
 Returns a timestamp that is guaranteed to be persisted to disk in a checkpoint. More...
 
virtual Timestamp getAllCommittedTimestamp () const override
 Returns the all committed timestamp. More...
 
bool supportsReadConcernSnapshot () const final
 Returns true if the storage engine supports the readConcern level "snapshot". More...
 
virtual void replicationBatchIsComplete () const override
 Notifies the storage engine that a replication batch has completed. More...
 
SnapshotManagergetSnapshotManager () const final
 Returns the SnapshotManager for this StorageEngine or NULL if not supported. More...
 
void setJournalListener (JournalListener *jl) final
 Sets a new JournalListener, which is used by the storage engine to alert the rest of the system about journaled write progress. More...
 
KVEnginegetEngine ()
 
const KVEnginegetEngine () const
 
KVCataloggetCatalog ()
 
const KVCataloggetCatalog () const
 
StatusWith< std::vector< StorageEngine::CollectionIndexNamePair > > reconcileCatalogAndIdents (OperationContext *opCtx) override
 Drop abandoned idents. More...
 
void loadCatalog (OperationContext *opCtx) final
 When loading after an unclean shutdown, this performs cleanup on the KVCatalog and unsets the startingAfterUncleanShutdown decoration on the global ServiceContext. More...
 
void closeCatalog (OperationContext *opCtx) final
 
- Public Member Functions inherited from mongo::StorageEngine
virtual ~StorageEngine ()
 The destructor should only be called if we are tearing down but not exiting the process. More...
 
virtual bool isMmapV1 () const
 Only MMAPv1 should override this and return true to trigger MMAPv1-specific behavior. More...
 

Private Types

using CollIter = std::list< std::string >::iterator
 
typedef std::map< std::string, KVDatabaseCatalogEntryBase * > DBMap
 

Private Member Functions

Status _dropCollectionsNoTimestamp (OperationContext *opCtx, KVDatabaseCatalogEntryBase *dbce, CollIter begin, CollIter end)
 Returns the first dropCollection error that this method encounters. More...
 
Status _dropCollectionsWithTimestamp (OperationContext *opCtx, KVDatabaseCatalogEntryBase *dbce, std::list< std::string > &toDrop, CollIter begin, CollIter end)
 
void _dumpCatalog (OperationContext *opCtx)
 

Private Attributes

stdx::function< KVDatabaseCatalogEntryFactory_databaseCatalogEntryFactory
 
KVStorageEngineOptions _options
 
std::unique_ptr< KVEngine_engine
 
const bool _supportsDocLocking
 
const bool _supportsDBLocking
 
const bool _supportsCappedCollections
 
Timestamp _initialDataTimestamp = Timestamp::kAllowUnstableCheckpointsSentinel
 
std::unique_ptr< RecordStore_catalogRecordStore
 
std::unique_ptr< KVCatalog_catalog
 
DBMap _dbs
 
stdx::mutex _dbsLock
 
bool _inBackupMode = false
 

Additional Inherited Members

- Public Types inherited from mongo::StorageEngine
typedef std::pair< std::string, std::string > CollectionIndexNamePair
 

Member Typedef Documentation

◆ CollIter

using mongo::KVStorageEngine::CollIter = std::list<std::string>::iterator
private

◆ DBMap

typedef std::map<std::string, KVDatabaseCatalogEntryBase*> mongo::KVStorageEngine::DBMap
private

Constructor & Destructor Documentation

◆ KVStorageEngine()

mongo::KVStorageEngine::KVStorageEngine ( KVEngine engine,
const KVStorageEngineOptions options = KVStorageEngineOptions(),
stdx::function< KVDatabaseCatalogEntryFactory databaseCatalogEntryFactory = defaultDatabaseCatalogEntryFactory 
)
Parameters
engine- ownership passes to me

◆ ~KVStorageEngine()

mongo::KVStorageEngine::~KVStorageEngine ( )
virtual

Member Function Documentation

◆ _dropCollectionsNoTimestamp()

Status mongo::KVStorageEngine::_dropCollectionsNoTimestamp ( OperationContext *  opCtx,
KVDatabaseCatalogEntryBase dbce,
CollIter  begin,
CollIter  end 
)
private

Returns the first dropCollection error that this method encounters.

This method will attempt to drop all collections, regardless of the error status.

◆ _dropCollectionsWithTimestamp()

Status mongo::KVStorageEngine::_dropCollectionsWithTimestamp ( OperationContext *  opCtx,
KVDatabaseCatalogEntryBase dbce,
std::list< std::string > &  toDrop,
CollIter  begin,
CollIter  end 
)
private

◆ _dumpCatalog()

void mongo::KVStorageEngine::_dumpCatalog ( OperationContext *  opCtx)
private

◆ beginBackup()

Status mongo::KVStorageEngine::beginBackup ( OperationContext *  opCtx)
virtual

Transitions the storage engine into backup mode.

During backup mode the storage engine must stabilize its on-disk files, and avoid any internal processing that may involve file I/O, such as online compaction, so a filesystem level backup may be performed.

Storage engines that do not support this feature should use the default implementation. Storage engines that implement this must also implement endBackup().

For Storage engines that implement beginBackup the _inBackupMode variable is provided to avoid multiple instance enterting/leaving backup concurrently.

If this function returns an OK status, MongoDB can call endBackup to signal the storage engine that filesystem writes may continue. This function should return a non-OK status if filesystem changes cannot be stopped to allow for online backup. If the function should be retried, returns a non-OK status. This function may throw a WriteConflictException, which should trigger a retry by the caller. All other exceptions should be treated as errors.

Reimplemented from mongo::StorageEngine.

◆ cleanShutdown()

void mongo::KVStorageEngine::cleanShutdown ( )
virtual

This method will be called before there is a clean shutdown.

Storage engines should override this method if they have clean-up to do that is different from unclean shutdown. MongoDB will not call into the storage subsystem after calling this function.

On error, the storage engine should assert and crash. There is intentionally no uncleanShutdown().

Implements mongo::StorageEngine.

◆ closeCatalog()

void mongo::KVStorageEngine::closeCatalog ( OperationContext *  opCtx)
finalvirtual

Reimplemented from mongo::StorageEngine.

◆ closeDatabase()

Status mongo::KVStorageEngine::closeDatabase ( OperationContext *  opCtx,
StringData  db 
)
virtual

Closes all file handles associated with a database.

Implements mongo::StorageEngine.

◆ dropDatabase()

Status mongo::KVStorageEngine::dropDatabase ( OperationContext *  opCtx,
StringData  db 
)
virtual

Deletes all data and metadata for a database.

Implements mongo::StorageEngine.

◆ endBackup()

void mongo::KVStorageEngine::endBackup ( OperationContext *  opCtx)
virtual

Transitions the storage engine out of backup mode.

Storage engines that do not support this feature should use the default implementation.

Storage engines implementing this feature should fassert when unable to leave backup mode.

Reimplemented from mongo::StorageEngine.

◆ finishInit()

void mongo::KVStorageEngine::finishInit ( )
virtual

Called after the globalStorageEngine pointer has been set up, before any other methods are called.

Any initialization work that requires the ability to create OperationContexts should be done here rather than in the constructor.

Reimplemented from mongo::StorageEngine.

◆ flushAllFiles()

int mongo::KVStorageEngine::flushAllFiles ( OperationContext *  opCtx,
bool  sync 
)
virtual
Returns
number of files flushed

Implements mongo::StorageEngine.

◆ getAllCommittedTimestamp()

Timestamp mongo::KVStorageEngine::getAllCommittedTimestamp ( ) const
overridevirtual

Returns the all committed timestamp.

All transactions with timestamps earlier than the all committed timestamp are committed. Only storage engines that support document level locking must provide an implementation. Other storage engines may provide a no-op implementation.

Implements mongo::StorageEngine.

◆ getCatalog() [1/2]

KVCatalog* mongo::KVStorageEngine::getCatalog ( )
inline

◆ getCatalog() [2/2]

const KVCatalog* mongo::KVStorageEngine::getCatalog ( ) const
inline

◆ getDatabaseCatalogEntry()

KVDatabaseCatalogEntryBase * mongo::KVStorageEngine::getDatabaseCatalogEntry ( OperationContext *  opCtx,
StringData  db 
)
overridevirtual

Return the DatabaseCatalogEntry that describes the database indicated by 'db'.

StorageEngine owns returned pointer. It should not be deleted by any caller.

Implements mongo::StorageEngine.

◆ getEngine() [1/2]

KVEngine* mongo::KVStorageEngine::getEngine ( )
inline

◆ getEngine() [2/2]

const KVEngine* mongo::KVStorageEngine::getEngine ( ) const
inline

◆ getLastStableCheckpointTimestamp()

boost::optional< Timestamp > mongo::KVStorageEngine::getLastStableCheckpointTimestamp ( ) const
overridevirtual

Returns a timestamp that is guaranteed to be persisted to disk in a checkpoint.

Returns boost::none if there is no stable checkpoint. This method should return at least the value of getRecoveryTimestamp if the node started from a stable checkpoint. fasserts if StorageEngine::supportsRecoverToStableTimestamp() would return false.

Reimplemented from mongo::StorageEngine.

◆ getRecoveryTimestamp()

boost::optional< Timestamp > mongo::KVStorageEngine::getRecoveryTimestamp ( ) const
overridevirtual

Returns the stable timestamp that the storage engine recovered to on startup.

If the recovery point was not stable, returns "none". fasserts if StorageEngine::supportsRecoverToStableTimestamp() would return false.

Reimplemented from mongo::StorageEngine.

◆ getSnapshotManager()

SnapshotManager * mongo::KVStorageEngine::getSnapshotManager ( ) const
finalvirtual

Returns the SnapshotManager for this StorageEngine or NULL if not supported.

Pointer remains owned by the StorageEngine, not the caller.

Reimplemented from mongo::StorageEngine.

◆ isCacheUnderPressure()

bool mongo::KVStorageEngine::isCacheUnderPressure ( OperationContext *  opCtx) const
overridevirtual

Indicates whether the storage engine cache is under pressure.

Retrieves a cache pressure value in the range [0, 100] from the storage engine, and compares it against storageGlobalParams.cachePressureThreshold, a dynamic server parameter, to determine whether cache pressure is too high.

Reimplemented from mongo::StorageEngine.

◆ isDurable()

bool mongo::KVStorageEngine::isDurable ( ) const
virtual

Returns whether the engine supports a journalling concept or not.

Implements mongo::StorageEngine.

◆ isEphemeral()

bool mongo::KVStorageEngine::isEphemeral ( ) const
virtual

Returns true if the engine does not persist data to disk; false otherwise.

Implements mongo::StorageEngine.

◆ listDatabases()

void mongo::KVStorageEngine::listDatabases ( std::vector< std::string > *  out) const
virtual

List the databases stored in this storage engine.

XXX: why doesn't this take OpCtx?

Implements mongo::StorageEngine.

◆ loadCatalog()

void mongo::KVStorageEngine::loadCatalog ( OperationContext *  opCtx)
finalvirtual

When loading after an unclean shutdown, this performs cleanup on the KVCatalog and unsets the startingAfterUncleanShutdown decoration on the global ServiceContext.

Reimplemented from mongo::StorageEngine.

◆ newRecoveryUnit()

RecoveryUnit * mongo::KVStorageEngine::newRecoveryUnit ( )
virtual

Returns a new interface to the storage engine's recovery unit.

The recovery unit is the durability interface. For details, see recovery_unit.h

Caller owns the returned pointer.

Implements mongo::StorageEngine.

◆ reconcileCatalogAndIdents()

StatusWith< std::vector< StorageEngine::CollectionIndexNamePair > > mongo::KVStorageEngine::reconcileCatalogAndIdents ( OperationContext *  opCtx)
overridevirtual

Drop abandoned idents.

This method reconciles differences between idents the KVEngine is aware of and the KVCatalog.

Returns a parallel list of index name, index spec pairs to rebuild.

There are three differences to consider:

First, a KVEngine may know of an ident that the KVCatalog does not. This method will drop the ident from the KVEngine.

Second, a KVCatalog may have a collection ident that the KVEngine does not. This is an illegal state and this method fasserts.

Third, a KVCatalog may have an index ident that the KVEngine does not. This method will rebuild the index.

Reimplemented from mongo::StorageEngine.

◆ recoverToStableTimestamp()

StatusWith< Timestamp > mongo::KVStorageEngine::recoverToStableTimestamp ( OperationContext *  opCtx)
overridevirtual

Recovers the storage engine state to the last stable timestamp.

"Stable" in this case refers to a timestamp that is guaranteed to never be rolled back. The stable timestamp used should be one provided by StorageEngine::setStableTimestamp().

The "local" database is exempt and should not roll back any state except for "local.replset.minvalid" which must roll back to the last stable timestamp.

If successful, returns the timestamp that the storage engine recovered to.

fasserts if StorageEngine::supportsRecoverToStableTimestamp() would return false. Returns a bad status if there is no stable timestamp to recover to.

It is illegal to call this concurrently with setStableTimestamp or setInitialDataTimestamp.

Reimplemented from mongo::StorageEngine.

◆ repairRecordStore()

Status mongo::KVStorageEngine::repairRecordStore ( OperationContext *  opCtx,
const std::string &  ns 
)
virtual

Recover as much data as possible from a potentially corrupt RecordStore.

This only recovers the record data, not indexes or anything else.

Generally, this method should not be called directly except by the repairDatabase() free function.

NOTE: MMAPv1 does not support this method and has its own repairDatabase() method.

Implements mongo::StorageEngine.

◆ replicationBatchIsComplete()

void mongo::KVStorageEngine::replicationBatchIsComplete ( ) const
overridevirtual

Notifies the storage engine that a replication batch has completed.

This means that all the writes associated with the oplog entries in the batch are finished and no new writes with timestamps associated with those oplog entries will show up in the future. This function can be used to ensure oplog visibility rules are not broken, for example.

Reimplemented from mongo::StorageEngine.

◆ setCachePressureForTest()

void mongo::KVStorageEngine::setCachePressureForTest ( int  pressure)
overridevirtual

For unit tests only.

Sets the cache pressure value with which isCacheUnderPressure() evalutates to 'pressure'.

Reimplemented from mongo::StorageEngine.

◆ setInitialDataTimestamp()

void mongo::KVStorageEngine::setInitialDataTimestamp ( Timestamp  timestamp)
overridevirtual

Tells the storage engine the timestamp of the data at startup.

This is necessary because timestamps are not persisted in the storage layer.

Reimplemented from mongo::StorageEngine.

◆ setJournalListener()

void mongo::KVStorageEngine::setJournalListener ( JournalListener jl)
finalvirtual

Sets a new JournalListener, which is used by the storage engine to alert the rest of the system about journaled write progress.

Implements mongo::StorageEngine.

◆ setOldestTimestamp()

void mongo::KVStorageEngine::setOldestTimestamp ( Timestamp  timestamp)
overridevirtual

Sets the oldest timestamp for which the storage engine must maintain snapshot history through.

Additionally, all future writes must be newer or equal to this value.

Reimplemented from mongo::StorageEngine.

◆ setOldestTimestampFromStable()

void mongo::KVStorageEngine::setOldestTimestampFromStable ( )
overridevirtual

Uses the current stable timestamp to set the oldest timestamp for which the storage engine must maintain snapshot history through.

oldest_timestamp will be set to stable_timestamp adjusted by 'targetSnapshotHistoryWindowInSeconds' to create a window of available snapshots on the storage engine from oldest to stable. Furthermore, oldest_timestamp will never be set ahead of the oplog read timestamp, ensuring the oplog reader's 'read_timestamp' can always be serviced.

Reimplemented from mongo::StorageEngine.

◆ setStableTimestamp()

void mongo::KVStorageEngine::setStableTimestamp ( Timestamp  timestamp)
overridevirtual

Sets the highest timestamp at which the storage engine is allowed to take a checkpoint.

This timestamp can never decrease, and thus should be a timestamp that can never roll back.

Reimplemented from mongo::StorageEngine.

◆ supportsCappedCollections()

virtual bool mongo::KVStorageEngine::supportsCappedCollections ( ) const
inlinevirtual

Returns whether the storage engine supports capped collections.

Reimplemented from mongo::StorageEngine.

◆ supportsDBLocking()

virtual bool mongo::KVStorageEngine::supportsDBLocking ( ) const
inlinevirtual

Returns whether the storage engine supports locking at a database level.

Reimplemented from mongo::StorageEngine.

◆ supportsDocLocking()

virtual bool mongo::KVStorageEngine::supportsDocLocking ( ) const
inlinevirtual

Returns whether the storage engine supports its own locking locking below the collection level.

If the engine returns true, MongoDB will acquire intent locks down to the collection level and will assume that the engine will ensure consistency at the level of documents. If false, MongoDB will lock the entire collection in Shared/Exclusive mode for read/write operations respectively.

Implements mongo::StorageEngine.

◆ supportsReadConcernSnapshot()

bool mongo::KVStorageEngine::supportsReadConcernSnapshot ( ) const
finalvirtual

Returns true if the storage engine supports the readConcern level "snapshot".

Reimplemented from mongo::StorageEngine.

◆ supportsRecoverToStableTimestamp()

bool mongo::KVStorageEngine::supportsRecoverToStableTimestamp ( ) const
overridevirtual

Returns whether the storage engine supports "recover to stable timestamp".

Returns true if the storage engine supports "recover to stable timestamp" but does not currently have a stable timestamp. In that case StorageEngine::recoverToStableTimestamp() will return a bad status.

Reimplemented from mongo::StorageEngine.

Member Data Documentation

◆ _catalog

std::unique_ptr<KVCatalog> mongo::KVStorageEngine::_catalog
private

◆ _catalogRecordStore

std::unique_ptr<RecordStore> mongo::KVStorageEngine::_catalogRecordStore
private

◆ _databaseCatalogEntryFactory

stdx::function<KVDatabaseCatalogEntryFactory> mongo::KVStorageEngine::_databaseCatalogEntryFactory
private

◆ _dbs

DBMap mongo::KVStorageEngine::_dbs
private

◆ _dbsLock

stdx::mutex mongo::KVStorageEngine::_dbsLock
mutableprivate

◆ _engine

std::unique_ptr<KVEngine> mongo::KVStorageEngine::_engine
private

◆ _inBackupMode

bool mongo::KVStorageEngine::_inBackupMode = false
private

◆ _initialDataTimestamp

Timestamp mongo::KVStorageEngine::_initialDataTimestamp = Timestamp::kAllowUnstableCheckpointsSentinel
private

◆ _options

KVStorageEngineOptions mongo::KVStorageEngine::_options
private

◆ _supportsCappedCollections

const bool mongo::KVStorageEngine::_supportsCappedCollections
private

◆ _supportsDBLocking

const bool mongo::KVStorageEngine::_supportsDBLocking
private

◆ _supportsDocLocking

const bool mongo::KVStorageEngine::_supportsDocLocking
private

The documentation for this class was generated from the following files: