Skip to content

Commit

Permalink
t-reftable-stack: add test for non-default compaction factor
Browse files Browse the repository at this point in the history
In a recent codebase update (commit ae8e378, merge branch
'ps/reftable-write-options', 2024/05/13) the geometric factor used
in auto-compaction of reftable tables was made configurable. Add
a test to verify the functionality introduced by this update.

Mentored-by: Patrick Steinhardt <[email protected]>
Mentored-by: Christian Couder <[email protected]>
Signed-off-by: Chandra Pratap <[email protected]>
  • Loading branch information
Chandra Pratap committed Aug 21, 2024
1 parent d771dc7 commit c38a96c
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions t/unit-tests/t-reftable-stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -837,12 +837,12 @@ static void t_empty_add(void)
reftable_stack_destroy(st2);
}

static int fastlog2(uint64_t sz)
static int fastlogN(uint64_t sz, uint64_t N)
{
int l = 0;
if (sz == 0)
return 0;
for (; sz; sz /= 2)
for (; sz; sz /= N)
l++;
return l - 1;
}
Expand Down Expand Up @@ -875,11 +875,43 @@ static void t_reftable_stack_auto_compaction(void)

err = reftable_stack_auto_compact(st);
check(!err);
check(i < 3 || st->merged->stack_len < 2 * fastlog2(i));
check(i < 2 || st->merged->stack_len < 2 * fastlogN(i, 2));
}

check_int(reftable_stack_compaction_stats(st)->entries_written, <,
(uint64_t)(N * fastlog2(N)));
(uint64_t)(N * fastlogN(N, 2)));

reftable_stack_destroy(st);
clear_dir(dir);
}

static void t_reftable_stack_auto_compaction_factor(void)
{
struct reftable_write_options opts = {
.auto_compaction_factor = 5,
};
struct reftable_stack *st = NULL;
char *dir = get_tmp_dir(__LINE__);
int err;
size_t N = 100;

err = reftable_new_stack(&st, dir, &opts);
check(!err);

for (size_t i = 0; i < N; i++) {
char name[20];
struct reftable_ref_record ref = {
.refname = name,
.update_index = reftable_stack_next_update_index(st),
.value_type = REFTABLE_REF_VAL1,
};
xsnprintf(name, sizeof(name), "branch%04"PRIuMAX, (uintmax_t)i);

err = reftable_stack_add(st, &write_test_ref, &ref);
check(!err);

check(i < 5 || st->merged->stack_len < 5 * fastlogN(i, 5));
}

reftable_stack_destroy(st);
clear_dir(dir);
Expand Down Expand Up @@ -1086,6 +1118,7 @@ int cmd_main(int argc, const char *argv[])
TEST(t_reftable_stack_add_one(), "add a single ref record to stack");
TEST(t_reftable_stack_add_performs_auto_compaction(), "addition to stack triggers auto-compaction");
TEST(t_reftable_stack_auto_compaction(), "stack must form geometric sequence after compaction");
TEST(t_reftable_stack_auto_compaction_factor(), "auto-compaction with non-default geometric factor");
TEST(t_reftable_stack_auto_compaction_fails_gracefully(), "failure on auto-compaction");
TEST(t_reftable_stack_auto_compaction_with_locked_tables(), "auto compaction with locked tables");
TEST(t_reftable_stack_compaction_concurrent(), "compaction with concurrent stack");
Expand Down

0 comments on commit c38a96c

Please sign in to comment.