1
<!--Copyright 1999-2002 by Sleepycat Software, Inc.-->
2
<!--All rights reserved.-->
5
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
6
<META NAME="GENERATOR" CONTENT="Mozilla/4.08 [en] (X11; I; FreeBSD 2.2.8-19990120-SNAP i386) [Netscape]">
11
<A NAME="Memory Pool Commands"></A>Memory Pool Commands</H2>
12
Memory pools are used in a manner similar to the other subsystems.
13
We create a handle to the pool and then use it for a variety of operations.
14
Some of the memory pool commands use the environment instead. Those are
16
<P><B>> <env> mpool_stat</B>
17
<P>This command returns the statistics associated with the memory
18
pool subsystem. It is a direct call to the <A HREF="../../docs/api_c/memp_stat.html">memp_stat</A>
19
function. It returns a list of name/value pairs of the DB_MPOOL_STAT
23
<BR><B>> <env> mpool_sync <I>lsn</I></B>
24
<P>This command flushes the memory pool for all pages with a log sequence
25
number less than <B><I>lsn</I></B>. It is a direct call to the <A HREF="../../docs/api_c/memp_sync.html">memp_sync </A>
26
function. It returns either a 0 (for success), a DB error message
27
or it throws a Tcl error with a system message.
30
<BR><B>> <env> mpool_trickle <I>percent</I></B>
31
<P>This command tells DB to ensure that at least <B><I>percent</I></B>
32
percent of the pages are clean by writing out enough to dirty pages to
33
achieve that percentage. It is a direct call to the <A HREF="../../docs/api_c/memp_trickle.html">memp_trickle</A>
34
function. The command will return the number of pages actually written.
35
It returns either the number of pages on success, or it throws a Tcl error
36
with a system message.
39
<P><B>> <env> mpool [-create] [-nommap] [-rdonly] [-mode <I>mode</I>]
40
-pagesize <I>size</I> [<I>file</I>]</B>
41
<P>This command creates a new memory pool. It invokes the <A HREF="../../docs/api_c/memp_fopen.html">memp_fopen</A>
42
function. After it successfully gets a handle to a memory pool, we
43
bind it to a new Tcl command of the form <B><I>$env.mpX</I></B>, where
44
X is an integer starting at 0 (e.g. <B>$env.mp0, $env.mp1, </B>etc).
45
We use the <I>Tcl_CreateObjCommand()</I> to create the top level memory
46
pool functions. It is through this handle that the user can manipulate
47
the pool. Internally, the handle we get back from DB will be stored
48
as the <I>ClientData</I> portion of the new command set so that future
49
memory pool calls will have that handle readily available. Additionally,
50
we need to maintain this handle in relation to the environment so that
51
if the user calls <A HREF="../../docs/api_tcl/env_close.html"><env> close</A> without closing
52
the memory pool we can properly clean up. The arguments are:
55
<B><I>file</I></B> is the name of the file to open</LI>
58
<B>-create </B>selects the DB_CREATE flag to create underlying file</LI>
61
<B>-mode <I>mode </I></B>sets the permissions of created file to <B><I>mode</I></B></LI>
64
<B>-nommap</B> selects the DB_NOMMAP flag to disallow using mmap'ed files</LI>
67
<B>-pagesize</B> sets the underlying file page size to <B><I>size</I></B></LI>
70
<B>-rdonly </B>selects the DB_RDONLY flag for read only access</LI>
74
<BR><B>> <mp> close</B>
75
<P>This command closes the memory pool. It is a direct call to the
76
<A HREF="../../docs/api_c/memp_fclose.html">memp_close</A>
77
function. It returns either a 0 (for success), a DB error message
78
or it throws a Tcl error with a system message.
79
<P>Additionally, since the handle is no longer valid, we will call
80
<I>Tcl_DeleteCommand()
82
that further uses of the handle will be dealt with properly by Tcl itself.
83
We must also remove the reference to this handle from the environment.
84
We will go through the list of pinned pages that were acquired by the <A HREF="#> <mp> get">get</A>
86
<A HREF="#> <pg> put">put</A> them back.
88
<BR><B>> <mp> fsync</B>
89
<P>This command flushes all of the file's dirty pages to disk. It
90
is a direct call to the <A HREF="../../docs/api_c/memp_fsync.html">memp_fsync</A>
91
function. It returns either a 0 (for success), a DB error message
92
or it throws a Tcl error with a system message.
94
<BR><A NAME="> <mp> get"></A><B>> <mp> get [-create] [-last] [-new]
96
<P>This command gets the <B><I>pgno </I></B>page from the memory
97
pool. It invokes the <A HREF="../../docs/api_c/memp_fget.html">memp_fget</A>
98
function and possibly the <A HREF="../../docs/api_c/memp_fset.html">memp_fset</A>
99
function if any options are chosen to set the page characteristics.
100
After it successfully gets a handle to a page, we bind it to and
101
return a new Tcl command of the form <B><I>$env.mpN.pX</I></B>, where X
102
is an integer starting at 0 (e.g. <B>$env.mp0.p0, $env.mp1.p0, </B>etc).
103
We use the <I>Tcl_CreateObjCommand()</I> to create the top level page functions.
104
It is through this handle that the user can manipulate the page.
105
Internally, the handle we get back from DB will be stored as the <I>ClientData</I>
106
portion of the new command set. We need to store this handle in
107
relation to the memory pool handle so that if the memory pool is closed,
108
we will <A HREF="#> <pg> put">put</A> back the pages (setting the discard
109
flag) and delete that set of commands.
110
<P>The arguments are:
113
<B>-create </B>selects the DB_MPOOL_CREATE flag to create the page
114
if it does not exist.</LI>
117
<B>-last</B> selects the DB_MPOOL_LAST flag to return the last page in
121
<B>-new</B> selects the DB_MPOOL_NEW flag to create a new page</LI>
125
<BR><B>> <pg> pgnum</B>
126
<P>This command returns the page number associated with this memory pool
127
page. Primarily it will be used after an <A HREF="#> <mp> get"><mp>
130
<HR WIDTH="100%"><B>> <pg> pgsize</B>
131
<P>This command returns the page size associated with this memory pool
132
page. Primarily it will be used after an <A HREF="#> <mp> get"><mp>
135
<HR WIDTH="100%"><B>> <pg> set [-clean] [-dirty] [-discard]</B>
136
<P>This command sets the characteristics of the page. It is a direct
137
call to the <A HREF="../../docs/api_c/memp_fset.html">memp_fset</A> function.
138
It returns either a 0 (for success), a DB error message or it throws a
139
Tcl error with a system message. The arguments are:
142
<B>-clean</B> selects the DB_MPOOL_CLEAN flag to indicate this is a clean
146
<B>-dirty</B> selects the DB_MPOOL_DIRTY flag to indicate this page should
147
be flushed before eviction</LI>
150
<B>-discard</B> selects the DB_MPOOL_DISCARD flag to indicate this page
155
<BR><A NAME="> <pg> put"></A><B>> <pg> put [-clean] [-dirty] [-discard]</B>
156
<P>This command will put back the page to the memory pool. It is
157
a direct call to the <A HREF="../../docs/api_c/memp_fput.html">memp_fput</A>
158
function. It returns either a 0 (for success), a DB error message
159
or it throws a Tcl error with a system message. Additionally, since the
160
handle is no longer valid, we will call
161
<I>Tcl_DeleteCommand()
163
further uses of the handle will be dealt with properly by Tcl itself.
164
We must also remove the reference to this handle from the memory pool.
165
<P>The arguments are:
168
<B>-clean</B> selects the DB_MPOOL_CLEAN flag to indicate this is a clean
172
<B>-dirty</B> selects the DB_MPOOL_DIRTY flag to indicate this page should
173
be flushed before eviction</LI>
176
<B>-discard</B> selects the DB_MPOOL_DISCARD flag to indicate this page
181
<BR><B>> <pg> init <I>val|string</I></B>
182
<P>This command initializes the page to the <B><I>val</I></B> given or
183
places the <B><I>string</I></B> given at the beginning of the page.
184
It returns a 0 for success or it throws a Tcl error with an error message.
187
<BR><B>> <pg> is_setto <I>val|string</I></B>
188
<P>This command verifies the page contains the <B><I>val</I></B> given
189
or checks that the <B>string</B> given is at the beginning of the page.
190
It returns a 1 if the page is correctly set to the value and a 0 otherwise.