Storage Engine API
mongo::WiredTigerSessionCache Class Reference

This cache implements a shared pool of WiredTiger sessions with the goal to amortize the cost of session creation and destruction over multiple uses. More...

#include <wiredtiger_session_cache.h>

Detailed Description

This cache implements a shared pool of WiredTiger sessions with the goal to amortize the cost of session creation and destruction over multiple uses.

Classes

class  WiredTigerSessionDeleter
 This deleter automatically releases WiredTigerSession objects when no longer needed. More...
 

Public Member Functions

 WiredTigerSessionCache (WiredTigerKVEngine *engine)
 
 WiredTigerSessionCache (WT_CONNECTION *conn)
 
 ~WiredTigerSessionCache ()
 
std::unique_ptr< WiredTigerSession, WiredTigerSessionDeletergetSession ()
 Returns a smart pointer to a previously released session for reuse, or creates a new session. More...
 
void closeAll ()
 Free all cached sessions and ensures that previously acquired sessions will be freed on release. More...
 
void closeCursorsForQueuedDrops ()
 Closes cached cursors for tables that are queued to be dropped. More...
 
void closeAllCursors (const std::string &uri)
 Closes all cached cursors matching the uri. More...
 
void shuttingDown ()
 Transitions the cache to shutting down mode. More...
 
bool isEphemeral ()
 
void waitUntilDurable (bool forceCheckpoint, bool stableCheckpoint)
 Waits until all commits that happened before this call are durable, either by flushing the log or forcing a checkpoint if forceCheckpoint is true or the journal is disabled. More...
 
void waitUntilPreparedUnitOfWorkCommitsOrAborts (OperationContext *opCtx)
 Waits until a prepared unit of work has ended (either been commited or aborted). More...
 
void notifyPreparedUnitOfWorkHasCommittedOrAborted ()
 Notifies waiters that the caller's perpared unit of work has ended (either committed or aborted). More...
 
WT_CONNECTION * conn () const
 
WiredTigerSnapshotManagersnapshotManager ()
 
const WiredTigerSnapshotManagersnapshotManager () const
 
void setJournalListener (JournalListener *jl)
 
uint64_t getCursorEpoch () const
 
WiredTigerKVEnginegetKVEngine () const
 

Static Public Member Functions

static bool isEngineCachingCursors ()
 Indicates that WiredTiger should be configured to cache cursors. More...
 

Private Types

typedef std::vector< WiredTigerSession * > SessionCache
 

Private Member Functions

void releaseSession (WiredTigerSession *session)
 Returns a session to the cache for later reuse. More...
 

Private Attributes

WiredTigerKVEngine_engine
 
WT_CONNECTION * _conn
 
WiredTigerSnapshotManager _snapshotManager
 
AtomicUInt32 _shuttingDown
 
stdx::mutex _cacheLock
 
SessionCache _sessions
 
AtomicUInt64 _epoch
 
AtomicUInt64 _cursorEpoch
 
AtomicUInt32 _lastSyncTime
 
stdx::mutex _lastSyncMutex
 
stdx::mutex _prepareCommittedOrAbortedMutex
 
stdx::condition_variable _prepareCommittedOrAbortedCond
 
std::uint64_t _lastCommitOrAbortCounter
 
stdx::mutex _journalListenerMutex
 
JournalListener_journalListener = &NoOpJournalListener::instance
 
WT_SESSION * _waitUntilDurableSession = nullptr
 

Static Private Attributes

static const uint32_t kShuttingDownMask = 1 << 31
 

Member Typedef Documentation

◆ SessionCache

Constructor & Destructor Documentation

◆ WiredTigerSessionCache() [1/2]

mongo::WiredTigerSessionCache::WiredTigerSessionCache ( WiredTigerKVEngine engine)

◆ WiredTigerSessionCache() [2/2]

mongo::WiredTigerSessionCache::WiredTigerSessionCache ( WT_CONNECTION *  conn)

◆ ~WiredTigerSessionCache()

mongo::WiredTigerSessionCache::~WiredTigerSessionCache ( )

Member Function Documentation

◆ closeAll()

void mongo::WiredTigerSessionCache::closeAll ( )

Free all cached sessions and ensures that previously acquired sessions will be freed on release.

◆ closeAllCursors()

void mongo::WiredTigerSessionCache::closeAllCursors ( const std::string &  uri)

Closes all cached cursors matching the uri.

If the uri is empty, all cached cursors are closed.

◆ closeCursorsForQueuedDrops()

void mongo::WiredTigerSessionCache::closeCursorsForQueuedDrops ( )

Closes cached cursors for tables that are queued to be dropped.

◆ conn()

WT_CONNECTION* mongo::WiredTigerSessionCache::conn ( ) const
inline

◆ getCursorEpoch()

uint64_t mongo::WiredTigerSessionCache::getCursorEpoch ( ) const
inline

◆ getKVEngine()

WiredTigerKVEngine* mongo::WiredTigerSessionCache::getKVEngine ( ) const
inline

◆ getSession()

