From: Dominik Csapak <d.csapak@proxmox.com>
To: Proxmox Backup Server development discussion
<pbs-devel@lists.proxmox.com>,
Hannes Laimer <h.laimer@proxmox.com>
Subject: Re: [pbs-devel] [PATCH proxmox-backup v5 5/8] api: add get_active_operations endpoint
Date: Mon, 31 Jan 2022 15:47:42 +0100 [thread overview]
Message-ID: <4a777343-a0bd-7a81-4650-742d0ebaee6f@proxmox.com> (raw)
In-Reply-To: <20220124123159.27086-6-h.laimer@proxmox.com>
comments inline
On 1/24/22 13:31, Hannes Laimer wrote:
> Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
> ---
> pbs-datastore/src/task_tracking.rs | 30 ++++++++++++++++++++++++++++
> src/api2/admin/datastore.rs | 32 +++++++++++++++++++++++++++++-
> 2 files changed, 61 insertions(+), 1 deletion(-)
>
> diff --git a/pbs-datastore/src/task_tracking.rs b/pbs-datastore/src/task_tracking.rs
> index 06266e55..3f9693fa 100644
> --- a/pbs-datastore/src/task_tracking.rs
> +++ b/pbs-datastore/src/task_tracking.rs
> @@ -14,6 +14,36 @@ struct TaskOperations {
> writing_operations: i64,
> }
>
> +pub fn get_active_operations(name: &str, operation: Operation) -> Result<i64, Error> {
imho it would make sense to get all types of operations back here,
that way we can save a call to this function later
(and with it the double parsing/locking (more on that below)/etc..)
> + let path = PathBuf::from(format!("{}/{}", crate::ACTIVE_OPERATIONS_DIR, name));
> + let lock_path = PathBuf::from(format!("{}/{}.lock", crate::ACTIVE_OPERATIONS_DIR, name));
> +
> + let user = pbs_config::backup_user()?;
> + let options = CreateOptions::new()
> + .group(user.gid)
> + .owner(user.uid)
> + .perm(nix::sys::stat::Mode::from_bits_truncate(0o660));
> +
> + let timeout = std::time::Duration::new(10, 0);
> + open_file_locked(&lock_path, timeout, true, options.clone())?;
we only read and parse the file here, no updating, so we do not
have to lock here (the file is written atomically)
that way, the api call does not block a datastore operation
> +
> + Ok(match file_read_optional_string(&path)? {
> + Some(data) => {
> + let active_tasks: Vec<TaskOperations> = serde_json::from_str(&data)?;
> + active_tasks.iter()
> + .filter(|task| procfs::check_process_running(task.pid as pid_t).is_some())
> + .map(|task| {
> + match operation {
> + Operation::Read => task.reading_operations,
> + Operation::Write => task.writing_operations,
> + }
> + })
> + .sum()
> + }
> + None => 0,
> + })
> +}
> +
> pub fn update_active_operations(name: &str, operation: Operation, count: i64) -> Result<(), Error> {
> let path = PathBuf::from(format!("{}/{}", crate::ACTIVE_OPERATIONS_DIR, name));
> let lock_path = PathBuf::from(format!("{}/{}.lock", crate::ACTIVE_OPERATIONS_DIR, name));
> diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs
> index ce710938..878f21d4 100644
> --- a/src/api2/admin/datastore.rs
> +++ b/src/api2/admin/datastore.rs
> @@ -43,7 +43,7 @@ use pbs_api_types::{ Authid, BackupContent, Counts, CryptMode,
> use pbs_client::pxar::create_zip;
> use pbs_datastore::{
> check_backup_owner, DataStore, BackupDir, BackupGroup, StoreProgress, LocalChunkReader,
> - CATALOG_NAME,
> + CATALOG_NAME, task_tracking
> };
> use pbs_datastore::backup_info::BackupInfo;
> use pbs_datastore::cached_chunk_reader::CachedChunkReader;
> @@ -1590,6 +1590,31 @@ pub fn get_rrd_stats(
> )
> }
>
> +#[api(
> + input: {
> + properties: {
> + store: {
> + schema: DATASTORE_SCHEMA,
> + },
> + },
> + },
> + access: {
> + permission: &Permission::Privilege(&["datastore", "{store}"], PRIV_DATASTORE_AUDIT, true),
> + },
> +)]
> +/// Read datastore stats
> +pub fn get_active_operations(
> + store: String,
> + _param: Value,
> +) -> Result<Value, Error> {
> + let reading = task_tracking::get_active_operations(&store, Operation::Read)?;
> + let writing = task_tracking::get_active_operations(&store, Operation::Write)?;
this is what i meant above. when the function returns both operation counters,
we only have to call it once here
> + Ok(json!({
> + "read": reading,
> + "write": writing
> + }))
> +}
> +
> #[api(
> input: {
> properties: {
> @@ -1947,6 +1972,11 @@ pub fn set_backup_owner(
>
> #[sortable]
> const DATASTORE_INFO_SUBDIRS: SubdirMap = &[
> + (
> + "active-operations",
> + &Router::new()
> + .get(&API_METHOD_GET_ACTIVE_OPERATIONS)
> + ),
> (
> "catalog",
> &Router::new()
next prev parent reply other threads:[~2022-01-31 14:47 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-24 12:31 [pbs-devel] [PATCH proxmox-backup v5 0/8] closes #3071: maintenance mode for datastore Hannes Laimer
2022-01-24 12:31 ` [pbs-devel] [PATCH proxmox-backup v5 1/8] api-types: add maintenance type Hannes Laimer
2022-01-24 12:31 ` [pbs-devel] [PATCH proxmox-backup v5 2/8] datastore: add check for maintenance in lookup Hannes Laimer
2022-01-24 12:31 ` [pbs-devel] [PATCH proxmox-backup v5 3/8] pbs-datastore: add active operations tracking Hannes Laimer
2022-01-24 12:31 ` [pbs-devel] [PATCH proxmox-backup v5 4/8] api: make maintenance_type updatable Hannes Laimer
2022-01-24 12:31 ` [pbs-devel] [PATCH proxmox-backup v5 5/8] api: add get_active_operations endpoint Hannes Laimer
2022-01-31 14:47 ` Dominik Csapak [this message]
2022-01-24 12:31 ` [pbs-devel] [PATCH proxmox-backup v5 6/8] ui: add option to change the maintenance type Hannes Laimer
2022-01-24 12:31 ` [pbs-devel] [PATCH proxmox-backup v5 7/8] datastore: avoid tuple-match, use plain if Hannes Laimer
2022-01-24 12:31 ` [pbs-devel] [PATCH proxmox-backup v5 8/8] api: tape: fix datastore lookup operations Hannes Laimer
2022-01-31 14:50 ` Dominik Csapak
2022-01-24 12:33 ` [pbs-devel] [PATCH proxmox-backup v5 0/8] closes #3071: maintenance mode for datastore Hannes Laimer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4a777343-a0bd-7a81-4650-742d0ebaee6f@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=h.laimer@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox