Storage Engine API
mongo::MMAPV1Engine Class Reference

#include <mmap_v1_engine.h>

Inheritance diagram for mongo::MMAPV1Engine:
mongo::StorageEngine

Public Member Functions

 MMAPV1Engine (const StorageEngineLockFile *lockFile, ClockSource *cs)
 
 MMAPV1Engine (const StorageEngineLockFile *lockFile, ClockSource *cs, std::unique_ptr< ExtentManager::Factory > extentManagerFactory)
 
virtual ~MMAPV1Engine ()
 
void finishInit ()
 Called after the globalStorageEngine pointer has been set up, before any other methods are called. More...
 
RecoveryUnitnewRecoveryUnit ()
 Returns a new interface to the storage engine's recovery unit. More...
 
void listDatabases (std::vector< std::string > *out) const
 List the databases stored in this storage engine. More...
 
int flushAllFiles (OperationContext *opCtx, bool sync)
 
Status beginBackup (OperationContext *opCtx)
 Transitions the storage engine into backup mode. More...
 
void endBackup (OperationContext *opCtx)
 Transitions the storage engine out of backup mode. More...
 
DatabaseCatalogEntrygetDatabaseCatalogEntry (OperationContext *opCtx, StringData db)
 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 isMmapV1 () const
 Only MMAPv1 should override this and return true to trigger MMAPv1-specific behavior. 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 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 void cleanShutdown ()
 This method will be called before there is a clean shutdown. More...
 
virtual Status repairRecordStore (OperationContext *opCtx, const std::string &ns)
 Recover as much data as possible from a potentially corrupt RecordStore. More...
 
Status repairDatabase (OperationContext *opCtx, const std::string &dbName, bool preserveClonedFilesOnFailure, bool backupOriginalFiles)
 
RecordAccessTrackergetRecordAccessTracker ()
 Gets a reference to the abstraction used by MMAP v1 to track recently used memory addresses. 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...
 
Timestamp getAllCommittedTimestamp () const override
 Returns the all committed timestamp. More...
 
- 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 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 void loadCatalog (OperationContext *opCtx)
 Populates and tears down in-memory data structures, respectively. More...
 
virtual void closeCatalog (OperationContext *opCtx)
 
virtual SnapshotManagergetSnapshotManager () const
 Returns the SnapshotManager for this StorageEngine or NULL if not supported. More...
 
virtual bool supportsRecoverToStableTimestamp () const
 Returns whether the storage engine supports "recover to stable timestamp". More...
 
virtual bool supportsReadConcernSnapshot () const
 Returns true if the storage engine supports the readConcern level "snapshot". More...
 
virtual StatusWith< Timestamp > recoverToStableTimestamp (OperationContext *opCtx)
 Recovers the storage engine state to the last stable timestamp. More...
 
virtual boost::optional< Timestamp > getRecoveryTimestamp () const
 Returns the stable timestamp that the storage engine recovered to on startup. More...
 
virtual boost::optional< Timestamp > getLastStableCheckpointTimestamp () const
 Returns a timestamp that is guaranteed to be persisted to disk in a checkpoint. More...
 
virtual void setStableTimestamp (Timestamp timestamp)
 Sets the highest timestamp at which the storage engine is allowed to take a checkpoint. More...
 
virtual void setInitialDataTimestamp (Timestamp timestamp)
 Tells the storage engine the timestamp of the data at startup. More...
 
virtual void setOldestTimestampFromStable ()
 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 timestamp)
 Sets the oldest timestamp for which the storage engine must maintain snapshot history through. More...
 
virtual bool isCacheUnderPressure (OperationContext *opCtx) const
 Indicates whether the storage engine cache is under pressure. More...
 
virtual void setCachePressureForTest (int pressure)
 For unit tests only. More...
 
virtual void replicationBatchIsComplete () const
 Notifies the storage engine that a replication batch has completed. More...
 
virtual StatusWith< std::vector< CollectionIndexNamePair > > reconcileCatalogAndIdents (OperationContext *opCtx)
 Drop abandoned idents. More...
 

Private Types

typedef std::map< std::string, MMAPV1DatabaseCatalogEntry * > EntryMap
 

Static Private Member Functions

static void _listDatabases (const std::string &directory, std::vector< std::string > *out)
 

Private Attributes

stdx::mutex _entryMapMutex
 
