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

Comparing BDB/BDB.pm (file contents):
Revision 1.44 by root, Wed Jul 9 21:08:29 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.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
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
229 db_exists (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = 0) 231 db_exists (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = 0) (v4.6)
230 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)
231 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
232 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)
233 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
234 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)
302 $int = $env->set_tmp_dir (const char *dir) 304 $int = $env->set_tmp_dir (const char *dir)
303 $int = $env->set_lg_dir (const char *dir) 305 $int = $env->set_lg_dir (const char *dir)
304 $int = $env->set_shm_key (long shm_key) 306 $int = $env->set_shm_key (long shm_key)
305 $int = $env->set_cachesize (U32 gbytes, U32 bytes, int ncache = 0) 307 $int = $env->set_cachesize (U32 gbytes, U32 bytes, int ncache = 0)
306 $int = $env->set_flags (U32 flags, int onoff = 1) 308 $int = $env->set_flags (U32 flags, int onoff = 1)
307 $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)
308 $int = $env->set_intermediate_dir_mode (const char *modestring) [v4.7] 310 $int = $env->set_intermediate_dir_mode (const char *modestring) (v4.7)
309 $env->set_errfile (FILE *errfile = 0) 311 $env->set_errfile (FILE *errfile = 0)
310 $env->set_msgfile (FILE *msgfile = 0) 312 $env->set_msgfile (FILE *msgfile = 0)
311 $int = $env->set_verbose (U32 which, int onoff = 1) 313 $int = $env->set_verbose (U32 which, int onoff = 1)
312 $int = $env->set_encrypt (const char *password, U32 flags = 0) 314 $int = $env->set_encrypt (const char *password, U32 flags = 0)
313 $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)
325 $int = $env->mutex_set_max (U32 max) 327 $int = $env->mutex_set_max (U32 max)
326 $int = $env->mutex_set_align (U32 align) 328 $int = $env->mutex_set_align (U32 align)
327 329
328 $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)
329 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
330 $txn = $env->cdsgroup_begin; 332 $txn = $env->cdsgroup_begin; (v4.5)
331 333
332=head4 Example: 334=head4 Example:
333 335
334 use AnyEvent; 336 use AnyEvent;
335 use BDB; 337 use BDB;
427 DESTROY (DBC_ornull *dbc) 429 DESTROY (DBC_ornull *dbc)
428 CODE: 430 CODE:
429 if (dbc) 431 if (dbc)
430 dbc->c_close (dbc); 432 dbc->c_close (dbc);
431 433
432 $int = $cursor->set_priority ($priority = PRIORITY_*) 434 $int = $cursor->set_priority ($priority = PRIORITY_*) (v4.6)
433 435
434=head4 Example: 436=head4 Example:
435 437
436 my $c = $db->cursor; 438 my $c = $db->cursor;
437 439
570 572
571BerkeleyDB comes in various versions, many of them have minor 573BerkeleyDB comes in various versions, many of them have minor
572incompatibilities. This means that traditional "at least version x.x" 574incompatibilities. This means that traditional "at least version x.x"
573checks are often not sufficient. 575checks are often not sufficient.
574 576
575Example: 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
576v4.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
577bug when the symbol isn't available. 579bug when the symbol isn't available.
578 580
579 $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;
580 $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;
613=back 615=back
614 616
615=cut 617=cut
616 618
617sub 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 {
618 if (@_ > 0) { 626 if (@_ > 0) {
619 return undef if VERSION_v lt $_[0]; 627 return undef if VERSION_v lt $_[0];
620 if (@_ > 1) { 628 if (@_ > 1) {
621 return undef if VERSION_v ge $_[1]; 629 return undef if VERSION_v ge $_[1];
630 }
622 } 631 }
632
633 VERSION_v
623 } 634 }
624
625 VERSION_v
626} 635}
627 636
628=head3 CONTROLLING THE NUMBER OF THREADS 637=head3 CONTROLLING THE NUMBER OF THREADS
629 638
630=over 4 639=over 4
694 703
695You can still queue as many requests as you want. Therefore, 704You can still queue as many requests as you want. Therefore,
696C<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
697as 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).
698 707
699=item BDB::set_sync_prepare $cb 708=item $old_cb = BDB::set_sync_prepare $cb
700 709
701Sets 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
702explicit 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
703as 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
704is 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
705C<$!> to the return status). 714C<$!> to the return status).
706 715
707This mechanism can be used to include BDB into other event mechanisms, 716This mechanism can be used to include BDB into other event mechanisms,
708such as L<AnyEvent::BDB> or L<Coro::BDB>. 717such as L<Coro::BDB>.
709 718
710The 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:
711 721
712 sub { 722 sub {
713 my $status; 723 my $status;
714 ( 724 (
715 sub { $status = $! }, 725 sub { $status = $! },
716 sub { BDB::poll while !defined $status; $! = $status }, 726 sub { BDB::poll while !defined $status; $! = $status },
717 ) 727 )
718 } 728 }
719 729
720It 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
721C<$!> 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
722BDB 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.
723 737
724=back 738=back
725 739
726=head3 STATISTICAL INFORMATION 740=head3 STATISTICAL INFORMATION
727 741
749 763
750=back 764=back
751 765
752=cut 766=cut
753 767
754set_sync_prepare { 768set_sync_prepare (undef);
755 my $status;
756 (
757 sub {
758 $status = $!;
759 },
760 sub {
761 BDB::poll while !defined $status;
762 $! = $status;
763 },
764 )
765};
766 769
767min_parallel 8; 770min_parallel 8;
768 771
769END { flush } 772END { flush }
770 773

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines