[PATCH v2 3/3] reftable/segment: make segment end inclusive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Justin Tobler <jltobler@xxxxxxxxx>

For a reftable segment, the start of the range is inclusive and the end
is exclusive. In practice we increment the end when creating the
compaction segment only to decrement the segment end when using it.

Simplify by making the segment end inclusive. The corresponding test,
`test_suggest_compaction_segment()`, is updated to show that the segment
end is now inclusive.

Signed-off-by: Justin Tobler <jltobler@xxxxxxxxx>
---
 reftable/stack.c      | 4 ++--
 reftable/stack_test.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/reftable/stack.c b/reftable/stack.c
index ef55dc75cde..0c16ae9b12d 100644
--- a/reftable/stack.c
+++ b/reftable/stack.c
@@ -1243,7 +1243,7 @@ struct segment suggest_compaction_segment(uint64_t *sizes, size_t n)
 	 */
 	for (i = n - 1; i > 0; i--) {
 		if (sizes[i - 1] < sizes[i] * 2) {
-			seg.end = i + 1;
+			seg.end = i;
 			bytes = sizes[i];
 			break;
 		}
@@ -1292,7 +1292,7 @@ int reftable_stack_auto_compact(struct reftable_stack *st)
 		suggest_compaction_segment(sizes, st->merged->stack_len);
 	reftable_free(sizes);
 	if (segment_size(&seg) > 0)
-		return stack_compact_range_stats(st, seg.start, seg.end - 1,
+		return stack_compact_range_stats(st, seg.start, seg.end,
 						 NULL);
 
 	return 0;
diff --git a/reftable/stack_test.c b/reftable/stack_test.c
index e5f6ff5c9e4..85600a9573e 100644
--- a/reftable/stack_test.c
+++ b/reftable/stack_test.c
@@ -727,7 +727,7 @@ static void test_suggest_compaction_segment(void)
 	struct segment min =
 		suggest_compaction_segment(sizes, ARRAY_SIZE(sizes));
 	EXPECT(min.start == 1);
-	EXPECT(min.end == 10);
+	EXPECT(min.end == 9);
 }
 
 static void test_suggest_compaction_segment_nothing(void)
-- 
gitgitgadget




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux