use std::collections::{BTreeMap, BTreeSet};
use std::time::Instant;
use nodedb_cluster::calvin::types::SequencedTxn;
use crate::control::cluster::calvin::scheduler::lock_manager::LockKey;
use crate::types::TenantId;
use nodedb_physical::physical_plan::meta::PassiveReadKeyId;
use nodedb_types::Value;
#[derive(Debug)]
pub struct ReadResultEvent {
pub epoch: u64,
pub position: u32,
pub passive_vshard: u32,
pub tenant_id: TenantId,
pub values: Vec<(PassiveReadKeyId, Value)>,
}
pub struct PendingDependentBarrier {
pub txn: SequencedTxn,
pub keys: BTreeSet<LockKey>,
pub lock_acquired_time: Instant,
pub waiting_for: BTreeSet<u32>,
pub received: BTreeMap<u32, Vec<(PassiveReadKeyId, Value)>>,
pub timeout_at: Instant,
}
impl PendingDependentBarrier {
pub fn is_complete(&self) -> bool {
self.waiting_for.is_empty()
}
pub fn assemble_injected_reads(&self) -> BTreeMap<PassiveReadKeyId, Value> {
let mut out = BTreeMap::new();
for values in self.received.values() {
for (key_id, value) in values {
out.insert(key_id.clone(), value.clone());
}
}
out
}
pub fn is_timed_out(&self) -> bool {
Instant::now() > self.timeout_at }
}