1 #include "../common/tdb_private.h"
3 /* Speed up the tests: setting TDB_NOSYNC removed recovery altogether. */
4 static inline int fake_fsync(int fd
)
8 #define fsync fake_fsync
11 static inline int fake_msync(void *addr
, size_t length
, int flags
)
15 #define msync fake_msync
19 static inline int fake_fdatasync(int fd
)
23 #define fdatasync fake_fdatasync
26 #include "../common/io.c"
27 #include "../common/tdb.c"
28 #include "../common/lock.c"
29 #include "../common/freelist.c"
30 #include "../common/traverse.c"
31 #include "../common/transaction.c"
32 #include "../common/error.c"
33 #include "../common/open.c"
34 #include "../common/check.c"
35 #include "../common/hash.c"
36 #include "tap-interface.h"
41 static void write_record(struct tdb_context
*tdb
, size_t extra_len
,
45 key
.dsize
= strlen("hi");
46 key
.dptr
= (void *)"hi";
48 data
->dsize
+= extra_len
;
49 tdb_transaction_start(tdb
);
50 tdb_store(tdb
, key
, *data
, TDB_REPLACE
);
51 tdb_transaction_commit(tdb
);
54 int main(int argc
, char *argv
[])
56 struct tdb_context
*tdb
;
59 struct tdb_record rec
;
63 tdb
= tdb_open_ex("run-transaction-expand.tdb",
64 1024, TDB_CLEAR_IF_FIRST
,
65 O_CREAT
|O_TRUNC
|O_RDWR
, 0600, &taplogctx
, NULL
);
69 data
.dptr
= calloc(1000, getpagesize());
71 /* Simulate a slowly growing record. */
72 for (i
= 0; i
< 1000; i
++)
73 write_record(tdb
, getpagesize(), &data
);
75 tdb_ofs_read(tdb
, TDB_RECOVERY_HEAD
, &off
);
76 tdb_read(tdb
, off
, &rec
, sizeof(rec
), DOCONV());
77 diag("TDB size = %zu, recovery = %u-%u",
78 (size_t)tdb
->map_size
, off
, off
+ sizeof(rec
) + rec
.rec_len
);
80 /* We should only be about 5 times larger than largest record. */
81 ok1(tdb
->map_size
< 6 * i
* getpagesize());
84 tdb
= tdb_open_ex("run-transaction-expand.tdb",
85 1024, TDB_CLEAR_IF_FIRST
,
86 O_CREAT
|O_TRUNC
|O_RDWR
, 0600, &taplogctx
, NULL
);
91 /* Simulate a slowly growing record, repacking to keep
92 * recovery area at end. */
93 for (i
= 0; i
< 1000; i
++) {
94 write_record(tdb
, getpagesize(), &data
);
99 tdb_ofs_read(tdb
, TDB_RECOVERY_HEAD
, &off
);
100 tdb_read(tdb
, off
, &rec
, sizeof(rec
), DOCONV());
101 diag("TDB size = %zu, recovery = %u-%u",
102 (size_t)tdb
->map_size
, off
, off
+ sizeof(rec
) + rec
.rec_len
);
104 /* We should only be about 4 times larger than largest record. */
105 ok1(tdb
->map_size
< 5 * i
* getpagesize());
109 return exit_status();