use std::sync::{Arc, Mutex};
use crate::layout::manifest::BlockTables;
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct BatchRows {
pub request_ids: Vec<String>,
pub request_pool_indices: Vec<i32>,
pub input_lengths: Vec<i32>,
pub prefill_lengths: Vec<i32>,
pub extend_prefix_lens: Vec<i32>,
pub state_prefix_cached: Vec<bool>,
pub decode_input_ids: Vec<i32>,
pub spec_candidate_ids: Vec<Vec<i32>>,
pub num_extends: usize,
pub tables: BlockTables,
}
#[derive(Debug, Clone, Default)]
pub(crate) struct Staged(Arc<Mutex<Option<BatchRows>>>);
impl Staged {
pub(crate) fn stage(&self, rows: BatchRows) -> Result<(), String> {
let mut staged = self.0.lock().expect("the staging lock is poisoned");
if staged.is_some() {
return Err(
"a plan's remote stream was staged before the previous was handed over".to_owned(),
);
}
*staged = Some(rows);
Ok(())
}
pub(crate) fn take(&self) -> Result<BatchRows, String> {
self.0
.lock()
.expect("the staging lock is poisoned")
.take()
.ok_or_else(|| {
"the data plane handed over a remote stream the plan has none of".to_owned()
})
}
pub(crate) fn is_pending(&self) -> bool {
self.0
.lock()
.expect("the staging lock is poisoned")
.is_some()
}
}