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

Comparing BDB/README (file contents):
Revision 1.10 by root, Tue Jul 8 08:35:12 2008 UTC vs.
Revision 1.13 by root, Sat Sep 27 12:02:21 2008 UTC

111 In the following, $int signifies an integer return value, "bdb_filename" 111 In the following, $int signifies an integer return value, "bdb_filename"
112 is a "filename" (octets on unix, madness on windows), "U32" is an 112 is a "filename" (octets on unix, madness on windows), "U32" is an
113 unsigned 32 bit integer, "int" is some integer, "NV" is a floating point 113 unsigned 32 bit integer, "int" is some integer, "NV" is a floating point
114 value. 114 value.
115 115
116 The "SV *" types are generic perl scalars (for input and output of data 116 Most "SV *" types are generic perl scalars (for input and output of data
117 values), and the "SV *callback" is the optional callback function to 117 values).
118 call when the request is completed.
119 118
120 The various "DB_ENV" etc. arguments are handles return by 119 The various "DB_ENV" etc. arguments are handles return by
121 "db_env_create", "db_create", "txn_begin" and so on. If they have an 120 "db_env_create", "db_create", "txn_begin" and so on. If they have an
122 appended "_ornull" this means they are optional and you can pass "undef" 121 appended "_ornull" this means they are optional and you can pass "undef"
123 for them, resulting a NULL pointer on the C level. 122 for them, resulting a NULL pointer on the C level.
123
124 The "SV *callback" is the optional callback function to call when the
125 request is completed. This last callback argument is special: the
126 callback is simply the last argument passed. If there are "optional"
127 arguments before the callback they can be left out. The callback itself
128 can be left out or specified as "undef", in which case the function will
129 be executed synchronously.
130
131 For example, "db_env_txn_checkpoint" usually is called with all integer
132 arguments zero. These can be left out, so all of these specify a call to
133 "DB_ENV->txn_checkpoint", to be executed asynchronously with a callback
134 to be called:
135
136 db_env_txn_checkpoint $db_env, 0, 0, 0, sub { };
137 db_env_txn_checkpoint $db_env, 0, 0, sub { };
138 db_env_txn_checkpoint $db_env, sub { };
139
140 While these all specify a call to "DB_ENV->txn_checkpoint" to be
141 executed synchronously:
142
143 db_env_txn_checkpoint $db_env, 0, 0, 0, undef;
144 db_env_txn_checkpoint $db_env, 0, 0, 0;
145 db_env_txn_checkpoint $db_env, 0;
124 146
125 BDB functions 147 BDB functions
126 Functions in the BDB namespace, exported by default: 148 Functions in the BDB namespace, exported by default:
127 149
128 $env = db_env_create (U32 env_flags = 0) 150 $env = db_env_create (U32 env_flags = 0)
152 flags: FREELIST_ONLY FREE_SPACE 174 flags: FREELIST_ONLY FREE_SPACE
153 db_sync (DB *db, U32 flags = 0, SV *callback = &PL_sv_undef) 175 db_sync (DB *db, U32 flags = 0, SV *callback = &PL_sv_undef)
154 db_key_range (DB *db, DB_TXN_ornull *txn, SV *key, SV *key_range, U32 flags = 0, SV *callback = &PL_sv_undef) 176 db_key_range (DB *db, DB_TXN_ornull *txn, SV *key, SV *key_range, U32 flags = 0, SV *callback = &PL_sv_undef)
155 db_put (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) 177 db_put (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef)
156 flags: APPEND NODUPDATA NOOVERWRITE 178 flags: APPEND NODUPDATA NOOVERWRITE
179 db_exists (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = 0) (v4.6)
157 db_get (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) 180 db_get (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef)
158 flags: CONSUME CONSUME_WAIT GET_BOTH SET_RECNO MULTIPLE READ_COMMITTED READ_UNCOMMITTED RMW 181 flags: CONSUME CONSUME_WAIT GET_BOTH SET_RECNO MULTIPLE READ_COMMITTED READ_UNCOMMITTED RMW
159 db_pget (DB *db, DB_TXN_ornull *txn, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) 182 db_pget (DB *db, DB_TXN_ornull *txn, SV *key, SV *pkey, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef)
160 flags: CONSUME CONSUME_WAIT GET_BOTH SET_RECNO MULTIPLE READ_COMMITTED READ_UNCOMMITTED RMW 183 flags: CONSUME CONSUME_WAIT GET_BOTH SET_RECNO MULTIPLE READ_COMMITTED READ_UNCOMMITTED RMW
161 db_del (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = &PL_sv_undef) 184 db_del (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = &PL_sv_undef)
227 $int = $env->set_tmp_dir (const char *dir) 250 $int = $env->set_tmp_dir (const char *dir)
228 $int = $env->set_lg_dir (const char *dir) 251 $int = $env->set_lg_dir (const char *dir)
229 $int = $env->set_shm_key (long shm_key) 252 $int = $env->set_shm_key (long shm_key)
230 $int = $env->set_cachesize (U32 gbytes, U32 bytes, int ncache = 0) 253 $int = $env->set_cachesize (U32 gbytes, U32 bytes, int ncache = 0)
231 $int = $env->set_flags (U32 flags, int onoff = 1) 254 $int = $env->set_flags (U32 flags, int onoff = 1)
232 $int = $env->log_set_config (U32 flags, int onoff = 1) [v4.7] 255 $int = $env->log_set_config (U32 flags, int onoff = 1) (v4.7)
233 $int = $env->set_intermediate_dir_mode (const char *modestring) [v4.7] 256 $int = $env->set_intermediate_dir_mode (const char *modestring) (v4.7)
234 $env->set_errfile (FILE *errfile = 0) 257 $env->set_errfile (FILE *errfile = 0)
235 $env->set_msgfile (FILE *msgfile = 0) 258 $env->set_msgfile (FILE *msgfile = 0)
236 $int = $env->set_verbose (U32 which, int onoff = 1) 259 $int = $env->set_verbose (U32 which, int onoff = 1)
237 $int = $env->set_encrypt (const char *password, U32 flags = 0) 260 $int = $env->set_encrypt (const char *password, U32 flags = 0)
238 $int = $env->set_timeout (NV timeout_seconds, U32 flags = SET_TXN_TIMEOUT) 261 $int = $env->set_timeout (NV timeout_seconds, U32 flags = SET_TXN_TIMEOUT)
250 $int = $env->mutex_set_max (U32 max) 273 $int = $env->mutex_set_max (U32 max)
251 $int = $env->mutex_set_align (U32 align) 274 $int = $env->mutex_set_align (U32 align)
252 275
253 $txn = $env->txn_begin (DB_TXN_ornull *parent = 0, U32 flags = 0) 276 $txn = $env->txn_begin (DB_TXN_ornull *parent = 0, U32 flags = 0)
254 flags: READ_COMMITTED READ_UNCOMMITTED TXN_NOSYNC TXN_NOWAIT TXN_SNAPSHOT TXN_SYNC TXN_WAIT TXN_WRITE_NOSYNC 277 flags: READ_COMMITTED READ_UNCOMMITTED TXN_NOSYNC TXN_NOWAIT TXN_SNAPSHOT TXN_SYNC TXN_WAIT TXN_WRITE_NOSYNC
278 $txn = $env->cdsgroup_begin; (v4.5)
255 279
256 Example: 280 Example:
257 use AnyEvent; 281 use AnyEvent;
258 use BDB; 282 use BDB;
259 283
343 DESTROY (DBC_ornull *dbc) 367 DESTROY (DBC_ornull *dbc)
344 CODE: 368 CODE:
345 if (dbc) 369 if (dbc)
346 dbc->c_close (dbc); 370 dbc->c_close (dbc);
347 371
348 $int = $cursor->set_priority ($priority = PRIORITY_*) 372 $int = $cursor->set_priority ($priority = PRIORITY_*) (v4.6)
349 373
350 Example: 374 Example:
351 my $c = $db->cursor; 375 my $c = $db->cursor;
352 376
353 for (;;) { 377 for (;;) {
469 VERSION CHECKING 493 VERSION CHECKING
470 BerkeleyDB comes in various versions, many of them have minor 494 BerkeleyDB comes in various versions, many of them have minor
471 incompatibilities. This means that traditional "at least version x.x" 495 incompatibilities. This means that traditional "at least version x.x"
472 checks are often not sufficient. 496 checks are often not sufficient.
473 497
474 Example: set the log_autoremove option in a way compatible with <v.47 498 Example: set the log_autoremove option in a way compatible with <v4.7
475 and v4.7. Note the use of & on the constants to avoid triggering a 499 and v4.7. Note the use of & on the constants to avoid triggering a
476 compiletime bug when the symbol isn't available. 500 compiletime bug when the symbol isn't available.
477 501
478 $DB_ENV->set_flags (&BDB::LOG_AUTOREMOVE ) if BDB::VERSION v0, v4.7; 502 $DB_ENV->set_flags (&BDB::LOG_AUTOREMOVE ) if BDB::VERSION v0, v4.7;
479 $DB_ENV->log_set_config (&BDB::LOG_AUTO_REMOVE) if BDB::VERSION v4.7; 503 $DB_ENV->log_set_config (&BDB::LOG_AUTO_REMOVE) if BDB::VERSION v4.7;
573 You can still queue as many requests as you want. Therefore, 597 You can still queue as many requests as you want. Therefore,
574 "max_oustsanding" is mainly useful in simple scripts (with low 598 "max_oustsanding" is mainly useful in simple scripts (with low
575 values) or as a stop gap to shield against fatal memory overflow 599 values) or as a stop gap to shield against fatal memory overflow
576 (with large values). 600 (with large values).
577 601
578 BDB::set_sync_prepare $cb 602 $old_cb = BDB::set_sync_prepare $cb
579 Sets a callback that is called whenever a request is created without 603 Sets a callback that is called whenever a request is created without
580 an explicit callback. It has to return two code references. The 604 an explicit callback. It has to return two code references. The
581 first is used as the request callback (it should save the return 605 first is used as the request callback (it should save the return
582 status), and the second is called to wait until the first callback 606 status), and the second is called to wait until the first callback
583 has been called (it must set $! to the return status). 607 has been called (it must set $! to the return status).
584 608
585 This mechanism can be used to include BDB into other event 609 This mechanism can be used to include BDB into other event
586 mechanisms, such as AnyEvent::BDB or Coro::BDB. 610 mechanisms, such as Coro::BDB.
587 611
588 The default implementation works like this: 612 To allow other, callback-based, events to be executed while
613 callback-less ones are run, you could use this sync prepare
614 function:
589 615
590 sub { 616 sub {
591 my $status; 617 my $status;
592 ( 618 (
593 sub { $status = $! }, 619 sub { $status = $! },
594 sub { BDB::poll while !defined $status; $! = $status }, 620 sub { BDB::poll while !defined $status; $! = $status },
595 ) 621 )
596 } 622 }
597 623
598 It simply blocks the process till the request has finished and then 624 It works by polling for results till the request has finished and
599 sets $! to the return value. This means that if you don't use a 625 then sets $! to the return value. This means that if you don't use a
600 callback, BDB will simply fall back to synchronous operations. 626 callback, BDB would simply fall back to synchronous operations.
627
628 By default, or if the sync prepare function is set to "undef", is to
629 execute callback-less BDB requests in the foreground thread, setting
630 $! to the return value, without polling for other events.
601 631
602 STATISTICAL INFORMATION 632 STATISTICAL INFORMATION
603 BDB::nreqs 633 BDB::nreqs
604 Returns the number of requests currently in the ready, execute or 634 Returns the number of requests currently in the ready, execute or
605 pending states (i.e. for which their callback has not been invoked 635 pending states (i.e. for which their callback has not been invoked

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines