|
|
@ -223,6 +223,22 @@ impl Data {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub enum SyncFileLock {
|
|
|
|
|
|
|
|
FileLock(flock::FileLock),
|
|
|
|
|
|
|
|
FileLockTaskHandle(tokio::task::JoinHandle<diskstore::flock::FileLock>),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl SyncFileLock {
|
|
|
|
|
|
|
|
pub async fn unlock(self) -> std::io::Result<()> {
|
|
|
|
|
|
|
|
match self {
|
|
|
|
|
|
|
|
SyncFileLock::FileLock(mut lock) => lock.unlock(),
|
|
|
|
|
|
|
|
SyncFileLock::FileLockTaskHandle(lock) => {
|
|
|
|
|
|
|
|
lock.await?.unlock()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl CoreDB {
|
|
|
|
impl CoreDB {
|
|
|
|
#[cfg(debug_assertions)]
|
|
|
|
#[cfg(debug_assertions)]
|
|
|
|
#[allow(dead_code)] // This has been kept for debugging purposes, so we'll suppress this lint
|
|
|
|
#[allow(dead_code)] // This has been kept for debugging purposes, so we'll suppress this lint
|
|
|
@ -286,7 +302,7 @@ impl CoreDB {
|
|
|
|
bgsave: BGSave,
|
|
|
|
bgsave: BGSave,
|
|
|
|
snapshot_cfg: SnapshotConfig,
|
|
|
|
snapshot_cfg: SnapshotConfig,
|
|
|
|
restore_file: Option<PathBuf>,
|
|
|
|
restore_file: Option<PathBuf>,
|
|
|
|
) -> TResult<(Self, Option<flock::FileLock>)> {
|
|
|
|
) -> TResult<(Self, SyncFileLock)> {
|
|
|
|
let coretable = diskstore::get_saved(restore_file)?;
|
|
|
|
let coretable = diskstore::get_saved(restore_file)?;
|
|
|
|
let mut background_tasks: usize = 0;
|
|
|
|
let mut background_tasks: usize = 0;
|
|
|
|
if !bgsave.is_disabled() {
|
|
|
|
if !bgsave.is_disabled() {
|
|
|
@ -325,11 +341,11 @@ impl CoreDB {
|
|
|
|
let lock = flock::FileLock::lock("data.bin")
|
|
|
|
let lock = flock::FileLock::lock("data.bin")
|
|
|
|
.map_err(|e| format!("Failed to acquire lock on data file with error '{}'", e))?;
|
|
|
|
.map_err(|e| format!("Failed to acquire lock on data file with error '{}'", e))?;
|
|
|
|
if bgsave.is_disabled() {
|
|
|
|
if bgsave.is_disabled() {
|
|
|
|
Ok((db, Some(lock)))
|
|
|
|
Ok((db, SyncFileLock::FileLock(lock)))
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// Spawn the BGSAVE service in a separate task
|
|
|
|
// Spawn the BGSAVE service in a separate task
|
|
|
|
tokio::spawn(diskstore::bgsave_scheduler(db.clone(), bgsave, lock));
|
|
|
|
let data = tokio::spawn(diskstore::bgsave_scheduler(db.clone(), bgsave, lock));
|
|
|
|
Ok((db, None))
|
|
|
|
Ok((db, SyncFileLock::FileLockTaskHandle(data)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/// Create an empty in-memory table
|
|
|
|
/// Create an empty in-memory table
|
|
|
|