]> git.ozlabs.org Git - ccan/blob - ccan/tdb2/doc/TDB1_porting.txt
ttxml: removed cruft from tests
[ccan] / ccan / tdb2 / doc / TDB1_porting.txt
1 Interface differences between TDB1 and TDB2.
2
3 - tdb2 uses 'struct tdb_data', tdb1 uses 'struct TDB_DATA'.  Use the
4   TDB_DATA typedef if you want portability between the two.
5
6 - tdb2 functions return 0 on success, and a negative error on failure,
7   whereas tdb1 functions returned 0 on success, and -1 on failure.
8   tdb1 then used tdb_error() to determine the error; this is also
9   supported in tdb2 to ease backwards compatibility, though the other
10   form is preferred.
11
12 - tdb2's tdb_fetch() returns an error, tdb1's returned the data directly
13   (or tdb_null, and you were supposed to check tdb_error() to find out why).
14
15 - tdb2's tdb_nextkey() frees the old key's dptr, in tdb2 you needed to do
16   this manually.
17
18 - tdb1's tdb_open/tdb_open_ex took an explicit hash size.  tdb2's hash table
19   resizes as required.
20
21 - tdb2 uses a linked list of attribute structures to implement logging and
22   alternate hashes.  tdb1 used tdb_open_ex, which was not extensible.
23
24 - tdb2 does locking on read-only databases (ie. O_RDONLY passed to tdb_open).
25   tdb1 did not: use the TDB_NOLOCK flag if you want to suppress locking.
26
27 - tdb2's log function is simpler than tdb1's log function.  The string is
28   already formatted, and it takes an enum tdb_log_level not a tdb_debug_level,
29   and which has only three values: TDB_LOG_ERROR, TDB_LOG_USE_ERROR and
30   TDB_LOG_WARNING.
31
32 - tdb2 provides tdb_deq() for comparing two struct tdb_data.
33
34 - tdb2's tdb_name() returns a copy of the name even for TDB_INTERNAL dbs.
35
36 - tdb2 does not need tdb_reopen() or tdb_reopen_all().  If you call
37   fork() after during certain operations the child should close the
38   tdb, or complete the operations before continuing to use the tdb:
39
40         tdb_transaction_start(): child must tdb_transaction_cancel()
41         tdb_lockall(): child must call tdb_unlockall()
42         tdb_lockall_read(): child must call tdb_unlockall_read()
43         tdb_chainlock(): child must call tdb_chainunlock()
44         tdb_parse() callback: child must return from tdb_parse()
45
46 - tdb2 will not open a non-tdb file, even if O_CREAT is specified.
47
48 - There is no tdb_traverse_read.  For operating on TDB1 files, you can
49   simulate it by tdb_add_flag(tdb, TDB_RDONLY); tdb_traverse();
50   tdb_remove_flag(tdb, TDB_RDONLY).  This may be desirable because
51   traverse on TDB1 files use a write lock on the entire database
52   unless it's read-only.
53
54 - Failure inside a transaction (such as a lock function failing) does
55   not implicitly cancel the transaction; you still need to call
56   tdb_transaction_cancel().
57
58 TDB1 Compatibility:
59
60 - tdb2's offers a tdb1_incompatible_hash function, which is the same
61   as the default hash with the TDB_INCOMPATIBLE_HASH flag.  There is
62   no way of marking an old TDB incompatible with versions < 1.2.6
63   while using any other hash.
64
65 - The TDB_ATTRIBUTE_TDB1_HASHSIZE attribute can be used to control the
66   hash size, but only when creating (ie. O_CREAT) a TDB1
67   (ie. TDB_VERSION1).
68
69 - There is no TDB_CLEAR_IF_FIRST flag; it has severe scalability and
70   API problems.  If necessary, you can emulate this by using the open
71   hook and placing a 1-byte lock at offset 4.  If your program forks,
72   you will need to place this lock again in the child.