use nodedb_physical::physical_plan::{GraphOp, PhysicalPlan};
use nodedb_physical::physical_task::{PhysicalTask, PostSetOp};
use super::extract::weight_properties;
use crate::control::server::surrogate_exchange::assign_surrogate_routed;
use crate::control::state::SharedState;
use crate::types::{DatabaseId, TenantId, TraceId, VShardId};
#[derive(Clone, Copy)]
pub(super) struct EdgeRouteCtx<'a> {
pub state: &'a SharedState,
pub tenant_id: TenantId,
pub database_id: DatabaseId,
pub trace_id: TraceId,
pub collection: &'a str,
pub src: &'a str,
pub dst: &'a str,
}
pub(super) async fn push_edge_delete(
ctx: EdgeRouteCtx<'_>,
out: &mut Vec<PhysicalTask>,
label: String,
) -> crate::Result<()> {
let EdgeRouteCtx {
state,
tenant_id,
database_id,
trace_id,
collection,
src,
dst,
} = ctx;
let vsrc = VShardId::from_key(src.as_bytes());
let vdst = VShardId::from_key(dst.as_bytes());
let src_surrogate = assign_surrogate_routed(
state,
vsrc,
database_id,
tenant_id,
collection,
src.as_bytes(),
trace_id,
)
.await?;
let dst_surrogate = assign_surrogate_routed(
state,
vdst,
database_id,
tenant_id,
collection,
dst.as_bytes(),
trace_id,
)
.await?;
out.push(PhysicalTask {
tenant_id,
vshard_id: vsrc,
database_id,
plan: PhysicalPlan::Graph(GraphOp::EdgeDelete {
collection: collection.to_string(),
src_id: src.to_string(),
label,
dst_id: dst.to_string(),
src_surrogate,
dst_surrogate,
}),
post_set_op: PostSetOp::None,
txn_id: None,
});
Ok(())
}
pub(super) async fn push_edge_put(
ctx: EdgeRouteCtx<'_>,
out: &mut Vec<PhysicalTask>,
label: String,
weight: Option<f64>,
) -> crate::Result<()> {
let EdgeRouteCtx {
state,
tenant_id,
database_id,
trace_id,
collection,
src,
dst,
} = ctx;
let properties = match weight {
Some(w) => weight_properties(w),
None => Vec::new(),
};
let vsrc = VShardId::from_key(src.as_bytes());
let vdst = VShardId::from_key(dst.as_bytes());
let src_surrogate = assign_surrogate_routed(
state,
vsrc,
database_id,
tenant_id,
collection,
src.as_bytes(),
trace_id,
)
.await?;
let dst_surrogate = assign_surrogate_routed(
state,
vdst,
database_id,
tenant_id,
collection,
dst.as_bytes(),
trace_id,
)
.await?;
out.push(PhysicalTask {
tenant_id,
vshard_id: vsrc,
database_id,
plan: PhysicalPlan::Graph(GraphOp::EdgePut {
collection: collection.to_string(),
src_id: src.to_string(),
label,
dst_id: dst.to_string(),
properties,
src_surrogate,
dst_surrogate,
}),
post_set_op: PostSetOp::None,
txn_id: None,
});
Ok(())
}