git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v6 5/6] t-reftable-stack: add test for non-default compaction factor

From
CPChandra Pratap <chandrapratap3519@gmail.com>
Date
Sep 8, 2024, 04:06 UTC
Message-ID
<20240908041632.4948-6-chandrapratap3519@gmail.com>
In-Reply-To
<20240908041632.4948-1-chandrapratap3519@gmail.com>

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>
---
 t/unit-tests/t-reftable-stack.c | 41 +++++++++++++++++++++++++++++----
 1 file changed, 37 insertions(+), 4 deletions(-)
diff --git a/t/unit-tests/t-reftable-stack.c b/t/unit-tests/t-reftable-stack.c
index 4f2ef1a8cc..4acf07ab0c 100644
--- a/t/unit-tests/t-reftable-stack.c
+++ b/t/unit-tests/t-reftable-stack.c
@@ -831,12 +831,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;
 }
@@ -869,11 +869,43 @@ static void t_reftable_stack_auto_compaction(void)
 
 		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);
@@ -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_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");
-- 
2.45.GIT
Previous: Patrick SteinhardtNext: Chandra Pratap
Message 70 of 72 in “t: port reftable/stack_test.c to the unit testing framework”
  1. Chandra PratapAug 6, 2024
  2. 1/6 t: move reftable/stack_test.c to the unit testing frameworkChandra Pratap, Aug 6, 2024
  3. 2/6 t: harmonize t-reftable-stack.c with coding guidelinesChandra Pratap, Aug 6, 2024
  4. Eric SunshineAug 6, 2024
  5. Patrick SteinhardtAug 7, 2024
  6. 3/6 t-reftable-stack: use Git's tempfile API instead of mkstemp()Chandra Pratap, Aug 6, 2024
  7. Junio C HamanoAug 6, 2024
  8. Patrick SteinhardtAug 7, 2024
  9. 4/6 t-reftable-stack: use reftable_ref_record_equal() to compare ref recordsChandra Pratap, Aug 6, 2024
  10. Patrick SteinhardtAug 7, 2024
  11. Chandra PratapAug 7, 2024
  12. Patrick SteinhardtAug 8, 2024
  13. 5/6 t-reftable-stack: add test for non-default compaction factorChandra Pratap, Aug 6, 2024
  14. 6/6 t-reftable-stack: add test for stack iteratorsChandra Pratap, Aug 6, 2024
  15. Patrick SteinhardtAug 7, 2024
  16. Junio C HamanoAug 6, 2024
  17. Chandra PratapAug 7, 2024
  18. [GSoC][PATCH v2 0/6] t: port reftable/stack_test.c to the unit testing frameworkChandra Pratap, Aug 23, 2024
  19. 1/6 t: move reftable/stack_test.c to the unit testing frameworkChandra Pratap, Aug 23, 2024
  20. 2/6 t: harmonize t-reftable-stack.c with coding guidelinesChandra Pratap, Aug 23, 2024
  21. Patrick SteinhardtAug 26, 2024
  22. 3/6 t-reftable-stack: use Git's tempfile API instead of mkstemp()Chandra Pratap, Aug 23, 2024
  23. 4/6 t-reftable-stack: use reftable_ref_record_equal() to compare ref recordsChandra Pratap, Aug 23, 2024
  24. 5/6 t-reftable-stack: add test for non-default compaction factorChandra Pratap, Aug 23, 2024
  25. 6/6 t-reftable-stack: add test for stack iteratorsChandra Pratap, Aug 23, 2024
  26. Patrick SteinhardtAug 26, 2024
  27. [GSoC][PATCH v3 0/6] t: port reftable/stack_test.c to the unit testing frameworkChandra Pratap, Aug 26, 2024
  28. 1/6 t: move reftable/stack_test.c to the unit testing frameworkChandra Pratap, Aug 26, 2024
  29. 2/6 t: harmonize t-reftable-stack.c with coding guidelinesChandra Pratap, Aug 26, 2024
  30. 3/6 t-reftable-stack: use Git's tempfile API instead of mkstemp()Chandra Pratap, Aug 26, 2024
  31. 4/6 t-reftable-stack: use reftable_ref_record_equal() to compare ref recordsChandra Pratap, Aug 26, 2024
  32. 5/6 t-reftable-stack: add test for non-default compaction factorChandra Pratap, Aug 26, 2024
  33. 6/6 t-reftable-stack: add test for stack iteratorsChandra Pratap, Aug 26, 2024
  34. Junio C HamanoAug 26, 2024
  35. Chandra PratapAug 26, 2024
  36. Junio C HamanoAug 26, 2024
  37. Junio C HamanoAug 26, 2024
  38. [GSoC][PATCH v4 0/6] t: port reftable/stack_test.c to the unit testing frameworkChandra Pratap, Sep 4, 2024
  39. 1/6 t: move reftable/stack_test.c to the unit testing frameworkChandra Pratap, Sep 4, 2024
  40. Junio C HamanoSep 4, 2024
  41. Patrick SteinhardtSep 5, 2024
  42. Chandra PratapSep 5, 2024
  43. Patrick SteinhardtSep 5, 2024
  44. Junio C HamanoSep 5, 2024
  45. Patrick SteinhardtSep 6, 2024
  46. 2/6 t: harmonize t-reftable-stack.c with coding guidelinesChandra Pratap, Sep 4, 2024
  47. 3/6 t-reftable-stack: use Git's tempfile API instead of mkstemp()Chandra Pratap, Sep 4, 2024
  48. Patrick SteinhardtSep 5, 2024
  49. 4/6 t-reftable-stack: use reftable_ref_record_equal() to compare ref recordsChandra Pratap, Sep 4, 2024
  50. Patrick SteinhardtSep 5, 2024
  51. 5/6 t-reftable-stack: add test for non-default compaction factorChandra Pratap, Sep 4, 2024
  52. 6/6 t-reftable-stack: add test for stack iteratorsChandra Pratap, Sep 4, 2024
  53. Patrick SteinhardtSep 5, 2024
  54. [GSoC][PATCH v5 0/7] t: port reftable/stack_test.c to the unit testing frameworkChandra Pratap, Sep 6, 2024
  55. 1/7 t: move reftable/stack_test.c to the unit testing frameworkChandra Pratap, Sep 6, 2024
  56. 2/7 t: harmonize t-reftable-stack.c with coding guidelinesChandra Pratap, Sep 6, 2024
  57. 3/7 t-reftable-stack: use Git's tempfile API instead of mkstemp()Chandra Pratap, Sep 6, 2024
  58. 4/7 t-reftable-stack: use reftable_ref_record_equal() to compare ref recordsChandra Pratap, Sep 6, 2024
  59. 5/7 t-reftable-stack: add test for non-default compaction factorChandra Pratap, Sep 6, 2024
  60. 6/7 t-reftable-stack: add test for stack iteratorsChandra Pratap, Sep 6, 2024
  61. 7/7 t: clean up leftover reftable test cruftChandra Pratap, Sep 6, 2024
  62. Junio C HamanoSep 6, 2024
  63. Junio C HamanoSep 6, 2024
  64. [GSoC][PATCH v6 0/6] t: port reftable/stack_test.c to the unit testing frameworkChandra Pratap, Sep 8, 2024
  65. 1/6 t: move reftable/stack_test.c to the unit testing frameworkChandra Pratap, Sep 8, 2024
  66. 2/6 t: harmonize t-reftable-stack.c with coding guidelinesChandra Pratap, Sep 8, 2024
  67. 3/6 t-reftable-stack: use Git's tempfile API instead of mkstemp()Chandra Pratap, Sep 8, 2024
  68. 4/6 t-reftable-stack: use reftable_ref_record_equal() to compare ref recordsChandra Pratap, Sep 8, 2024
  69. Patrick SteinhardtSep 9, 2024
  70. 5/6 t-reftable-stack: add test for non-default compaction factorChandra Pratap, Sep 8, 2024
  71. 6/6 t-reftable-stack: add test for stack iteratorsChandra Pratap, Sep 8, 2024
  72. Patrick SteinhardtSep 9, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.