UniqueWiredTigerSession mongo::WiredTigerSessionCache::getSession ( )

Returns a smart pointer to a previously released session for reuse, or creates a new session.

This method must only be called while holding the global lock to avoid races with shuttingDown, but otherwise is thread safe.

◆ isEngineCachingCursors()

bool mongo::WiredTigerSessionCache::isEngineCachingCursors ( )
static

Indicates that WiredTiger should be configured to cache cursors.

◆ isEphemeral()

bool mongo::WiredTigerSessionCache::isEphemeral ( )

◆ notifyPreparedUnitOfWorkHasCommittedOrAborted()

void mongo::WiredTigerSessionCache::notifyPreparedUnitOfWorkHasCommittedOrAborted ( )

Notifies waiters that the caller's perpared unit of work has ended (either committed or aborted).

◆ releaseSession()

void mongo::WiredTigerSessionCache::releaseSession ( WiredTigerSession session)
private

Returns a session to the cache for later reuse.

If closeAll was called between getting this session and releasing it, the session is directly released. This method is thread safe.

◆ setJournalListener()

void mongo::WiredTigerSessionCache::setJournalListener ( JournalListener jl)

◆ shuttingDown()

void mongo::WiredTigerSessionCache::shuttingDown ( )

Transitions the cache to shutting down mode.

Any already released sessions are freed and any sessions released subsequently are leaked. Must be called while holding the global lock in exclusive mode to avoid races with getSession.

◆ snapshotManager() [1/2]

WiredTigerSnapshotManager& mongo::WiredTigerSessionCache::snapshotManager ( )
inline

◆ snapshotManager() [2/2]

const WiredTigerSnapshotManager& mongo::WiredTigerSessionCache::snapshotManager ( ) const
inline

◆ waitUntilDurable()

void mongo::WiredTigerSessionCache::waitUntilDurable ( bool  forceCheckpoint,
bool  stableCheckpoint 
)

Waits until all commits that happened before this call are durable, either by flushing the log or forcing a checkpoint if forceCheckpoint is true or the journal is disabled.

Uses a temporary session. Safe to call without any locks, even during shutdown.

◆ waitUntilPreparedUnitOfWorkCommitsOrAborts()

void mongo::WiredTigerSessionCache::waitUntilPreparedUnitOfWorkCommitsOrAborts ( OperationContext *  opCtx)

Waits until a prepared unit of work has ended (either been commited or aborted).

This should be used when encountering WT_PREPARE_CONFLICT errors. The caller is required to retry the conflicting WiredTiger API operation. A return from this function does not guarantee that the conflicting transaction has ended, only that one prepared unit of work in the process has signaled that it has ended. Accepts an OperationContext that will throw an AssertionException when interrupted.

This method is provided in WiredTigerSessionCache and not RecoveryUnit because all recovery units share the same session cache, and we want a recovery unit on one thread to signal all recovery units waiting for prepare conflicts across all other threads.

Member Data Documentation

◆ _cacheLock

stdx::mutex mongo::WiredTigerSessionCache::_cacheLock
private

◆ _conn

WT_CONNECTION* mongo::WiredTigerSessionCache::_conn
private

◆ _cursorEpoch

AtomicUInt64 mongo::WiredTigerSessionCache::_cursorEpoch
private

◆ _engine

WiredTigerKVEngine* mongo::WiredTigerSessionCache::_engine
private

◆ _epoch

AtomicUInt64 mongo::WiredTigerSessionCache::_epoch
private

◆ _journalListener

JournalListener* mongo::WiredTigerSessionCache::_journalListener = &NoOpJournalListener::instance
private

◆ _journalListenerMutex

stdx::mutex mongo::WiredTigerSessionCache::_journalListenerMutex
private

◆ _lastCommitOrAbortCounter

std::uint64_t mongo::WiredTigerSessionCache::_lastCommitOrAbortCounter
private

◆ _lastSyncMutex

stdx::mutex mongo::WiredTigerSessionCache::_lastSyncMutex
private

◆ _lastSyncTime

AtomicUInt32 mongo::WiredTigerSessionCache::_lastSyncTime
private

◆ _prepareCommittedOrAbortedCond

stdx::condition_variable mongo::WiredTigerSessionCache::_prepareCommittedOrAbortedCond
private

◆ _prepareCommittedOrAbortedMutex

stdx::mutex mongo::WiredTigerSessionCache::_prepareCommittedOrAbortedMutex
private

◆ _sessions

SessionCache mongo::WiredTigerSessionCache::_sessions
private

◆ _shuttingDown

AtomicUInt32 mongo::WiredTigerSessionCache::_shuttingDown
private

◆ _snapshotManager

WiredTigerSnapshotManager mongo::WiredTigerSessionCache::_snapshotManager
private

◆ _waitUntilDurableSession

WT_SESSION* mongo::WiredTigerSessionCache::_waitUntilDurableSession = nullptr
private

◆ kShuttingDownMask

const uint32_t mongo::WiredTigerSessionCache::kShuttingDownMask = 1 << 31
staticprivate

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