… | |
… | |
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: |
… | |
… | |
84 | Request has reached the end of its lifetime and holds no resources |
87 | Request has reached the end of its lifetime and holds no resources |
85 | anymore (except possibly for the Perl object, but its connection to |
88 | anymore (except possibly for the Perl object, but its connection to |
86 | the actual aio request is severed and calling its methods will |
89 | the actual aio request is severed and calling its methods will |
87 | either do nothing or result in a runtime error). |
90 | either do nothing or result in a runtime error). |
88 | |
91 | |
|
|
92 | WIN32 FILENAMES/DATABASE NAME MESS |
|
|
93 | Perl on Win32 supports only ASCII filenames (the reason is that it |
|
|
94 | abuses an internal flag to store wether a filename is Unicode or ANSI, |
|
|
95 | but that flag is used for somethign else in the perl core, so there is |
|
|
96 | no way to detect wether a filename is ANSI or Unicode-encoded). The BDB |
|
|
97 | module tries to work around this issue by assuming that the filename is |
|
|
98 | an ANSI filename and BDB was built for unicode support. |
|
|
99 | |
89 | BERKELEYDB FUNCTIONS |
100 | BERKELEYDB FUNCTIONS |
90 | All of these are functions. The create functions simply return a new |
101 | 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 |
102 | object and never block. All the remaining functions take an optional |
92 | callback as last argument. If it is missing, then the fucntion will be |
103 | callback as last argument. If it is missing, then the function will be |
93 | executed synchronously. |
104 | executed synchronously. In both cases, $! will reflect the return value |
|
|
105 | of the function. |
94 | |
106 | |
95 | BDB functions that cannot block (mostly functions that manipulate |
107 | BDB functions that cannot block (mostly functions that manipulate |
96 | settings) are method calls on the relevant objects, so the rule of thumb |
108 | 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 |
109 | is: if it's a method, it's not blocking, if it's a function, it takes a |
98 | callback as last argument. |
110 | callback as last argument. |
99 | |
111 | |
100 | In the following, $int signifies an integer return value, "octetstring" |
112 | In the following, $int signifies an integer return value, "octetstring" |
101 | is a "binary string" (i.e. a perl string with no character indices |
113 | is a "binary string" (i.e. a perl string with no character indices |
102 | >255), "U32" is an unsigned 32 bit integer, "int" is some integer, "NV" |
114 | >255), "U32" is an unsigned 32 bit integer, "int" is some integer, "NV" |
… | |
… | |
132 | |
144 | |
133 | db_open (DB *db, DB_TXN_ornull *txnid, octetstring file, octetstring database, int type, U32 flags, int mode, SV *callback = &PL_sv_undef) |
145 | 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 |
146 | 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) |
147 | db_close (DB *db, U32 flags = 0, SV *callback = &PL_sv_undef) |
136 | flags: DB_NOSYNC |
148 | flags: DB_NOSYNC |
|
|
149 | 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) |
150 | 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 |
151 | flags: FREELIST_ONLY FREE_SPACE |
139 | db_sync (DB *db, U32 flags = 0, SV *callback = &PL_sv_undef) |
152 | 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) |
153 | 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) |
154 | 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) |
340 | DESTROY (DBC_ornull *dbc) |
328 | CODE: |
341 | CODE: |
329 | if (dbc) |
342 | if (dbc) |
330 | dbc->c_close (dbc); |
343 | dbc->c_close (dbc); |
331 | |
344 | |
|
|
345 | $int = $cursor->set_priority ($priority = PRIORITY_*) |
|
|
346 | |
332 | Example: |
347 | Example: |
333 | my $c = $db->cursor; |
348 | my $c = $db->cursor; |
334 | |
349 | |
335 | for (;;) { |
350 | for (;;) { |
336 | db_c_get $c, my $key, my $data, BDB::NEXT; |
351 | db_c_get $c, my $key, my $data, BDB::NEXT; |
… | |
… | |
354 | flags: SEQ_DEC SEQ_INC SEQ_WRAP |
369 | flags: SEQ_DEC SEQ_INC SEQ_WRAP |
355 | $int = $seq->set_range (db_seq_t min, db_seq_t max) |
370 | $int = $seq->set_range (db_seq_t min, db_seq_t max) |
356 | |
371 | |
357 | Example: |
372 | Example: |
358 | my $seq = $db->sequence; |
373 | my $seq = $db->sequence; |
359 | |
374 | |
360 | db_sequence_open $seq, undef, "seq", BDB::CREATE; |
375 | db_sequence_open $seq, undef, "seq", BDB::CREATE; |
361 | db_sequence_get $seq, undef, 1, my $value; |
376 | db_sequence_get $seq, undef, 1, my $value; |
362 | |
377 | |
363 | SUPPORT FUNCTIONS |
378 | SUPPORT FUNCTIONS |
364 | EVENT PROCESSING AND EVENT LOOP INTEGRATION |
379 | EVENT PROCESSING AND EVENT LOOP INTEGRATION |
|
|
380 | $msg = BDB::strerror [$errno] |
|
|
381 | Returns the string corresponding to the given errno value. If no |
|
|
382 | argument is given, use $!. |
|
|
383 | |
|
|
384 | Note that the BDB module also patches the $! variable directly, so |
|
|
385 | you should be able to get a bdb error string by simply stringifying |
|
|
386 | $!. |
|
|
387 | |
365 | $fileno = BDB::poll_fileno |
388 | $fileno = BDB::poll_fileno |
366 | Return the *request result pipe file descriptor*. This filehandle |
389 | Return the *request result pipe file descriptor*. This filehandle |
367 | must be polled for reading by some mechanism outside this module |
390 | 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 |
391 | (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. |
392 | becomes readable you have to call "poll_cb" to check the results. |
… | |
… | |
556 | |
579 | |
557 | In short: the parent will, after a short pause, continue as if fork had |
580 | 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 |
581 | not been called, while the child will act as if BDB has not been used |
559 | yet. |
582 | yet. |
560 | |
583 | |
|
|
584 | Win32 note: there is no fork on win32, and perls emulation of it is too |
|
|
585 | broken to be supported, so do not use BDB in a windows pseudo-fork, |
|
|
586 | better yet, switch to a more capable platform. |
|
|
587 | |
561 | MEMORY USAGE |
588 | MEMORY USAGE |
562 | Per-request usage: |
589 | Per-request usage: |
563 | |
590 | |
564 | Each aio request uses - depending on your architecture - around 100-200 |
591 | Each aio request uses - depending on your architecture - around 100-200 |
565 | bytes of memory. In addition, stat requests need a stat buffer (possibly |
592 | bytes of memory. In addition, stat requests need a stat buffer (possibly |