Additional span logging of counter state; trace logging of contents.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk
2025-07-29 22:42:10 +00:00
parent 59b62b1453
commit 1bb16c8b73
9 changed files with 101 additions and 19 deletions

View File

@@ -2,8 +2,7 @@
use std::{
collections::VecDeque,
fmt::Debug,
ops::Deref,
ops::{Deref, Range},
sync::{Arc, RwLock},
};
@@ -23,14 +22,12 @@ use crate::{Result, checked, is_equal_to};
/// value, but that value has no Pdu found because its write has not been
/// completed with global visibility. Client-sync will then move on to the next
/// counter value having missed the data from the current one.
#[derive(Debug)]
pub struct Counter<F: Fn(u64) -> Result + Sync> {
/// Self is intended to be Arc<Counter> with inner state mutable via Lock.
inner: RwLock<State<F>>,
}
/// Inner protected state for Two-Phase Counter.
#[derive(Debug)]
pub struct State<F: Fn(u64) -> Result + Sync> {
/// Monotonic counter. The next sequence number is drawn by adding one to
/// this value. That number will be persisted and added to `pending`.
@@ -50,7 +47,6 @@ pub struct State<F: Fn(u64) -> Result + Sync> {
release: F,
}
#[derive(Debug)]
pub struct Permit<F: Fn(u64) -> Result + Sync> {
/// Link back to the shared-state.
state: Arc<Counter<F>>,
@@ -80,6 +76,17 @@ impl<F: Fn(u64) -> Result + Sync> Counter<F> {
Ok(Permit::<F> { state: self.clone(), retired, id })
}
/// Load the current and dispatched values simultaneously
#[inline]
pub fn range(&self) -> Range<u64> {
let inner = self.inner.read().expect("locked for reading");
Range {
start: inner.retired(),
end: inner.dispatched,
}
}
/// Load the highest sequence number safe for reading, also known as the
/// retirement value with writes "globally visible."
#[inline]