EntryMap _entryMap
 
RecordAccessTracker _recordAccessTracker
 
std::unique_ptr< ExtentManager::Factory_extentManagerFactory
 
ClockSource * _clock
 
int64_t _startMs
 

Additional Inherited Members

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

Member Typedef Documentation

◆ EntryMap

typedef std::map<std::string, MMAPV1DatabaseCatalogEntry*> mongo::MMAPV1Engine::EntryMap
private

Constructor & Destructor Documentation

◆ MMAPV1Engine() [1/2]

mongo::MMAPV1Engine::MMAPV1Engine ( const StorageEngineLockFile lockFile,
ClockSource *  cs 
)

◆ MMAPV1Engine() [2/2]

mongo::MMAPV1Engine::MMAPV1Engine ( const StorageEngineLockFile lockFile,
ClockSource *  cs,
std::unique_ptr< ExtentManager::Factory extentManagerFactory 
)

◆ ~MMAPV1Engine()

mongo::MMAPV1Engine::~MMAPV1Engine ( )
virtual

Member Function Documentation

◆ _listDatabases()

void mongo::MMAPV1Engine::_listDatabases ( const std::string &  directory,
std::vector< std::string > *  out 
)
staticprivate

◆ beginBackup()

Status mongo::MMAPV1Engine::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::MMAPV1Engine::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.

◆ closeDatabase()

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

Closes all file handles associated with a database.

Implements mongo::StorageEngine.

◆ dropDatabase()

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

Deletes all data and metadata for a database.

Implements mongo::StorageEngine.

◆ endBackup()

void mongo::MMAPV1Engine::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::MMAPV1Engine::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::MMAPV1Engine::flushAllFiles ( OperationContext *  opCtx,
bool  sync 
)
virtual
Returns
number of files flushed

Implements mongo::StorageEngine.

◆ getAllCommittedTimestamp()

Timestamp mongo::MMAPV1Engine::getAllCommittedTimestamp ( ) const
inlineoverridevirtual

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.

◆ getDatabaseCatalogEntry()

DatabaseCatalogEntry * mongo::MMAPV1Engine::getDatabaseCatalogEntry ( OperationContext *  opCtx,
StringData  db 
)
virtual

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.

◆ getRecordAccessTracker()

RecordAccessTracker & mongo::MMAPV1Engine::getRecordAccessTracker ( )

Gets a reference to the abstraction used by MMAP v1 to track recently used memory addresses.

MMAPv1 specific (non-virtual). This is non-const because callers are allowed to use the returned reference to modify the RecordAccessTracker.

The RecordAccessTracker is thread-safe (it uses its own mutex internally).

◆ isDurable()

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

Returns whether the engine supports a journalling concept or not.

Implements mongo::StorageEngine.

◆ isEphemeral()

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

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

Implements mongo::StorageEngine.

◆ isMmapV1()

virtual bool mongo::MMAPV1Engine::isMmapV1 ( ) const
inlinevirtual

Only MMAPv1 should override this and return true to trigger MMAPv1-specific behavior.

Reimplemented from mongo::StorageEngine.

◆ listDatabases()

void mongo::MMAPV1Engine::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.

◆ newRecoveryUnit()

RecoveryUnit * mongo::MMAPV1Engine::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.

◆ repairDatabase()

Status mongo::MMAPV1Engine::repairDatabase ( OperationContext *  opCtx,
const std::string &  dbName,
bool  preserveClonedFilesOnFailure,
bool  backupOriginalFiles 
)

◆ repairRecordStore()

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

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.

◆ setJournalListener()

void mongo::MMAPV1Engine::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.

◆ supportsDocLocking()

virtual bool mongo::MMAPV1Engine::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.

Member Data Documentation

◆ _clock

ClockSource* mongo::MMAPV1Engine::_clock
private

◆ _entryMap

EntryMap mongo::MMAPV1Engine::_entryMap
private

◆ _entryMapMutex

stdx::mutex mongo::MMAPV1Engine::_entryMapMutex
private

◆ _extentManagerFactory

std::unique_ptr<ExtentManager::Factory> mongo::MMAPV1Engine::_extentManagerFactory
private

◆ _recordAccessTracker

RecordAccessTracker mongo::MMAPV1Engine::_recordAccessTracker
private

◆ _startMs

int64_t mongo::MMAPV1Engine::_startMs
private

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