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 pub max_stream_queries: usize,
93}
94
95pub type StorageServiceStoreConfig = LruCachingConfig<StorageServiceStoreInternalConfig>;
97
98impl StorageServiceStoreInternalConfig {
99 pub fn http_address(&self) -> String {
101 format!("http://{}", self.endpoint)
102 }
103}
104
105pub async fn get_service_storage_binary() -> Result<PathBuf, StorageServiceStoreError> {
109 let binary = resolve_binary("linera-storage-server", "linera-storage-service").await;
110 if let Ok(binary) = binary {
111 return Ok(binary);
112 }
113 let binary = resolve_binary("../linera-storage-server", "linera-storage-service").await;
114 if let Ok(binary) = binary {
115 return Ok(binary);
116 }
117 Err(StorageServiceStoreError::FailedToFindStorageServerBinary)
118}