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;
21
22#[repr(u8)]
24pub enum KeyPrefix {
25 Key,
27 Namespace,
29 RootKey,
31}
32
33#[derive(Debug, Error)]
35pub enum StorageServiceStoreError {
36 #[error("Store already exists during a create operation")]
38 StoreAlreadyExists,
39
40 #[error("Not matching entry")]
42 NotMatchingEntry,
43
44 #[error("Failed to find the linera-storage-server binary")]
46 FailedToFindStorageServerBinary,
47
48 #[error(transparent)]
50 GrpcError(#[from] Box<Status>),
51
52 #[error("The key size must be at most 1 MB")]
54 KeyTooLong,
55
56 #[error(transparent)]
58 TransportError(#[from] tonic::transport::Error),
59
60 #[error(transparent)]
62 VarError(#[from] std::env::VarError),
63
64 #[error(transparent)]
66 BcsError(#[from] bcs::Error),
67}
68
69impl From<Status> for StorageServiceStoreError {
70 fn from(error: Status) -> Self {
71 Box::new(error).into()
72 }
73}
74
75impl KeyValueStoreError for StorageServiceStoreError {
76 const BACKEND: &'static str = "service";
77}
78
79pub fn storage_service_test_endpoint() -> Result<String, StorageServiceStoreError> {
81 Ok(std::env::var("LINERA_STORAGE_SERVICE")?)
82}
83
84#[derive(Clone, Debug, Deserialize, Serialize)]
86pub struct StorageServiceStoreInternalConfig {
87 pub endpoint: String,
89 pub max_concurrent_queries: Option<usize>,
91}
92
93pub type StorageServiceStoreConfig = LruCachingConfig<StorageServiceStoreInternalConfig>;
95
96impl StorageServiceStoreInternalConfig {
97 pub fn http_address(&self) -> String {
99 format!("http://{}", self.endpoint)
100 }
101}
102
103pub async fn get_service_storage_binary() -> Result<PathBuf, StorageServiceStoreError> {
107 let binary = resolve_binary("linera-storage-server", "linera-storage-service").await;
108 if let Ok(binary) = binary {
109 return Ok(binary);
110 }
111 let binary = resolve_binary("../linera-storage-server", "linera-storage-service").await;
112 if let Ok(binary) = binary {
113 return Ok(binary);
114 }
115 Err(StorageServiceStoreError::FailedToFindStorageServerBinary)
116}