use crate::bridge::envelope::Response;
use crate::data::executor::core_loop::CoreLoop;
use crate::data::executor::handlers::transaction::overlay::{Staged, StagedTtl};
use crate::data::executor::handlers::transaction::stage_write::hex_key;
use crate::data::executor::task::ExecutionTask;
use crate::engine::kv::current_ms;
use nodedb_types::Surrogate;
impl CoreLoop {
pub(in crate::data::executor) fn overlay_point_lookup(
&self,
task: &ExecutionTask,
tid: u64,
collection: &str,
document_id: &str,
surrogate: Surrogate,
) -> Option<Result<Vec<u8>, Response>> {
let txn_id = task.request.txn_id?;
self.touch_overlay(txn_id);
let coll_key = (
task.request.database_id,
crate::types::TenantId::new(tid),
collection.to_string(),
);
let overlay = self.txn_overlays.get(&txn_id)?;
let staged = overlay
.get_by_doc_id(&coll_key, document_id)
.or_else(|| overlay.get(&coll_key, surrogate.0))?;
match staged {
Staged::Put(body) => Some(Ok(body.clone())),
Staged::Tombstone => Some(Err(self.response_with_payload(task, Vec::new()))),
}
}
pub(in crate::data::executor) fn kv_overlay_body(
&self,
task: &ExecutionTask,
tid: u64,
collection: &str,
key: &[u8],
) -> Option<Option<Vec<u8>>> {
let txn_id = task.request.txn_id?;
self.touch_overlay(txn_id);
let coll_key = (
task.request.database_id,
crate::types::TenantId::new(tid),
collection.to_string(),
);
let doc_id = hex_key(key);
let overlay = self.txn_overlays.get(&txn_id)?;
if matches!(
overlay.get_ttl_by_doc_id(&coll_key, &doc_id),
Some(StagedTtl::ExpireAt(t)) if t <= current_ms()
) {
return Some(None);
}
let staged = overlay.get_by_doc_id(&coll_key, &doc_id)?;
Some(match staged {
Staged::Put(body) => Some(body.clone()),
Staged::Tombstone => None,
})
}
}