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

Comparing BDB/BDB.pm (file contents):
Revision 1.41 by root, Wed Jul 9 12:15:36 2008 UTC vs.
Revision 1.52 by root, Mon Oct 20 02:33:40 2008 UTC

108no warnings; 108no warnings;
109use strict 'vars'; 109use strict 'vars';
110 110
111use base 'Exporter'; 111use base 'Exporter';
112 112
113our $VERSION;
114
113BEGIN { 115BEGIN {
114 our $VERSION = '1.6'; 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
332 $txn = $env->cdsgroup_begin; (v4.5)
329 333
330=head4 Example: 334=head4 Example:
331 335
332 use AnyEvent; 336 use AnyEvent;
333 use BDB; 337 use BDB;
425 DESTROY (DBC_ornull *dbc) 429 DESTROY (DBC_ornull *dbc)
426 CODE: 430 CODE:
427 if (dbc) 431 if (dbc)
428 dbc->c_close (dbc); 432 dbc->c_close (dbc);
429 433
430 $int = $cursor->set_priority ($priority = PRIORITY_*) 434 $int = $cursor->set_priority ($priority = PRIORITY_*) (v4.6)
431 435
432=head4 Example: 436=head4 Example:
433 437
434 my $c = $db->cursor; 438 my $c = $db->cursor;
435 439
568 572
569BerkeleyDB comes in various versions, many of them have minor 573BerkeleyDB comes in various versions, many of them have minor
570incompatibilities. This means that traditional "at least version x.x" 574incompatibilities. This means that traditional "at least version x.x"
571checks are often not sufficient. 575checks are often not sufficient.
572 576
573Example: set the log_autoremove option in a way compatible with <v.47 and 577Example: set the log_autoremove option in a way compatible with <v4.7 and
574v4.7. Note the use of & on the constants to avoid triggering a compiletime 578v4.7. Note the use of & on the constants to avoid triggering a compiletime
575bug when the symbol isn't available. 579bug when the symbol isn't available.
576 580
577 $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;
578 $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;
611=back 615=back
612 616
613=cut 617=cut
614 618
615sub VERSION { 619sub 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 {
616 if (@_ > 0) { 626 if (@_ > 0) {
617 return undef if VERSION_v lt $_[0]; 627 return undef if VERSION_v lt $_[0];
618 if (@_ > 1) { 628 if (@_ > 1) {
619 return undef if VERSION_v ge $_[1]; 629 return undef if VERSION_v ge $_[1];
630 }
620 } 631 }
632
633 VERSION_v
621 } 634 }
622
623 VERSION_v
624} 635}
625 636
626=head3 CONTROLLING THE NUMBER OF THREADS 637=head3 CONTROLLING THE NUMBER OF THREADS
627 638
628=over 4 639=over 4
692 703
693You can still queue as many requests as you want. Therefore, 704You can still queue as many requests as you want. Therefore,
694C<max_oustsanding> is mainly useful in simple scripts (with low values) or 705C<max_oustsanding> is mainly useful in simple scripts (with low values) or
695as a stop gap to shield against fatal memory overflow (with large values). 706as a stop gap to shield against fatal memory overflow (with large values).
696 707
697=item BDB::set_sync_prepare $cb 708=item $old_cb = BDB::set_sync_prepare $cb
698 709
699Sets a callback that is called whenever a request is created without an 710Sets a callback that is called whenever a request is created without an
700explicit callback. It has to return two code references. The first is used 711explicit callback. It has to return two code references. The first is used
701as the request callback (it should save the return status), and the second 712as the request callback (it should save the return status), and the second
702is called to wait until the first callback has been called (it must set 713is called to wait until the first callback has been called (it must set
703C<$!> to the return status). 714C<$!> to the return status).
704 715
705This mechanism can be used to include BDB into other event mechanisms, 716This mechanism can be used to include BDB into other event mechanisms,
706such as L<AnyEvent::BDB> or L<Coro::BDB>. 717such as L<Coro::BDB>.
707 718
708The default implementation works like this: 719To allow other, callback-based, events to be executed while callback-less
720ones are run, you could use this sync prepare function:
709 721
710 sub { 722 sub {
711 my $status; 723 my $status;
712 ( 724 (
713 sub { $status = $! }, 725 sub { $status = $! },
714 sub { BDB::poll while !defined $status; $! = $status }, 726 sub { BDB::poll while !defined $status; $! = $status },
715 ) 727 )
716 } 728 }
717 729
718It simply blocks the process till the request has finished and then sets 730It works by polling for results till the request has finished and then
719C<$!> to the return value. This means that if you don't use a callback, 731sets C<$!> to the return value. This means that if you don't use a
720BDB will simply fall back to synchronous operations. 732callback, BDB would simply fall back to synchronous operations.
733
734By default, or if the sync prepare function is set to C<undef>, is to
735execute callback-less BDB requests in the foreground thread, setting C<$!>
736to the return value, without polling for other events.
721 737
722=back 738=back
723 739
724=head3 STATISTICAL INFORMATION 740=head3 STATISTICAL INFORMATION
725 741
747 763
748=back 764=back
749 765
750=cut 766=cut
751 767
752set_sync_prepare { 768set_sync_prepare (undef);
753 my $status;
754 (
755 sub {
756 $status = $!;
757 },
758 sub {
759 BDB::poll while !defined $status;
760 $! = $status;
761 },
762 )
763};
764 769
765min_parallel 8; 770min_parallel 8;
766 771
767END { flush } 772END { flush }
768 773

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines