public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dietmar Maurer <dietmar@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 v6 03/23] datastore: rename and simplify update-datastore-cache socket command
Date: Fri, 19 Apr 2024 08:53:34 +0200 (CEST)	[thread overview]
Message-ID: <1715382082.8413.1713509614273@webmail.proxmox.com> (raw)
In-Reply-To: <20240418142931.122618-4-h.laimer@proxmox.com>

First, you may not simply change the command name, because that can
potentially trigger problems when updating packages.

Anyways, I would like to avoid such changes at the current stage.

Cleanup up the update_datastore_cache() is a great idea, but I would do it later (after we applied the removable datastore patches).

> On 18.4.2024 16:29 CEST Hannes Laimer <h.laimer@proxmox.com> wrote:
> 
>  
> ... by always dropping the cache entry and not allowing it to be
> re-added based on the maintenance mode. The check is only needed for
> Lookup operations since lookups with those wouldn't fail based on
> maintenance mode alone. Already running tasks won't be affected and
> since they're the only ones holding a reference to a DataStore, it
> and the file handles it holds will be dropped automatically once the
> task finishes.
> 
> Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
> ---
>  pbs-datastore/src/datastore.rs  | 26 ++++++++++----------------
>  src/api2/config/datastore.rs    |  9 ++++-----
>  src/bin/proxmox-backup-proxy.rs |  8 ++++----
>  3 files changed, 18 insertions(+), 25 deletions(-)
> 
> diff --git a/pbs-datastore/src/datastore.rs b/pbs-datastore/src/datastore.rs
> index f95da761..e1028778 100644
> --- a/pbs-datastore/src/datastore.rs
> +++ b/pbs-datastore/src/datastore.rs
> @@ -190,10 +190,15 @@ impl DataStore {
>              )?)
>          };
>  
> +        let is_offline = config
> +            .get_maintenance_mode()
> +            .map_or(false, |m| m.is_offline());
>          let datastore = DataStore::with_store_and_config(chunk_store, config, Some(digest))?;
>  
>          let datastore = Arc::new(datastore);
> -        datastore_cache.insert(name.to_string(), datastore.clone());
> +        if !is_offline {
> +            datastore_cache.insert(name.to_string(), datastore.clone());
> +        }
>  
>          Ok(Arc::new(Self {
>              inner: datastore,
> @@ -211,21 +216,10 @@ impl DataStore {
>          Ok(())
>      }
>  
> -    /// trigger clearing cache entry based on maintenance mode. Entry will only
> -    /// be cleared iff there is no other task running, if there is, the end of the
> -    /// last running task will trigger the clearing of the cache entry.
> -    pub fn update_datastore_cache(name: &str) -> Result<(), Error> {
> -        let (config, _digest) = pbs_config::datastore::config()?;
> -        let datastore: DataStoreConfig = config.lookup("datastore", name)?;
> -        if datastore
> -            .get_maintenance_mode()
> -            .map_or(false, |m| m.is_offline())
> -        {
> -            // the datastore drop handler does the checking if tasks are running and clears the
> -            // cache entry, so we just have to trigger it here
> -            let _ = DataStore::lookup_datastore(name, Some(Operation::Lookup));
> -        }
> -
> +    /// removes datastore from cache
> +    pub fn drop_from_datastore_cache(name: &str) -> Result<(), Error> {
> +        let mut datastore_cache = DATASTORE_MAP.lock().unwrap();
> +        datastore_cache.remove(name);
>          Ok(())
>      }
>  
> diff --git a/src/api2/config/datastore.rs b/src/api2/config/datastore.rs
> index 87425ff5..af5f5429 100644
> --- a/src/api2/config/datastore.rs
> +++ b/src/api2/config/datastore.rs
> @@ -389,16 +389,15 @@ pub fn update_datastore(
>          data.tuning = update.tuning;
>      }
>  
> -    let mut maintenance_mode_changed = false;
> +    let mut drop_store_from_cache = false;
>      if update.maintenance_mode.is_some() {
> -        maintenance_mode_changed = data.maintenance_mode != update.maintenance_mode;
> -
>          let maintenance_mode = match update.maintenance_mode {
>              Some(mode_str) => Some(MaintenanceMode::deserialize(
>                  proxmox_schema::de::SchemaDeserializer::new(mode_str, &MaintenanceMode::API_SCHEMA),
>              )?),
>              None => None,
>          };
> +        drop_store_from_cache = maintenance_mode.as_ref().map_or(false, |m| m.is_offline());
>          data.set_maintenance_mode(maintenance_mode)?;
>      }
>  
> @@ -413,7 +412,7 @@ pub fn update_datastore(
>      }
>  
>      // tell the proxy it might have to clear a cache entry
> -    if maintenance_mode_changed {
> +    if drop_store_from_cache {
>          tokio::spawn(async move {
>              if let Ok(proxy_pid) =
>                  proxmox_rest_server::read_pid(pbs_buildcfg::PROXMOX_BACKUP_PROXY_PID_FN)
> @@ -422,7 +421,7 @@ pub fn update_datastore(
>                  let _ = proxmox_rest_server::send_raw_command(
>                      sock,
>                      &format!(
> -                        "{{\"command\":\"update-datastore-cache\",\"args\":\"{}\"}}\n",
> +                        "{{\"command\":\"drop-from-datastore-cache\",\"args\":\"{}\"}}\n",
>                          &name
>                      ),
>                  )
> diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs
> index f79ec2f5..073f85ac 100644
> --- a/src/bin/proxmox-backup-proxy.rs
> +++ b/src/bin/proxmox-backup-proxy.rs
> @@ -289,11 +289,11 @@ async fn run() -> Result<(), Error> {
>          Ok(Value::Null)
>      })?;
>  
> -    // clear cache entry for datastore that is in a specific maintenance mode
> -    command_sock.register_command("update-datastore-cache".to_string(), |value| {
> +    // clear cache entry for datastore
> +    command_sock.register_command("drop-from-datastore-cache".to_string(), |value| {
>          if let Some(name) = value.and_then(Value::as_str) {
> -            if let Err(err) = DataStore::update_datastore_cache(name) {
> -                log::error!("could not trigger update datastore cache: {err}");
> +            if let Err(err) = DataStore::drop_from_datastore_cache(name) {
> +                log::error!("could not drop datastore from cache: {err}");
>              }
>          }
>          Ok(Value::Null)
> -- 
> 2.39.2
> 
> 
> 
> _______________________________________________
> pbs-devel mailing list
> pbs-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel


_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel


  reply	other threads:[~2024-04-19  6:53 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-18 14:29 [pbs-devel] [PATCH proxmox-backup v6 00/23] add removable datastores Hannes Laimer
2024-04-18 14:29 ` [pbs-devel] [PATCH proxmox-backup v6 01/23] pbs-api-types: new MaintenanceType::Unmount, implement and use set_maintenance_mode Hannes Laimer
2024-04-18 14:29 ` [pbs-devel] [PATCH proxmox-backup v6 02/23] pbs-api-types: use SchemaDeserializer for maintenance mode Hannes Laimer
2024-04-18 14:29 ` [pbs-devel] [PATCH proxmox-backup v6 03/23] datastore: rename and simplify update-datastore-cache socket command Hannes Laimer
2024-04-19  6:53   ` Dietmar Maurer [this message]
2024-04-18 14:29 ` [pbs-devel] [PATCH proxmox-backup v6 04/23] tools: add disks utility functions Hannes Laimer
2024-04-18 14:29 ` [pbs-devel] [PATCH proxmox-backup v6 05/23] pbs-api-types: add backing-device to DataStoreConfig Hannes Laimer
2024-04-18 14:29 ` [pbs-devel] [PATCH proxmox-backup v6 06/23] disks: add UUID to partition info Hannes Laimer
2024-04-18 14:29 ` [pbs-devel] [PATCH proxmox-backup v6 07/23] add helper for checking if a removable datastore is available Hannes Laimer
2024-04-18 14:29 ` [pbs-devel] [PATCH proxmox-backup v6 08/23] api2: admin: add (un)mount endpoint for removable datastores Hannes Laimer
2024-04-19  7:27   ` Dietmar Maurer
2024-04-19  7:34     ` Dietmar Maurer
2024-04-18 14:29 ` [pbs-devel] [PATCH proxmox-backup v6 09/23] api2: removable datastore creation Hannes Laimer
2024-04-18 14:29 ` [pbs-devel] [PATCH proxmox-backup v6 10/23] api2: disks list: add only-unused flag Hannes Laimer
2024-04-18 14:50   ` Christian Ebner
2024-04-18 14:29 ` [pbs-devel] [PATCH proxmox-backup v6 11/23] pbs-api-types: add removable/is-available flag to DataStoreListItem Hannes Laimer
2024-04-18 14:29 ` [pbs-devel] [PATCH proxmox-backup v6 12/23] bin: manager: add (un)mount command Hannes Laimer
2024-04-18 14:29 ` [pbs-devel] [PATCH proxmox-backup v6 13/23] add auto-mounting for removable datastores Hannes Laimer
2024-04-18 14:29 ` [pbs-devel] [PATCH proxmox-backup v6 14/23] datastore: handle deletion of removable datastore properly Hannes Laimer
2024-04-18 14:29 ` [pbs-devel] [PATCH proxmox-backup v6 15/23] docs: add removable datastores section Hannes Laimer
2024-04-18 14:29 ` [pbs-devel] [PATCH proxmox-backup v6 16/23] ui: add partition selector form Hannes Laimer
2024-04-18 14:29 ` [pbs-devel] [PATCH proxmox-backup v6 17/23] ui: add removable datastore creation support Hannes Laimer
2024-04-18 14:29 ` [pbs-devel] [PATCH proxmox-backup v6 18/23] ui: add (un)mount button to summary Hannes Laimer
2024-04-18 14:29 ` [pbs-devel] [PATCH proxmox-backup v6 19/23] ui: tree: render unmounted datastores correctly Hannes Laimer
2024-04-18 14:29 ` [pbs-devel] [PATCH proxmox-backup v6 20/23] ui: utils: make parseMaintenanceMode more robust Hannes Laimer
2024-04-18 14:29 ` [pbs-devel] [PATCH proxmox-backup v6 21/23] ui: add datastore status mask for unmounted removable datastores Hannes Laimer
2024-04-18 14:29 ` [pbs-devel] [PATCH proxmox-backup v6 22/23] ui: maintenance: fix disable msg field if no type is selected Hannes Laimer
2024-04-18 14:29 ` [pbs-devel] [PATCH proxmox-backup v6 23/23] ui: render 'unmount' maintenance mode correctly 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=1715382082.8413.1713509614273@webmail.proxmox.com \
    --to=dietmar@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