fix(consensus-db): count a decided-block write once in DB metrics (#142) - #228
fix(consensus-db): count a decided-block write once in DB metrics (#142)#228devorun wants to merge 2 commits into
Conversation
insert_decided_block timed and reported the whole method, including the insert_certificate call, while insert_certificate also reported its own write via update_write_metrics. Because update_write_metrics both observes write_time and increments write_count (through add_write_bytes), every decided block was counted as two writes: the certificate's write_time was observed twice and write_count incremented twice. Give the committing method sole ownership of the metrics. insert_certificate now returns the number of bytes written and records nothing; it runs inside the caller's transaction and never commits on its own. insert_decided_block sums block and certificate bytes and reports a single write that also covers the commit. extend_certificate keeps recording its own single write. A decided block is now counted exactly once. Add a regression test asserting store_decided_block increments write_count by exactly one. Fixes circlefin#142
|
Read the full diff plus the surrounding 1. let start = Instant::now();
let write_bytes = self.insert_certificate(...)?;
let write_time = start.elapsed(); // <-- clock stops here
tx.commit()?; // <-- durable-write cost excluded
self.update_write_metrics(write_bytes, write_time);Meanwhile 2. Test is well-targeted; consider one cheap extension. Minor observations, no action needed: the With the |
Address review on circlefin#142: extend_certificate stopped its timer before tx.commit(), excluding redb's durable-write (fsync) cost -- the dominant term -- so it fed write_time with a narrower scope than insert_decided_block. Record write_time after the commit so both write paths share one scope. Also add a regression test for extend_certificate asserting write_count increments by exactly one, mirroring the decided-block test.
|
Thanks for the careful read — both points were spot on. 1. Fixed in 2. Added |
|
Verified both at On your open question — keep Nothing further from me — once CI is green and this leaves draft, it's a clean fix for #142 that also leaves the metrics ownership rule documented where the next contributor will trip over it. Nice turnaround. |
|
Appreciate the thorough review — and the confirmation on the timer placement. Marking this ready for review. |
Summary
Fixes #142.
insert_decided_blocktimed and reported the entire method — including theinsert_certificatecall — whileinsert_certificatealso reported its own write throughupdate_write_metrics. Sinceupdate_write_metricsboth observeswrite_timeand incrementswrite_count(viaadd_write_bytes), every decided block was counted as two writes: the certificate'swrite_timewas observed twice andwrite_countincremented twice, overstating both DB write latency and write throughput.Fix
Give the committing method sole ownership of the write metrics:
insert_certificatenow returns the number of bytes written and records no metrics itself. It runs inside the caller's write transaction and never commits on its own, so it should not be reported as an independent write.insert_decided_blocksums block + certificate bytes and emits a singleupdate_write_metricscall that also covers the commit (the real cost of the durable write).extend_certificate— the otherinsert_certificatecaller — now records its own single write, preserving its previous behavior.Net effect: a decided block (block + certificate committed in one transaction) is counted exactly once.
Test
Adds
store_decided_block_counts_a_single_write, assertingwrite_countincreases by exactly one across astore_decided_blockcall (previously two). Uses the existing test harness (tempdir,arbitrary_payload) plus a small test-onlyDbMetrics::write_count()accessor.Notes
insert_certificateis a private method with two in-crate callers, both updated.