… | |
… | |
22 | db_put $db, undef, "key", "data", 0, sub { |
22 | db_put $db, undef, "key", "data", 0, sub { |
23 | db_del $db, undef, "key"; |
23 | db_del $db, undef, "key"; |
24 | }; |
24 | }; |
25 | db_sync $db; |
25 | db_sync $db; |
26 | |
26 | |
|
|
27 | # when you also use Coro, management is easy: |
|
|
28 | use Coro::BDB; |
|
|
29 | |
27 | # automatic result processing with AnyEvent: |
30 | # automatic result processing with AnyEvent: |
28 | our $FH; open $FH, "<&=" . BDB::poll_fileno; |
31 | our $FH; open $FH, "<&=" . BDB::poll_fileno; |
29 | our $WATCHER = AnyEvent->io (fh => $FH, poll => 'r', cb => \&BDB::poll_cb); |
32 | our $WATCHER = AnyEvent->io (fh => $FH, poll => 'r', cb => \&BDB::poll_cb); |
30 | |
33 | |
31 | # automatic result processing with EV: |
34 | # automatic result processing with EV: |
… | |
… | |
87 | either do nothing or result in a runtime error). |
90 | either do nothing or result in a runtime error). |
88 | |
91 | |
89 | BERKELEYDB FUNCTIONS |
92 | BERKELEYDB FUNCTIONS |
90 | All of these are functions. The create functions simply return a new |
93 | All of these are functions. The create functions simply return a new |
91 | object and never block. All the remaining functions all take an optional |
94 | object and never block. All the remaining functions all take an optional |
92 | callback as last argument. If it is missing, then the fucntion will be |
95 | callback as last argument. If it is missing, then the function will be |
93 | executed synchronously. |
96 | executed synchronously. In both cases, $! will reflect the return value |
|
|
97 | of the function. |
94 | |
98 | |
95 | BDB functions that cannot block (mostly functions that manipulate |
99 | BDB functions that cannot block (mostly functions that manipulate |
96 | settings) are method calls on the relevant objects, so the rule of thumb |
100 | settings) are method calls on the relevant objects, so the rule of thumb |
97 | is: if its a method, its not blocking, if its a function, it takes a |
101 | is: if its a method, its not blocking, if its a function, it takes a |
98 | callback as last argument. |
102 | callback as last argument. |
… | |
… | |
132 | |
136 | |
133 | db_open (DB *db, DB_TXN_ornull *txnid, octetstring file, octetstring database, int type, U32 flags, int mode, SV *callback = &PL_sv_undef) |
137 | db_open (DB *db, DB_TXN_ornull *txnid, octetstring file, octetstring database, int type, U32 flags, int mode, SV *callback = &PL_sv_undef) |
134 | flags: AUTO_COMMIT CREATE EXCL MULTIVERSION NOMMAP RDONLY READ_UNCOMMITTED THREAD TRUNCATE |
138 | flags: AUTO_COMMIT CREATE EXCL MULTIVERSION NOMMAP RDONLY READ_UNCOMMITTED THREAD TRUNCATE |
135 | db_close (DB *db, U32 flags = 0, SV *callback = &PL_sv_undef) |
139 | db_close (DB *db, U32 flags = 0, SV *callback = &PL_sv_undef) |
136 | flags: DB_NOSYNC |
140 | flags: DB_NOSYNC |
|
|
141 | db_upgrade (DB *db, octetstring file, U32 flags = 0, SV *callback = &PL_sv_undef) |
137 | db_compact (DB *db, DB_TXN_ornull *txn = 0, SV *start = 0, SV *stop = 0, SV *unused1 = 0, U32 flags = DB_FREE_SPACE, SV *unused2 = 0, SV *callback = &PL_sv_undef) |
142 | db_compact (DB *db, DB_TXN_ornull *txn = 0, SV *start = 0, SV *stop = 0, SV *unused1 = 0, U32 flags = DB_FREE_SPACE, SV *unused2 = 0, SV *callback = &PL_sv_undef) |
138 | flags: FREELIST_ONLY FREE_SPACE |
143 | flags: FREELIST_ONLY FREE_SPACE |
139 | db_sync (DB *db, U32 flags = 0, SV *callback = &PL_sv_undef) |
144 | db_sync (DB *db, U32 flags = 0, SV *callback = &PL_sv_undef) |
140 | db_key_range (DB *db, DB_TXN_ornull *txn, SV *key, SV *key_range, U32 flags = 0, SV *callback = &PL_sv_undef) |
145 | db_key_range (DB *db, DB_TXN_ornull *txn, SV *key, SV *key_range, U32 flags = 0, SV *callback = &PL_sv_undef) |
141 | db_put (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) |
146 | db_put (DB *db, DB_TXN_ornull *txn, SV *key, SV *data, U32 flags = 0, SV *callback = &PL_sv_undef) |
… | |
… | |
327 | DESTROY (DBC_ornull *dbc) |
332 | DESTROY (DBC_ornull *dbc) |
328 | CODE: |
333 | CODE: |
329 | if (dbc) |
334 | if (dbc) |
330 | dbc->c_close (dbc); |
335 | dbc->c_close (dbc); |
331 | |
336 | |
|
|
337 | $int = $cursor->set_priority ($priority = PRIORITY_*) |
|
|
338 | |
332 | Example: |
339 | Example: |
333 | my $c = $db->cursor; |
340 | my $c = $db->cursor; |
334 | |
341 | |
335 | for (;;) { |
342 | for (;;) { |
336 | db_c_get $c, my $key, my $data, BDB::NEXT; |
343 | db_c_get $c, my $key, my $data, BDB::NEXT; |
… | |
… | |
360 | db_sequence_open $seq, undef, "seq", BDB::CREATE; |
367 | db_sequence_open $seq, undef, "seq", BDB::CREATE; |
361 | db_sequence_get $seq, undef, 1, my $value; |
368 | db_sequence_get $seq, undef, 1, my $value; |
362 | |
369 | |
363 | SUPPORT FUNCTIONS |
370 | SUPPORT FUNCTIONS |
364 | EVENT PROCESSING AND EVENT LOOP INTEGRATION |
371 | EVENT PROCESSING AND EVENT LOOP INTEGRATION |
|
|
372 | $msg = BDB::strerror [$errno] |
|
|
373 | Returns the string corresponding to the given errno value. If no |
|
|
374 | argument is given, use $!. |
|
|
375 | |
365 | $fileno = BDB::poll_fileno |
376 | $fileno = BDB::poll_fileno |
366 | Return the *request result pipe file descriptor*. This filehandle |
377 | Return the *request result pipe file descriptor*. This filehandle |
367 | must be polled for reading by some mechanism outside this module |
378 | must be polled for reading by some mechanism outside this module |
368 | (e.g. Event or select, see below or the SYNOPSIS). If the pipe |
379 | (e.g. Event or select, see below or the SYNOPSIS). If the pipe |
369 | becomes readable you have to call "poll_cb" to check the results. |
380 | becomes readable you have to call "poll_cb" to check the results. |
… | |
… | |
556 | |
567 | |
557 | In short: the parent will, after a short pause, continue as if fork had |
568 | In short: the parent will, after a short pause, continue as if fork had |
558 | not been called, while the child will act as if BDB has not been used |
569 | not been called, while the child will act as if BDB has not been used |
559 | yet. |
570 | yet. |
560 | |
571 | |
|
|
572 | Win32 note: there is no fork on win32, and perls emulation of it is too |
|
|
573 | broken to be supported, so do not use BDB in a windows pseudo-fork, |
|
|
574 | better yet, switch to a more capable platform. |
|
|
575 | |
561 | MEMORY USAGE |
576 | MEMORY USAGE |
562 | Per-request usage: |
577 | Per-request usage: |
563 | |
578 | |
564 | Each aio request uses - depending on your architecture - around 100-200 |
579 | Each aio request uses - depending on your architecture - around 100-200 |
565 | bytes of memory. In addition, stat requests need a stat buffer (possibly |
580 | bytes of memory. In addition, stat requests need a stat buffer (possibly |