ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/TDB_FileX/TDB_FileX.pm
Revision: 1.22
Committed: Mon May 5 08:20:31 2025 UTC (16 months, 2 weeks ago) by root
Branch: MAIN
Changes since 1.21: +2 -3 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 package TDB_FileX;
2    
3     use common::sense;
4    
5     use Exporter ();
6     use XSLoader ();
7    
8     our @ISA = qw(Exporter);
9    
10     # Items to export into callers namespace by default. Note: do not export
11     # names by default without a very good reason. Use EXPORT_OK instead.
12     # Do not simply export all your public functions/methods/constants.
13    
14     our %EXPORT_TAGS = (
15     flags => [qw(
16     ALLOW_NESTING
17     BIGENDIAN
18     CLEAR_IF_FIRST
19     CONVERT
20     DEFAULT
21     DISALLOW_NESTING
22     INCOMPATIBLE_HASH
23     INTERNAL
24     MUTEX_LOCKING
25     NOLOCK
26     NOMMAP
27     NOSYNC
28     SEQNUM
29     VOLATILE
30     )],
31     insert => [qw(
32     INSERT
33     MODIFY
34     REPLACE
35     )],
36     error => [qw(
37     SUCCESS
38     ERR_CORRUPT
39     ERR_EXISTS
40     ERR_IO
41     ERR_LOCK
42     ERR_LOCK_TIMEOUT
43     ERR_NOEXIST
44     ERR_NOLOCK
45     ERR_OOM
46     ERR_EINVAL
47     ERR_RDONLY
48     )],
49     debug => [qw(
50     DEBUG_FATAL
51     DEBUG_ERROR
52     DEBUG_WARNING
53     DEBUG_TRACE}
54     )],
55     );
56    
57     our @EXPORT_OK;
58    
59     Exporter::export_ok_tags qw(flags insert error debug);
60    
61     $EXPORT_TAGS{all} = \@EXPORT_OK;
62    
63     our $VERSION = '0.97';
64    
65     XSLoader::load __PACKAGE__, $VERSION;
66    
67     1;
68     __END__
69    
70     =head1 NAME
71    
72     TDB_FileX - Perl access to the trivial database library
73    
74     =head1 SYNOPSIS
75    
76     use TDB_FileX;
77    
78     # tie interface
79     tie %hash, TDB_FileX => $filename,
80     hash_size => 8000,
81     mutex => 1,
82     ;
83     $hash{key} = 'value';
84     while (my ($k, $v) = each %hash) { print "$k -> $v\n" }
85    
86     # OO interface
87     my $tdb = TDB_FileX->open ($filename, flags => TDB_FileX::CLEAR_IF_FIRST)
88     or die $!;
89    
90     $tdb->store (key => 'value') or die $tdb->errorstr;
91     $tdb->traverse (sub { print "$_[0] -> $_[1]\n" });
92    
93     =head1 DESCRIPTION
94    
95     TDB is a simple database similar to GDBM, but allows multiple simultaneous
96     writers. It's main drawback is the need to manually configure a hash table
97     size in advance - see the C<hash_size> option for C<open>.
98    
99     TDB_FileX provides a simple C<tie> interface, similar to DB_File and
100 root 1.3 friends; and an object-oriented interface, which provides access to most
101     of the functions in the TDB library.
102    
103 root 1.16 =head2 COMPARISON TO OTHER DBMS
104    
105     TDB stands for trivial database - and indeed, the database structure is
106     very simple, requiring manual sizing at creation time, and being limited
107     to 4GB size.
108    
109     But otherwise, TDB has features that no other simple DBM has -
110     fine-grained locking, multiprocess database access and transactions.
111    
112     GDBM_File for example has a single per-process lock, so only one process
113     can write to the database. Most others have no locking and will happily
114     corrupt your database. TDB_FileX is safe to use from multiple processes.
115    
116     As for data safety, GDBM databases easily corrupt (in current version of
117     GDBM), and while GDBM databases can be 30% more compact than equivalent
118     TDB databases, they tend to grow over time (I regularly find 10GB GDBM
119     databases (actual disk usage) that reorganize to 300MB files and have
120     never stored more than that). TDB files do not usually have such bad
121     growth behaviour, but also have no reorganize function to shrink the
122     database again.
123    
124     So, if you want safe access from multiple proceses and have a good idea
125     of how many keys to store, TDB_FileX is the thing. If you only want
126     protectioon against obvious data corruption and processes can wait, GDBM
127     is a probably a better choice.
128    
129 root 1.3 =head1 ERROR HANDLKING
130    
131 root 1.17 The TDB C API is not well designed - among other things, error handling is
132     a bit erratic. To compensate, many TDB functions that normally succeed are
133     marked with a [CROAK] - these will throw an exception on "unusual" error
134     conditions, the exception string being the error message. C<$!> is set to
135     the numerical error value in that case (and will stringify into the wrong
136     OS-error string, so don't do that!).
137    
138     This is so that you can concentrate on the important parts without having
139     to check for an error status on every call, while there are still no
140     silent unexpected errors, as TDB_FileX will croak for you.
141 root 1.3
142     The other functions will not generally croak - check their description for
143     details on how errors are handled.
144 root 1.1
145 root 1.14 Functions that are not part of the TDB API (such as
146     C<register_hash_function>) may croak on errors without being marked as
147     such. The above only refers to TDB API functions, as they cannot throw
148 root 1.17 Perl exceptions themselves.
149 root 1.14
150 root 1.1 =head2 FUNCTIONS
151    
152     =over 4
153    
154 root 1.3 =item $tdb = tie %hash, TDB_FileX => $path[ , key => value...]
155    
156     =item $tdb = TDB_FileX->open ($path[, key => value...])
157    
158     TDB_FileX constructor (same as C<TIE>). Opens $path and returns a
159     TDB_FileX object. The same arguments may be passed to the C<tie>
160     function. On error, C<undef> is returned.
161 root 1.1
162 root 1.10 You should consider specifying at least C<log_cb> and C<hash_size> (and
163     possibly C<mutex>), everything else has sensible defaults.
164    
165 root 1.3 To open a tdb file that is created and used by another application
166 root 1.6 (maximising compatibility):
167 root 1.3
168     my $tdb = TDB_FileX->open ($path, log_cb => sub { warn $_[1] })
169     or die "$path: failed to open\n";
170    
171 root 1.10 To successfully open another database, you might have to duplicate some of
172     the settings, e.g. whether mutex locking is used or the hash function. The
173     C<log_cb> output usually will tell you what's wrong.
174    
175 root 1.3 To open a tdb file with good performance for many thousands of large keys,
176 root 1.10 maybe not compatible to other programs:
177 root 1.3
178     my $tdb = TDB_FileX->open ($path,
179     hash_size => 10000,
180     hash => "xxh3",
181     mutex => 1,
182 root 1.6 nocow => 1,
183 root 1.3 log_cb => sub { warn $_[1] },
184     ) or die "$path: failed to open\n";
185 root 1.1
186 root 1.10 The following key-value pairs are understood:
187 root 1.1
188     =over
189    
190     =item tdb_flags => $flags (default: C<TDB_FileX::DEFAULT>)
191    
192     A set of flags that influence the behaviour and format of the database.
193    
194 root 1.11 =over
195    
196     =item C<DEFAULT>
197    
198     Same as C<0> - no flags.
199    
200     =item C<CLEAR_IF_FIRST>
201    
202     If this is the first open, wipe the db.
203    
204     =item C<INTERNAL>
205    
206     In-memory database only, path will be ignored.
207    
208     =item C<NOLOCK>
209    
210     Don't do any locking.
211    
212     =item C<NOMMAP>
213    
214     Don't use mmap.
215    
216     =item C<NOSYNC>
217    
218     Don't use synchronous transactions.
219 root 1.1
220 root 1.11 =item C<SEQNUM>
221    
222     Maintain a sequence number.
223    
224     =item C<VOLATILE>
225    
226 root 1.13 Activate the per-hashchain freelist, default 5. (Same as calling
227     C<set_max_dead> with C<5> instead of the default C<0>).
228 root 1.11
229     =item C<ALLOW_NESTING>
230    
231     Allow transactions to nest.
232    
233     =item C<DISALLOW_NESTING>
234    
235     Disallow transactions to nest.
236    
237     =item C<INCOMPATIBLE_HASH>
238    
239 root 1.17 Better default hash function, but can't be opened by tdb < 1.2.6.
240 root 1.11
241     =item C<MUTEX_LOCKING>
242    
243     Optimized locking using robust mutexes if supported,
244    
245     =back
246 root 1.10
247 root 1.1 =item open_flags => $flags (default: C<Fcntl::O_RDWR | Fcntl::O_CREAT>)
248    
249     Standard open flags, as used in C<sysopen>.
250    
251     =item mode => $mode (default: C<0666>)
252    
253 root 1.17 Standard file open mode, as used in C<sysopen>. Only used when creating
254 root 1.1 the database file.
255    
256     =item hash_size => $int (default: internal to libtdb, but normally C<131>)
257    
258     The size of the internal hash table - only used when creating the
259     database. The default is usually very low and only good for a few thousand
260     keys. As a rule of thumb, it should be at least one percent of the number
261     of keys you plan to store, e.g. for C<800000> keys you should use around a
262     size of C<8000>.
263    
264 root 1.17 Every hash entry is only 4 octets, so usually it isn't an issue to make the
265 root 1.2 hash table too large.
266    
267     To give you an idea of the performance, I inserted about 600000 records,
268     3GB of data, into a TDB file, using different hash sizes.
269 root 1.1
270     size time
271     131 160s
272     256 85s
273     1024 12s
274     4096 5s
275     8192 4s
276    
277 root 1.17 As you can see, the default hash table size for this case caused it to use
278     40 times the time to insert than a larger hash table, the optimum being
279     around 75 keys per hash entry. But this database was easily cached in
280     memory - if that is not the case, you might want to consider a hash table
281 root 1.3 that is larger than the number of keys you want to store - each hash slot
282     only uses 4 octets.
283 root 1.1
284     =item log_cb => $cb->($level, $msg)
285    
286 root 1.17 Specifies a code reference that is called with a message and a log level
287 root 1.1 (lower means more important, there are C<DEBUG_FATAL>, C<DEBUG_ERROR>,
288     C<DEBUG_WARNING> and C<DEBUG_TRACE}>). Unlike the "debug" in the name
289     might indicate, if you want to find out why, for instance, you could not
290     open a database, you need to use a logging callback.
291    
292     =item hash => $hash (default: C<undef>)
293    
294     Selects a hash function to use.
295    
296     =over
297    
298     =item C<"default"> or C<undef>
299    
300     Use autodetection and use either C<"jenkins"> or the original tdb hash function.
301    
302     =item C<"jenkins">
303    
304     The jenkins hash function. Relatively fast, and recommended for modern tdb databases
305     that need to be interoperable between implementations.
306    
307     =item C<"fnv1ax">
308    
309 root 1.10 The FNV1-A hash with 32 bit post-mixing. Pretty good and very fast for
310 root 1.1 keys up to 10-20 octets.
311    
312     =item C<"xxh3">
313    
314     The XXH3 hash. Very good and fast especially for long keys.
315    
316 root 1.17 =item a value returned by C<register_hash_function>
317 root 1.1
318 root 1.14 Use a custom hash function registered via C<register_hash_function>.
319 root 1.1
320     =back
321    
322     =item mutex => $bool (default: C<0>)
323    
324 root 1.17 TDB can take advantage of fast interprocess mutexes, which can be orders
325     of magnitude faster than the syscall-based locking used by default, but
326     only work on the same machine (the default C<fcntl>-based locking works
327     e.g. over NFS).
328 root 1.6
329     Normally, you need to call C<TDB_FileX::runtime_check_for_robust_mutexes>
330     and set the C<MUTEX_LOCKING> flag if support is indicated.
331 root 1.1
332 root 1.17 This option, when true, enables C<MUTEX_LOCKING> if it is supported
333     by the platform - which involves forking the process when opening the
334     database. When false, it will remove the flag.
335 root 1.1
336 root 1.17 It is recommended to keep this on, but enabling this changes the format
337 root 1.1 of the database, so might not be an option if interoperability with other
338     programs is required.
339    
340 root 1.6 =item nocow => $bool (default: C<0>)
341    
342     Set the no-copy-on-write flag I<iff> this flag is true, C<open_flags>
343 root 1.7 contains C<O_CREAT>, C<tdb_flags> do not contain C<INTERNAL> and this is
344     supported on the platform and filesystem. Copy-on-write filesystems have
345     to make a copy of every block written to, which can both be costly and can
346     cause massive fragmentation of the database file.
347 root 1.6
348     Setting the no-copy-on-write flag (same as C<chattr +C>) disables this,
349     usually at the expense of data protection (checksumming), reducing the
350     safety to the level of a normal filesystem such as ext4.
351    
352     This is best effort and usually only takes effect when the
353     database is initially created. If it fails, TDB_FileX will simply
354     continue. Correctness should not be affected either way.
355    
356 root 1.1 =back
357    
358     There is no explicit close function. The database is closed implicitly
359     when there are no remaining references.
360    
361 root 1.17 =item $tdb->set_logging_function ($cb->($level, $msg))
362    
363     Set the logging function to use when this database object encounters
364     errors.
365    
366     $cb is called with the severity level (an integer) and the message (a
367     string).
368    
369     =item $code = $tdb->error
370    
371     Returns the current error state of the C<$tdb> object. See the list of
372     error codes given in L<EXPORTS>.
373    
374     =item $mesage = $tdb->errorstr
375    
376     Returns a printable string that describes the error state of the
377     database.
378    
379 root 1.3 =item $tdb->store ($key, $value[, $flag=REPLACE]) [CROAK]
380 root 1.1
381     Store $value in the database with key w$key. The $flag defaults to
382     C<REPLACE>, but can also be C<INSERT> or C<MODIFY>, see tdb_store(3) for
383     details.
384    
385 root 1.3 =item $tdb->append ($key, $value) [CROAK]
386    
387     Appends $data to the data already stored for $key, or creates a new entry with it.
388 root 1.1
389 root 1.12 =item $data = $tdb->fetch ($key) [CROAK]
390 root 1.1
391 root 1.3 Fetch the value associated with $key, or C<undef> if it is not found (or
392     on any error).
393 root 1.1
394 root 1.3 =item $tdb->delete ($key) [CROAK]
395 root 1.1
396     Delete the value associated with $key.
397    
398 root 1.3 =item $bool = $tdb->exists ($key)
399 root 1.1
400     Return true if the $key is found, false otherwise.
401    
402 root 1.12 =item $key = $tdb->firstkey
403 root 1.1
404     Return the key of the first value in the database. Returns C<undef> on
405     failure or if there are no keys in the database. See tdb_firstkey(3)
406     for details.
407    
408 root 1.12 =item $key = $tdb->nextkey ($lastkey)
409 root 1.1
410     Return the next key in the database after $lastkey. Returns C<undef> on
411     failure or if there are no more keys in the database. See tdb_nextkey(3)
412     for details.
413    
414 root 1.3 =item $tdb->reopen [CROAK]
415 root 1.1
416     Closes and reopens the database. Required after a
417     L<fork|perlfunc/fork>, if both processes wish to use the database.
418    
419 root 1.3 B<NB:> If C<reopen> fails, then it is unsafe to call any further methods
420     on C<$tdb>. Thus, the only way to find out I<why> C<reopen> failed is to
421     use a logging function.
422 root 1.1
423 root 1.3 =item TDB_FileX::reopen_all [CROAK]
424 root 1.1
425 root 1.12 Closes and reopens all open databases. See C<reopen>.
426 root 1.1
427 root 1.3 B<NB:> If C<reopen_all> fails, there is no indication of I<which> C<$tdb>
428     objects failed or why. If you have to survive failures, you may wish to do
429     your own C<reopen> loop instead.
430 root 1.1
431 root 1.4 =item $tdb->traverse ($cb->($key, $data)) [CROAK]
432 root 1.1
433 root 1.4 Call $cb for each entry in the database. The callback should return false
434     to continue, or a true value to abort the traversal.
435 root 1.1
436 root 1.3 The callback is called with the key and value as arguments and should
437 root 1.4 return a false value if you wish to continue traversal, and a true value
438     if the traversal should be aborted.
439 root 1.1
440 root 1.4 C<traverse> returns the number of elements traversed. If $cb is C<undef>,
441     then this function simply counts the number of elements.
442    
443     =item $tdb->traverse_read ($cb->($key, $data)) [CROAK]
444    
445     Like C<traverse>, but only acquires a read lock.
446 root 1.1
447 root 1.3 =item $tdb->lockall [CROAK]
448 root 1.1
449 root 1.2 Lock an entire database with an exclusive write lock, returning false on
450     error. The purpose of this call is to avoid locking overhead for many
451     operations, but the database has to be unlocked manually when done.
452 root 1.1
453 root 1.3 =item $tdb->unlockall [CROAK]
454 root 1.1
455     Unlock an entire database previously locked with
456 root 1.12 C<lockall>.
457 root 1.1
458 root 1.3 =item $tdb->lockall_read [CROAK]
459 root 1.2
460 root 1.12 Same as C<lockall>, but uses a shared read lock instead of a writer lock.
461 root 1.2
462 root 1.3 =item $tdb->unlockall_read [CROAK]
463 root 1.2
464 root 1.12 Opposite of C<lockall_read>.
465 root 1.2
466 root 1.3 =item $tdb->lockall_mark [CROAK]
467 root 1.2
468 root 1.3 =item $tdb->lockall_unmark [CROAK]
469 root 1.2
470 root 1.8 These apparently mark and unmark locks internally, but do not actually do
471     locking. Probably you should not use this, but feel free to tell me when
472     these are useful.
473 root 1.2
474 root 1.3 =item $tdb->lockall_nonblock [CROAK]
475 root 1.2
476 root 1.8 =item $success = $tdb->lockall_read_nonblock [CROAK]
477 root 1.2
478 root 1.8 Try to lock, but instead of waiting, fail if the lock could not
479     be acquired. Returns true if the lock could be acquired, false
480     otherwise. Croaks on all other errors.
481 root 1.2
482 root 1.3 =item $tdb->transaction_start [CROAK]
483 root 1.2
484     Starts a transaction - all operations will be queued, but not applied
485 root 1.12 to the database, until the transaction is either committed C<transaction_commit>
486     or aborted/thrown away, with C<transaction_cancel>.
487 root 1.2
488 root 1.3 =item $tdb->transaction_start_nonblock [CROAK]
489 root 1.2
490 root 1.8 Tries to start a transaction, but instead of waiting, fail if the lock
491     could not be acquired. Returns true if the transaction could be started,
492     false otherwise. Croaks on all other errors.
493    
494 root 1.2 Please tell me what this does.
495    
496 root 1.3 =item $tdb->transaction_commit [CROAK]
497 root 1.2
498     Applies all changes in the transaction.
499    
500 root 1.3 =item $tdb->transaction_cancel [CROAK]
501 root 1.2
502     Throws away all changes in the transaction.
503    
504 root 1.3 =item $tdb->transaction_prepare_commit [CROAK]
505 root 1.2
506 root 1.18 Instead of calling C<transaction_commit> you can do the commit in two
507     phases by calling this method before C<transaction_commit>, which does the
508     expensive steps first.
509 root 1.2
510     =item $bool = $tdb->transaction_active
511    
512     Returns true if a transaction is currently active.
513    
514     =item $tdb->enable_seqnum
515    
516 root 1.18 Enables sequence number generation support for the database.
517 root 1.2
518     =item $seq = $tdb->get_seqnum
519    
520     Returns the current sequence number. Internally, this is a 32 bit unsigned
521     integer, but the API converts it into a native integer, so the same
522     internal sequence number might be represented differently on different
523     machines.
524    
525     =item $tdb->increment_seqnum_nonblock
526    
527     Increments the sequence number. Note that the sequence number is also
528     incremented by TDB itself oon many operations.
529    
530     =item $size = $tdb->hash_size
531    
532     Returns the size of the hash table. The size cannot be changed other than
533     by recreating the database.
534    
535     =item $octets = $tdb->map_size
536    
537     Returns the current mmap size for the database.
538    
539     =item $flags = $tdb->get_flags
540    
541     Returns the flags for the database (the same as the C<tdb_flags> in C<open>).
542    
543     =item $tdb->add_flags ($flag)
544    
545     Tried to add flags to the database - yes, the parameter says C<$flag> (singular)
546     but the documentation and the code say I<flags> (plural).
547    
548     =item $tdb->remove_flags ($flag)
549    
550     Attempts to remove flags from the database.
551    
552 root 1.13 =item $tdb->set_max_dead ($max_dead)
553    
554     Set the maximum number of dead records per hash chain.
555    
556 root 1.2 =item $fileno = $tdb->fd
557    
558     Returns the file descriptor (not file handle) for the underlying database file.
559    
560     =item $path = $tdb->name
561    
562     Returns the path used to open the database.
563    
564 root 1.3 =item $tdb->wipe_all [CROAK]
565 root 1.2
566     Efficientlly deletes all entries in the database. This does not shrink the
567     file itself.
568    
569 root 1.3 =item $tdb->repack [CROAK]
570 root 1.2
571     Tries to improve layout of the database by copying all items into a
572     temporary in-memory database, wiping the database, and copying all items
573 root 1.3 back. Yes, everything must fit into memory.
574 root 1.2
575 root 1.18 =item $bool = $tdb->check ([$cb->($key, $value)])
576 root 1.4
577 root 1.18 Does extensive checks on the database, optionally (if not C<undef> or
578     missing) calling a check function for each pair, which must return true if
579     the data is valid.
580 root 1.4
581     Returns a boolean indicating whether the database was found healthy and
582     all the calls to the callback returned true.
583    
584     =item $bool = $tdb->rescue ($cb->($key, $value))
585    
586     Tries to recover some or all key-value pairs from a potentially damanged
587     database file. For each recovered pair it calls the given callback.
588    
589     Returns a boolean indicating whether the database was found healthy and
590     all the calls to the callback returned true.
591    
592 root 1.2 =item $bool = TDB_FileX::runtime_check_for_robust_mutexes
593    
594     Tests whether robust mutexes are available for locking. This involves
595     forking the process, so it can be costly and problematic. This function
596     needs to be called before using the C<MUTEX_LOCKING> flag. But see the
597     C<mutex> parametrer to C<open> for an alternative.
598    
599 root 1.1 =item $tdb->dump_all
600    
601     Dump the records and freelist to STDOUT in an almost human readable
602     form.
603    
604 root 1.9 =item $summary = $tdb->summary
605    
606     Return a textual summary of the database. The format isn't documented,
607     but for some random databas,e I got this output:
608    
609     Size of file/data: 325001216/238324906
610     Header offset/logical size: 4001792/320999424
611     Number of records: 117209
612     Incompatible hash: no
613     Active/supported feature flags: 0x00000001/0x00000001
614     Robust mutexes locking: yes
615     Smallest/average/largest keys: 11/36/102
616     Smallest/average/largest data: 10/1997/2921430
617     Smallest/average/largest padding: 9/530/749374
618     Number of dead records: 0
619     Smallest/average/largest dead records: 0/0/0
620     Number of free records: 1126
621     Smallest/average/largest free records: 12/15312/14681136
622     Number of hash chains: 100000
623     Smallest/average/largest hash chains: 0/1/8
624     Number of uncoalesced records: 0
625     Smallest/average/largest uncoalesced runs: 0/0/0
626     Percentage keys/data/padding/free/dead/rechdrs&tailers/hashes: 1/72/19/5/0/1/0
627    
628     =item $octets = $tdb->freelist_size
629    
630     Returns the total number of free (unused) octets in the file.
631    
632 root 1.1 =item $tdb->printfreelist
633    
634     Dump the freelist to STDOUT.
635    
636 root 1.15 =item $num_entries = $tdb->validate_freelist [CROAK]
637    
638     Verifies consistency of freelist and return the number of entries. This
639     loads the whole freelist into memory, using an in-memory tdb database,
640     which did strike Jeremy as extremely clever.
641    
642 root 1.20 =item $func_id = TDB_FileX::register_hash_function $callback->($key)
643 root 1.14
644     Registers a custom hash function. The callback should take a key and
645     return a 32 bit integer hash of it.
646    
647     Returns a value that is suitable to be used as the name of a hash function
648     (C<hash> argument to C<open>).
649    
650 root 1.21 A maximum of four custom hash functions can be registered.
651 root 1.14
652 root 1.20 =item TDB_FileX::unregister_hash_function $func_id
653 root 1.14
654     Frees the hash function registered by a previous call to
655     C<register_hash_function>. Note that you I<MUST NOT> unregister a function
656     that is still in use.
657    
658 root 1.1 =back
659    
660     =head2 EXPORTS
661    
662 root 1.22 The tag C<:all> exports all of the constants. Nothing is exported by
663     default.
664 root 1.1
665     Individually or with the tag C<:flags>:
666    
667     DEFAULT
668     CLEAR_IF_FIRST
669     INTERNAL
670     NOLOCK
671     NOMMAP
672     CONVERT
673     BIGENDIAN
674     NOSYNC
675     SEQNUM
676     VOLATILE
677     ALLOW_NESTING
678     DISALLOW_NESTING
679     INCOMPATIBLE_HASH
680     MUTEX_LOCKING
681    
682     Individually or with the tag C<:insert>:
683    
684     REPLACE
685     INSERT
686     MODIFY
687    
688     Individually or with the tag C<:error>:
689    
690     SUCCESS
691     ERR_CORRUPT
692     ERR_IO
693     ERR_LOCK
694     ERR_OOM
695     ERR_EXISTS
696     ERR_NOLOCK
697     ERR_LOCK_TIMEOUT
698     ERR_NOEXIST
699     ERR_EINVAL
700     ERR_RDONLY
701    
702     Individually or with the tag C<:debug>:
703    
704     DEBUG_FATAL
705     DEBUG_ERROR
706     DEBUG_WARNING
707     DEBUG_TRACE
708    
709 root 1.2 =head1 UNICODE HANDLING
710    
711     TDB databases can only store octet strings. Unlike most other database
712     interfaces, TDB_FileX will safely handle Perl strings by downgrading
713 root 1.21 them. Perl will warn about strings that cannot be downgraded.
714 root 1.2
715     =head1 DISK USAGE
716    
717     TDB databses use 24 octets for every key-value pair, plus the octet size
718     of the key and sata, e.g. the pair "key" => "value" takes up 24+3+5 octets
719     on disk.
720    
721     The database header is 168 octets (if I haven't miscounted).
722    
723     Each hashtable entry is 4 octets, and one more than the hash size is
724 root 1.10 allocated, so the hash table size is (hash_size + 1) * 4.
725 root 1.2
726     =head1 LIMITATIONS
727    
728     =head2 Database Size
729    
730 root 1.14 As far as I can see, TDB databases are limited to 4 GB.
731 root 1.2
732     =head2 Hash Functions
733    
734     Hash functioons need to be set globally - they are limited to a maximum of
735     4, but this can be easily extended, but requires source code editing. This
736     is due to a limitation of the TDB C API.
737    
738 root 1.14 =head2 No recovery after failed C<reopoen_all>
739 root 1.1
740     There is no way to survive an error during C<reopen_all>.
741     Unfortunately this is a limitation in the TDB C API.
742    
743 root 1.14 =head2 No way to resize hash table
744    
745     Performance degrades majorly when the databse grows larger then
746     accomodated by the hash table size, and the hash table size needs to be
747     set at database creation time and cannot be resized later.
748    
749 root 1.1 =head1 SEE ALSO
750    
751     tdb(3), L<perltie>.
752    
753     =head1 AUTHOR
754    
755     Angus Lees, E<lt>gus@inodes.org>
756    
757     Currently maintained by Marc A. Lehmann <schmorp@schmorp.de>
758     http://home.schmorp.de/
759    
760     =cut