@@ -25,6 +25,7 @@ use crate::auth::Auth;
25
25
use crate :: error:: Error ;
26
26
use crate :: postgres:: service:: PgConnectionFactory ;
27
27
use crate :: server:: Server ;
28
+ use crate :: stats:: Stats ;
28
29
29
30
pub use sqld_libsql_bindings as libsql;
30
31
@@ -39,6 +40,7 @@ mod query_analysis;
39
40
mod replication;
40
41
pub mod rpc;
41
42
mod server;
43
+ mod stats;
42
44
mod utils;
43
45
44
46
#[ derive( clap:: ValueEnum , Clone , Debug , PartialEq ) ]
@@ -97,6 +99,7 @@ async fn run_service(
97
99
config : & Config ,
98
100
join_set : & mut JoinSet < anyhow:: Result < ( ) > > ,
99
101
idle_shutdown_layer : Option < IdleShutdownLayer > ,
102
+ stats : Stats ,
100
103
) -> anyhow:: Result < ( ) > {
101
104
let auth = get_auth ( config) ?;
102
105
@@ -122,6 +125,7 @@ async fn run_service(
122
125
upgrade_tx,
123
126
config. enable_http_console ,
124
127
idle_shutdown_layer. clone ( ) ,
128
+ stats,
125
129
) ) ;
126
130
}
127
131
@@ -183,6 +187,7 @@ async fn start_replica(
183
187
join_set : & mut JoinSet < anyhow:: Result < ( ) > > ,
184
188
addr : & str ,
185
189
idle_shutdown_layer : Option < IdleShutdownLayer > ,
190
+ stats : Stats ,
186
191
) -> anyhow:: Result < ( ) > {
187
192
let ( factory, handle) = WriteProxyDbFactory :: new (
188
193
addr,
@@ -191,6 +196,7 @@ async fn start_replica(
191
196
config. writer_rpc_key . clone ( ) ,
192
197
config. writer_rpc_ca_cert . clone ( ) ,
193
198
config. db_path . clone ( ) ,
199
+ stats. clone ( ) ,
194
200
)
195
201
. await
196
202
. context ( "failed to start WriteProxy DB" ) ?;
@@ -201,7 +207,7 @@ async fn start_replica(
201
207
join_set. spawn ( async move { handle. await . expect ( "WriteProxy DB task failed" ) } ) ;
202
208
203
209
let service = DbFactoryService :: new ( Arc :: new ( factory) ) ;
204
- run_service ( service, config, join_set, idle_shutdown_layer) . await ?;
210
+ run_service ( service, config, join_set, idle_shutdown_layer, stats ) . await ?;
205
211
206
212
Ok ( ( ) )
207
213
}
@@ -214,6 +220,7 @@ async fn start_primary(
214
220
config : & Config ,
215
221
join_set : & mut JoinSet < anyhow:: Result < ( ) > > ,
216
222
idle_shutdown_layer : Option < IdleShutdownLayer > ,
223
+ stats : Stats ,
217
224
) -> anyhow:: Result < ( ) > {
218
225
let is_fresh_db = check_fresh_db ( & config. db_path ) ;
219
226
let logger = Arc :: new ( ReplicationLogger :: open (
@@ -237,10 +244,12 @@ async fn start_primary(
237
244
dump_loader. load_dump ( path. into ( ) ) . await ?;
238
245
}
239
246
247
+ let stats_clone = stats. clone ( ) ;
240
248
let db_factory = Arc :: new ( move || {
241
249
let db_path = path_clone. clone ( ) ;
242
250
let hook = hook. clone ( ) ;
243
- async move { LibSqlDb :: new ( db_path, hook, enable_bottomless) }
251
+ let stats_clone = stats_clone. clone ( ) ;
252
+ async move { LibSqlDb :: new ( db_path, hook, enable_bottomless, stats_clone) }
244
253
} ) ;
245
254
let service = DbFactoryService :: new ( db_factory. clone ( ) ) ;
246
255
if let Some ( ref addr) = config. rpc_server_addr {
@@ -256,7 +265,7 @@ async fn start_primary(
256
265
) ) ;
257
266
}
258
267
259
- run_service ( service, config, join_set, idle_shutdown_layer) . await ?;
268
+ run_service ( service, config, join_set, idle_shutdown_layer, stats ) . await ?;
260
269
261
270
Ok ( ( ) )
262
271
}
@@ -309,11 +318,13 @@ pub async fn run_server(config: Config) -> anyhow::Result<()> {
309
318
. idle_shutdown_timeout
310
319
. map ( |d| IdleShutdownLayer :: new ( d, shutdown_notify. clone ( ) ) ) ;
311
320
321
+ let stats = Stats :: new ( & config. db_path ) ?;
322
+
312
323
match config. writer_rpc_addr {
313
324
Some ( ref addr) => {
314
- start_replica ( & config, & mut join_set, addr, idle_shutdown_layer) . await ?
325
+ start_replica ( & config, & mut join_set, addr, idle_shutdown_layer, stats ) . await ?
315
326
}
316
- None => start_primary ( & config, & mut join_set, idle_shutdown_layer) . await ?,
327
+ None => start_primary ( & config, & mut join_set, idle_shutdown_layer, stats ) . await ?,
317
328
}
318
329
319
330
let reset = HARD_RESET . clone ( ) ;
0 commit comments