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