tdb2: test: convert (non-invasive) run tests to api tests. This reduces compilation time, since these are merely linked with the pre-built module, rather than recompiling it into the test (which allows for fancy things like failtest). This reduces the test compile time down from about 62 seconds to 45 seconds. Since ccanlint compiles tests three times (once normally, once with coverage, and once with reduced config.h) this makes a difference: we go from 780 seconds to 729 seconds.
tdb2: test: try (almost) all tests with TDB_VERSION1 flag. There are some minor changes required, in particular: 1) Make sure lockcheck understands tdb1 allrecord lock upgrades. 2) Handle tdb1 sequence number jumps: various operations increment the sequence number twice, especually tdb_append. 3) Don't test fail on unlock, since it gets triggered with traversal on the tdb1 backend (we didn't actually ever test this case for tdb2). 4) Move clear_if_first to offset 4, to match tdb1.
tdb2: make tests include a single mega-header to simplify future patches This lets us add the new files to a single place.
tdb2: check pid before unlock. The original code assumed that unlocking would fail if we didn't have a lock; this isn't true (at least, on my machine). So we have to always check the pid before unlocking.
tdb2: check PID if we are holding a lock. tdb1 has tdb_reopen/tdb_reopen_all, which you are supposed to call after a fork(). But we can detect PID changes whenever we grab a lock, which is to say, before we do anything. We currently assume that pread and pwrite work, so the only problem with fork() is if we are holding locks and expect them to still be there in the child. This is unusual, but most likely caused by a fork() inside a transaction. In such cases, allow the child to unlock without complaint; they can then use the TDB as expected. Performance before and after shows no measurable speed difference: Total of 5 runs of tools/speed 100000: Before: Adding: 18899ns Finding: 7040ns Missing: 5802ns Traversing: 6466ns Deleting: 12607ns Re-adding: 14185ns Appending: 20770ns Churning: 93845ns After: Adding: 18073ns Finding: 6795ns Missing: 5549ns Traversing: 6333ns Deleting: 12313ns Re-adding: 13835ns Appending: 20343ns Churning: 92208ns