… | |
… | |
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 | |
184 | This is not a Berkeley DB function but a BDB module extension. It is very |
184 | This is not actually a Berkeley DB function but a BDB module |
|
|
185 | extension. The background for this exytension is: It is very annoying to |
185 | annoying to have to check every single BDB function for error returns and |
186 | have to check every single BDB function for error returns and provide a |
186 | provide a codepath out of your transaction. While the BDB module still |
187 | codepath out of your transaction. While the BDB module still makes this |
187 | makes this possible, it contains the following extensions: |
188 | possible, it contains the following extensions: |
188 | |
189 | |
189 | When a transaction-protected function returns any operating system |
190 | When a transaction-protected function returns any operating system |
190 | error (errno > 0), BDB will set the C<TXN_DEADLOCK> flag on the |
191 | error (errno > 0), BDB will set the C<TXN_DEADLOCK> flag on the |
191 | transaction. This flag is also set by Berkeley DB functions externally |
192 | transaction. This flag is also set by Berkeley DB functions themselves |
192 | when an operation fails with LOCK_DEADLOCK, and it causes all further |
193 | when an operation fails with LOCK_DEADLOCK, and it causes all further |
193 | operations on that transaction (including C<db_txn_commit>) to fail. |
194 | operations on that transaction (including C<db_txn_commit>) to fail. |
194 | |
195 | |
195 | The C<db_txn_finish> request will look at this flag, and, if it is set, |
196 | The C<db_txn_finish> request will look at this flag, and, if it is set, |
196 | will automatically call C<db_txn_abort> (setting errno to C<LOCK_DEADLOCK> |
197 | will automatically call C<db_txn_abort> (setting errno to C<LOCK_DEADLOCK> |
197 | if it isn't set). If it isn't set, it will call C<db_txn_commit> and |
198 | if it isn't set to something else yet). If it isn't set, it will call |
198 | return the error normally. |
199 | C<db_txn_commit> and return the error normally. |
199 | |
200 | |
200 | How to use this? Easy: just write your transaction normally: |
201 | How 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; |
… | |
… | |
208 | That is, handle only the expected errors. If something unexpected happens |
209 | That 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 |
210 | requests (db_put in this case) will simply be skipped (they will fail with |
211 | requests (db_put in this case) will simply be skipped (they will fail with |
211 | LOCK_DEADLOCK) and the transaction will be aborted. |
212 | LOCK_DEADLOCK) and the transaction will be aborted. |
212 | |
213 | |
213 | You cna use the C<< $txn->failed >> method to check wether a transaction |
214 | You can use the C<< $txn->failed >> method to check wether a transaction |
214 | has failed in this way and abort further processing (excluding |
215 | has failed in this way and abort further processing (excluding |
215 | C<db_txn_finish>). |
216 | C<db_txn_finish>). |
216 | |
217 | |
217 | =head3 DB_ENV/database environment methods |
218 | =head3 DB_ENV/database environment methods |
218 | |
219 | |