From db2508840d55842ebaf0c0d7a2fa3c855498e75f Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 18 Jun 2012 22:30:29 +0930 Subject: ntdb: create initial database to be multiple of NTDB_PGSIZE. As copied from tdb1, there is logic in the transaction code to handle a non-PGSIZE multiple db, but in fact this only happens for a completely unused database: as soon as we add anything to it, it is expanded to a NTDB_PGSIZE multiple. If we create the database with a free record which pads it out to NTDB_PGSIZE, we can remove this last-page-is-different logic. Of course, the fake ntdbs we create in our tests now also need to be multiples of NTDB_PGSIZE, so we change some numbers there too. Signed-off-by: Rusty Russell --- lib/ntdb/test/run-30-exhaust-before-expand.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'lib/ntdb/test/run-30-exhaust-before-expand.c') diff --git a/lib/ntdb/test/run-30-exhaust-before-expand.c b/lib/ntdb/test/run-30-exhaust-before-expand.c index e3831f51a7..24c48b005a 100644 --- a/lib/ntdb/test/run-30-exhaust-before-expand.c +++ b/lib/ntdb/test/run-30-exhaust-before-expand.c @@ -27,11 +27,11 @@ int main(int argc, char *argv[]) NTDB_INTERNAL|NTDB_CONVERT, NTDB_CONVERT, NTDB_NOMMAP|NTDB_CONVERT }; - plan_tests(sizeof(flags) / sizeof(flags[0]) * 11 + 1); + plan_tests(sizeof(flags) / sizeof(flags[0]) * 7 + 1); for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) { NTDB_DATA k, d; - uint64_t size, old_size; + uint64_t size; bool was_empty = false; k.dptr = (void *)&j; @@ -43,22 +43,15 @@ int main(int argc, char *argv[]) if (!ntdb) continue; - old_size = ntdb->file->map_size; - - ok1(empty_freetable(ntdb)); - /* Need some hash lock for expand. */ - ok1(ntdb_lock_hashes(ntdb, 0, 1, F_WRLCK, NTDB_LOCK_WAIT) == 0); - /* Create some free space. */ - ok1(ntdb_expand(ntdb, 1) == 0); - ok1(ntdb_unlock_hashes(ntdb, 0, 1, F_WRLCK) == 0); ok1(ntdb_check(ntdb, NULL, NULL) == 0); + /* There's one empty record in initial db. */ ok1(!empty_freetable(ntdb)); size = ntdb->file->map_size; /* Create one record to chew up most space. */ - d.dsize = (size - old_size - 32); - d.dptr = malloc(d.dsize); + d.dsize = size - sizeof(struct new_database) - 32; + d.dptr = calloc(d.dsize, 1); j = 0; ok1(ntdb_store(ntdb, k, d, NTDB_INSERT) == 0); ok1(ntdb->file->map_size == size); -- cgit