3434
3535use parking_lot:: RwLock ;
3636use signet_libmdbx:: {
37- Environment , EnvironmentFlags , Geometry , HandleSlowReadersReturnCode ,
38- MaxReadTransactionDuration , Mode , PageSize , RO , RW , SyncMode , ffi ,
37+ Environment , EnvironmentFlags , Geometry , Mode , Ro , RoSync , Rw , RwSync , SyncMode , ffi ,
38+ sys :: { HandleSlowReadersReturnCode , PageSize } ,
3939} ;
4040use std:: {
4141 collections:: HashMap ,
@@ -45,7 +45,7 @@ use std::{
4545} ;
4646
4747mod cursor;
48- pub use cursor:: { Cursor , CursorRO , CursorRW } ;
48+ pub use cursor:: { Cursor , CursorRo , CursorRoSync , CursorRw , CursorRwSync } ;
4949
5050mod db_info;
5151pub use db_info:: { FixedSizeInfo , FsiCache } ;
@@ -105,8 +105,6 @@ pub struct DatabaseArguments {
105105 /// Database geometry settings.
106106 geometry : Geometry < Range < usize > > ,
107107
108- /// Maximum duration of a read transaction. If [None], the default value is used.
109- max_read_transaction_duration : Option < MaxReadTransactionDuration > ,
110108 /// Open environment in exclusive/monopolistic mode. If [None], the default value is used.
111109 ///
112110 /// This can be used as a replacement for `MDB_NOLOCK`, which don't supported by MDBX. In this
@@ -165,7 +163,6 @@ impl DatabaseArguments {
165163 shrink_threshold : Some ( 0 ) ,
166164 page_size : Some ( PageSize :: Set ( utils:: default_page_size ( ) ) ) ,
167165 } ,
168- max_read_transaction_duration : None ,
169166 exclusive : None ,
170167 max_readers : None ,
171168 sync_mode : SyncMode :: Durable ,
@@ -206,23 +203,6 @@ impl DatabaseArguments {
206203 self
207204 }
208205
209- /// Set the maximum duration of a read transaction.
210- pub const fn max_read_transaction_duration (
211- & mut self ,
212- max_read_transaction_duration : Option < MaxReadTransactionDuration > ,
213- ) {
214- self . max_read_transaction_duration = max_read_transaction_duration;
215- }
216-
217- /// Set the maximum duration of a read transaction.
218- pub const fn with_max_read_transaction_duration (
219- mut self ,
220- max_read_transaction_duration : Option < MaxReadTransactionDuration > ,
221- ) -> Self {
222- self . max_read_transaction_duration ( max_read_transaction_duration) ;
223- self
224- }
225-
226206 /// Set the mdbx exclusive flag.
227207 pub const fn with_exclusive ( mut self , exclusive : Option < bool > ) -> Self {
228208 self . exclusive = exclusive;
@@ -372,28 +352,40 @@ impl DatabaseEnv {
372352 // https://github.com/paradigmxyz/reth/blob/fa2b9b685ed9787636d962f4366caf34a9186e66/crates/storage/libmdbx-rs/mdbx-sys/libmdbx/mdbx.c#L16017.
373353 inner_env. set_rp_augment_limit ( 256 * 1024 ) ;
374354
375- if let Some ( max_read_transaction_duration) = args. max_read_transaction_duration {
376- inner_env. set_max_read_transaction_duration ( max_read_transaction_duration) ;
377- }
378-
379355 let fsi_cache = Arc :: new ( RwLock :: new ( HashMap :: new ( ) ) ) ;
380356 let env = Self { inner : inner_env. open ( path) ?, fsi_cache, _lock_file } ;
381357
382358 Ok ( env)
383359 }
384360
385361 /// Start a new read-only transaction.
386- fn tx ( & self ) -> Result < Tx < RO > , MdbxError > {
362+ pub fn tx ( & self ) -> Result < Tx < Ro > , MdbxError > {
387363 self . inner
388- . begin_ro_txn ( )
364+ . begin_ro_unsync ( )
389365 . map ( |tx| Tx :: new ( tx, self . fsi_cache . clone ( ) ) )
390366 . map_err ( MdbxError :: Mdbx )
391367 }
392368
393369 /// Start a new read-write transaction.
394- fn tx_mut ( & self ) -> Result < Tx < RW > , MdbxError > {
370+ pub fn tx_rw ( & self ) -> Result < Tx < Rw > , MdbxError > {
371+ self . inner
372+ . begin_rw_unsync ( )
373+ . map ( |tx| Tx :: new ( tx, self . fsi_cache . clone ( ) ) )
374+ . map_err ( MdbxError :: Mdbx )
375+ }
376+
377+ /// Start a new read-only synchronous transaction.
378+ pub fn tx_sync ( & self ) -> Result < Tx < RoSync > , MdbxError > {
379+ self . inner
380+ . begin_ro_sync ( )
381+ . map ( |tx| Tx :: new ( tx, self . fsi_cache . clone ( ) ) )
382+ . map_err ( MdbxError :: Mdbx )
383+ }
384+
385+ /// Start a new read-write synchronous transaction.
386+ pub fn tx_rw_sync ( & self ) -> Result < Tx < RwSync > , MdbxError > {
395387 self . inner
396- . begin_rw_txn ( )
388+ . begin_rw_sync ( )
397389 . map ( |tx| Tx :: new ( tx, self . fsi_cache . clone ( ) ) )
398390 . map_err ( MdbxError :: Mdbx )
399391 }
@@ -408,14 +400,14 @@ impl Deref for DatabaseEnv {
408400}
409401
410402impl HotKv for DatabaseEnv {
411- type RoTx = Tx < RO > ;
412- type RwTx = Tx < RW > ;
403+ type RoTx = Tx < Ro > ;
404+ type RwTx = Tx < Rw > ;
413405
414406 fn reader ( & self ) -> Result < Self :: RoTx , HotKvError > {
415407 self . tx ( ) . map_err ( HotKvError :: from_err)
416408 }
417409
418410 fn writer ( & self ) -> Result < Self :: RwTx , HotKvError > {
419- self . tx_mut ( ) . map_err ( HotKvError :: from_err)
411+ self . tx_rw ( ) . map_err ( HotKvError :: from_err)
420412 }
421413}
0 commit comments