mirror of
https://github.com/uqbar-dao/nectar.git
synced 2024-12-24 09:06:10 +03:00
state and dbs: backups
This commit is contained in:
parent
8e633809b4
commit
a45d14470d
@ -267,8 +267,11 @@ async fn handle_request(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
KvAction::Backup => {
|
KvAction::Backup => {
|
||||||
// loop through all db directories and backup.
|
// looping through open dbs and flushing their memtables
|
||||||
//
|
for db_ref in open_kvs.iter() {
|
||||||
|
let db = db_ref.value();
|
||||||
|
db.flush()?;
|
||||||
|
}
|
||||||
(serde_json::to_vec(&KvResponse::Ok).unwrap(), None)
|
(serde_json::to_vec(&KvResponse::Ok).unwrap(), None)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -448,10 +448,11 @@ async fn check_caps(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
SqliteAction::Backup => {
|
SqliteAction::Backup => {
|
||||||
if source.process != *STATE_PROCESS_ID {
|
// flushing WALs for backup
|
||||||
return Err(SqliteError::NoCap {
|
// check caps.
|
||||||
error: request.action.to_string(),
|
for db_ref in open_dbs.iter() {
|
||||||
});
|
let db = db_ref.value().lock().await;
|
||||||
|
db.execute("pragma wal_checkpoint", [])?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
26
src/state.rs
26
src/state.rs
@ -218,15 +218,21 @@ async fn handle_request(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
StateAction::Backup => {
|
StateAction::Backup => {
|
||||||
// handle Backup action
|
let checkpoint_dir = format!("{}/vfs/kernel_backup", &home_directory_path);
|
||||||
println!("got backup");
|
|
||||||
let checkpoint_dir = format!("{}/kernel/checkpoint", &home_directory_path);
|
|
||||||
|
|
||||||
if Path::new(&checkpoint_dir).exists() {
|
if Path::new(&checkpoint_dir).exists() {
|
||||||
let _ = fs::remove_dir_all(&checkpoint_dir).await;
|
fs::remove_dir_all(&checkpoint_dir).await?;
|
||||||
}
|
}
|
||||||
let checkpoint = Checkpoint::new(&db).unwrap();
|
let checkpoint = Checkpoint::new(&db).map_err(|e| StateError::RocksDBError {
|
||||||
checkpoint.create_checkpoint(&checkpoint_dir).unwrap();
|
action: "BackupCheckpointNew".into(),
|
||||||
|
error: e.to_string(),
|
||||||
|
})?;
|
||||||
|
|
||||||
|
checkpoint.create_checkpoint(&checkpoint_dir).map_err(|e| StateError::RocksDBError {
|
||||||
|
action: "BackupCheckpointCreate".into(),
|
||||||
|
error: e.to_string(),
|
||||||
|
})?;
|
||||||
|
|
||||||
(serde_json::to_vec(&StateResponse::Backup).unwrap(), None)
|
(serde_json::to_vec(&StateResponse::Backup).unwrap(), None)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -609,6 +615,14 @@ async fn get_zipped_packages() -> Vec<(String, zip::ZipArchive<std::io::Cursor<&
|
|||||||
packages
|
packages
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<std::io::Error> for StateError {
|
||||||
|
fn from(err: std::io::Error) -> Self {
|
||||||
|
StateError::IOError {
|
||||||
|
error: err.to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn make_error_message(our_name: String, km: &KernelMessage, error: StateError) -> KernelMessage {
|
fn make_error_message(our_name: String, km: &KernelMessage, error: StateError) -> KernelMessage {
|
||||||
KernelMessage {
|
KernelMessage {
|
||||||
id: km.id,
|
id: km.id,
|
||||||
|
Loading…
Reference in New Issue
Block a user