Skip to content

Commit e879524

Browse files
Chandra Pratapgitster
authored andcommitted
t-reftable-stack: add test for non-default compaction factor
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]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1052280 commit e879524

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

t/unit-tests/t-reftable-stack.c

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -831,12 +831,12 @@ static void t_empty_add(void)
831831
reftable_stack_destroy(st2);
832832
}
833833

834-
static int fastlog2(uint64_t sz)
834+
static int fastlogN(uint64_t sz, uint64_t N)
835835
{
836836
int l = 0;
837837
if (sz == 0)
838838
return 0;
839-
for (; sz; sz /= 2)
839+
for (; sz; sz /= N)
840840
l++;
841841
return l - 1;
842842
}
@@ -869,11 +869,43 @@ static void t_reftable_stack_auto_compaction(void)
869869

870870
err = reftable_stack_auto_compact(st);
871871
check(!err);
872-
check(i < 3 || st->merged->readers_len < 2 * fastlog2(i));
872+
check(i < 2 || st->merged->readers_len < 2 * fastlogN(i, 2));
873873
}
874874

875875
check_int(reftable_stack_compaction_stats(st)->entries_written, <,
876-
(uint64_t)(N * fastlog2(N)));
876+
(uint64_t)(N * fastlogN(N, 2)));
877+
878+
reftable_stack_destroy(st);
879+
clear_dir(dir);
880+
}
881+
882+
static void t_reftable_stack_auto_compaction_factor(void)
883+
{
884+
struct reftable_write_options opts = {
885+
.auto_compaction_factor = 5,
886+
};
887+
struct reftable_stack *st = NULL;
888+
char *dir = get_tmp_dir(__LINE__);
889+
int err;
890+
size_t N = 100;
891+
892+
err = reftable_new_stack(&st, dir, &opts);
893+
check(!err);
894+
895+
for (size_t i = 0; i < N; i++) {
896+
char name[20];
897+
struct reftable_ref_record ref = {
898+
.refname = name,
899+
.update_index = reftable_stack_next_update_index(st),
900+
.value_type = REFTABLE_REF_VAL1,
901+
};
902+
xsnprintf(name, sizeof(name), "branch%04"PRIuMAX, (uintmax_t)i);
903+
904+
err = reftable_stack_add(st, &write_test_ref, &ref);
905+
check(!err);
906+
907+
check(i < 5 || st->merged->readers_len < 5 * fastlogN(i, 5));
908+
}
877909

878910
reftable_stack_destroy(st);
879911
clear_dir(dir);
@@ -1186,6 +1218,7 @@ int cmd_main(int argc UNUSED, const char *argv[] UNUSED)
11861218
TEST(t_reftable_stack_add_one(), "add a single ref record to stack");
11871219
TEST(t_reftable_stack_add_performs_auto_compaction(), "addition to stack triggers auto-compaction");
11881220
TEST(t_reftable_stack_auto_compaction(), "stack must form geometric sequence after compaction");
1221+
TEST(t_reftable_stack_auto_compaction_factor(), "auto-compaction with non-default geometric factor");
11891222
TEST(t_reftable_stack_auto_compaction_fails_gracefully(), "failure on auto-compaction");
11901223
TEST(t_reftable_stack_auto_compaction_with_locked_tables(), "auto compaction with locked tables");
11911224
TEST(t_reftable_stack_compaction_concurrent(), "compaction with concurrent stack");

0 commit comments

Comments
 (0)