public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Wolfgang Bumiller <w.bumiller@proxmox.com>
To: Hannes Laimer <h.laimer@proxmox.com>
Cc: pbs-devel@lists.proxmox.com
Subject: Re: [pbs-devel] [PATCH proxmox-backup v7 3/6] pbs-datastore: add active operations tracking
Date: Tue, 8 Feb 2022 11:13:00 +0100	[thread overview]
Message-ID: <20220208101300.23b2et6v3weq2y5e@olga.proxmox.com> (raw)
In-Reply-To: <20220204111729.22107-4-h.laimer@proxmox.com>

On Fri, Feb 04, 2022 at 11:17:26AM +0000, Hannes Laimer wrote:
> Saves the currently active read/write operation counts in a file. The
> file is updated whenever a reference returned by lookup_datastore is
> dropped and whenever a reference is returned by lookup_datastore. The
> files are locked before every access, there is one file per datastore.
> 
> Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
> ---
>  pbs-api-types/src/maintenance.rs   |   1 +
>  pbs-datastore/Cargo.toml           |   1 +
>  pbs-datastore/src/datastore.rs     | 114 +++++++++++++++++++----------
>  pbs-datastore/src/lib.rs           |   4 +
>  pbs-datastore/src/task_tracking.rs |  81 ++++++++++++++++++++
>  src/bin/proxmox-backup-api.rs      |   1 +
>  src/server/mod.rs                  |  16 +++-
>  7 files changed, 180 insertions(+), 38 deletions(-)
>  create mode 100644 pbs-datastore/src/task_tracking.rs
> 
> diff --git a/pbs-api-types/src/maintenance.rs b/pbs-api-types/src/maintenance.rs
> index 4d3ccb3b..1b5753d2 100644
> --- a/pbs-api-types/src/maintenance.rs
> +++ b/pbs-api-types/src/maintenance.rs
> @@ -25,6 +25,7 @@ pub enum MaintenanceType {
>      Offline(String),
>  }
>  
> +#[derive(Copy ,Clone)]

^ wrong space

>  /// Operation requirments, used when checking for maintenance mode.
>  pub enum Operation {
>      Read,
> diff --git a/pbs-datastore/Cargo.toml b/pbs-datastore/Cargo.toml
> index d8cefa00..0c703d44 100644
> @@ -54,13 +56,42 @@ pub fn check_backup_owner(
>  ///
>  /// A Datastore can store severals backups, and provides the
>  /// management interface for backup.
> -pub struct DataStore {
> +pub struct DataStoreImpl {
>      chunk_store: Arc<ChunkStore>,
>      gc_mutex: Mutex<()>,
>      last_gc_status: Mutex<GarbageCollectionStatus>,
>      verify_new: bool,
>  }
>  
> +pub struct DataStore {
> +    inner: Arc<DataStoreImpl>,
> +    operation: Option<Operation>,
> +}
> +
> +impl Clone for DataStore {
> +    fn clone(&self) -> Self {
> +        if let Some(operation) = self.operation.clone() {
> +            if let Err(e) = update_active_operations(self.name(), operation, 1) {
> +                eprintln!("could not update active operations - {}", e);

I think if this fails we should return a value with `operation: None`
*or* have the count as a separate field, otherwise `Drop` will cause a
miscount here, no?

Also, please prefer `log::error!` here over `eprintln!`.

> +            }
> +        }
> +        DataStore {
> +            inner: self.inner.clone(),
> +            operation: self.operation.clone(),
> +        }
> +    }
> +}
> +
> +impl Drop for DataStore {
> +    fn drop(&mut self) {
> +        if let Some(operation) = self.operation.clone() {
> +            if let Err(e) = update_active_operations(self.name(), operation, -1) {
> +                eprintln!("could not update active operations - {}", e);

here too, `eprintln!` -> `log::error!`

> +            }
> +        }
> +    }
> +}
> +
>  impl DataStore {
>      pub fn lookup_datastore(
>          name: &str,
> diff --git a/pbs-datastore/src/lib.rs b/pbs-datastore/src/lib.rs
> index d50a64a5..131040c6 100644
> diff --git a/pbs-datastore/src/task_tracking.rs b/pbs-datastore/src/task_tracking.rs
> new file mode 100644
> index 00000000..a02d9a17
> --- /dev/null
> +++ b/pbs-datastore/src/task_tracking.rs
> @@ -0,0 +1,81 @@
> +use anyhow::Error;
> +use libc::pid_t;
> +use nix::unistd::Pid;
> +use std::path::PathBuf;
> +
> +use pbs_api_types::Operation;
> +use proxmox_sys::fs::{file_read_optional_string, open_file_locked, replace_file, CreateOptions};
> +use proxmox_sys::linux::procfs;
> +use serde::{Deserialize, Serialize};
> +
> +#[derive(Deserialize, Serialize, Clone)]
> +struct TaskOperations {
> +    pid: u32,
> +    starttime: u64,
> +    reading_operations: i64,
> +    writing_operations: i64,
> +}
> +
> +pub fn update_active_operations(name: &str, operation: Operation, count: i64) -> Result<(), Error> {

I'm thinking there might be a way to use shared memory here, but dealing
with dead processes becomes a bit more tricky.

If you're motivated, you could take a look at
`pbs-config/src/config_version_cache.rs` to see what I mean
(DataStoreImpl could contain the mmapped region, but dealing with dead
processes is still a bit of work, would need some atomics for the PID
and registration state of a process...)

> +    let path = PathBuf::from(format!("{}/{}", crate::ACTIVE_OPERATIONS_DIR, name));
> +    let lock_path = PathBuf::from(format!("{}/{}.lock", crate::ACTIVE_OPERATIONS_DIR, name));
> (...)




  reply	other threads:[~2022-02-08 10:13 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-04 11:17 [pbs-devel] [PATCH proxmox-backup v7 0/6] closes #3071: maintenance mode for datastore Hannes Laimer
2022-02-04 11:17 ` [pbs-devel] [PATCH proxmox-backup v7 1/6] api-types: add maintenance type Hannes Laimer
2022-02-08  9:40   ` Wolfgang Bumiller
2022-02-04 11:17 ` [pbs-devel] [PATCH proxmox-backup v7 2/6] datastore: add check for maintenance in lookup Hannes Laimer
2022-02-08  9:43   ` Wolfgang Bumiller
2022-02-04 11:17 ` [pbs-devel] [PATCH proxmox-backup v7 3/6] pbs-datastore: add active operations tracking Hannes Laimer
2022-02-08 10:13   ` Wolfgang Bumiller [this message]
2022-02-04 11:17 ` [pbs-devel] [PATCH proxmox-backup v7 4/6] api: make maintenance_type updatable Hannes Laimer
2022-02-04 11:17 ` [pbs-devel] [PATCH proxmox-backup v7 5/6] api: add get_active_operations endpoint Hannes Laimer
2022-02-04 11:17 ` [pbs-devel] [PATCH proxmox-backup v7 6/6] ui: add option to change the maintenance type 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=20220208101300.23b2et6v3weq2y5e@olga.proxmox.com \
    --to=w.bumiller@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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal