Skip to main content

zlayer_types/api/
edge_cache.rs

1//! Edge-cache eligibility API DTOs.
2//!
3//! Wire types for the edge-cache eligibility endpoints exposed by
4//! `zlayer-api` and consumed by upstream control-plane callers (the
5//! consuming cluster manager). The host-side cache fill,
6//! eviction, hit-counting subsystem is out of scope here — these types
7//! describe only the API surface used to mark a node eligible or
8//! ineligible for edge caching and to read placeholder hit/miss counters.
9
10use serde::{Deserialize, Serialize};
11use utoipa::ToSchema;
12
13/// Per-node capacity advertised when registering for edge-cache eligibility.
14///
15/// Mirrors `zlayer_overlay::edge_cache::NodeCapacity` 1:1 over the wire.
16#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
17pub struct NodeCapacityDto {
18    /// Number of CPU cores the node is willing to dedicate to cache work.
19    pub cpu_cores: u32,
20    /// Resident memory (MiB) the node will allow the cache to occupy.
21    pub ram_mib: u64,
22    /// On-disk cache budget (MiB).
23    pub disk_mib: u64,
24    /// Optional geo / region label (e.g. `"us-east-1"`) used by future
25    /// placement decisions. `None` means "no geo preference declared".
26    #[serde(default)]
27    pub geo: Option<String>,
28}
29
30/// Body for `POST /api/v1/nodes/{node_id}/edge-cache`.
31#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
32pub struct EnableEdgeCacheRequest {
33    /// Capacity this node is willing to contribute to the edge cache.
34    pub capacity: NodeCapacityDto,
35}
36
37/// Response body for `GET /api/v1/nodes/{node_id}/edge-cache/stats`.
38///
39/// Stats are placeholders that always report zeroes today — the real
40/// hit/miss counters land in the follow-on cache subsystem. The endpoint
41/// exists now so upstream integration tests (Zatabase Wave 1.3.3.7) can
42/// build against a stable shape.
43#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
44pub struct EdgeCacheStatsResponse {
45    /// Total cache hits observed for this node since registration.
46    pub hits: u64,
47    /// Total cache misses observed for this node since registration.
48    pub misses: u64,
49}