diff --git a/server/src/coredb/mod.rs b/server/src/coredb/mod.rs index 76f1fe4..2887bbd 100644 --- a/server/src/coredb/mod.rs +++ b/server/src/coredb/mod.rs @@ -286,7 +286,7 @@ impl CoreDB { bgsave: BGSave, snapshot_cfg: SnapshotConfig, restore_file: Option, - ) -> TResult<(Self, Option, flock::FileLock)> { + ) -> TResult<(Self, Option)> { let coretable = diskstore::get_saved(restore_file)?; let mut background_tasks: usize = 0; if !bgsave.is_disabled() { @@ -324,13 +324,12 @@ impl CoreDB { )); let lock = flock::FileLock::lock("data.bin") .map_err(|e| format!("Failed to acquire lock on data file with error '{}'", e))?; - let cloned_descriptor = lock.try_clone()?; if bgsave.is_disabled() { - Ok((db, Some(lock), cloned_descriptor)) + Ok((db, Some(lock))) } else { // Spawn the BGSAVE service in a separate task tokio::spawn(diskstore::bgsave_scheduler(db.clone(), bgsave, lock)); - Ok((db, None, cloned_descriptor)) + Ok((db, None)) } } /// Create an empty in-memory table diff --git a/server/src/dbnet/mod.rs b/server/src/dbnet/mod.rs index 598142f..96b1e3a 100644 --- a/server/src/dbnet/mod.rs +++ b/server/src/dbnet/mod.rs @@ -316,17 +316,16 @@ pub async fn run( snapshot_cfg: SnapshotConfig, sig: impl Future, restore_filepath: Option, -) -> (CoreDB, flock::FileLock) { +) -> CoreDB { let (signal, _) = broadcast::channel(1); let (terminate_tx, terminate_rx) = mpsc::channel(1); - let (db, lock, cloned_descriptor) = - match CoreDB::new(bgsave_cfg, snapshot_cfg, restore_filepath) { - Ok((db, lock, cloned_descriptor)) => (db, lock, cloned_descriptor), - Err(e) => { - log::error!("ERROR: {}", e); - process::exit(0x100); - } - }; + let (db, lock) = match CoreDB::new(bgsave_cfg, snapshot_cfg, restore_filepath) { + Ok((db, lock)) => (db, lock), + Err(e) => { + log::error!("ERROR: {}", e); + process::exit(0x100); + } + }; match fs::create_dir_all(&*DIR_REMOTE_SNAPSHOT) { Ok(_) => (), Err(e) => match e.kind() { @@ -393,7 +392,7 @@ pub async fn run( log::error!("Failed to release lock on data file with '{}'", e); process::exit(0x100); } - (db, cloned_descriptor) + (db) } /// This is a **test only** function diff --git a/server/src/main.rs b/server/src/main.rs index b0b0074..f223356 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -77,10 +77,10 @@ fn main() { .enable_all() .build() .unwrap(); - let (db, mut descriptor) = runtime.block_on(async { + let db = runtime.block_on(async { let (tcplistener, bgsave_config, snapshot_config, restore_filepath) = check_args_and_get_cfg().await; - let (db, descriptor) = run( + let db = run( tcplistener, bgsave_config, snapshot_config, @@ -88,7 +88,7 @@ fn main() { restore_filepath, ) .await; - (db, descriptor) + db }); // Make sure all background workers terminate drop(runtime); @@ -97,19 +97,19 @@ fn main() { 1, "Maybe the compiler reordered the drop causing more than one instance of CoreDB to live at this point" ); - // Try to acquire lock almost immediately - if let Err(e) = descriptor.reacquire() { - log::error!("Failed to reacquire lock on data file with error: '{}'", e); - panic!("FATAL: data file relocking failure"); - } - if let Err(e) = flush_db!(db, descriptor) { + // // Try to acquire lock almost immediately + // if let Err(e) = descriptor.reacquire() { + // log::error!("Failed to reacquire lock on data file with error: '{}'", e); + // panic!("FATAL: data file relocking failure"); + // } + if let Err(e) = flush_db!(db) { log::error!("Failed to flush data to disk with '{}'", e); loop { // Keep looping until we successfully write the in-memory table to disk log::warn!("Press enter to try again..."); io::stdout().flush().unwrap(); io::stdin().read(&mut [0]).unwrap(); - if let Ok(_) = flush_db!(db, descriptor) { + if let Ok(_) = flush_db!(db) { log::info!("Successfully saved data to disk"); break; } else {