From e2c2596e1e30ed215591aa8285834b7d81a814d5 Mon Sep 17 00:00:00 2001 From: Niko PLP Date: Mon, 8 Jul 2024 14:01:53 +0300 Subject: [PATCH] handle error about rocksdb lock already taken. concurrent start of ngd in same working directory --- ng-repo/src/errors.rs | 1 + ng-storage-rocksdb/src/block_storage.rs | 9 ++++++++- ng-storage-rocksdb/src/kcv_storage.rs | 9 ++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/ng-repo/src/errors.rs b/ng-repo/src/errors.rs index 8f67688..d67eea5 100644 --- a/ng-repo/src/errors.rs +++ b/ng-repo/src/errors.rs @@ -218,6 +218,7 @@ pub enum StorageError { OverlayBranchNotFound, Abort, NotEmpty, + ServerAlreadyRunningInOtherProcess, } impl core::fmt::Display for StorageError { diff --git a/ng-storage-rocksdb/src/block_storage.rs b/ng-storage-rocksdb/src/block_storage.rs index 33d394e..66675f0 100644 --- a/ng-storage-rocksdb/src/block_storage.rs +++ b/ng-storage-rocksdb/src/block_storage.rs @@ -79,7 +79,14 @@ impl RocksDbBlockStorage { let env = Env::enc_env(key).unwrap(); opts.set_env(&env); let tx_options = TransactionDBOptions::new(); - let db: TransactionDB = TransactionDB::open(&opts, &tx_options, &path).unwrap(); + let db: TransactionDB = TransactionDB::open(&opts, &tx_options, &path).map_err(|e| { + log_err!("{e}"); + if e.into_string().starts_with("IO error: While lock file") { + StorageError::ServerAlreadyRunningInOtherProcess + } else { + StorageError::BackendError + } + })?; log_info!( "created blockstorage with Rocksdb Version: {}", diff --git a/ng-storage-rocksdb/src/kcv_storage.rs b/ng-storage-rocksdb/src/kcv_storage.rs index 7d9a253..b497c30 100644 --- a/ng-storage-rocksdb/src/kcv_storage.rs +++ b/ng-storage-rocksdb/src/kcv_storage.rs @@ -702,7 +702,14 @@ impl RocksDbKCVStorage { // TODO: use open_cf and choose which column family to create/ versus using set_prefix_extractor and doing prefix seek let tx_options = TransactionDBOptions::new(); - let db: TransactionDB = TransactionDB::open(&opts, &tx_options, &path).unwrap(); + let db: TransactionDB = TransactionDB::open(&opts, &tx_options, &path).map_err(|e| { + log_err!("{e}"); + if e.into_string().starts_with("IO error: While lock file") { + StorageError::ServerAlreadyRunningInOtherProcess + } else { + StorageError::BackendError + } + })?; log_info!( "created kcv storage with Rocksdb Version: {}",