… | |
… | |
108 | no warnings; |
108 | no warnings; |
109 | use strict 'vars'; |
109 | use strict 'vars'; |
110 | |
110 | |
111 | use base 'Exporter'; |
111 | use base 'Exporter'; |
112 | |
112 | |
|
|
113 | our $VERSION; |
|
|
114 | |
113 | BEGIN { |
115 | BEGIN { |
114 | our $VERSION = '1.7'; |
116 | $VERSION = '1.81'; |
115 | |
117 | |
116 | our @BDB_REQ = qw( |
118 | our @BDB_REQ = qw( |
117 | db_env_open db_env_close db_env_txn_checkpoint db_env_lock_detect |
119 | db_env_open db_env_close db_env_txn_checkpoint db_env_lock_detect |
118 | db_env_memp_sync db_env_memp_trickle db_env_dbrename db_env_dbremove |
120 | db_env_memp_sync db_env_memp_trickle db_env_dbrename db_env_dbremove |
119 | db_open db_close db_compact db_sync db_upgrade |
121 | db_open db_close db_compact db_sync db_upgrade |
120 | db_put db_get db_pget db_del db_key_range |
122 | db_put db_exists db_get db_pget db_del db_key_range |
121 | db_txn_commit db_txn_abort db_txn_finish |
123 | db_txn_commit db_txn_abort db_txn_finish |
122 | db_c_close db_c_count db_c_put db_c_get db_c_pget db_c_del |
124 | db_c_close db_c_count db_c_put db_c_get db_c_pget db_c_del |
123 | db_sequence_open db_sequence_close |
125 | db_sequence_open db_sequence_close |
124 | db_sequence_get db_sequence_remove |
126 | db_sequence_get db_sequence_remove |
125 | ); |
127 | ); |
… | |
… | |
224 | flags: FREELIST_ONLY FREE_SPACE |
226 | flags: FREELIST_ONLY FREE_SPACE |
225 | db_sync (DB *db, U32 flags = 0, SV *callback = &PL_sv_undef) |
227 | db_sync (DB *db, U32 flags = 0, SV *callback = &PL_sv_undef) |
226 | db_key_range (DB *db, DB_TXN_ornull *txn, SV *key, SV *key_range, U32 flags = 0, SV *callback = &PL_sv_undef) |
228 | db_key_range (DB *db, DB_TXN_ornull *txn, SV *key, SV *key_range, U32 flags = 0, SV *callback = &PL_sv_undef) |
227 | db_put (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) |
229 | db_put (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) |
228 | flags: APPEND NODUPDATA NOOVERWRITE |
230 | flags: APPEND NODUPDATA NOOVERWRITE |
|
|
231 | db_exists (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = 0) (v4.6) |
229 | db_get (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) |
232 | db_get (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) |
230 | flags: CONSUME CONSUME_WAIT GET_BOTH SET_RECNO MULTIPLE READ_COMMITTED READ_UNCOMMITTED RMW |
233 | flags: CONSUME CONSUME_WAIT GET_BOTH SET_RECNO MULTIPLE READ_COMMITTED READ_UNCOMMITTED RMW |
231 | db_pget (DB *db, DB_TXN_ornull *txn, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) |
234 | db_pget (DB *db, DB_TXN_ornull *txn, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) |
232 | flags: CONSUME CONSUME_WAIT GET_BOTH SET_RECNO MULTIPLE READ_COMMITTED READ_UNCOMMITTED RMW |
235 | flags: CONSUME CONSUME_WAIT GET_BOTH SET_RECNO MULTIPLE READ_COMMITTED READ_UNCOMMITTED RMW |
233 | db_del (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = &PL_sv_undef) |
236 | db_del (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = &PL_sv_undef) |
… | |
… | |
301 | $int = $env->set_tmp_dir (const char *dir) |
304 | $int = $env->set_tmp_dir (const char *dir) |
302 | $int = $env->set_lg_dir (const char *dir) |
305 | $int = $env->set_lg_dir (const char *dir) |
303 | $int = $env->set_shm_key (long shm_key) |
306 | $int = $env->set_shm_key (long shm_key) |
304 | $int = $env->set_cachesize (U32 gbytes, U32 bytes, int ncache = 0) |
307 | $int = $env->set_cachesize (U32 gbytes, U32 bytes, int ncache = 0) |
305 | $int = $env->set_flags (U32 flags, int onoff = 1) |
308 | $int = $env->set_flags (U32 flags, int onoff = 1) |
306 | $int = $env->log_set_config (U32 flags, int onoff = 1) [v4.7] |
309 | $int = $env->log_set_config (U32 flags, int onoff = 1) (v4.7) |
307 | $int = $env->set_intermediate_dir_mode (const char *modestring) [v4.7] |
310 | $int = $env->set_intermediate_dir_mode (const char *modestring) (v4.7) |
308 | $env->set_errfile (FILE *errfile = 0) |
311 | $env->set_errfile (FILE *errfile = 0) |
309 | $env->set_msgfile (FILE *msgfile = 0) |
312 | $env->set_msgfile (FILE *msgfile = 0) |
310 | $int = $env->set_verbose (U32 which, int onoff = 1) |
313 | $int = $env->set_verbose (U32 which, int onoff = 1) |
311 | $int = $env->set_encrypt (const char *password, U32 flags = 0) |
314 | $int = $env->set_encrypt (const char *password, U32 flags = 0) |
312 | $int = $env->set_timeout (NV timeout_seconds, U32 flags = SET_TXN_TIMEOUT) |
315 | $int = $env->set_timeout (NV timeout_seconds, U32 flags = SET_TXN_TIMEOUT) |
… | |
… | |
324 | $int = $env->mutex_set_max (U32 max) |
327 | $int = $env->mutex_set_max (U32 max) |
325 | $int = $env->mutex_set_align (U32 align) |
328 | $int = $env->mutex_set_align (U32 align) |
326 | |
329 | |
327 | $txn = $env->txn_begin (DB_TXN_ornull *parent = 0, U32 flags = 0) |
330 | $txn = $env->txn_begin (DB_TXN_ornull *parent = 0, U32 flags = 0) |
328 | flags: READ_COMMITTED READ_UNCOMMITTED TXN_NOSYNC TXN_NOWAIT TXN_SNAPSHOT TXN_SYNC TXN_WAIT TXN_WRITE_NOSYNC |
331 | flags: READ_COMMITTED READ_UNCOMMITTED TXN_NOSYNC TXN_NOWAIT TXN_SNAPSHOT TXN_SYNC TXN_WAIT TXN_WRITE_NOSYNC |
329 | $txn = $env->cdsgroup_begin; |
332 | $txn = $env->cdsgroup_begin; (v4.5) |
330 | |
333 | |
331 | =head4 Example: |
334 | =head4 Example: |
332 | |
335 | |
333 | use AnyEvent; |
336 | use AnyEvent; |
334 | use BDB; |
337 | use BDB; |
… | |
… | |
426 | DESTROY (DBC_ornull *dbc) |
429 | DESTROY (DBC_ornull *dbc) |
427 | CODE: |
430 | CODE: |
428 | if (dbc) |
431 | if (dbc) |
429 | dbc->c_close (dbc); |
432 | dbc->c_close (dbc); |
430 | |
433 | |
431 | $int = $cursor->set_priority ($priority = PRIORITY_*) |
434 | $int = $cursor->set_priority ($priority = PRIORITY_*) (v4.6) |
432 | |
435 | |
433 | =head4 Example: |
436 | =head4 Example: |
434 | |
437 | |
435 | my $c = $db->cursor; |
438 | my $c = $db->cursor; |
436 | |
439 | |
… | |
… | |
569 | |
572 | |
570 | BerkeleyDB comes in various versions, many of them have minor |
573 | BerkeleyDB comes in various versions, many of them have minor |
571 | incompatibilities. This means that traditional "at least version x.x" |
574 | incompatibilities. This means that traditional "at least version x.x" |
572 | checks are often not sufficient. |
575 | checks are often not sufficient. |
573 | |
576 | |
574 | Example: set the log_autoremove option in a way compatible with <v.47 and |
577 | Example: set the log_autoremove option in a way compatible with <v4.7 and |
575 | v4.7. Note the use of & on the constants to avoid triggering a compiletime |
578 | v4.7. Note the use of & on the constants to avoid triggering a compiletime |
576 | bug when the symbol isn't available. |
579 | bug when the symbol isn't available. |
577 | |
580 | |
578 | $DB_ENV->set_flags (&BDB::LOG_AUTOREMOVE ) if BDB::VERSION v0, v4.7; |
581 | $DB_ENV->set_flags (&BDB::LOG_AUTOREMOVE ) if BDB::VERSION v0, v4.7; |
579 | $DB_ENV->log_set_config (&BDB::LOG_AUTO_REMOVE) if BDB::VERSION v4.7; |
582 | $DB_ENV->log_set_config (&BDB::LOG_AUTO_REMOVE) if BDB::VERSION v4.7; |
… | |
… | |
612 | =back |
615 | =back |
613 | |
616 | |
614 | =cut |
617 | =cut |
615 | |
618 | |
616 | sub VERSION { |
619 | sub VERSION { |
|
|
620 | # I was dumb enough to override the VERSION method here, so let's try |
|
|
621 | # to fix it up. |
|
|
622 | |
|
|
623 | if ($_[0] eq __PACKAGE__) { |
|
|
624 | $VERSION |
|
|
625 | } else { |
617 | if (@_ > 0) { |
626 | if (@_ > 0) { |
618 | return undef if VERSION_v lt $_[0]; |
627 | return undef if VERSION_v lt $_[0]; |
619 | if (@_ > 1) { |
628 | if (@_ > 1) { |
620 | return undef if VERSION_v ge $_[1]; |
629 | return undef if VERSION_v ge $_[1]; |
|
|
630 | } |
621 | } |
631 | } |
|
|
632 | |
|
|
633 | VERSION_v |
622 | } |
634 | } |
623 | |
|
|
624 | VERSION_v |
|
|
625 | } |
635 | } |
626 | |
636 | |
627 | =head3 CONTROLLING THE NUMBER OF THREADS |
637 | =head3 CONTROLLING THE NUMBER OF THREADS |
628 | |
638 | |
629 | =over 4 |
639 | =over 4 |
… | |
… | |
693 | |
703 | |
694 | You can still queue as many requests as you want. Therefore, |
704 | You can still queue as many requests as you want. Therefore, |
695 | C<max_oustsanding> is mainly useful in simple scripts (with low values) or |
705 | C<max_oustsanding> is mainly useful in simple scripts (with low values) or |
696 | as a stop gap to shield against fatal memory overflow (with large values). |
706 | as a stop gap to shield against fatal memory overflow (with large values). |
697 | |
707 | |
698 | =item BDB::set_sync_prepare $cb |
708 | =item $old_cb = BDB::set_sync_prepare $cb |
699 | |
709 | |
700 | Sets a callback that is called whenever a request is created without an |
710 | Sets a callback that is called whenever a request is created without an |
701 | explicit callback. It has to return two code references. The first is used |
711 | explicit callback. It has to return two code references. The first is used |
702 | as the request callback (it should save the return status), and the second |
712 | as the request callback (it should save the return status), and the second |
703 | is called to wait until the first callback has been called (it must set |
713 | is called to wait until the first callback has been called (it must set |
704 | C<$!> to the return status). |
714 | C<$!> to the return status). |
705 | |
715 | |
706 | This mechanism can be used to include BDB into other event mechanisms, |
716 | This mechanism can be used to include BDB into other event mechanisms, |
707 | such as L<AnyEvent::BDB> or L<Coro::BDB>. |
717 | such as L<Coro::BDB>. |
708 | |
718 | |
709 | The default implementation works like this: |
719 | To allow other, callback-based, events to be executed while callback-less |
|
|
720 | ones are run, you could use this sync prepare function: |
710 | |
721 | |
711 | sub { |
722 | sub { |
712 | my $status; |
723 | my $status; |
713 | ( |
724 | ( |
714 | sub { $status = $! }, |
725 | sub { $status = $! }, |
715 | sub { BDB::poll while !defined $status; $! = $status }, |
726 | sub { BDB::poll while !defined $status; $! = $status }, |
716 | ) |
727 | ) |
717 | } |
728 | } |
718 | |
729 | |
719 | It simply blocks the process till the request has finished and then sets |
730 | It works by polling for results till the request has finished and then |
720 | C<$!> to the return value. This means that if you don't use a callback, |
731 | sets C<$!> to the return value. This means that if you don't use a |
721 | BDB will simply fall back to synchronous operations. |
732 | callback, BDB would simply fall back to synchronous operations. |
|
|
733 | |
|
|
734 | By default, or if the sync prepare function is set to C<undef>, is to |
|
|
735 | execute callback-less BDB requests in the foreground thread, setting C<$!> |
|
|
736 | to the return value, without polling for other events. |
722 | |
737 | |
723 | =back |
738 | =back |
724 | |
739 | |
725 | =head3 STATISTICAL INFORMATION |
740 | =head3 STATISTICAL INFORMATION |
726 | |
741 | |
… | |
… | |
748 | |
763 | |
749 | =back |
764 | =back |
750 | |
765 | |
751 | =cut |
766 | =cut |
752 | |
767 | |
753 | set_sync_prepare { |
768 | set_sync_prepare (undef); |
754 | my $status; |
|
|
755 | ( |
|
|
756 | sub { |
|
|
757 | $status = $!; |
|
|
758 | }, |
|
|
759 | sub { |
|
|
760 | BDB::poll while !defined $status; |
|
|
761 | $! = $status; |
|
|
762 | }, |
|
|
763 | ) |
|
|
764 | }; |
|
|
765 | |
769 | |
766 | min_parallel 8; |
770 | min_parallel 8; |
767 | |
771 | |
768 | END { flush } |
772 | END { flush } |
769 | |
773 | |