… | |
… | |
109 | use strict 'vars'; |
109 | use strict 'vars'; |
110 | |
110 | |
111 | use base 'Exporter'; |
111 | use base 'Exporter'; |
112 | |
112 | |
113 | BEGIN { |
113 | BEGIN { |
114 | our $VERSION = '1.5'; |
114 | our $VERSION = '1.7'; |
115 | |
115 | |
116 | our @BDB_REQ = qw( |
116 | our @BDB_REQ = qw( |
117 | db_env_open db_env_close db_env_txn_checkpoint db_env_lock_detect |
117 | 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 |
118 | 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 |
119 | db_open db_close db_compact db_sync db_upgrade |
… | |
… | |
160 | In the following, C<$int> signifies an integer return value, |
160 | In the following, C<$int> signifies an integer return value, |
161 | C<bdb_filename> is a "filename" (octets on unix, madness on windows), |
161 | C<bdb_filename> is a "filename" (octets on unix, madness on windows), |
162 | C<U32> is an unsigned 32 bit integer, C<int> is some integer, C<NV> is a |
162 | C<U32> is an unsigned 32 bit integer, C<int> is some integer, C<NV> is a |
163 | floating point value. |
163 | floating point value. |
164 | |
164 | |
165 | The C<SV *> types are generic perl scalars (for input and output of data |
165 | Most C<SV *> types are generic perl scalars (for input and output of data |
166 | values), and the C<SV *callback> is the optional callback function to call |
166 | values). |
167 | when the request is completed. |
|
|
168 | |
167 | |
169 | The various C<DB_ENV> etc. arguments are handles return by |
168 | The various C<DB_ENV> etc. arguments are handles return by |
170 | C<db_env_create>, C<db_create>, C<txn_begin> and so on. If they have an |
169 | C<db_env_create>, C<db_create>, C<txn_begin> and so on. If they have an |
171 | appended C<_ornull> this means they are optional and you can pass C<undef> |
170 | appended C<_ornull> this means they are optional and you can pass C<undef> |
172 | for them, resulting a NULL pointer on the C level. |
171 | for them, resulting a NULL pointer on the C level. |
|
|
172 | |
|
|
173 | The C<SV *callback> is the optional callback function to call when the |
|
|
174 | request is completed. This last callback argument is special: the callback |
|
|
175 | is simply the last argument passed. If there are "optional" arguments |
|
|
176 | before the callback they can be left out. The callback itself can be left |
|
|
177 | out or specified as C<undef>, in which case the function will be executed |
|
|
178 | synchronously. |
|
|
179 | |
|
|
180 | For example, C<db_env_txn_checkpoint> usually is called with all integer |
|
|
181 | arguments zero. These can be left out, so all of these specify a call |
|
|
182 | to C<< DB_ENV->txn_checkpoint >>, to be executed asynchronously with a |
|
|
183 | callback to be called: |
|
|
184 | |
|
|
185 | db_env_txn_checkpoint $db_env, 0, 0, 0, sub { }; |
|
|
186 | db_env_txn_checkpoint $db_env, 0, 0, sub { }; |
|
|
187 | db_env_txn_checkpoint $db_env, sub { }; |
|
|
188 | |
|
|
189 | While these all specify a call to C<< DB_ENV->txn_checkpoint >> to be |
|
|
190 | executed synchronously: |
|
|
191 | |
|
|
192 | db_env_txn_checkpoint $db_env, 0, 0, 0, undef; |
|
|
193 | db_env_txn_checkpoint $db_env, 0, 0, 0; |
|
|
194 | db_env_txn_checkpoint $db_env, 0; |
173 | |
195 | |
174 | =head3 BDB functions |
196 | =head3 BDB functions |
175 | |
197 | |
176 | Functions in the BDB namespace, exported by default: |
198 | Functions in the BDB namespace, exported by default: |
177 | |
199 | |
… | |
… | |
278 | $int = $env->set_data_dir (const char *dir) |
300 | $int = $env->set_data_dir (const char *dir) |
279 | $int = $env->set_tmp_dir (const char *dir) |
301 | $int = $env->set_tmp_dir (const char *dir) |
280 | $int = $env->set_lg_dir (const char *dir) |
302 | $int = $env->set_lg_dir (const char *dir) |
281 | $int = $env->set_shm_key (long shm_key) |
303 | $int = $env->set_shm_key (long shm_key) |
282 | $int = $env->set_cachesize (U32 gbytes, U32 bytes, int ncache = 0) |
304 | $int = $env->set_cachesize (U32 gbytes, U32 bytes, int ncache = 0) |
283 | $int = $env->set_flags (U32 flags, int onoff) |
305 | $int = $env->set_flags (U32 flags, int onoff = 1) |
|
|
306 | $int = $env->log_set_config (U32 flags, int onoff = 1) [v4.7] |
|
|
307 | $int = $env->set_intermediate_dir_mode (const char *modestring) [v4.7] |
284 | $env->set_errfile (FILE *errfile = 0) |
308 | $env->set_errfile (FILE *errfile = 0) |
285 | $env->set_msgfile (FILE *msgfile = 0) |
309 | $env->set_msgfile (FILE *msgfile = 0) |
286 | $int = $env->set_verbose (U32 which, int onoff = 1) |
310 | $int = $env->set_verbose (U32 which, int onoff = 1) |
287 | $int = $env->set_encrypt (const char *password, U32 flags = 0) |
311 | $int = $env->set_encrypt (const char *password, U32 flags = 0) |
288 | $int = $env->set_timeout (NV timeout_seconds, U32 flags = SET_TXN_TIMEOUT) |
312 | $int = $env->set_timeout (NV timeout_seconds, U32 flags = SET_TXN_TIMEOUT) |
… | |
… | |
300 | $int = $env->mutex_set_max (U32 max) |
324 | $int = $env->mutex_set_max (U32 max) |
301 | $int = $env->mutex_set_align (U32 align) |
325 | $int = $env->mutex_set_align (U32 align) |
302 | |
326 | |
303 | $txn = $env->txn_begin (DB_TXN_ornull *parent = 0, U32 flags = 0) |
327 | $txn = $env->txn_begin (DB_TXN_ornull *parent = 0, U32 flags = 0) |
304 | flags: READ_COMMITTED READ_UNCOMMITTED TXN_NOSYNC TXN_NOWAIT TXN_SNAPSHOT TXN_SYNC TXN_WAIT TXN_WRITE_NOSYNC |
328 | flags: READ_COMMITTED READ_UNCOMMITTED TXN_NOSYNC TXN_NOWAIT TXN_SNAPSHOT TXN_SYNC TXN_WAIT TXN_WRITE_NOSYNC |
|
|
329 | $txn = $env->cdsgroup_begin; |
305 | |
330 | |
306 | =head4 Example: |
331 | =head4 Example: |
307 | |
332 | |
308 | use AnyEvent; |
333 | use AnyEvent; |
309 | use BDB; |
334 | use BDB; |
… | |
… | |
537 | |
562 | |
538 | BDB::poll_wait, BDB::poll_cb |
563 | BDB::poll_wait, BDB::poll_cb |
539 | while BDB::nreqs; |
564 | while BDB::nreqs; |
540 | |
565 | |
541 | =back |
566 | =back |
|
|
567 | |
|
|
568 | =head3 VERSION CHECKING |
|
|
569 | |
|
|
570 | BerkeleyDB comes in various versions, many of them have minor |
|
|
571 | incompatibilities. This means that traditional "at least version x.x" |
|
|
572 | checks are often not sufficient. |
|
|
573 | |
|
|
574 | Example: set the log_autoremove option in a way compatible with <v.47 and |
|
|
575 | v4.7. Note the use of & on the constants to avoid triggering a compiletime |
|
|
576 | bug when the symbol isn't available. |
|
|
577 | |
|
|
578 | $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; |
|
|
580 | |
|
|
581 | =over 4 |
|
|
582 | |
|
|
583 | =item BDB::VERSION |
|
|
584 | |
|
|
585 | The C<BDB::VERSION> function, when called without arguments, returns the |
|
|
586 | Berkeley DB version as a v-string (usually with 3 components). You should |
|
|
587 | use C<lt> and C<ge> operators exclusively to make comparisons. |
|
|
588 | |
|
|
589 | Example: check for at least version 4.7. |
|
|
590 | |
|
|
591 | BDB::VERSION ge v4.7 or die; |
|
|
592 | |
|
|
593 | =item BDB::VERSION min-version |
|
|
594 | |
|
|
595 | Returns true if the BDB version is at least the given version (specified |
|
|
596 | as a v-string), false otherwise. |
|
|
597 | |
|
|
598 | Example: check for at least version 4.5. |
|
|
599 | |
|
|
600 | BDB::VERSION v4.7 or die; |
|
|
601 | |
|
|
602 | =item BDB::VERSION min-version, max-version |
|
|
603 | |
|
|
604 | Returns true of the BDB version is at least version C<min-version> (specify C<undef> or C<v0> for any minimum version) |
|
|
605 | and less then C<max-version>. |
|
|
606 | |
|
|
607 | Example: check wether version is strictly less then v4.7. |
|
|
608 | |
|
|
609 | BDB::VERSION v0, v4.7 |
|
|
610 | or die "version 4.7 is not yet supported"; |
|
|
611 | |
|
|
612 | =back |
|
|
613 | |
|
|
614 | =cut |
|
|
615 | |
|
|
616 | sub VERSION { |
|
|
617 | if (@_ > 0) { |
|
|
618 | return undef if VERSION_v lt $_[0]; |
|
|
619 | if (@_ > 1) { |
|
|
620 | return undef if VERSION_v ge $_[1]; |
|
|
621 | } |
|
|
622 | } |
|
|
623 | |
|
|
624 | VERSION_v |
|
|
625 | } |
542 | |
626 | |
543 | =head3 CONTROLLING THE NUMBER OF THREADS |
627 | =head3 CONTROLLING THE NUMBER OF THREADS |
544 | |
628 | |
545 | =over 4 |
629 | =over 4 |
546 | |
630 | |