fix(dump): detect sparse absolute persistence loss

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
This commit is contained in:
Martin Vogel committed 2026-08-27 10:15:09 +02:00
1 parent 909051ccee
commit ffc29f73bb
3 files changed
+15 -4

No files matched your search

+6 -3
View File
@@ -17,12 +17,15 @@ bool cbm_dump_verify_is_degraded(int committed_nodes, int persisted_nodes, doubl
if (committed_nodes < 0) {
return false;
}
if (committed_nodes <= min_floor) {
return false;
}
if (persisted_nodes < 0) {
return true;
}
if (committed_nodes > 0 && persisted_nodes == 0) {
return true;
}
if (committed_nodes <= min_floor) {
return false;
}
return (double)persisted_nodes < (double)committed_nodes * ratio;
}
+2 -1
View File
@@ -20,7 +20,8 @@ enum { CBM_DUMP_VERIFY_MIN_FLOOR = 50 };
* True when persisted_nodes is implausibly below committed_nodes.
*
* Returns false when ratio <= 0 (gate disabled), committed_nodes < 0 (no dump),
* committed_nodes <= min_floor (sparse repo), or persisted >= committed * ratio.
* or persisted >= committed * ratio. Sparse repositories skip the ratio gate,
* but complete persistence loss is degraded for every positive committed count.
* Returns true when persisted_nodes < 0 (count error).
*/
bool cbm_dump_verify_is_degraded(int committed_nodes, int persisted_nodes, double ratio,
+7
View File
@@ -22,6 +22,11 @@ TEST(dump_verify_sparse_at_floor) {
PASS();
}
TEST(dump_verify_sparse_zero_persisted) {
ASSERT_TRUE(cbm_dump_verify_is_degraded(12, 0, 0.5, CBM_DUMP_VERIFY_MIN_FLOOR));
PASS();
}
TEST(dump_verify_shortfall_below_ratio) {
ASSERT_TRUE(cbm_dump_verify_is_degraded(1000, 400, 0.5, CBM_DUMP_VERIFY_MIN_FLOOR));
PASS();
@@ -54,6 +59,7 @@ TEST(dump_verify_count_error) {
TEST(dump_verify_ratio_zero_disables) {
ASSERT_FALSE(cbm_dump_verify_is_degraded(1000, 10, 0.0, CBM_DUMP_VERIFY_MIN_FLOOR));
ASSERT_FALSE(cbm_dump_verify_is_degraded(12, 0, 0.0, CBM_DUMP_VERIFY_MIN_FLOOR));
PASS();
}
@@ -76,6 +82,7 @@ TEST(dump_verify_edges_shrank_nodes_ok) {
SUITE(dump_verify) {
RUN_TEST(dump_verify_no_baseline);
RUN_TEST(dump_verify_sparse_at_floor);
RUN_TEST(dump_verify_sparse_zero_persisted);
RUN_TEST(dump_verify_shortfall_below_ratio);
RUN_TEST(dump_verify_just_above_ratio);
RUN_TEST(dump_verify_just_below_ratio);