Skip to main content

reddb_server/application/
native.rs

1use std::collections::BTreeMap;
2
3use crate::application::ports::RuntimeNativePort;
4use crate::health::HealthReport;
5use crate::physical::{ExportDescriptor, ManifestEvent, PhysicalMetadataFile, SnapshotDescriptor};
6use crate::storage::engine::PhysicalFileHeader;
7use crate::storage::unified::devx::{
8    NativeVectorArtifactBatchInspection, NativeVectorArtifactInspection, PhysicalAuthorityStatus,
9};
10use crate::storage::unified::store::{
11    NativeCatalogSummary, NativeManifestSummary, NativeMetadataStateSummary, NativePhysicalState,
12    NativeRecoverySummary, NativeRegistrySummary, NativeVectorArtifactPageSummary,
13};
14use crate::RedDBResult;
15
16#[derive(Debug, Clone)]
17pub struct InspectNativeArtifactInput {
18    pub collection: String,
19    pub artifact_kind: Option<String>,
20}
21
22#[derive(Debug, Clone, Copy, PartialEq, Eq)]
23pub struct RuntimeReadiness {
24    pub query: bool,
25    pub query_serverless: bool,
26    pub write: bool,
27    pub write_serverless: bool,
28    pub repair: bool,
29    pub repair_serverless: bool,
30}
31
32pub struct NativeUseCases<'a, P: ?Sized> {
33    runtime: &'a P,
34}
35
36impl<'a, P: RuntimeNativePort + ?Sized> NativeUseCases<'a, P> {
37    pub fn new(runtime: &'a P) -> Self {
38        Self { runtime }
39    }
40
41    pub fn collection_roots(&self) -> RedDBResult<BTreeMap<String, u64>> {
42        self.runtime.collection_roots()
43    }
44
45    pub fn health(&self) -> HealthReport {
46        self.runtime.health_report()
47    }
48
49    pub fn health_from_catalog(
50        &self,
51        catalog: &crate::catalog::CatalogModelSnapshot,
52    ) -> HealthReport {
53        self.runtime.health_report_from_catalog(catalog)
54    }
55
56    pub fn snapshots(&self) -> RedDBResult<Vec<SnapshotDescriptor>> {
57        self.runtime.snapshots()
58    }
59
60    pub fn exports(&self) -> RedDBResult<Vec<ExportDescriptor>> {
61        self.runtime.exports()
62    }
63
64    pub fn physical_metadata(&self) -> RedDBResult<PhysicalMetadataFile> {
65        self.runtime.physical_metadata()
66    }
67
68    pub fn manifest_events_filtered(
69        &self,
70        collection: Option<&str>,
71        kind: Option<&str>,
72        since_snapshot: Option<u64>,
73    ) -> RedDBResult<Vec<ManifestEvent>> {
74        self.runtime
75            .manifest_events_filtered(collection, kind, since_snapshot)
76    }
77
78    pub fn create_snapshot(&self) -> RedDBResult<SnapshotDescriptor> {
79        self.runtime.create_snapshot()
80    }
81
82    pub fn create_export(&self, name: String) -> RedDBResult<ExportDescriptor> {
83        self.runtime.create_export(name)
84    }
85
86    pub fn checkpoint(&self) -> RedDBResult<()> {
87        self.runtime.checkpoint()
88    }
89
90    pub fn apply_retention_policy(&self) -> RedDBResult<()> {
91        self.runtime.apply_retention_policy()
92    }
93
94    pub fn run_maintenance(&self) -> RedDBResult<()> {
95        self.runtime.run_maintenance()
96    }
97
98    pub fn native_header(&self) -> RedDBResult<PhysicalFileHeader> {
99        self.runtime.native_header()
100    }
101
102    pub fn native_collection_roots(&self) -> RedDBResult<BTreeMap<String, u64>> {
103        self.runtime.native_collection_roots()
104    }
105
106    pub fn native_manifest_summary(&self) -> RedDBResult<NativeManifestSummary> {
107        self.runtime.native_manifest_summary()
108    }
109
110    pub fn native_registry_summary(&self) -> RedDBResult<NativeRegistrySummary> {
111        self.runtime.native_registry_summary()
112    }
113
114    pub fn native_recovery_summary(&self) -> RedDBResult<NativeRecoverySummary> {
115        self.runtime.native_recovery_summary()
116    }
117
118    pub fn native_catalog_summary(&self) -> RedDBResult<NativeCatalogSummary> {
119        self.runtime.native_catalog_summary()
120    }
121
122    pub fn native_physical_state(&self) -> RedDBResult<NativePhysicalState> {
123        self.runtime.native_physical_state()
124    }
125
126    pub fn native_vector_artifact_pages(
127        &self,
128    ) -> RedDBResult<Vec<NativeVectorArtifactPageSummary>> {
129        self.runtime.native_vector_artifact_pages()
130    }
131
132    pub fn inspect_vector_artifact(
133        &self,
134        input: InspectNativeArtifactInput,
135    ) -> RedDBResult<NativeVectorArtifactInspection> {
136        self.runtime
137            .inspect_native_vector_artifact(&input.collection, input.artifact_kind.as_deref())
138    }
139
140    pub fn warmup_vector_artifact(
141        &self,
142        input: InspectNativeArtifactInput,
143    ) -> RedDBResult<NativeVectorArtifactInspection> {
144        self.runtime
145            .warmup_native_vector_artifact(&input.collection, input.artifact_kind.as_deref())
146    }
147
148    pub fn inspect_vector_artifacts(&self) -> RedDBResult<NativeVectorArtifactBatchInspection> {
149        self.runtime.inspect_native_vector_artifacts()
150    }
151
152    pub fn warmup_vector_artifacts(&self) -> RedDBResult<NativeVectorArtifactBatchInspection> {
153        self.runtime.warmup_native_vector_artifacts()
154    }
155
156    pub fn native_header_repair_policy(&self) -> RedDBResult<String> {
157        self.runtime.native_header_repair_policy()
158    }
159
160    pub fn repair_native_header_from_metadata(&self) -> RedDBResult<String> {
161        self.runtime.repair_native_header_from_metadata()
162    }
163
164    pub fn rebuild_physical_metadata_from_native_state(&self) -> RedDBResult<bool> {
165        self.runtime.rebuild_physical_metadata_from_native_state()
166    }
167
168    pub fn repair_native_physical_state_from_metadata(&self) -> RedDBResult<bool> {
169        self.runtime.repair_native_physical_state_from_metadata()
170    }
171
172    pub fn native_metadata_state_summary(&self) -> RedDBResult<NativeMetadataStateSummary> {
173        self.runtime.native_metadata_state_summary()
174    }
175
176    pub fn physical_authority_status(&self) -> PhysicalAuthorityStatus {
177        self.runtime.physical_authority_status()
178    }
179
180    pub fn validate_current_serverless_generation(&self) -> RedDBResult<()> {
181        self.runtime.validate_current_serverless_generation()
182    }
183
184    pub fn readiness(&self) -> RuntimeReadiness {
185        self.readiness_from_health(&self.health())
186    }
187
188    pub fn readiness_from_health(&self, report: &HealthReport) -> RuntimeReadiness {
189        self.runtime.readiness_from_health(report)
190    }
191}