Skip to content

Commit ded5ba7

Browse files
committed
fmt + remove dbgs
1 parent b5dba72 commit ded5ba7

File tree

12 files changed

+111
-145
lines changed

12 files changed

+111
-145
lines changed

libsql-server/src/http/admin/stats.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,10 @@ pub(super) async fn handle_stats<C>(
140140
State(app_state): State<Arc<AppState<C>>>,
141141
Path(namespace): Path<String>,
142142
) -> crate::Result<Json<StatsResponse>> {
143-
dbg!();
144143
let stats = app_state
145144
.namespaces
146145
.stats(NamespaceName::from_string(namespace)?)
147146
.await?;
148-
dbg!();
149147
let resp: StatsResponse = stats.as_ref().into();
150148

151149
Ok(Json(resp))

libsql-server/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,6 @@ where
591591
.configure(&mut join_set);
592592
}
593593
DatabaseKind::Replica => {
594-
dbg!();
595594
let (channel, uri) = client_config.clone().unwrap();
596595
let replication_svc = ReplicationLogProxyService::new(channel.clone(), uri.clone());
597596
let proxy_svc = ReplicaProxyService::new(
@@ -611,7 +610,6 @@ where
611610
service_shutdown.clone(),
612611
)
613612
.configure(&mut join_set);
614-
dbg!();
615613
}
616614
};
617615

libsql-server/src/namespace/configurator/fork.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub(super) async fn fork(
5858
Database::Schema(db) => db.wal_wrapper.wrapper().logger(),
5959
_ => {
6060
return Err(crate::Error::Fork(ForkError::Internal(anyhow::Error::msg(
61-
"Invalid source database type for fork",
61+
"Invalid source database type for fork",
6262
))));
6363
}
6464
};
@@ -114,7 +114,7 @@ pub struct ForkTask {
114114
pub to_namespace: NamespaceName,
115115
pub to_config: MetaStoreHandle,
116116
pub restore_to: Option<PointInTimeRestore>,
117-
pub store: NamespaceStore
117+
pub store: NamespaceStore,
118118
}
119119

120120
pub struct PointInTimeRestore {
@@ -156,7 +156,8 @@ impl ForkTask {
156156
let dest_path = self.base_path.join("dbs").join(self.to_namespace.as_str());
157157
tokio::fs::rename(temp_dir.path(), dest_path).await?;
158158

159-
self.store.make_namespace(&self.to_namespace, self.to_config, RestoreOption::Latest)
159+
self.store
160+
.make_namespace(&self.to_namespace, self.to_config, RestoreOption::Latest)
160161
.await
161162
.map_err(|e| ForkError::CreateNamespace(Box::new(e)))
162163
}

libsql-server/src/namespace/configurator/helpers.rs

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,29 @@ use std::time::Duration;
66
use anyhow::Context as _;
77
use bottomless::replicator::Options;
88
use bytes::Bytes;
9+
use enclose::enclose;
910
use futures::Stream;
1011
use libsql_sys::wal::Sqlite3WalManager;
1112
use tokio::io::AsyncBufReadExt as _;
1213
use tokio::sync::watch;
1314
use tokio::task::JoinSet;
1415
use tokio_util::io::StreamReader;
15-
use enclose::enclose;
1616

1717
use crate::connection::config::DatabaseConfig;
1818
use crate::connection::connection_manager::InnerWalManager;
1919
use crate::connection::libsql::{open_conn, MakeLibSqlConn};
2020
use crate::connection::{Connection as _, MakeConnection as _};
21+
use crate::database::{PrimaryConnection, PrimaryConnectionMaker};
2122
use crate::error::LoadDumpError;
23+
use crate::namespace::broadcasters::BroadcasterHandle;
24+
use crate::namespace::meta_store::MetaStoreHandle;
25+
use crate::namespace::replication_wal::{make_replication_wal_wrapper, ReplicationWalWrapper};
26+
use crate::namespace::{
27+
NamespaceBottomlessDbId, NamespaceBottomlessDbIdInit, NamespaceName, ResolveNamespacePathFn,
28+
RestoreOption,
29+
};
2230
use crate::replication::{FrameNo, ReplicationLogger};
2331
use crate::stats::Stats;
24-
use crate::namespace::{NamespaceBottomlessDbId, NamespaceBottomlessDbIdInit, NamespaceName, ResolveNamespacePathFn, RestoreOption};
25-
use crate::namespace::replication_wal::{make_replication_wal_wrapper, ReplicationWalWrapper};
26-
use crate::namespace::meta_store::MetaStoreHandle;
27-
use crate::namespace::broadcasters::BroadcasterHandle;
28-
use crate::database::{PrimaryConnection, PrimaryConnectionMaker};
2932
use crate::{StatsSender, BLOCKING_RT, DB_CREATE_TIMEOUT, DEFAULT_AUTO_CHECKPOINT};
3033

3134
use super::{BaseNamespaceConfig, PrimaryExtraConfig};
@@ -74,8 +77,7 @@ pub(super) async fn make_primary_connection_maker(
7477
tracing::debug!("Checkpointed before initializing bottomless");
7578
let options = make_bottomless_options(options, bottomless_db_id, name.clone());
7679
let (replicator, did_recover) =
77-
init_bottomless_replicator(db_path.join("data"), options, &restore_option)
78-
.await?;
80+
init_bottomless_replicator(db_path.join("data"), options, &restore_option).await?;
7981
tracing::debug!("Completed init of bottomless replicator");
8082
is_dirty |= did_recover;
8183
Some(replicator)
@@ -93,14 +95,14 @@ pub(super) async fn make_primary_connection_maker(
9395
};
9496

9597
let logger = Arc::new(ReplicationLogger::open(
96-
&db_path,
97-
primary_config.max_log_size,
98-
primary_config.max_log_duration,
99-
is_dirty,
100-
auto_checkpoint,
101-
primary_config.scripted_backup.clone(),
102-
name.clone(),
103-
None,
98+
&db_path,
99+
primary_config.max_log_size,
100+
primary_config.max_log_duration,
101+
is_dirty,
102+
auto_checkpoint,
103+
primary_config.scripted_backup.clone(),
104+
name.clone(),
105+
None,
104106
)?);
105107

106108
tracing::debug!("sending stats");
@@ -113,7 +115,7 @@ pub(super) async fn make_primary_connection_maker(
113115
name.clone(),
114116
logger.new_frame_notifier.subscribe(),
115117
)
116-
.await?;
118+
.await?;
117119

118120
tracing::debug!("Making replication wal wrapper");
119121
let wal_wrapper = make_replication_wal_wrapper(bottomless_replicator, logger.clone());
@@ -136,13 +138,13 @@ pub(super) async fn make_primary_connection_maker(
136138
resolve_attach_path,
137139
make_wal_manager.clone(),
138140
)
139-
.await?
140-
.throttled(
141-
base_config.max_concurrent_connections.clone(),
142-
Some(DB_CREATE_TIMEOUT),
143-
base_config.max_total_response_size,
144-
base_config.max_concurrent_requests,
145-
);
141+
.await?
142+
.throttled(
143+
base_config.max_concurrent_connections.clone(),
144+
Some(DB_CREATE_TIMEOUT),
145+
base_config.max_total_response_size,
146+
base_config.max_concurrent_requests,
147+
);
146148

147149
tracing::debug!("Completed opening libsql connection");
148150

@@ -356,10 +358,7 @@ pub(super) async fn make_stats(
356358
}
357359
});
358360

359-
join_set.spawn(run_storage_monitor(
360-
db_path.into(),
361-
Arc::downgrade(&stats),
362-
));
361+
join_set.spawn(run_storage_monitor(db_path.into(), Arc::downgrade(&stats)));
363362

364363
tracing::debug!("done sending stats, and creating bg tasks");
365364

@@ -369,10 +368,7 @@ pub(super) async fn make_stats(
369368
// Periodically check the storage used by the database and save it in the Stats structure.
370369
// TODO: Once we have a separate fiber that does WAL checkpoints, running this routine
371370
// right after checkpointing is exactly where it should be done.
372-
async fn run_storage_monitor(
373-
db_path: PathBuf,
374-
stats: Weak<Stats>,
375-
) -> anyhow::Result<()> {
371+
async fn run_storage_monitor(db_path: PathBuf, stats: Weak<Stats>) -> anyhow::Result<()> {
376372
// on initialization, the database file doesn't exist yet, so we wait a bit for it to be
377373
// created
378374
tokio::time::sleep(Duration::from_secs(1)).await;

libsql-server/src/namespace/configurator/libsql_wal_replica.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use std::pin::Pin;
21
use std::future::Future;
2+
use std::pin::Pin;
33
use std::sync::Arc;
44

55
use chrono::prelude::NaiveDateTime;
@@ -66,7 +66,7 @@ impl ConfigureNamespace for LibsqlWalReplicaConfigurator {
6666
name.clone(),
6767
applied_frame_no_receiver.clone(),
6868
)
69-
.await?;
69+
.await?;
7070

7171
let connection_maker = MakeWriteProxyConn::new(
7272
db_path.clone(),
@@ -84,13 +84,13 @@ impl ConfigureNamespace for LibsqlWalReplicaConfigurator {
8484
resolve_attach_path,
8585
self.make_wal_manager.clone(),
8686
)
87-
.await?
88-
.throttled(
89-
self.base.max_concurrent_connections.clone(),
90-
Some(DB_CREATE_TIMEOUT),
91-
self.base.max_total_response_size,
92-
self.base.max_concurrent_requests,
93-
);
87+
.await?
88+
.throttled(
89+
self.base.max_concurrent_connections.clone(),
90+
Some(DB_CREATE_TIMEOUT),
91+
self.base.max_total_response_size,
92+
self.base.max_concurrent_requests,
93+
);
9494

9595
Ok(Namespace {
9696
tasks: join_set,

libsql-server/src/namespace/configurator/mod.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ use crate::StatsSender;
1313

1414
use super::broadcasters::BroadcasterHandle;
1515
use super::meta_store::MetaStoreHandle;
16-
use super::{Namespace, NamespaceBottomlessDbIdInit, NamespaceName, NamespaceStore, ResetCb, ResolveNamespacePathFn, RestoreOption};
16+
use super::{
17+
Namespace, NamespaceBottomlessDbIdInit, NamespaceName, NamespaceStore, ResetCb,
18+
ResolveNamespacePathFn, RestoreOption,
19+
};
1720

21+
pub mod fork;
1822
mod helpers;
23+
mod libsql_wal_replica;
1924
mod primary;
2025
mod replica;
2126
mod schema;
22-
pub mod fork;
2327

2428
pub use primary::PrimaryConfigurator;
2529
pub use replica::ReplicaConfigurator;
@@ -68,12 +72,18 @@ impl NamespaceConfigurators {
6872
}
6973
}
7074

71-
pub fn with_primary(&mut self, c: impl ConfigureNamespace + Send + Sync + 'static) -> &mut Self {
75+
pub fn with_primary(
76+
&mut self,
77+
c: impl ConfigureNamespace + Send + Sync + 'static,
78+
) -> &mut Self {
7279
self.primary_configurator = Some(Box::new(c));
7380
self
7481
}
7582

76-
pub fn with_replica(&mut self, c: impl ConfigureNamespace + Send + Sync + 'static) -> &mut Self {
83+
pub fn with_replica(
84+
&mut self,
85+
c: impl ConfigureNamespace + Send + Sync + 'static,
86+
) -> &mut Self {
7787
self.replica_configurator = Some(Box::new(c));
7888
self
7989
}

libsql-server/src/namespace/configurator/primary.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use crate::namespace::broadcasters::BroadcasterHandle;
1212
use crate::namespace::configurator::helpers::make_primary_connection_maker;
1313
use crate::namespace::meta_store::MetaStoreHandle;
1414
use crate::namespace::{
15-
Namespace, NamespaceBottomlessDbIdInit, NamespaceName, NamespaceStore,
16-
ResetCb, ResolveNamespacePathFn, RestoreOption,
15+
Namespace, NamespaceBottomlessDbIdInit, NamespaceName, NamespaceStore, ResetCb,
16+
ResolveNamespacePathFn, RestoreOption,
1717
};
1818
use crate::run_periodic_checkpoint;
1919
use crate::schema::{has_pending_migration_task, setup_migration_table};
@@ -168,7 +168,8 @@ impl ConfigureNamespace for PrimaryConfigurator {
168168
db_config,
169169
prune_all,
170170
bottomless_db_id_init,
171-
).await
171+
)
172+
.await
172173
})
173174
}
174175

@@ -186,10 +187,10 @@ impl ConfigureNamespace for PrimaryConfigurator {
186187
from_config,
187188
to_ns,
188189
to_config,
189-
timestamp,
190+
timestamp,
190191
store,
191192
&self.primary_config,
192-
self.base.base_path.clone()))
193+
self.base.base_path.clone(),
194+
))
193195
}
194196
}
195-

