1 /* We need this otherwise fcntl locking fails. */
2 #define _FILE_OFFSET_BITS 64
3 #define _XOPEN_SOURCE 500
4 #include <ccan/tdb/tdb_private.h>
6 /* Speed up the tests: setting TDB_NOSYNC removed recovery altogether. */
7 static inline int fake_fsync(int fd)
11 #define fsync fake_fsync
14 static inline int fake_msync(void *addr, size_t length, int flags)
18 #define msync fake_msync
21 #include <ccan/tdb/tdb.h>
22 #include <ccan/tdb/io.c>
23 #include <ccan/tdb/tdb.c>
24 #include <ccan/tdb/lock.c>
25 #include <ccan/tdb/freelist.c>
26 #include <ccan/tdb/traverse.c>
27 #include <ccan/tdb/transaction.c>
28 #include <ccan/tdb/error.c>
29 #include <ccan/tdb/open.c>
30 #include <ccan/tdb/check.c>
31 #include <ccan/tdb/hash.c>
32 #include <ccan/tap/tap.h>
37 static void write_record(struct tdb_context *tdb, size_t extra_len,
41 key.dsize = strlen("hi");
42 key.dptr = (void *)"hi";
44 data->dptr = realloc(data->dptr, data->dsize + extra_len);
45 memset(data->dptr + data->dsize, 'x', extra_len);
46 data->dsize += extra_len;
47 tdb_transaction_start(tdb);
48 tdb_store(tdb, key, *data, TDB_REPLACE);
49 tdb_transaction_commit(tdb);
50 diag("TDB size = %zu", (size_t)tdb->map_size);
53 int main(int argc, char *argv[])
55 struct tdb_context *tdb;
60 tdb = tdb_open_ex("run-transaction-expand.tdb",
61 1024, TDB_CLEAR_IF_FIRST,
62 O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
68 /* Simulate a slowly growing record. */
69 for (i = 0; i < 1000; i++)
70 write_record(tdb, getpagesize(), &data);
72 /* We should only be about 3 times larger than largest record. */
73 ok1(tdb->map_size < 3 * i * getpagesize());