From: Lukas Wagner <l.wagner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [RFC pve-storage 7/7] stats: api: cache storage plugin status
Date: Mon, 21 Aug 2023 15:44:44 +0200 [thread overview]
Message-ID: <20230821134444.620021-8-l.wagner@proxmox.com> (raw)
In-Reply-To: <20230821134444.620021-1-l.wagner@proxmox.com>
Cache storage plugin status so that pvestatd and API calls can use the
cached results, without having to query all storage plugins again.
Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
src/PVE/API2/Storage/Config.pm | 10 +++++++++
src/PVE/Storage.pm | 40 ++++++++++++++++++++++++----------
2 files changed, 39 insertions(+), 11 deletions(-)
diff --git a/src/PVE/API2/Storage/Config.pm b/src/PVE/API2/Storage/Config.pm
index e04b6ab..8c3df99 100755
--- a/src/PVE/API2/Storage/Config.pm
+++ b/src/PVE/API2/Storage/Config.pm
@@ -16,6 +16,7 @@ use PVE::JSONSchema qw(get_standard_option);
use PVE::RPCEnvironment;
use PVE::RESTHandler;
+use PVE::RS::Cache;
use base qw(PVE::RESTHandler);
@@ -274,6 +275,9 @@ __PACKAGE__->register_method ({
die $err;
}
+ # Remove cached plugin status on configuration changes.
+ PVE::RS::Cache->pvestatd_cache()->delete("storage_plugin_status");
+
PVE::Storage::write_config($cfg);
}, "create storage failed");
@@ -373,6 +377,9 @@ __PACKAGE__->register_method ({
." in Proxmox VE 9. Use 'create-base-path' or 'create-subdirs' instead.\n"
}
+ # Remove cached plugin status on configuration changes.
+ PVE::RS::Cache->pvestatd_cache()->delete("storage_plugin_status");
+
PVE::Storage::write_config($cfg);
}, "update storage failed");
@@ -422,6 +429,9 @@ __PACKAGE__->register_method ({
delete $cfg->{ids}->{$storeid};
+ # Remove cached plugin status on configuration changes.
+ PVE::RS::Cache->pvestatd_cache()->delete("storage_plugin_status");
+
PVE::Storage::write_config($cfg);
}, "delete storage failed");
diff --git a/src/PVE/Storage.pm b/src/PVE/Storage.pm
index a4d85e1..7aa3b2e 100755
--- a/src/PVE/Storage.pm
+++ b/src/PVE/Storage.pm
@@ -23,6 +23,7 @@ use PVE::INotify;
use PVE::RPCEnvironment;
use PVE::SSHInfo;
use PVE::RESTEnvironment qw(log_warn);
+use PVE::RS::Cache;
use PVE::Storage::Plugin;
use PVE::Storage::DirPlugin;
@@ -1276,6 +1277,10 @@ sub storage_info {
my $cache = {};
+ my $status_cache = PVE::RS::Cache->pvestatd_cache();
+ my $cached_status = $status_cache->get("storage_plugin_status");
+ my $refresh_status = !$cached_status;
+
foreach my $storeid (keys %$ids) {
my $scfg = $ids->{$storeid};
@@ -1291,21 +1296,34 @@ sub storage_info {
if $pd->{select_existing};
}
- eval { activate_storage($cfg, $storeid, $cache); };
- if (my $err = $@) {
- warn $err;
- next;
+ if ($refresh_status) {
+ eval { activate_storage($cfg, $storeid, $cache); };
+ if (my $err = $@) {
+ warn $err;
+ next;
+ }
+ $cached_status->{$storeid} = eval { $plugin->status($storeid, $scfg, $cache); };
+
+ my ($total, $avail, $used, $active) = eval { $plugin->status($storeid, $scfg, $cache); };
+ warn $@ if $@;
+ $cached_status->{$storeid} = {};
+
+ $cached_status->{$storeid}->{total} = int($total);
+ $cached_status->{$storeid}->{avail} = int($avail);
+ $cached_status->{$storeid}->{used} = int($used);
+ $cached_status->{$storeid}->{active} = $active;
+ next if !$active;
}
- my ($total, $avail, $used, $active) = eval { $plugin->status($storeid, $scfg, $cache); };
- warn $@ if $@;
- next if !$active;
- $info->{$storeid}->{total} = int($total);
- $info->{$storeid}->{avail} = int($avail);
- $info->{$storeid}->{used} = int($used);
- $info->{$storeid}->{active} = $active;
+ $info->{$storeid}->{total} = $cached_status->{$storeid}->{total};
+ $info->{$storeid}->{avail} = $cached_status->{$storeid}->{avail};
+ $info->{$storeid}->{used} = $cached_status->{$storeid}->{used};
+ $info->{$storeid}->{active} = $cached_status->{$storeid}->{active};
}
+ # TODO: How long should status results be valid?
+ $status_cache->set('storage_plugin_status', $cached_status, 30) if $refresh_status;
+
return $info;
}
--
2.39.2
next prev parent reply other threads:[~2023-08-21 13:45 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-21 13:44 [pve-devel] [RFC storage/proxmox{, -perl-rs} 0/7] cache storage plugin status for pvestatd/API status update calls Lukas Wagner
2023-08-21 13:44 ` [pve-devel] [RFC proxmox 1/7] sys: fs: move tests to a sub-module Lukas Wagner
2023-08-30 15:38 ` [pve-devel] applied: " Thomas Lamprecht
2023-08-21 13:44 ` [pve-devel] [RFC proxmox 2/7] sys: add make_tmp_dir Lukas Wagner
2023-08-22 8:39 ` Wolfgang Bumiller
2023-08-21 13:44 ` [pve-devel] [RFC proxmox 3/7] sys: fs: remove unnecessary clippy allow directive Lukas Wagner
2023-08-21 13:44 ` [pve-devel] [RFC proxmox 4/7] cache: add new crate 'proxmox-cache' Lukas Wagner
2023-08-22 10:08 ` Max Carrara
2023-08-22 11:33 ` Lukas Wagner
2023-08-22 12:01 ` Wolfgang Bumiller
2023-08-22 11:56 ` Wolfgang Bumiller
2023-08-22 13:52 ` Max Carrara
2023-08-21 13:44 ` [pve-devel] [RFC proxmox 5/7] cache: add debian packaging Lukas Wagner
2023-08-21 13:44 ` [pve-devel] [RFC proxmox-perl-rs 6/7] cache: add bindings for `SharedCache` from `proxmox-cache` Lukas Wagner
2023-08-21 13:44 ` Lukas Wagner [this message]
2023-08-22 8:51 ` [pve-devel] [RFC pve-storage 7/7] stats: api: cache storage plugin status Lukas Wagner
2023-08-22 9:17 ` [pve-devel] [RFC storage/proxmox{, -perl-rs} 0/7] cache storage plugin status for pvestatd/API status update calls Fiona Ebner
2023-08-22 11:25 ` Wolfgang Bumiller
2023-08-30 17:07 ` Wolf Noble
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=20230821134444.620021-8-l.wagner@proxmox.com \
--to=l.wagner@proxmox.com \
--cc=pve-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.