use std::sync::atomic::Ordering;
use super::TransactionContext;
use crate::types::*;
use linkrs_core::types::CommitLsn;
impl TransactionContext {
pub fn drain_budget_warnings(&self) -> Vec<TransactionEvent> {
std::mem::take(&mut *self.budget_warnings.lock())
}
pub fn pending_budget_warnings(&self) -> usize {
self.budget_warnings.lock().len()
}
pub fn staged_bytes(&self) -> u64 {
self.staged_bytes.load(Ordering::Relaxed)
}
pub fn mark_commit_published(&self, commit_lsn: CommitLsn) {
self.commit_lsn.store(commit_lsn.get(), Ordering::Release);
self.commit_published.store(true);
}
pub fn commit_published(&self) -> bool {
self.commit_published.load()
}
pub fn commit_lsn(&self) -> CommitLsn {
CommitLsn::new(self.commit_lsn.load(Ordering::Acquire))
}
pub fn add_staged_bytes(&self, bytes: u64) {
self.staged_bytes.fetch_add(bytes, Ordering::Relaxed);
}
pub fn increment_query_count(&self) {
self.query_count.fetch_add(1, Ordering::Relaxed);
}
pub fn query_count(&self) -> u64 {
self.query_count.load(Ordering::Relaxed)
}
pub fn schema_catalog_version(&self) -> u64 {
self.schema_catalog_version.load(Ordering::Relaxed)
}
pub fn bump_schema_catalog_version(&self) -> u64 {
self.schema_catalog_version.fetch_add(1, Ordering::Relaxed) + 1
}
pub fn set_pessimistic_lock(&self) {
self.pessimistic_lock_held.store(true);
}
pub fn has_pessimistic_lock(&self) -> bool {
self.pessimistic_lock_held.load()
}
pub fn clear_pessimistic_lock(&self) {
self.pessimistic_lock_held.store(false);
}
}