@ -61,7 +61,6 @@ use tokio::sync::Semaphore;
use tokio ::sync ::{ broadcast , mpsc } ;
use tokio ::sync ::{ broadcast , mpsc } ;
pub mod connection ;
pub mod connection ;
mod tls ;
mod tls ;
use crate ::flush_db ;
/// Responsible for gracefully shutting down the server instead of dying randomly
/// Responsible for gracefully shutting down the server instead of dying randomly
// Sounds very sci-fi ;)
// Sounds very sci-fi ;)
@ -95,8 +94,6 @@ impl Terminator {
}
}
}
}
use std ::io ::{ self , prelude ::* } ;
/// Multiple Listener Interface
/// Multiple Listener Interface
///
///
/// A `MultiListener` is an abstraction over an `SslListener` or a `Listener` to facilitate
/// A `MultiListener` is an abstraction over an `SslListener` or a `Listener` to facilitate
@ -318,7 +315,7 @@ pub async fn run(
snapshot_cfg : SnapshotConfig ,
snapshot_cfg : SnapshotConfig ,
sig : impl Future ,
sig : impl Future ,
restore_filepath : Option < PathBuf > ,
restore_filepath : Option < PathBuf > ,
) {
) -> CoreDB {
let ( signal , _ ) = broadcast ::channel ( 1 ) ;
let ( signal , _ ) = broadcast ::channel ( 1 ) ;
let ( terminate_tx , terminate_rx ) = mpsc ::channel ( 1 ) ;
let ( terminate_tx , terminate_rx ) = mpsc ::channel ( 1 ) ;
let ( db , lock ) = match CoreDB ::new ( bgsave_cfg , snapshot_cfg , restore_filepath ) {
let ( db , lock ) = match CoreDB ::new ( bgsave_cfg , snapshot_cfg , restore_filepath ) {
@ -394,23 +391,7 @@ pub async fn run(
log ::error ! ( "Failed to release lock on data file with '{}'" , e ) ;
log ::error ! ( "Failed to release lock on data file with '{}'" , e ) ;
process ::exit ( 0x100 ) ;
process ::exit ( 0x100 ) ;
}
}
if let Err ( e ) = flush_db ! ( 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 ) {
log ::info ! ( "Successfully saved data to disk" ) ;
break ;
} else {
continue ;
}
}
} else {
log ::info ! ( "Successfully saved data to disk" ) ;
}
}
}
/// This is a **test only** function
/// This is a **test only** function