-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdata_sources.html
194 lines (194 loc) · 16.3 KB
/
data_sources.html
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<!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 Sources</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);
$(window).load(resizeHeight);
</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 2.9.2</span>
</div>
<div id="projectbrief"><!-- 2.9.2 --></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.10 -->
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main Page</span></a></li>
<li class="current"><a href="pages.html"><span>Related Pages</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="examples.html"><span>Examples</span></a></li>
<li><a href="community.html"><span>Community</span></a></li>
<li><a href="license.html"><span>License</span></a></li>
</ul>
</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('data_sources.html','');});
</script>
<div id="doc-content">
<div class="header">
<div class="headertitle">
<div class="title">Data Sources </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>WiredTiger provides access to data from a variety of sources. At the lowest level, data may be stored in a file using a tree structure. A relational schema supporting tables, indices and column groups is layered on top of file. Additional sources include LSM trees and statistics, and applications can further extend the supported types by implementing the <a class="el" href="struct_w_t___d_a_t_a___s_o_u_r_c_e.html" title="Applications can extend WiredTiger by providing new implementations of the WT_DATA_SOURCE class...">WT_DATA_SOURCE</a> interface.</p>
<p>Common operations on all data sources are performed using <a class="el" href="struct_w_t___c_u_r_s_o_r.html" title="A WT_CURSOR handle is the interface to a cursor. ">WT_CURSOR</a> handles. See <a class="el" href="cursor_ops.html">Cursor operations</a> for a description of how to use cursors.</p>
<h1><a class="anchor" id="data_builtin"></a>
Builtin data sources</h1>
<p>The following are the builtin basic cursor types: </p><table class="doxtable">
<tr>
<th>URI</th><th>Type</th><th>Notes </th></tr>
<tr>
<td><code>table:<table name>[<projection>]</code></td><td>table cursor</td><td>table key, table value(s) with optional projection of columns </td></tr>
<tr>
<td><code>colgroup:<table name>:<column group name></code></td><td>column group cursor</td><td>table key, column group value(s) </td></tr>
<tr>
<td><code>index:<table name>:<index name>[<projection>]</code></td><td>index cursor</td><td>key=index key, value=table value(s) with optional projection of columns </td></tr>
<tr>
<td><code>join:table:<table name>[<projection>]</code></td><td>join cursor</td><td>key=table key, value=table value(s) with optional projection of columns </td></tr>
</table>
<p>Some administrative tasks can be accomplished using the following special cursor types that give access to data managed by WiredTiger: </p><table class="doxtable">
<tr>
<th>URI</th><th>Type</th><th>Notes </th></tr>
<tr>
<td><code>backup:</code></td><td>backup cursor</td><td>key=<code>string</code>, see <a class="el" href="backup.html">Backups</a> for details </td></tr>
<tr>
<td><code>log:</code></td><td>log cursor</td><td>key=<code>(long fileID, long offset, int seqno)</code>,<br />
value=<code>(uint64_t txnid, uint32_t rectype,<br />
uint32_t optype, uint32_t fileid,<br />
<a class="el" href="group__wt.html#struct_w_t___i_t_e_m" title="A raw item of data to be managed, including a pointer to the data and a length. ">WT_ITEM</a> key, <a class="el" href="group__wt.html#struct_w_t___i_t_e_m" title="A raw item of data to be managed, including a pointer to the data and a length. ">WT_ITEM</a> value)</code>,<br />
see <a class="el" href="cursor_log.html">Log cursors</a> for details </td></tr>
<tr>
<td><code>metadata:[create]</code></td><td>metadata cursor (optionally only returning configuration strings for <a class="el" href="struct_w_t___s_e_s_s_i_o_n.html#a358ca4141d59c345f401c58501276bbb" title="Create a table, column group, index or file. ">WT_SESSION::create</a> if <code>create</code> is appended</td><td>key=<code>string</code>, value=<code>string</code>,<br />
see <a class="el" href="cursors.html#metadata">Reading WiredTiger Metadata</a> for details </td></tr>
<tr>
<td><code>statistics:[<data source URI>]</code></td><td>database</td><td>data source or join statistics cursor</td><td>key=<code>int id</code>,<br />
value=<code>(string description, string value, uint64_t value)</code>,<br />
see <a class="el" href="data_sources.html#data_statistics">Statistics Data</a> for details </td></tr>
</table>
<p>Advanced applications may also open the following low-level cursor types: </p><table class="doxtable">
<tr>
<th>URI</th><th>Type</th><th>Notes </th></tr>
<tr>
<td><code>file:<file name></code></td><td>file cursor</td><td>file key, file value(s) </td></tr>
<tr>
<td><code>lsm:<name></code></td><td>LSM cursor (key=LSM key, value=LSM value)</td><td>LSM key, LSM value,<br />
see <a class="el" href="lsm.html">Log-Structured Merge Trees</a> </td></tr>
</table>
<h2><a class="anchor" id="data_files"></a>
Raw Files</h2>
<p>WiredTiger's schema layer can be bypassed by opening cursors with a <code>"file:"</code> URI, using the name of the underlying file. This can be useful for seeing the contents of a column group or index without reading all of the columns from the table.</p>
<p>For example, if an index becomes inconsistent with its primary, a file cursor can read from the index without errors (even though some of the keys that are returned may not exist in the primary).</p>
<h2><a class="anchor" id="data_indices"></a>
Table Index data</h2>
<p>When an index is created for a table, records are inserted into the index whenever the table is updated. These records use a different key to the primary table, as specified when the index is created with the <a class="el" href="struct_w_t___s_e_s_s_i_o_n.html#a358ca4141d59c345f401c58501276bbb" title="Create a table, column group, index or file. ">WT_SESSION::create</a> method.</p>
<p>A cursor opened on an index has the specified index columns as its key, accessed by <a class="el" href="struct_w_t___c_u_r_s_o_r.html#ad1088d719df40babc1f57d086691ebdc" title="Set the key for the next operation. ">WT_CURSOR::set_key</a> and <a class="el" href="struct_w_t___c_u_r_s_o_r.html#af19f6f9d9c7fc248ab38879032620b2f" title="Get the key for the current record. ">WT_CURSOR::get_key</a>. The value columns default to returning the value columns from the table, but this can be overridden by configuring a projection cursor (see <a class="el" href="cursors.html#cursor_projections">Projections</a>), which can access the table key columns or a subset of the value columns.</p>
<h2><a class="anchor" id="data_statistics"></a>
Statistics Data</h2>
<p>Statistics cursors can be used to retrieve run-time statistics about a WiredTiger database as well as statistics for individual data sources. The statistics are at two levels: per-database and per-individual data source. Database-wide statistics are retrieved with the <code>"statistics:"</code> URI; individual data source statistics are available by specifying <code>"statistics:<data source URI>"</code>. Additionally, statistics about a join cursor can be retrieved by specifying <code>"statistics:join"</code> and supplying the join cursor as an argument in the SESSION::open_cursor call.</p>
<p>The statistic key is an integer from the list of keys in <a class="el" href="group__wt.html#statistics_keys">Statistics Keys</a>. Statistics cursors return three values from the <a class="el" href="struct_w_t___c_u_r_s_o_r.html#af85364a5af50b95bbc46c82e72f75c01" title="Get the value for the current record. ">WT_CURSOR::get_value</a> call: a printable description of the statistic, a printable version of the entry's value, and the entry's unsigned 64-bit integral value, respectively.</p>
<p>The cursor's statistics values are loaded when the cursor is opened and remain unchanged for the life of the cursor, unless the cursor is reset by calling the <a class="el" href="struct_w_t___c_u_r_s_o_r.html#afc1b42c22c9c85e1ba08ce3b34437565" title="Reset the cursor. ">WT_CURSOR::reset</a> method, which reloads the values.</p>
<p>The following is an example of printing run-time statistics about the WiredTiger engine:</p>
<div class="fragment"><div class="line"> <span class="keywordflow">if</span> ((ret = session-><a class="code" href="struct_w_t___s_e_s_s_i_o_n.html#afb5b4a69c2c5cafe411b2b04fdc1c75d">open_cursor</a>(session,</div>
<div class="line"> <span class="stringliteral">"statistics:"</span>, NULL, NULL, &cursor)) != 0)</div>
<div class="line"> <span class="keywordflow">return</span> (ret);</div>
<div class="line"></div>
<div class="line"> ret = print_cursor(cursor);</div>
<div class="line"> ret = cursor-><a class="code" href="struct_w_t___c_u_r_s_o_r.html#aeea071f192cab12245a50fbe71c3460b">close</a>(cursor);</div>
</div><!-- fragment --><p> The following is an example of printing statistics about a table:</p>
<div class="fragment"><div class="line"> <span class="keywordflow">if</span> ((ret = session-><a class="code" href="struct_w_t___s_e_s_s_i_o_n.html#afb5b4a69c2c5cafe411b2b04fdc1c75d">open_cursor</a>(session,</div>
<div class="line"> <span class="stringliteral">"statistics:table:access"</span>, NULL, NULL, &cursor)) != 0)</div>
<div class="line"> <span class="keywordflow">return</span> (ret);</div>
<div class="line"></div>
<div class="line"> ret = print_cursor(cursor);</div>
<div class="line"> ret = cursor-><a class="code" href="struct_w_t___c_u_r_s_o_r.html#aeea071f192cab12245a50fbe71c3460b">close</a>(cursor);</div>
</div><!-- fragment --><p> The following is an example of printing statistics about a join cursor:</p>
<div class="fragment"><div class="line"> <span class="keywordflow">if</span> ((ret = session-><a class="code" href="struct_w_t___s_e_s_s_i_o_n.html#afb5b4a69c2c5cafe411b2b04fdc1c75d">open_cursor</a>(session,</div>
<div class="line"> <span class="stringliteral">"statistics:join"</span>, join_cursor, NULL, &stat_cursor)) != 0)</div>
<div class="line"> <span class="keywordflow">return</span> (ret);</div>
<div class="line"></div>
<div class="line"> ret = print_cursor(stat_cursor);</div>
<div class="line"> ret = stat_cursor->close(stat_cursor);</div>
</div><!-- fragment --><p> These three examples can use a common display routine that iterates through the statistics until the cursor returns the end of the list.</p>
<div class="fragment"><div class="line"><span class="keywordtype">int</span></div>
<div class="line">print_cursor(<a class="code" href="struct_w_t___c_u_r_s_o_r.html">WT_CURSOR</a> *cursor)</div>
<div class="line">{</div>
<div class="line"> <span class="keyword">const</span> <span class="keywordtype">char</span> *desc, *pvalue;</div>
<div class="line"> uint64_t value;</div>
<div class="line"> <span class="keywordtype">int</span> ret;</div>
<div class="line"></div>
<div class="line"> <span class="keywordflow">while</span> ((ret = cursor-><a class="code" href="struct_w_t___c_u_r_s_o_r.html#a0503f16bd8f3d05aa3552f229b3a8e1b">next</a>(cursor)) == 0 &&</div>
<div class="line"> (ret = cursor-><a class="code" href="struct_w_t___c_u_r_s_o_r.html#af85364a5af50b95bbc46c82e72f75c01">get_value</a>(cursor, &desc, &pvalue, &value)) == 0)</div>
<div class="line"> <span class="keywordflow">if</span> (value != 0)</div>
<div class="line"> printf(<span class="stringliteral">"%s=%s\n"</span>, desc, pvalue);</div>
<div class="line"></div>
<div class="line"> <span class="keywordflow">return</span> (ret == <a class="code" href="group__wt.html#ga3c9e1b494d95cf34404ab7a974af6bf8">WT_NOTFOUND</a> ? 0 : ret);</div>
<div class="line">}</div>
</div><!-- fragment --><p> Individual statistics values can be retrieved by searching for the corresponding key, as shown in the following example:</p>
<div class="fragment"><div class="line"> <a class="code" href="struct_w_t___c_u_r_s_o_r.html">WT_CURSOR</a> *cursor;</div>
<div class="line"> <span class="keyword">const</span> <span class="keywordtype">char</span> *desc, *pvalue;</div>
<div class="line"> uint64_t value;</div>
<div class="line"> <span class="keywordtype">int</span> ret;</div>
<div class="line"></div>
<div class="line"> <span class="keywordflow">if</span> ((ret = session-><a class="code" href="struct_w_t___s_e_s_s_i_o_n.html#afb5b4a69c2c5cafe411b2b04fdc1c75d">open_cursor</a>(session,</div>
<div class="line"> <span class="stringliteral">"statistics:table:access"</span>, NULL, NULL, &cursor)) != 0)</div>
<div class="line"> <span class="keywordflow">return</span> (ret);</div>
<div class="line"></div>
<div class="line"> cursor-><a class="code" href="struct_w_t___c_u_r_s_o_r.html#ad1088d719df40babc1f57d086691ebdc">set_key</a>(cursor, <a class="code" href="group__wt.html#ga079f2d70ac0826f54e36b8535d7194e5">WT_STAT_DSRC_BTREE_OVERFLOW</a>);</div>
<div class="line"> ret = cursor-><a class="code" href="struct_w_t___c_u_r_s_o_r.html#a7e25b2ced2cf3ec68bd5429bf921c79f">search</a>(cursor);</div>
<div class="line"> ret = cursor-><a class="code" href="struct_w_t___c_u_r_s_o_r.html#af85364a5af50b95bbc46c82e72f75c01">get_value</a>(cursor, &desc, &pvalue, &value);</div>
<div class="line"> printf(<span class="stringliteral">"%s=%s\n"</span>, desc, pvalue);</div>
<div class="line"></div>
<div class="line"> ret = cursor-><a class="code" href="struct_w_t___c_u_r_s_o_r.html#aeea071f192cab12245a50fbe71c3460b">close</a>(cursor);</div>
</div><!-- fragment --><p> See <a class="el" href="tune_statistics.html">Performance monitoring with statistics</a> for more examples of how statistics can be used. </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="programming.html">Writing WiredTiger applications</a></li><li class="navelem"><a class="el" href="cursors.html">Cursors</a></li>
<li class="footer">Copyright (c) 2008-2016 MongoDB, Inc. All rights reserved. Contact <a href="mailto:[email protected]">[email protected]</a> for more information.</li>
</ul>
</div>
</body>
</html>