src/api2/admin/datastore/backup.rs: implement close for dynamic writers
This commit is contained in:
parent
4e93f8c164
commit
a20772525f
|
@ -144,6 +144,10 @@ fn backup_api() -> Router {
|
|||
.download(api_method_dynamic_chunk_index())
|
||||
.post(api_method_create_dynamic_index())
|
||||
)
|
||||
.subdir(
|
||||
"dynamic_close", Router::new()
|
||||
.post(api_method_close_dynamic_index())
|
||||
)
|
||||
.subdir("test1", test1)
|
||||
.subdir("test2", test2)
|
||||
.list_subdirs();
|
||||
|
@ -200,13 +204,40 @@ fn create_dynamic_index(
|
|||
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(¶m, "wid")? as usize;
|
||||
|
||||
let env: &BackupEnvironment = rpcenv.as_ref();
|
||||
|
||||
env.dynamic_writer_close(wid)?;
|
||||
|
||||
Ok(Value::Null)
|
||||
}
|
||||
|
||||
|
||||
|
||||
fn test1_get (
|
||||
_param: Value,
|
||||
_info: &ApiMethod,
|
||||
rpcenv: &mut RpcEnvironment,
|
||||
) -> Result<Value, Error> {
|
||||
|
||||
println!("TYPEID {:?}", (*rpcenv).type_id());
|
||||
|
||||
let env: &BackupEnvironment = rpcenv.as_ref();
|
||||
|
||||
|
|
|
@ -89,6 +89,20 @@ impl BackupEnvironment {
|
|||
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) {
|
||||
self.worker.log(msg);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue