From: Dietmar Maurer <dietmar@proxmox.com>
To: Proxmox Backup Server development discussion
<pbs-devel@lists.proxmox.com>,
Dominik Csapak <d.csapak@proxmox.com>
Subject: Re: [pbs-devel] [PATCH proxmox-backup 3/3] admin/datastore: add more info to status call
Date: Tue, 3 Nov 2020 06:52:11 +0100 (CET) [thread overview]
Message-ID: <846767739.645.1604382732187@webmail.proxmox.com> (raw)
In-Reply-To: <20201023143233.14949-4-d.csapak@proxmox.com>
This change makes the API call very slow. because it scans over the whole directory tree.
Is this really necessary?
> On 10/23/2020 4:32 PM Dominik Csapak <d.csapak@proxmox.com> wrote:
>
>
> add also the snapshot counts as well as the status of the last garbage
> collection
>
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
> src/api2/admin/datastore.rs | 61 +++++++++++++++++++++++++++++++++++--
> 1 file changed, 58 insertions(+), 3 deletions(-)
>
> diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs
> index feeff8af..e1a0aacc 100644
> --- a/src/api2/admin/datastore.rs
> +++ b/src/api2/admin/datastore.rs
> @@ -423,6 +423,37 @@ pub fn list_snapshots (
> Ok(snapshots)
> }
>
> +// returns a map from type to (group_count, snapshot_count)
> +fn get_snaphots_count(store: &DataStore) -> Result<HashMap<String, (usize, usize)>, Error> {
> + let base_path = store.base_path();
> + let backup_list = BackupInfo::list_backups(&base_path)?;
> + let mut groups = HashSet::new();
> + let mut result: HashMap<String, (usize, usize)> = HashMap::new();
> + for info in backup_list {
> + let group = info.backup_dir.group();
> +
> + let id = group.backup_id();
> + let backup_type = group.backup_type();
> +
> + let mut new_id = false;
> +
> + if groups.insert(format!("{}-{}", &backup_type, &id)) {
> + new_id = true;
> + }
> +
> + if let Some(mut counts) = result.get_mut(backup_type) {
> + counts.1 += 1;
> + if new_id {
> + counts.0 +=1;
> + }
> + } else {
> + result.insert(backup_type.to_string(), (1, 1));
> + }
> + }
> +
> + Ok(result)
> +}
> +
> #[api(
> input: {
> properties: {
> @@ -432,7 +463,21 @@ pub fn list_snapshots (
> },
> },
> returns: {
> - type: StorageStatus,
> + description: "The overall Datastore status and information.",
> + type: Object,
> + properties: {
> + storage: {
> + type: StorageStatus,
> + },
> + counts: {
> + description: "Group and Snapshot counts per Type",
> + type: Object,
> + properties: { },
> + },
> + "gc-status": {
> + type: GarbageCollectionStatus,
> + },
> + },
> },
> access: {
> permission: &Permission::Privilege(&["datastore", "{store}"], PRIV_DATASTORE_AUDIT | PRIV_DATASTORE_BACKUP, true),
> @@ -443,9 +488,19 @@ pub fn status(
> store: String,
> _info: &ApiMethod,
> _rpcenv: &mut dyn RpcEnvironment,
> -) -> Result<StorageStatus, Error> {
> +) -> Result<Value, Error> {
> let datastore = DataStore::lookup_datastore(&store)?;
> - crate::tools::disks::disk_usage(&datastore.base_path())
> + let storage_status = crate::tools::disks::disk_usage(&datastore.base_path())?;
> + let counts = get_snaphots_count(&datastore)?;
> + let gc_status = datastore.last_gc_status();
> +
> + let res = json!({
> + "storage": storage_status,
> + "counts": counts,
> + "gc-status": gc_status,
> + });
> +
> + Ok(res)
> }
>
> #[api(
> --
> 2.20.1
>
>
>
> _______________________________________________
> pbs-devel mailing list
> pbs-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
next prev parent reply other threads:[~2020-11-03 5:53 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-23 14:32 [pbs-devel] [PATCH proxmox-backup 0/3] improve and extend admin/datastore/status api Dominik Csapak
2020-10-23 14:32 ` [pbs-devel] [PATCH proxmox-backup 1/3] backup/datastore: count still bad chunks for the status Dominik Csapak
2020-10-23 14:32 ` [pbs-devel] [PATCH proxmox-backup 2/3] backup/datastore: save garbage collection status to disk Dominik Csapak
2020-10-23 14:32 ` [pbs-devel] [PATCH proxmox-backup 3/3] admin/datastore: add more info to status call Dominik Csapak
2020-11-03 5:52 ` Dietmar Maurer [this message]
2020-11-03 6:53 ` Dominik Csapak
2020-10-27 16:44 ` [pbs-devel] applied-series: [PATCH proxmox-backup 0/3] improve and extend admin/datastore/status api Thomas Lamprecht
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=846767739.645.1604382732187@webmail.proxmox.com \
--to=dietmar@proxmox.com \
--cc=d.csapak@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