Skip to content

Commit ffc29f7

Browse files
committed
fix(dump): detect sparse absolute persistence loss
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 909051c commit ffc29f7

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

‎src/foundation/dump_verify.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@ bool cbm_dump_verify_is_degraded(int committed_nodes, int persisted_nodes, doubl
1717
if (committed_nodes < 0) {
1818
return false;
1919
}
20-
if (committed_nodes <= min_floor) {
21-
return false;
22-
}
2320
if (persisted_nodes < 0) {
2421
return true;
2522
}
23+
if (committed_nodes > 0 && persisted_nodes == 0) {
24+
return true;
25+
}
26+
if (committed_nodes <= min_floor) {
27+
return false;
28+
}
2629
return (double)persisted_nodes < (double)committed_nodes * ratio;
2730
}
2831

‎src/foundation/dump_verify.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ enum { CBM_DUMP_VERIFY_MIN_FLOOR = 50 };
2020
* True when persisted_nodes is implausibly below committed_nodes.
2121
*
2222
* Returns false when ratio <= 0 (gate disabled), committed_nodes < 0 (no dump),
23-
* committed_nodes <= min_floor (sparse repo), or persisted >= committed * ratio.
23+
* or persisted >= committed * ratio. Sparse repositories skip the ratio gate,
24+
* but complete persistence loss is degraded for every positive committed count.
2425
* Returns true when persisted_nodes < 0 (count error).
2526
*/
2627
bool cbm_dump_verify_is_degraded(int committed_nodes, int persisted_nodes, double ratio,

‎tests/test_dump_verify.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ TEST(dump_verify_sparse_at_floor) {
2222
PASS();
2323
}
2424

25+
TEST(dump_verify_sparse_zero_persisted) {
26+
ASSERT_TRUE(cbm_dump_verify_is_degraded(12, 0, 0.5, CBM_DUMP_VERIFY_MIN_FLOOR));
27+
PASS();
28+
}
29+
2530
TEST(dump_verify_shortfall_below_ratio) {
2631
ASSERT_TRUE(cbm_dump_verify_is_degraded(1000, 400, 0.5, CBM_DUMP_VERIFY_MIN_FLOOR));
2732
PASS();
@@ -54,6 +59,7 @@ TEST(dump_verify_count_error) {
5459

5560
TEST(dump_verify_ratio_zero_disables) {
5661
ASSERT_FALSE(cbm_dump_verify_is_degraded(1000, 10, 0.0, CBM_DUMP_VERIFY_MIN_FLOOR));
62+
ASSERT_FALSE(cbm_dump_verify_is_degraded(12, 0, 0.0, CBM_DUMP_VERIFY_MIN_FLOOR));
5763
PASS();
5864
}
5965

@@ -76,6 +82,7 @@ TEST(dump_verify_edges_shrank_nodes_ok) {
7682
SUITE(dump_verify) {
7783
RUN_TEST(dump_verify_no_baseline);
7884
RUN_TEST(dump_verify_sparse_at_floor);
85+
RUN_TEST(dump_verify_sparse_zero_persisted);
7986
RUN_TEST(dump_verify_shortfall_below_ratio);
8087
RUN_TEST(dump_verify_just_above_ratio);
8188
RUN_TEST(dump_verify_just_below_ratio);

0 commit comments

Comments
 (0)