![]() |
Storage Engine API
|
#include <kv_storage_engine.h>
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 RecoveryUnit * | newRecoveryUnit () |
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... | |
KVDatabaseCatalogEntryBase * | getDatabaseCatalogEntry (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... | |
SnapshotManager * | getSnapshotManager () 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... | |
KVEngine * | getEngine () |
const KVEngine * | getEngine () const |
KVCatalog * | getCatalog () |
const KVCatalog * | getCatalog () 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 |
![]() | |
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 | |
![]() | |
typedef std::pair< std::string, std::string > | CollectionIndexNamePair |
|
private |
|
private |
mongo::KVStorageEngine::KVStorageEngine | ( | KVEngine * | engine, |
const KVStorageEngineOptions & | options = KVStorageEngineOptions() , |
||
stdx::function< KVDatabaseCatalogEntryFactory > | databaseCatalogEntryFactory = defaultDatabaseCatalogEntryFactory |
||
) |
engine | - ownership passes to me |
|
virtual |
|
private |
Returns the first dropCollection
error that this method encounters.
This method will attempt to drop all collections, regardless of the error status.
|
private |
|
private |
|
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.
|
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.
|
finalvirtual |
Reimplemented from mongo::StorageEngine.
|
virtual |
Closes all file handles associated with a database.
Implements mongo::StorageEngine.
|
virtual |
Deletes all data and metadata for a database.
Implements mongo::StorageEngine.
|
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.
|
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.
|
virtual |
Implements mongo::StorageEngine.
|
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.
|
inline |
|
inline |
|
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.
|
inline |
|
inline |
|
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.
|
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.
|
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.
|
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.
|
virtual |
Returns whether the engine supports a journalling concept or not.
Implements mongo::StorageEngine.
|
virtual |
Returns true if the engine does not persist data to disk; false otherwise.
Implements mongo::StorageEngine.
|
virtual |
List the databases stored in this storage engine.
XXX: why doesn't this take OpCtx?
Implements mongo::StorageEngine.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
overridevirtual |
For unit tests only.
Sets the cache pressure value with which isCacheUnderPressure() evalutates to 'pressure'.
Reimplemented from mongo::StorageEngine.
|
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.
|
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.
|
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.
|
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.
|
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.
|
inlinevirtual |
Returns whether the storage engine supports capped collections.
Reimplemented from mongo::StorageEngine.
|
inlinevirtual |
Returns whether the storage engine supports locking at a database level.
Reimplemented from mongo::StorageEngine.
|
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.
|
finalvirtual |
Returns true if the storage engine supports the readConcern level "snapshot".
Reimplemented from mongo::StorageEngine.
|
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.
|
private |
|
private |
|
private |
|
private |
|
mutableprivate |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |