linera_storage_service/
common.rs1use std::path::PathBuf;
5
6use linera_base::command::resolve_binary;
7use linera_views::{lru_caching::LruCachingConfig, store::KeyValueStoreError};
8use serde::{Deserialize, Serialize};
9use thiserror::Error;
10use tonic::Status;
11
12pub const MAX_PAYLOAD_SIZE: usize = 4000000;
20
21#[repr(u8)]
23pub enum KeyPrefix {
24 Key,
26 Namespace,
28 RootKey,
30}
31
32#[derive(Debug, Error)]
33pub enum ServiceStoreError {
34 #[error("Store already exists during a create operation")]
36 StoreAlreadyExists,
37
38 #[error("Not matching entry")]
40 NotMatchingEntry,
41
42 #[error("Failed to find the linera-storage-server binary")]
44 FailedToFindStorageServerBinary,
45
46 #[error(transparent)]
48 GrpcError(#[from] Box<Status>),
49
50 #[error("The key size must be at most 1 MB")]
52 KeyTooLong,
53
54 #[error(transparent)]
56 TransportError(#[from] tonic::transport::Error),
57
58 #[error(transparent)]
60 VarError(#[from] std::env::VarError),
61
62 #[error(transparent)]
64 BcsError(#[from] bcs::Error),
65}
66
67impl From<Status> for ServiceStoreError {
68 fn from(error: Status) -> Self {
69 Box::new(error).into()
70 }
71}
72
73impl KeyValueStoreError for ServiceStoreError {
74 const BACKEND: &'static str = "service";
75}
76
77pub fn storage_service_test_endpoint() -> Result<String, ServiceStoreError> {
78 Ok(std::env::var("LINERA_STORAGE_SERVICE")?)
79}
80
81#[derive(Clone, Debug, Deserialize, Serialize)]
82pub struct ServiceStoreInternalConfig {
83 pub endpoint: String,
85 pub max_concurrent_queries: Option<usize>,
87 pub max_stream_queries: usize,
89}
90
91pub type ServiceStoreConfig = LruCachingConfig<ServiceStoreInternalConfig>;
93
94impl ServiceStoreInternalConfig {
95 pub fn http_address(&self) -> String {
96 format!("http://{}", self.endpoint)
97 }
98}
99
100pub async fn get_service_storage_binary() -> Result<PathBuf, ServiceStoreError> {
104 let binary = resolve_binary("linera-storage-server", "linera-storage-service").await;
105 if let Ok(binary) = binary {
106 return Ok(binary);
107 }
108 let binary = resolve_binary("../linera-storage-server", "linera-storage-service").await;
109 if let Ok(binary) = binary {
110 return Ok(binary);
111 }
112 Err(ServiceStoreError::FailedToFindStorageServerBinary)
113}