void WiredTigerSession::releaseCursor(uint64_t id, WT_CURSOR* cursor) { invariant(_session); invariant(cursor); _cursorsOut--; invariantWTOK(cursor->reset(cursor)); // Cursors are pushed to the front of the list and removed from the back _cursors.push_front(WiredTigerCachedCursor(id, _cursorGen++, cursor)); // A negative value for wiredTigercursorCacheSize means to use hybrid caching. std::uint32_t cacheSize = abs(kWiredTigerCursorCacheSize.load()); while (!_cursors.empty() && _cursorGen - _cursors.back()._gen > cacheSize) { cursor = _cursors.back()._cursor; _cursors.pop_back(); invariantWTOK(cursor->close(cursor)); } }
void WiredTigerSession::releaseCursor(uint64_t id, WT_CURSOR* cursor) { invariant(_session); invariant(cursor); _cursorsOut--; invariantWTOK(cursor->reset(cursor)); // Cursors are pushed to the front of the list and removed from the back _cursors.push_front(WiredTigerCachedCursor(id, _cursorGen++, cursor)); _cursorsCached++; // "Old" is defined as not used in the last N**2 operations, if we have N cursors cached. // The reasoning here is to imagine a workload with N tables performing operations randomly // across all of them (i.e., each cursor has 1/N chance of used for each operation). We // would like to cache N cursors in that case, so any given cursor could go N**2 operations // in between use. while (_cursorGen - _cursors.back()._gen > 10000) { cursor = _cursors.back()._cursor; _cursors.pop_back(); _cursorsCached--; invariantWTOK(cursor->close(cursor)); } }