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;
}
err = reftable_stack_auto_compact(st);
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, <,
- (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);
clear_dir(dir);
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");