src/api2/admin/datastore/backup.rs: implement close for dynamic writers

This commit is contained in:
Dietmar Maurer 2019-05-15 07:58:05 +02:00
parent 4e93f8c164
commit a20772525f
2 changed files with 46 additions and 1 deletions

View File

@ -144,6 +144,10 @@ fn backup_api() -> Router {
.download(api_method_dynamic_chunk_index()) .download(api_method_dynamic_chunk_index())
.post(api_method_create_dynamic_index()) .post(api_method_create_dynamic_index())
) )
.subdir(
"dynamic_close", Router::new()
.post(api_method_close_dynamic_index())
)
.subdir("test1", test1) .subdir("test1", test1)
.subdir("test2", test2) .subdir("test2", test2)
.list_subdirs(); .list_subdirs();
@ -200,13 +204,40 @@ fn create_dynamic_index(
Ok(json!(uid)) Ok(json!(uid))
} }
pub fn api_method_close_dynamic_index() -> ApiMethod {
ApiMethod::new(
close_dynamic_index,
ObjectSchema::new("Close dynamic index writer.")
.required("wid", IntegerSchema::new("Dynamic writer ID.")
.minimum(1)
.maximum(256)
)
)
}
fn close_dynamic_index (
param: Value,
_info: &ApiMethod,
rpcenv: &mut RpcEnvironment,
) -> Result<Value, Error> {
let wid = tools::required_integer_param(&param, "wid")? as usize;
let env: &BackupEnvironment = rpcenv.as_ref();
env.dynamic_writer_close(wid)?;
Ok(Value::Null)
}
fn test1_get ( fn test1_get (
_param: Value, _param: Value,
_info: &ApiMethod, _info: &ApiMethod,
rpcenv: &mut RpcEnvironment, rpcenv: &mut RpcEnvironment,
) -> Result<Value, Error> { ) -> Result<Value, Error> {
println!("TYPEID {:?}", (*rpcenv).type_id());
let env: &BackupEnvironment = rpcenv.as_ref(); let env: &BackupEnvironment = rpcenv.as_ref();

View File

@ -89,6 +89,20 @@ impl BackupEnvironment {
Ok(()) Ok(())
} }
/// Close dynamic writer
pub fn dynamic_writer_close(&self, wid: usize) -> Result<(), Error> {
let mut state = self.state.lock().unwrap();
let mut data = match state.dynamic_writers.remove(&wid) {
Some(data) => data,
None => bail!("dynamic writer '{}' not registered", wid),
};
data.1.close()?;
Ok(())
}
pub fn log<S: AsRef<str>>(&self, msg: S) { pub fn log<S: AsRef<str>>(&self, msg: S) {
self.worker.log(msg); self.worker.log(msg);
} }