summaryrefslogtreecommitdiff
path: root/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.h')
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.h167
1 files changed, 86 insertions, 81 deletions
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.h b/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.h
index 2f9e8d64d4d..9fd575232b9 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.h
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.h
@@ -44,113 +44,118 @@
namespace mongo {
- class WiredTigerKVEngine;
+class WiredTigerKVEngine;
+/**
+ * This is a structure that caches 1 cursor for each uri.
+ * The idea is that there is a pool of these somewhere.
+ * NOT THREADSAFE
+ */
+class WiredTigerSession {
+public:
/**
- * This is a structure that caches 1 cursor for each uri.
- * The idea is that there is a pool of these somewhere.
- * NOT THREADSAFE
+ * Creates a new WT session on the specified connection.
+ *
+ * @param conn WT connection
+ * @param cachePartition If the session comes from the session cache, this indicates to
+ * which partition it should be returned. Value of -1 means it doesn't come from
+ * cache and that it should not be cached, but closed directly.
+ * @param epoch In which session cache cleanup epoch was this session instantiated. Value
+ * of -1 means that this value is not necessary since the session will not be
+ * cached.
*/
- class WiredTigerSession {
- public:
-
- /**
- * Creates a new WT session on the specified connection.
- *
- * @param conn WT connection
- * @param cachePartition If the session comes from the session cache, this indicates to
- * which partition it should be returned. Value of -1 means it doesn't come from
- * cache and that it should not be cached, but closed directly.
- * @param epoch In which session cache cleanup epoch was this session instantiated. Value
- * of -1 means that this value is not necessary since the session will not be
- * cached.
- */
- WiredTigerSession(WT_CONNECTION* conn, int cachePartition = -1, int epoch = -1);
- ~WiredTigerSession();
-
- WT_SESSION* getSession() const { return _session; }
-
- WT_CURSOR* getCursor(const std::string& uri,
- uint64_t id,
- bool forRecordStore);
- void releaseCursor(uint64_t id, WT_CURSOR *cursor);
+ WiredTigerSession(WT_CONNECTION* conn, int cachePartition = -1, int epoch = -1);
+ ~WiredTigerSession();
- void closeAllCursors();
+ WT_SESSION* getSession() const {
+ return _session;
+ }
- int cursorsOut() const { return _cursorsOut; }
+ WT_CURSOR* getCursor(const std::string& uri, uint64_t id, bool forRecordStore);
+ void releaseCursor(uint64_t id, WT_CURSOR* cursor);
- static uint64_t genCursorId();
+ void closeAllCursors();
- /**
- * For "metadata:" cursors. Guaranteed never to collide with genCursorId() ids.
- */
- static const uint64_t kMetadataCursorId = 0;
+ int cursorsOut() const {
+ return _cursorsOut;
+ }
- private:
- friend class WiredTigerSessionCache;
+ static uint64_t genCursorId();
- typedef std::vector<WT_CURSOR*> Cursors;
- typedef std::map<uint64_t, Cursors> CursorMap;
+ /**
+ * For "metadata:" cursors. Guaranteed never to collide with genCursorId() ids.
+ */
+ static const uint64_t kMetadataCursorId = 0;
+private:
+ friend class WiredTigerSessionCache;
- // Used internally by WiredTigerSessionCache
- int _getEpoch() const { return _epoch; }
- int _getCachePartition() const { return _cachePartition; }
+ typedef std::vector<WT_CURSOR*> Cursors;
+ typedef std::map<uint64_t, Cursors> CursorMap;
- const int _cachePartition;
- const int _epoch;
- WT_SESSION* _session; // owned
- CursorMap _curmap; // owned
- int _cursorsOut;
- };
+ // Used internally by WiredTigerSessionCache
+ int _getEpoch() const {
+ return _epoch;
+ }
+ int _getCachePartition() const {
+ return _cachePartition;
+ }
- class WiredTigerSessionCache {
- public:
- WiredTigerSessionCache( WiredTigerKVEngine* engine );
- WiredTigerSessionCache( WT_CONNECTION* conn );
- ~WiredTigerSessionCache();
+ const int _cachePartition;
+ const int _epoch;
+ WT_SESSION* _session; // owned
+ CursorMap _curmap; // owned
+ int _cursorsOut;
+};
- WiredTigerSession* getSession();
- void releaseSession( WiredTigerSession* session );
+class WiredTigerSessionCache {
+public:
+ WiredTigerSessionCache(WiredTigerKVEngine* engine);
+ WiredTigerSessionCache(WT_CONNECTION* conn);
+ ~WiredTigerSessionCache();
- void closeAll();
+ WiredTigerSession* getSession();
+ void releaseSession(WiredTigerSession* session);
- void shuttingDown();
+ void closeAll();
- WT_CONNECTION* conn() const { return _conn; }
+ void shuttingDown();
- private:
- typedef std::vector<WiredTigerSession*> SessionPool;
+ WT_CONNECTION* conn() const {
+ return _conn;
+ }
- enum { NumSessionCachePartitions = 64 };
+private:
+ typedef std::vector<WiredTigerSession*> SessionPool;
- struct SessionCachePartition {
- SessionCachePartition() : epoch(0) { }
- ~SessionCachePartition() {
- invariant(pool.empty());
- }
+ enum { NumSessionCachePartitions = 64 };
- SpinLock lock;
- int epoch;
- SessionPool pool;
- };
+ struct SessionCachePartition {
+ SessionCachePartition() : epoch(0) {}
+ ~SessionCachePartition() {
+ invariant(pool.empty());
+ }
+ SpinLock lock;
+ int epoch;
+ SessionPool pool;
+ };
- WiredTigerKVEngine* _engine; // not owned, might be NULL
- WT_CONNECTION* _conn; // not owned
- // Partitioned cache of WT sessions. The partition key is not important, but it is
- // important that sessions be returned to the same partition they were taken from in order
- // to have some form of balance between the partitions.
- SessionCachePartition _cache[NumSessionCachePartitions];
+ WiredTigerKVEngine* _engine; // not owned, might be NULL
+ WT_CONNECTION* _conn; // not owned
- // Regular operations take it in shared mode. Shutdown sets the _shuttingDown flag and
- // then takes it in exclusive mode. This ensures that all threads, which would return
- // sessions to the cache would leak them.
- boost::shared_mutex _shutdownLock;
- AtomicUInt32 _shuttingDown; // Used as boolean - 0 = false, 1 = true
- };
+ // Partitioned cache of WT sessions. The partition key is not important, but it is
+ // important that sessions be returned to the same partition they were taken from in order
+ // to have some form of balance between the partitions.
+ SessionCachePartition _cache[NumSessionCachePartitions];
+ // Regular operations take it in shared mode. Shutdown sets the _shuttingDown flag and
+ // then takes it in exclusive mode. This ensures that all threads, which would return
+ // sessions to the cache would leak them.
+ boost::shared_mutex _shutdownLock;
+ AtomicUInt32 _shuttingDown; // Used as boolean - 0 = false, 1 = true
+};
}