@@ -6,7 +6,7 @@ use tokio::sync::RwLock;
6
6
7
7
use crate :: {
8
8
environment:: RemoteEnvironmentConfig , CommitLatency , Cursor , DatabaseFlags , Environment ,
9
- EnvironmentBuilder , Stat , Transaction , TransactionKind , WriteFlags , RO , RW ,
9
+ EnvironmentBuilder , Info , Stat , Transaction , TransactionKind , WriteFlags , RO , RW ,
10
10
} ;
11
11
12
12
#[ tarpc:: service]
@@ -18,6 +18,7 @@ pub trait RemoteMDBX {
18
18
async fn env_sync ( env : u64 , force : bool ) -> Result < bool , ServerError > ;
19
19
async fn env_close ( env : u64 ) -> Result < ( ) , ServerError > ;
20
20
async fn env_stat ( env : u64 ) -> Result < Stat , ServerError > ;
21
+ async fn env_info ( env : u64 ) -> Result < Info , ServerError > ;
21
22
22
23
async fn tx_create_db (
23
24
env : u64 ,
@@ -230,7 +231,26 @@ impl RemoteMDBX for RemoteMDBXServer {
230
231
. ok_or ( ServerError :: NOENV ) ?
231
232
. env
232
233
. clone ( ) ;
233
- let ret = tokio:: task:: spawn_blocking ( move || env. stat ( ) ) . await ??;
234
+ let ret = env. stat ( ) ?;
235
+
236
+ Ok ( ret)
237
+ }
238
+
239
+ async fn env_info (
240
+ self ,
241
+ _context : tarpc:: context:: Context ,
242
+ env : u64 ,
243
+ ) -> Result < Info , ServerError > {
244
+ let env = self
245
+ . state
246
+ . read ( )
247
+ . await
248
+ . envs
249
+ . get ( & env)
250
+ . ok_or ( ServerError :: NOENV ) ?
251
+ . env
252
+ . clone ( ) ;
253
+ let ret = env. info ( ) ?;
234
254
235
255
Ok ( ret)
236
256
}
@@ -250,6 +270,7 @@ impl RemoteMDBX for RemoteMDBXServer {
250
270
. ok_or ( ServerError :: NOENV ) ?
251
271
. env
252
272
. clone ( ) ;
273
+ // This can block for a very time, though not forever
253
274
let ret = tokio:: task:: spawn_blocking ( move || env. sync ( force) ) . await ??;
254
275
255
276
Ok ( ret)
@@ -344,7 +365,8 @@ impl RemoteMDBX for RemoteMDBXServer {
344
365
if flags. contains ( DatabaseFlags :: CREATE ) {
345
366
return Err ( ServerError :: NOWRITABLE ) ;
346
367
}
347
- // This can block
368
+ // This can block? can it?
369
+ // But anyway opening databases should be not so frequent so overhead should be acceptable.
348
370
tokio:: task:: spawn_blocking ( move || tx. open_db ( db. as_deref ( ) ) ) . await ??
349
371
} else {
350
372
return Err ( ServerError :: NOTX ) ;
@@ -440,6 +462,7 @@ impl RemoteMDBX for RemoteMDBXServer {
440
462
env. rwtxs . remove ( & tx) . ok_or ( ServerError :: NOTX ) ?
441
463
} ;
442
464
465
+ // This can be slow, wrap it in spawn_blocking
443
466
Ok ( tokio:: task:: spawn_blocking ( move || tx. tx . commit ( ) ) . await ??)
444
467
}
445
468
@@ -487,6 +510,7 @@ impl RemoteMDBX for RemoteMDBXServer {
487
510
. tx
488
511
. clone ( ) ;
489
512
513
+ // Can this block forever? Anyway, wrap it with spawn_blocking for safety.
490
514
let new_tx = tokio:: task:: spawn_blocking ( move || tx. begin_nested_txn ( ) ) . await ??;
491
515
492
516
let mut lg = self . state . write ( ) . await ;
@@ -518,11 +542,11 @@ impl RemoteMDBX for RemoteMDBXServer {
518
542
let stat = if let Some ( rw) = env. rwtxs . get ( & tx) {
519
543
let tx = rw. tx . clone ( ) ;
520
544
drop ( lg) ;
521
- tokio :: task :: spawn_blocking ( move || tx. db_stat_with_dbi ( dbi) ) . await ? ?
545
+ tx. db_stat_with_dbi ( dbi) ?
522
546
} else if let Some ( ro) = env. rotxs . get ( & tx) {
523
547
let tx = ro. tx . clone ( ) ;
524
548
drop ( lg) ;
525
- tokio :: task :: spawn_blocking ( move || tx. db_stat_with_dbi ( dbi) ) . await ? ?
549
+ tx. db_stat_with_dbi ( dbi) ?
526
550
} else {
527
551
return Err ( ServerError :: NOTX ) ;
528
552
} ;
@@ -550,6 +574,7 @@ impl RemoteMDBX for RemoteMDBXServer {
550
574
. tx
551
575
. clone ( ) ;
552
576
577
+ // This can be slow
553
578
tokio:: task:: spawn_blocking ( move || tx. clear_db ( dbi) ) . await ??;
554
579
Ok ( ( ) )
555
580
}
0 commit comments