1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>WiredTiger: Data Handle Lifecycle</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
$(document).ready(initResizable);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="wiredtiger.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectlogo"><a href="http://wiredtiger.com/"><img alt="Logo" src="LogoFinal-header.png" alt="WiredTiger" /></a></td>
<td style="padding-left: 0.5em;">
<div id="projectname">
 <span id="projectnumber">Version 3.2.1</span>
</div>
<div id="projectbrief"><!-- 3.2.1 --></div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="banner">
<a href="https://github.com/wiredtiger/wiredtiger">Fork me on GitHub</a>
<a class="last" href="http://groups.google.com/group/wiredtiger-users">Join my user group</a>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
initMenu('',false,false,'search.php','Search');
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('devdoc-dhandle-lifecycle.html','');});
</script>
<div id="doc-content">
<div class="header">
<div class="headertitle">
<div class="title">Data Handle Lifecycle </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>A WiredTiger Data Handle (dhandle) is a generic representation of any named data source. This representation contains information such as its name, how many references there are to it, individual data source statistics and what type of underlying data object it is.</p>
<p>WiredTiger maintains all dhandles in a global dhandle list accessed from the connection. Multiple sessions access this list, which is protected by a R/W lock. Each session also maintains a session dhandle cache which is a cache of dhandles a session has operated upon. The entries in the cache are references into the global dhandle list.</p>
<h1><a class="anchor" id="dhandle-creation"></a>
dhandle creation</h1>
<p>When a cursor in a session attempts to access a WiredTiger table that has not been accessed before, the dhandle for the table will neither be in the session's dhandle cache nor in the connection's global dhandle list. A new dhandle will have to be created for this table. The cursor trying to access a table first attempts to find the dhandle in the session dhandle cache. When it doesn't find the dhandle in the session cache, it searches in the global dhandle list while holding the read lock. When it doesn't find the dhandle there, it creates a dhandle for this table and puts it in the global dhandle list while holding the write lock on the global dhandle list. The cursor operation then puts a reference to the dhandle in the session's dhandle cache.</p>
<p>There are two relevant reference counters in the dhandle structure, <code>session_ref</code> and <code>session_inuse</code>. <code>session_ref</code> counts the number of session dhandle cache lists that this contain dhandle. <code>session_inuse</code> is a count of cursors opened and operating on this dhandle. Both these counters are incremented by this session as the cursor attempts to use this dhandle. When the operation completes and the cursor is closed, the <code>session_inuse</code> is decremented. The dhandle reference is not removed immediately from the session dhandle cache. If this session accesses the same table again in the near future, having the dhandle reference already in the session dhandle cache is a performance optimization.</p>
<h1><a class="anchor" id="session-cache-sweep"></a>
dhandle session cache sweep</h1>
<p>Dhandle cache sweep is the only way a cleanup is performed on the session' dhandle cache list. The references to the dhandles that have not been accessed by this session in a long time are removed from the cache. Since a session is single-threaded, a session's dhandle cache can only be altered by that session alone.</p>
<p>Each time a session accesses a dhandle, it checks if enough time has elapsed to do a session cache sweep for that session. As it walks the session dhandle cache list, it notices if any dhandle on its list has been marked dead (idle too long). If it has, the session removes that dhandle from its list and decrements the <code>session_ref</code> count.</p>
<p>Since accessing a dhandle involves walking the session dhandle cache list anyway, cache cleanup is piggy-backed on this operation.</p>
<h1><a class="anchor" id="dhandle-sweep"></a>
sweep-server dhandle sweep</h1>
<p>WiredTiger maintains a sweep server in the background for the cleanup of the global dhandle list. The sweep server periodically (<code>close_scan_interval</code>) revisits the dhandles in the global list and if the dhandles are not being used, i.e., the <code>session_inuse</code> count is 0, it assigns the current time as the time of death for the dhandle, if not already done before.</p>
<p>If a dhandle has already got a time of death set for it in a previous iteration of the dhandle sweep and the dhandle has stayed not in use, the sweep server compares the time of death with the current time to check if the dhandle has remained idle for the configured idle time (<code>close_idle_time</code>). If the dhandle has remained idle, the sweep server closes the associated btree contained in the dhandle and releases some of the resources for that dhandle. It also marks the dhandle as dead so that the next time a session with a reference walks its own cache list, it will see the handle marked dead and remove it from the session's dhandle cache list (see above).</p>
<p>The sweep server then checks for whether or not any session is referencing this dhandle, i.e., if a session's dhandle cache still contains a reference to this dhandle. If a dhandle stays referenced by at least one session, i.e., the <code>session_ref</code> count is not 0, the dhandle can't be removed from the global list. If this dhandle is not referenced by any session, i.e., <code>session_ref</code> count is 0, the sweep server removes the dhandle from the global dhandle list and frees any remaining resources associated with it. The removal of the dhandle from the global list hence completes this dhandle's lifecycle. Any future access of the associated table would need to start by creating the dhandle again.</p>
<p>Note: The sweep server's scan interval and a dhandle's close idle time can be configured using <code>file_manager</code> configuration settings of the connection handle. </p>
</div></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a class="el" href="index.html">Reference Guide</a></li><li class="navelem"><a class="el" href="devdoc-index.html">Developer Documentation</a></li>
<li class="footer">Copyright (c) 2008-2019 MongoDB, Inc. All rights reserved. Contact <a href="mailto:info@wiredtiger.com">info@wiredtiger.com</a> for more information.</li>
</ul>
</div>
</body>
</html>
|