use nodedb_physical::physical_plan::meta::PassiveReadKeyId;
use nodedb_types::Value;
use crate::data::executor::core_loop::CoreLoop;
use crate::types::TenantId;
impl CoreLoop {
pub(super) fn read_passive_key(
&self,
tenant_id: &TenantId,
engine_key: &nodedb_cluster::calvin::types::EngineKeySet,
) -> Vec<(PassiveReadKeyId, Value)> {
use nodedb_cluster::calvin::types::EngineKeySet;
match engine_key {
EngineKeySet::Document {
collection,
surrogates,
}
| EngineKeySet::Vector {
collection,
surrogates,
} => surrogates
.iter()
.map(|&surrogate| {
let value = self
.read_surrogate_value(tenant_id, collection, surrogate)
.unwrap_or(Value::Null);
(
PassiveReadKeyId {
collection: collection.clone(),
surrogate,
},
value,
)
})
.collect(),
EngineKeySet::Kv { collection, keys } => keys
.iter()
.map(|k| {
let value = self
.read_kv_value(tenant_id, collection, k)
.unwrap_or(Value::Null);
let key_hash = stable_kv_hash(k);
(
PassiveReadKeyId {
collection: collection.clone(),
surrogate: key_hash,
},
value,
)
})
.collect(),
EngineKeySet::Edge {
collection, edges, ..
} => edges
.iter()
.map(|&(src, dst)| {
let edge_hash = stable_edge_hash(src, dst);
(
PassiveReadKeyId {
collection: collection.clone(),
surrogate: edge_hash,
},
Value::Null, )
})
.collect(),
}
}
pub(super) fn read_surrogate_value(
&self,
tenant_id: &TenantId,
collection: &str,
surrogate: u32,
) -> Option<Value> {
let _ = (tenant_id, collection, surrogate);
None
}
pub(super) fn read_kv_value(
&self,
tenant_id: &TenantId,
collection: &str,
key: &[u8],
) -> Option<Value> {
let _ = (tenant_id, collection, key);
None
}
}
fn stable_kv_hash(key: &[u8]) -> u32 {
const FNV_OFFSET: u32 = 2_166_136_261;
const FNV_PRIME: u32 = 16_777_619;
let mut hash = FNV_OFFSET;
for &byte in key {
hash ^= u32::from(byte);
hash = hash.wrapping_mul(FNV_PRIME);
}
hash
}
fn stable_edge_hash(src: u32, dst: u32) -> u32 {
let combined: u64 = (u64::from(src) << 32) | u64::from(dst);
stable_kv_hash(&combined.to_le_bytes())
}