@@ -420,14 +420,14 @@ MDBXWrapper::MDBXWrapper(const DBParams& params)
420
420
: CDBWrapperBase(params),
421
421
m_db_context{std::make_unique<MDBXContext>()}
422
422
{
423
- if (params.wipe_data ) {
423
+ if (params.wipe_data && !params. read_only ) {
424
424
LogInfo (" Wiping MDBX in %s\n " , fs::PathToString (params.path ));
425
425
DestroyDB (fs::PathToString (params.path ));
426
426
}
427
427
428
428
TryCreateDirectories (params.path );
429
429
430
- LogPrintf (" Opening MDBX in %s\n " , fs::PathToString (params.path ));
430
+ LogPrintf (" Opening MDBX in %s (read-only: %s) \n " , fs::PathToString (params.path ), params. read_only ? " yes " : " no " );
431
431
432
432
DBContext ().create_params .geometry .pagesize = 16384 ;
433
433
@@ -436,17 +436,24 @@ MDBXWrapper::MDBXWrapper(const DBParams& params)
436
436
DBContext ().operate_params .options .no_sticky_threads = true ;
437
437
DBContext ().operate_params .durability = mdbx::env::whole_fragile;
438
438
439
+ // Set read-only mode if specified
440
+ if (params.read_only ) {
441
+ DBContext ().operate_params .mode = mdbx::env::mode::readonly;
442
+ }
443
+
439
444
// initialize the mdbx environment.
440
445
DBContext ().env = mdbx::env_managed (params.path , DBContext ().create_params , DBContext ().operate_params );
441
446
442
447
auto txn = DBContext ().env .start_read ();
443
448
DBContext ().map = txn.open_map (nullptr , mdbx::key_mode::usual, mdbx::value_mode::single);
444
449
txn.commit ();
445
450
446
- if (params.obfuscate && WriteObfuscateKeyIfNotExists ()){
447
- LogInfo (" Wrote new obfuscate key for %s: %s\n " , fs::PathToString (params.path ), HexStr (obfuscate_key));
451
+ if (!params.read_only ) {
452
+ if (params.obfuscate && WriteObfuscateKeyIfNotExists ()){
453
+ LogInfo (" Wrote new obfuscate key for %s: %s\n " , fs::PathToString (params.path ), HexStr (obfuscate_key));
454
+ }
455
+ LogInfo (" Using obfuscation key for %s: %s\n " , fs::PathToString (params.path ), HexStr (GetObfuscateKey ()));
448
456
}
449
- LogInfo (" Using obfuscation key for %s: %s\n " , fs::PathToString (params.path ), HexStr (GetObfuscateKey ()));
450
457
}
451
458
452
459
MDBXWrapper::~MDBXWrapper () = default ;
0 commit comments