t-reftable-stack: add test for non-default compaction factor
In a recent codebase update (commit ae8e378430, 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 <ps@pks.im> Mentored-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
1052280136
commit
e87952443a
@ -831,12 +831,12 @@ static void t_empty_add(void)
|
|||||||
reftable_stack_destroy(st2);
|
reftable_stack_destroy(st2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fastlog2(uint64_t sz)
|
static int fastlogN(uint64_t sz, uint64_t N)
|
||||||
{
|
{
|
||||||
int l = 0;
|
int l = 0;
|
||||||
if (sz == 0)
|
if (sz == 0)
|
||||||
return 0;
|
return 0;
|
||||||
for (; sz; sz /= 2)
|
for (; sz; sz /= N)
|
||||||
l++;
|
l++;
|
||||||
return l - 1;
|
return l - 1;
|
||||||
}
|
}
|
||||||
@ -869,11 +869,43 @@ static void t_reftable_stack_auto_compaction(void)
|
|||||||
|
|
||||||
err = reftable_stack_auto_compact(st);
|
err = reftable_stack_auto_compact(st);
|
||||||
check(!err);
|
check(!err);
|
||||||
check(i < 3 || st->merged->readers_len < 2 * fastlog2(i));
|
check(i < 2 || st->merged->readers_len < 2 * fastlogN(i, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
check_int(reftable_stack_compaction_stats(st)->entries_written, <,
|
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->readers_len < 5 * fastlogN(i, 5));
|
||||||
|
}
|
||||||
|
|
||||||
reftable_stack_destroy(st);
|
reftable_stack_destroy(st);
|
||||||
clear_dir(dir);
|
clear_dir(dir);
|
||||||
@ -1186,6 +1218,7 @@ int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
|
|||||||
TEST(t_reftable_stack_add_one(), "add a single ref record to stack");
|
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_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(), "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_fails_gracefully(), "failure on auto-compaction");
|
||||||
TEST(t_reftable_stack_auto_compaction_with_locked_tables(), "auto compaction with locked tables");
|
TEST(t_reftable_stack_auto_compaction_with_locked_tables(), "auto compaction with locked tables");
|
||||||
TEST(t_reftable_stack_compaction_concurrent(), "compaction with concurrent stack");
|
TEST(t_reftable_stack_compaction_concurrent(), "compaction with concurrent stack");
|
||||||
|
Reference in New Issue
Block a user