Skip to main content

ic_storage/runtime/
directory_model.rs

1//! Owned named-allocation directory and durable extent validation.
2pub(super) mod leases;
3mod persistence;
4
5use crate::StableKey;
6use serde::{Deserialize, Serialize};
7
8///
9/// `StorageConfig`
10///
11/// Resource ceilings checked when creating, opening and extending the directory.
12/// Physical page accounting includes reserved metadata and bucket slack.
13/// Table capacities are fixed when creating an image; reopening may impose
14/// smaller live-usage limits but cannot increase the image capacities.
15///
16
17#[derive(Clone, Copy, Debug)]
18pub struct StorageConfig {
19    /// Maximum retained named allocations, including currently omitted names.
20    pub allocations: usize,
21    /// Maximum allocated eight-page buckets across every allocation.
22    pub extents: usize,
23    /// Maximum physical backing extent, in 64 KiB Wasm pages.
24    pub pages: u64,
25}
26
27impl Default for StorageConfig {
28    fn default() -> Self {
29        Self {
30            allocations: 4_096,
31            extents: 16_384,
32            pages: 1_048_576,
33        }
34    }
35}
36
37///
38/// `AllocationId`
39///
40/// Opaque durable identity assigned by the directory. It grants no access.
41///
42
43#[derive(Clone, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)]
44pub struct AllocationId(u64);
45impl AllocationId {
46    /// Opaque diagnostic identity; callers cannot choose an allocation ID.
47    #[must_use]
48    pub const fn get(self) -> u64 {
49        self.0
50    }
51}
52
53#[derive(Debug, thiserror::Error)]
54pub enum Error {
55    /// Logical page count overflowed before any backing access.
56    #[error("allocation page count overflow")]
57    ArithmeticOverflow,
58    #[error("directory budget exceeded")]
59    Budget,
60    #[error("invalid directory: {0}")]
61    Invalid(&'static str),
62    #[error("allocation already has a live lease")]
63    AlreadyOpen,
64    #[error("access exceeds allocation bounds")]
65    Bounds,
66    #[error("backing already has a live owner")]
67    AlreadyClaimed,
68    #[error("allocation does not exist")]
69    Missing,
70    #[error("backing growth refused")]
71    Growth,
72    #[error("directory owner is poisoned after interrupted backing IO")]
73    Poisoned,
74}