summaryrefslogtreecommitdiffstats
path: root/src/state
diff options
context:
space:
mode:
Diffstat (limited to 'src/state')
-rw-r--r--src/state/mod.rs13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/state/mod.rs b/src/state/mod.rs
index a51339c..962d62a 100644
--- a/src/state/mod.rs
+++ b/src/state/mod.rs
@@ -29,7 +29,7 @@ use tokio::sync::{Mutex, RwLock, broadcast, mpsc, watch};
use tokio::time::Instant;
use tracing::{debug, error, warn};
-use crate::document::replica::{Epoch, Replica};
+use crate::document::replica::{Epoch, Replica, Stamp};
use crate::locks::MutexExt;
use crate::remake::{Host, RemakeState};
use crate::swarm::sync::{ChangeSet, SyncEvent};
@@ -52,6 +52,8 @@ pub(crate) struct AppState {
/// Copy of `doc.epoch` for cheap, lock-free reads (handshakes, keepalives, /peers).
/// Only ever changed while holding `doc`'s write lock, together with `doc.epoch`.
pub(crate) epoch_tx: watch::Sender<Epoch>,
+ /// `doc`'s epoch label and heads, readable without its lock (`Replica::stamps`).
+ pub(crate) stamp: watch::Receiver<Stamp>,
pub(crate) lifecycle: Arc<RwLock<NodeLifecycle>>,
@@ -186,10 +188,11 @@ impl AppState {
*self.epoch_tx.borrow()
}
- /// The local epoch and `Replica::epoch_seq`, read together.
- pub(crate) async fn epoch_stamp(&self) -> (Epoch, u32) {
- let replica = self.doc.read().await;
- (replica.epoch, replica.epoch_seq)
+ /// The local epoch and `Replica::epoch_seq`, read together, without waiting for the
+ /// document's lock.
+ pub(crate) fn epoch_stamp(&self) -> (Epoch, u32) {
+ let stamp = self.stamp.borrow();
+ (stamp.epoch, stamp.epoch_seq)
}
pub(crate) async fn is_ready(&self) -> bool {