pub fn new(config: &RocksDbConfig, shutdown: Arc<AtomicBool>) -> Result<RocksDb, String> {
        if config.restore_from_backup_at_startup && config.enabled {
            if let Ok(mut backup_engine) = RocksDb::create_backup_engine(&config) {
                let mut restore_option = rocksdb::backup::RestoreOptions::default();
                restore_option.set_keep_log_files(config.keep_log_file_while_restore);
                let mut wal_dir = config.wal_dir.clone();

                if wal_dir.is_empty() {
                    wal_dir = config.db_path.clone();
                }
                if let Err(e) = backup_engine.restore_from_latest_backup(
                    &config.db_path,
                    &wal_dir,
                    &restore_option,
                ) {
                    error!("Failed to restore from the backup. Error:{:?}", e);
                    return Err(e.to_string());
                }
                info!("Restoring DB from a backup path: {}", config.backup_path);
            } else {}
        } else {
            info!("Initializing DB from a path: {}", config.db_path);
        }
        if !config.enabled {
            warn!("DB not enabled for DB Path: {}", config.db_path);
        }

        let db = Arc::new(RocksDb::init_rocks_db(&config)?);

        //let (tx, rx) = mpsc::unbounded::<KeyVal>();
        let (tx, rx) = mpsc::bounded::<KeyVal>(config.async_write_queue_length);

        if config.async_write && config.enabled {
            for _i in 0..config.num_async_writer_threads {
                let config_clone = config.clone();
                let db_clone = db.clone();
                let rx = rx.clone();
                let shutdown = shutdown.clone();
                thread::spawn(move || {
                    RocksDb::write_to_db(config_clone, db_clone, rx, shutdown);
                });
            }
        }

        Ok(RocksDb {
            enabled: config.enabled,
            db,
            sender: tx,
            config: config.clone(),
        })
    }
/// create a RocksDB instance from the config
create a RocksDB instance from the config
create a RocksDB instance from the config
pub fn new(config: &RocksDbConfig, shutdown: Arc<AtomicBool>) -> Result<RocksDb, String> {
        if config.restore_from_backup_at_startup && config.enabled {
            if let Ok(mut backup_engine) = RocksDb::create_backup_engine(&config) {
                let mut restore_option = rocksdb::backup::RestoreOptions::default();
                restore_option.set_keep_log_files(config.keep_log_file_while_restore);
                let mut wal_dir = config.wal_dir.clone();
                if wal_dir.is_empty() {
                    wal_dir = config.db_path.clone();
                }
                if let Err(e) = backup_engine.restore_from_latest_backup(
                    &config.db_path,
                    &wal_dir,
                    &restore_option,
                ) {
                    error!("Failed to restore from the backup. Error:{:?}", e);
                    return Err(e.to_string());
                }
                info!("Restoring DB from a backup path: {}", config.backup_path);
            } else {}
        } else {
            info!("Initializing DB from a path: {}", config.db_path);
        }
        if !config.enabled {
            warn!("DB not enabled for DB Path: {}", config.db_path);
        }
        let db = Arc::new(RocksDb::init_rocks_db(&config)?);
        //let (tx, rx) = mpsc::unbounded::<KeyVal>();
        let (tx, rx) = mpsc::bounded::<KeyVal>(config.async_write_queue_length);
        if config.async_write && config.enabled {
            for _i in 0..config.num_async_writer_threads {
                let config_clone = config.clone();
                let db_clone = db.clone();
                let rx = rx.clone();
                let shutdown = shutdown.clone();
                thread::spawn(move || {
                    RocksDb::write_to_db(config_clone, db_clone, rx, shutdown);
                });
            }
        }
        Ok(RocksDb {
            enabled: config.enabled,
            db,
            sender: tx,
            config: config.clone(),
        })
    }
pub fn new ( config : & RocksDbConfig , shutdown : Arc < AtomicBool > ) -> Result < RocksDb , String > { if config . restore_from_backup_at_startup && config . enabled { if let Ok ( mut backup_engine ) = RocksDb :: create_backup_engine ( & config ) { let mut restore_option = rocksdb :: backup :: RestoreOptions :: default ( ) ; restore_option . set_keep_log_files ( config . keep_log_file_while_restore ) ; let mut wal_dir = config . wal_dir . clone ( ) ; if wal_dir . is_empty ( ) { wal_dir = config . db_path . clone ( ) ; } if let Err ( e ) = backup_engine . restore_from_latest_backup ( & config . db_path , & wal_dir , & restore_option , ) { error ! ( " " e ) ; return Err ( e . to_string ( ) ) ; } info ! ( " " config backup_path ) ; } else { } } else { info ! ( " " config db_path ) ; } if ! config . enabled { warn ! ( " " config db_path ) ; } let db = Arc :: new ( RocksDb :: init_rocks_db ( & config ) ? ) ; //let (tx, rx) = mpsc::unbounded::<KeyVal>(); let ( tx , rx ) = mpsc :: bounded :: < KeyVal > ( config . async_write_queue_length ) ; if config . async_write && config . enabled { for _i in 0 .. config . num_async_writer_threads { let config_clone = config . clone ( ) ; let db_clone = db . clone ( ) ; let rx = rx . clone ( ) ; let shutdown = shutdown . clone ( ) ; thread :: spawn ( move | | { RocksDb :: write_to_db ( config_clone , db_clone , rx , shutdown ) ; } ) ; } } Ok ( RocksDb { enabled : config . enabled , db , sender : tx , config : config . clone ( ) , } ) }
create a RocksDB instance from the config
create a RocksDB instance from the config
config
&RocksDbConfig
shutdown
Arc<AtomicBool>