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

Comparing BDB/README (file contents):
Revision 1.4 by root, Fri Dec 7 13:39:04 2007 UTC vs.
Revision 1.9 by root, Sat May 10 20:23:19 2008 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines