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.75 [en] (X11; U; Linux 2.2.16-22 i686) [Netscape]">
11
<a NAME="Locking Commands"></a>Locking Commands</h2>
12
Most locking commands work with the environment handle. However,
13
when a user gets a lock we create a new lock handle that they then use
14
with in a similar manner to all the other handles to release the lock.
15
We present the general locking functions first, and then those that manipulate
17
<p><b>> <env> lock_detect [default|oldest|youngest|random]</b>
18
<p>This command runs the deadlock detector. It directly translates
19
to the <a href="../../docs/api_c/lock_detect.html">lock_detect</a> DB call.
20
It returns either a 0 (for success), a DB error message or it throws a
21
Tcl error with a system message. The first argument sets the policy
22
for deadlock as follows:
25
<b>default</b> selects the DB_LOCK_DEFAULT policy for default detection
26
(default if not specified)</li>
29
<b>oldest </b>selects DB_LOCK_OLDEST to abort the oldest locker on a deadlock</li>
32
<b>random</b> selects DB_LOCK_RANDOM to abort a random locker on a deadlock</li>
35
<b>youngest</b> selects DB_LOCK_YOUNGEST to abort the youngest locker on
40
<br><b>> <env> lock_stat</b>
41
<p>This command returns a list of name/value pairs where the names correspond
42
to the C-structure field names of DB_LOCK_STAT and the values are the data
43
returned. This command is a direct translation of the <a href="../../docs/api_c/lock_stat.html">lock_stat</a>
46
<br><a NAME="> <env> lock_id"></a><b>> <env> lock_id</b>
47
<p>This command returns a unique locker ID value. It directly translates
48
to the <a href="../../docs/api_c/lock_id.html">lock_id</a> DB call.
51
<br><a NAME="> <env> lock_id"></a><b>> <env> lock_id_free </b><i>locker</i>
52
<p>This command frees the locker allockated by the lock_id call. It directly
53
translates to the <a href="../../docs/api_c/lock_id.html">lock_id_free
57
<br><a NAME="> <env> lock_id"></a><b>> <env> lock_id_set </b><i>current
59
<p>This is a diagnostic command to set the locker id that will get
60
allocated next and the maximum id that
61
<br>will trigger the id reclaim algorithm.
63
<br><a NAME="> <env> lock_get"></a><b>> <env> lock_get [-nowait]<i>lockmode
65
<p>This command gets a lock. It will invoke the <a href="../../docs/api_c/lock_get.html">lock_get</a>
66
function. After it successfully gets a handle to a lock, we bind
67
it to a new Tcl command of the form <b><i>$env.lockX</i></b>, where X is
68
an integer starting at 0 (e.g. <b>$env.lock0, $env.lock1, </b>etc).
69
We use the <i>Tcl_CreateObjCommand()</i> to create the top level locking
70
command function. It is through this handle that the user can release
71
the lock. Internally, the handle we get back from DB will be stored
72
as the <i>ClientData</i> portion of the new command set so that future
73
locking calls will have that handle readily available.
77
<b><i>locker</i></b> specifies the locker ID returned from the <a href="#> <env> lock_id">lock_id</a>
81
<b><i>obj</i></b> specifies an object to lock</li>
84
the <b><i>lock mode</i></b> is specified as one of the following:</li>
88
<b>ng </b>specifies DB_LOCK_NG for not granted (always 0)</li>
91
<b>read</b> specifies DB_LOCK_READ for a read (shared) lock</li>
94
<b>write</b> specifies DB_LOCK_WRITE for an exclusive write lock</li>
97
<b>iwrite </b>specifies DB_LOCK_IWRITE for intent for exclusive write lock</li>
100
<b>iread </b>specifies DB_LOCK_IREAD for intent for shared read lock</li>
103
<b>iwr </b>specifies DB_LOCK_IWR for intent for eread and write lock</li>
107
<b>-nowait</b> selects the DB_LOCK_NOWAIT to indicate that we do not want
108
to wait on the lock</li>
112
<br><b>> <lock> put</b>
113
<p>This command releases the lock referenced by the command. It is
114
a direct translation of the <a href="../../docs/api_c/lock_put.html">lock_put</a>
115
function. It returns either a 0 (for success), a DB error message
116
or it throws a Tcl error with a system message. Additionally, since
117
the handle is no longer valid, we will call
118
<i>Tcl_DeleteCommand()
120
that further uses of the handle will be dealt with properly by Tcl itself.
123
<br><a NAME="> <env> lock_vec"></a><b>> <env> lock_vec [-nowait] <i>locker
124
</i>{get|put|put_all|put_obj
125
[<i>obj</i>] [<i>lockmode</i>] [<i>lock</i>]} ...</b>
126
<p>This command performs a series of lock calls. It is a direct translation
127
of the <a href="../../docs/api_c/lock_vec.html">lock_vec</a> function.
128
This command will return a list of the return values from each operation
129
specified in the argument list. For the 'put' operations the entry
130
in the return value list is either a 0 (for success) or an error.
131
For the 'get' operation, the entry is the lock widget handle, <b>$env.lockN</b>
132
(as described above in <a href="#> <env> lock_get"><env> lock_get</a>)
133
or an error. If an error occurs, the return list will contain the
134
return values for all the successful operations up the erroneous one and
135
the error code for that operation. Subsequent operations will be
137
<p>As for the other operations, if we are doing a 'get' we will create
138
the commands and if we are doing a 'put' we will have to delete the commands.
139
Additionally, we will have to do this after the call to the DB lock_vec
140
and iterate over the results, creating and/or deleting Tcl commands.
141
It is possible that we may return a lock widget from a get operation that
142
is considered invalid, if, for instance, there was a <b>put_all</b> operation
143
performed later in the vector of operations. The arguments are:
146
<b><i>locker</i></b> specifies the locker ID returned from the <a href="#> <env> lock_id">lock_id</a>
150
<b>-nowait</b> selects the DB_LOCK_NOWAIT to indicate that we do not want
151
to wait on the lock</li>
154
the lock vectors are tuple consisting of {an operation, lock object, lock
155
mode, lock handle} where what is required is based on the operation desired:</li>
159
<b>get</b> specifes DB_LOCK_GET to get a lock. Requires a tuple <b>{get
167
<b>ng </b>specifies DB_LOCK_NG for not granted (always 0)</li>
170
<b>read</b> specifies DB_LOCK_READ for a read (shared) lock</li>
173
<b>write</b> specifies DB_LOCK_WRITE for an exclusive write lock</li>
176
<b>iwrite </b>specifies DB_LOCK_IWRITE for intent for exclusive write lock</li>
179
<b>iread </b>specifies DB_LOCK_IREAD for intent for shared read lock</li>
182
<b>iwr </b>specifies DB_LOCK_IWR for intent for eread and write lock</li>
186
<b>put</b> specifies DB_LOCK_PUT to release a <b><i>lock</i></b>.
187
Requires a tuple <b>{put <i>lock}</i></b></li>
190
<b>put_all </b>specifies DB_LOCK_PUT_ALL to release all locks held by <b><i>locker</i></b>.
191
Requires a tuple <b>{put_all}</b></li>
194
<b>put_obj</b> specifies DB_LOCK_PUT_OBJ to release all locks held by <b><i>locker</i></b>
195
associated with the given <b><i>obj</i></b>. Requires a tuple <b>{put_obj
201
<br><a NAME="> <env> lock_vec"></a><b>> <env> lock_timeout <i>timeout</i></b>
202
<p>This command sets the lock timeout for all future locks in this environment.
203
The timeout is in micorseconds.