#include <ccan/tdb2/tdb.c>
+#include <ccan/tdb2/open.c>
#include <ccan/tdb2/free.c>
#include <ccan/tdb2/lock.c>
#include <ccan/tdb2/io.c>
#include <ccan/tdb2/hash.c>
#include <ccan/tdb2/check.c>
+#include <ccan/tdb2/transaction.c>
#include <ccan/tap/tap.h>
#include <ccan/ilog/ilog.h>
#include "logging.h"
struct hash_info h;
off = find_and_lock(tdb, key, F_RDLCK, &h, &rec, NULL);
- if (unlikely(off == TDB_OFF_ERR))
+ if (TDB_OFF_IS_ERR(off))
return 0;
tdb_unlock_hashes(tdb, h.hlock_start, h.hlock_range, F_RDLCK);
return off;
int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
TDB_NOMMAP|TDB_CONVERT };
- struct tdb_data key = { (unsigned char *)"key", 3 };
+ struct tdb_data key = tdb_mkdata("key", 3);
struct tdb_data data;
buffer = malloc(MAX_SIZE);
buffer[i] = i;
plan_tests(sizeof(flags) / sizeof(flags[0])
- * ((3 + MAX_SIZE/SIZE_STEP * 4) * 2 + 6)
+ * ((3 + MAX_SIZE/SIZE_STEP * 5) * 2 + 7)
+ 1);
/* Using tdb_store. */
data.dsize = j;
ok1(tdb_store(tdb, key, data, TDB_REPLACE) == 0);
ok1(tdb_check(tdb, NULL, NULL) == 0);
- data = tdb_fetch(tdb, key);
+ ok1(tdb_fetch(tdb, key, &data) == TDB_SUCCESS);
ok1(data.dsize == j);
ok1(memcmp(data.dptr, buffer, data.dsize) == 0);
free(data.dptr);
moves++;
oldoff = newoff;
}
- ok1(!tdb_has_locks(tdb));
+ ok1(!tdb->file || (tdb->file->allrecord_lock.count == 0
+ && tdb->file->num_lockrecs == 0));
/* We should increase by 50% each time... */
ok(moves <= ilog64(j / SIZE_STEP)*2, "Moved %u times", moves);
tdb_close(tdb);
data.dsize = j - prev_len;
ok1(tdb_append(tdb, key, data) == 0);
ok1(tdb_check(tdb, NULL, NULL) == 0);
- data = tdb_fetch(tdb, key);
+ ok1(tdb_fetch(tdb, key, &data) == TDB_SUCCESS);
ok1(data.dsize == j);
ok1(memcmp(data.dptr, buffer, data.dsize) == 0);
free(data.dptr);
moves++;
oldoff = newoff;
}
- ok1(!tdb_has_locks(tdb));
+ ok1(!tdb->file || (tdb->file->allrecord_lock.count == 0
+ && tdb->file->num_lockrecs == 0));
/* We should increase by 50% each time... */
ok(moves <= ilog64(j / SIZE_STEP)*2, "Moved %u times", moves);
tdb_close(tdb);
data.dsize = MAX_SIZE;
ok1(tdb_append(tdb, key, data) == 0);
ok1(tdb_check(tdb, NULL, NULL) == 0);
- data = tdb_fetch(tdb, key);
+ ok1(tdb_fetch(tdb, key, &data) == TDB_SUCCESS);
ok1(data.dsize == MAX_SIZE);
ok1(memcmp(data.dptr, buffer, data.dsize) == 0);
free(data.dptr);
- ok1(!tdb_has_locks(tdb));
+ ok1(!tdb->file || (tdb->file->allrecord_lock.count == 0
+ && tdb->file->num_lockrecs == 0));
tdb_close(tdb);
}
ok1(tap_log_messages == 0);
+ free(buffer);
return exit_status();
}