libsql-server/src/namespace/configurator/schema.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ use tokio::task::JoinSet;
66
use crate::connection::config::DatabaseConfig;
77
use crate::connection::connection_manager::InnerWalManager;
88
use crate::database::{Database, SchemaDatabase};
9+
use crate::namespace::broadcasters::BroadcasterHandle;
910
use crate::namespace::meta_store::MetaStoreHandle;
1011
use crate::namespace::{
11-
Namespace, NamespaceName, NamespaceStore,
12-
ResetCb, ResolveNamespacePathFn, RestoreOption,
12+
Namespace, NamespaceName, NamespaceStore, ResetCb, ResolveNamespacePathFn, RestoreOption,
1313
};
14-
use crate::namespace::broadcasters::BroadcasterHandle;
1514
use crate::schema::SchedulerHandle;
1615

1716
use super::helpers::{cleanup_primary, make_primary_connection_maker};
@@ -25,8 +24,18 @@ pub struct SchemaConfigurator {
2524
}
2625

2726
impl SchemaConfigurator {
28-
pub fn new(base: BaseNamespaceConfig, primary_config: PrimaryExtraConfig, make_wal_manager: Arc<dyn Fn() -> InnerWalManager + Sync + Send + 'static>, migration_scheduler: SchedulerHandle) -> Self {
29-
Self { base, primary_config, make_wal_manager, migration_scheduler }
27+
pub fn new(
28+
base: BaseNamespaceConfig,
29+
primary_config: PrimaryExtraConfig,
30+
make_wal_manager: Arc<dyn Fn() -> InnerWalManager + Sync + Send + 'static>,
31+
migration_scheduler: SchedulerHandle,
32+
) -> Self {
33+
Self {
34+
base,
35+
primary_config,
36+
make_wal_manager,
37+
migration_scheduler,
38+
}
3039
}
3140
}
3241

@@ -58,7 +67,7 @@ impl ConfigureNamespace for SchemaConfigurator {
5867
&mut join_set,
5968
resolve_attach_path,
6069
broadcaster,
61-
self.make_wal_manager.clone()
70+
self.make_wal_manager.clone(),
6271
)
6372
.await?;
6473

@@ -94,7 +103,8 @@ impl ConfigureNamespace for SchemaConfigurator {
94103
db_config,
95104
prune_all,
96105
bottomless_db_id_init,
97-
).await
106+
)
107+
.await
98108
})
99109
}
100110

@@ -112,9 +122,10 @@ impl ConfigureNamespace for SchemaConfigurator {
112122
from_config,
113123
to_ns,
114124
to_config,
115-
timestamp,
125+
timestamp,
116126
store,
117127
&self.primary_config,
118-
self.base.base_path.clone()))
128+
self.base.base_path.clone(),
129+
))
119130
}
120131
}

libsql-server/src/namespace/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ pub use self::name::NamespaceName;
1919
pub use self::store::NamespaceStore;
2020

2121
pub mod broadcasters;
22+
pub(crate) mod configurator;
2223
pub mod meta_store;
2324
mod name;
2425
pub mod replication_wal;
2526
mod schema_lock;
2627
mod store;
27-
pub(crate) mod configurator;
2828

2929
pub type ResetCb = Box<dyn Fn(ResetOp) + Send + Sync + 'static>;
3030
pub type ResolveNamespacePathFn =

0 commit comments

Comments
 (0)