Commit ec88af5d authored by Rusty Russell's avatar Rusty Russell

tdb2: make summary command handle recovery "dead zone"

We can run summary with a recovery area, or a dead zone.
parent d95645d5
...@@ -381,7 +381,7 @@ static bool check_free_list(struct tdb_context *tdb, ...@@ -381,7 +381,7 @@ static bool check_free_list(struct tdb_context *tdb,
} }
/* Slow, but should be very rare. */ /* Slow, but should be very rare. */
static size_t dead_space(struct tdb_context *tdb, tdb_off_t off) size_t dead_space(struct tdb_context *tdb, tdb_off_t off)
{ {
size_t len; size_t len;
......
...@@ -391,6 +391,9 @@ int set_header(struct tdb_context *tdb, ...@@ -391,6 +391,9 @@ int set_header(struct tdb_context *tdb,
unsigned int size_to_bucket(tdb_len_t data_len); unsigned int size_to_bucket(tdb_len_t data_len);
tdb_off_t bucket_off(tdb_off_t flist_off, unsigned bucket); tdb_off_t bucket_off(tdb_off_t flist_off, unsigned bucket);
/* Used by tdb_summary */
size_t dead_space(struct tdb_context *tdb, tdb_off_t off);
/* io.c: */ /* io.c: */
/* Initialize tdb->methods. */ /* Initialize tdb->methods. */
void tdb_io_init(struct tdb_context *tdb); void tdb_io_init(struct tdb_context *tdb);
......
...@@ -53,17 +53,22 @@ static bool summarize(struct tdb_context *tdb, ...@@ -53,17 +53,22 @@ static bool summarize(struct tdb_context *tdb,
union { union {
struct tdb_used_record u; struct tdb_used_record u;
struct tdb_free_record f; struct tdb_free_record f;
struct tdb_recovery_record r;
} pad, *p; } pad, *p;
p = tdb_get(tdb, off, &pad, sizeof(pad)); /* We might not be able to get the whole thing. */
p = tdb_get(tdb, off, &pad, sizeof(p->f));
if (!p) if (!p)
return false; return false;
if (rec_magic(&p->u) != TDB_MAGIC) { if (p->r.magic == TDB_RECOVERY_INVALID_MAGIC
|| p->r.magic == TDB_RECOVERY_MAGIC) {
len = sizeof(p->r) + p->r.max_len;
} else if (rec_magic(&p->u) != TDB_MAGIC) {
len = p->f.data_len; len = p->f.data_len;
tally_add(free, len); tally_add(free, len);
tally_add(buckets, size_to_bucket(len)); tally_add(buckets, size_to_bucket(len));
len += sizeof(p->u); len += sizeof(p->u);
unc++; unc++;
} else { } else if (frec_magic(&p->f) == TDB_FREE_MAGIC) {
if (unc) { if (unc) {
tally_add(uncoal, unc); tally_add(uncoal, unc);
unc = 0; unc = 0;
...@@ -91,7 +96,8 @@ static bool summarize(struct tdb_context *tdb, ...@@ -91,7 +96,8 @@ static bool summarize(struct tdb_context *tdb,
tally_add(data, rec_data_length(&p->u)); tally_add(data, rec_data_length(&p->u));
} }
tally_add(extra, rec_extra_padding(&p->u)); tally_add(extra, rec_extra_padding(&p->u));
} } else
len = dead_space(tdb, off);
} }
if (unc) if (unc)
tally_add(uncoal, unc); tally_add(uncoal, unc);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment