ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/BDB/BDB.pm
(Generate patch)

Comparing BDB/BDB.pm (file contents):
Revision 1.15 by root, Thu Sep 13 21:34:00 2007 UTC vs.
Revision 1.16 by root, Sun Sep 16 18:17:58 2007 UTC

179 db_sequence_remove (DB_SEQUENCE *seq, DB_TXN_ornull *txnid = 0, U32 flags = 0, SV *callback = &PL_sv_undef) 179 db_sequence_remove (DB_SEQUENCE *seq, DB_TXN_ornull *txnid = 0, U32 flags = 0, SV *callback = &PL_sv_undef)
180 flags: TXN_NOSYNC 180 flags: TXN_NOSYNC
181 181
182=head4 db_txn_finish (DB_TXN *txn, U32 flags = 0, SV *callback = &PL_sv_undef) 182=head4 db_txn_finish (DB_TXN *txn, U32 flags = 0, SV *callback = &PL_sv_undef)
183 183
184This is not a Berkeley DB function but a BDB module extension. It is very 184This is not actually a Berkeley DB function but a BDB module
185extension. The background for this exytension is: It is very annoying to
185annoying to have to check every single BDB function for error returns and 186have to check every single BDB function for error returns and provide a
186provide a codepath out of your transaction. While the BDB module still 187codepath out of your transaction. While the BDB module still makes this
187makes this possible, it contains the following extensions: 188possible, it contains the following extensions:
188 189
189When a transaction-protected function returns any operating system 190When a transaction-protected function returns any operating system
190error (errno > 0), BDB will set the C<TXN_DEADLOCK> flag on the 191error (errno > 0), BDB will set the C<TXN_DEADLOCK> flag on the
191transaction. This flag is also set by Berkeley DB functions externally 192transaction. This flag is also set by Berkeley DB functions themselves
192when an operation fails with LOCK_DEADLOCK, and it causes all further 193when an operation fails with LOCK_DEADLOCK, and it causes all further
193operations on that transaction (including C<db_txn_commit>) to fail. 194operations on that transaction (including C<db_txn_commit>) to fail.
194 195
195The C<db_txn_finish> request will look at this flag, and, if it is set, 196The C<db_txn_finish> request will look at this flag, and, if it is set,
196will automatically call C<db_txn_abort> (setting errno to C<LOCK_DEADLOCK> 197will automatically call C<db_txn_abort> (setting errno to C<LOCK_DEADLOCK>
197if it isn't set). If it isn't set, it will call C<db_txn_commit> and 198if it isn't set to something else yet). If it isn't set, it will call
198return the error normally. 199C<db_txn_commit> and return the error normally.
199 200
200How to use this? Easy: just write your transaction normally: 201How to use this? Easy: just write your transaction normally:
201 202
202 my $txn = $db_env->txn_begin; 203 my $txn = $db_env->txn_begin;
203 db_get $db, $txn, "key", my $data; 204 db_get $db, $txn, "key", my $data;
208That is, handle only the expected errors. If something unexpected happens 209That is, handle only the expected errors. If something unexpected happens
209(EIO, LOCK_NOTGRANTED or a deadlock in either db_get or db_put), then the remaining 210(EIO, LOCK_NOTGRANTED or a deadlock in either db_get or db_put), then the remaining
210requests (db_put in this case) will simply be skipped (they will fail with 211requests (db_put in this case) will simply be skipped (they will fail with
211LOCK_DEADLOCK) and the transaction will be aborted. 212LOCK_DEADLOCK) and the transaction will be aborted.
212 213
213You cna use the C<< $txn->failed >> method to check wether a transaction 214You can use the C<< $txn->failed >> method to check wether a transaction
214has failed in this way and abort further processing (excluding 215has failed in this way and abort further processing (excluding
215C<db_txn_finish>). 216C<db_txn_finish>).
216 217
217=head3 DB_ENV/database environment methods 218=head3 DB_ENV/database environment methods
218 219

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines