Skip to content

Commit 5f0be83

Browse files
Marin Postmapsarna
andcommitted
libsql-server: use LRU cache to store active namespaces
This is a port of Marin's libsql/sqld#689 This PR replaces the namespace store dumb hashmap with an LRU cache to bound the maximum number of namespaces loaded into memory while unbounding the number of namespaces allocated on a sqld instance. Additionally, this enables fully concurrent access to namespaces by removing the global lock on the namespace store. Co-authored-by: Piotr Sarna <[email protected]>
1 parent b3145d8 commit 5f0be83

File tree

3 files changed

+205
-95
lines changed

3 files changed

+205
-95
lines changed

libsql-server/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
7676
http-body = "0.4"
7777
url = { version = "2.3", features = ["serde"] }
7878
uuid = { version = "1.3", features = ["v4", "serde"] }
79+
moka = { version = "0.12.1", features = ["future"] }
7980

8081
[dev-dependencies]
8182
arbitrary = { version = "1.3.0", features = ["derive_arbitrary"] }

libsql-server/src/error.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ pub enum Error {
9292
UrlParseError(#[from] url::ParseError),
9393
#[error("Namespace store has shutdown")]
9494
NamespaceStoreShutdown,
95+
// This is for errors returned by moka
96+
#[error(transparent)]
97+
Ref(#[from] std::sync::Arc<Self>),
9598
}
9699

97100
trait ResponseError: std::error::Error {
@@ -105,6 +108,12 @@ trait ResponseError: std::error::Error {
105108
impl ResponseError for Error {}
106109

107110
impl IntoResponse for Error {
111+
fn into_response(self) -> axum::response::Response {
112+
(&self).into_response()
113+
}
114+
}
115+
116+
impl IntoResponse for &Error {
108117
fn into_response(self) -> axum::response::Response {
109118
use Error::*;
110119

@@ -150,6 +159,7 @@ impl IntoResponse for Error {
150159
PrimaryStreamInterupted => self.format_err(StatusCode::INTERNAL_SERVER_ERROR),
151160
UrlParseError(_) => self.format_err(StatusCode::BAD_REQUEST),
152161
NamespaceStoreShutdown => self.format_err(StatusCode::SERVICE_UNAVAILABLE),
162+
Ref(this) => this.as_ref().into_response(),
153163
}
154164
}
155165
}
@@ -224,7 +234,7 @@ pub enum LoadDumpError {
224234

225235
impl ResponseError for LoadDumpError {}
226236

227-
impl IntoResponse for LoadDumpError {
237+
impl IntoResponse for &LoadDumpError {
228238
fn into_response(self) -> axum::response::Response {
229239
use LoadDumpError::*;
230240

@@ -244,7 +254,7 @@ impl IntoResponse for LoadDumpError {
244254

245255
impl ResponseError for ForkError {}
246256

247-
impl IntoResponse for ForkError {
257+
impl IntoResponse for &ForkError {
248258
fn into_response(self) -> axum::response::Response {
249259
match self {
250260
ForkError::Internal(_)

0 commit comments

Comments
 (0)