public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Wolfgang Bumiller <w.bumiller@proxmox.com>
To: Lukas Wagner <l.wagner@proxmox.com>
Cc: Max Carrara <m.carrara@proxmox.com>,
	 Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Subject: Re: [pve-devel] [RFC proxmox 4/7] cache: add new crate 'proxmox-cache'
Date: Tue, 22 Aug 2023 14:01:54 +0200	[thread overview]
Message-ID: <wwojtuxonmaw7igbxb4qgbwswqbpmcqjj6fekdny7qlkztzecn@w6koixnfzaxa> (raw)
In-Reply-To: <8aaefb26-be4b-477c-b6a7-9e2fbe598215@proxmox.com>

On Tue, Aug 22, 2023 at 01:33:44PM +0200, Lukas Wagner wrote:
(...)
> > ... can be replaced as follows, in order to make it similar to
> > std::collections::{HashMap, BTreeMap}:
> > 
> > impl<K: AsRef<str>> for SharedCache<K, Value> {
> >      // Returns old value on successful insert, if given
> >      fn insert(&self, k: K, v: Value) -> Result<Option<Value>, Error> {
> >          // ...
> >      }
> > 
> >      fn get(&self, k: K) -> Result<Option<Value>, Error> {
> >          // ...
> >      }
> > 
> >      fn remove(&self, k: K) -> Result<Option<Value>, Error> {
> >          // ...
> >      }
> > }
> > 
> > If necessary / sensible, other methods (inspired by {HashMap, BTreeMap} can
> > be added as well, such as remove_entry, retain, clear, etc.
> > 
> 
> I don't have any hard feelings regarding the naming, but not returning a
> Value from `delete` was a conscious decision - we simply don't need it right
> now. I don't want to deserialize to just throw away the value.
> Also, reading *and* deleting at the same time *might* introduce the need for
> file locking - although I'm not completely sure about that yet.
> 
> If we ever need a `remove` that also returns the value, we could just
> introduce a second method, e.g. `take`.

Locking might make sense though.

If we want to refresh data, it may make sense to first lock the cache
entry, then re-check the expiration time, and only then do the actual
refresh.
That way, 5 concurrent accesses will cause only a single refresh, since
afterwards they all see the new value.

As for `take` vs locking: You *could* have the first operation be a
`rename` to a random string, then open,delete,read (but then you need
something that cleans up after left-overs when a process gets killed
between the rename & delete.
But I don't quite see the value in this functionality here for now :-)




  reply	other threads:[~2023-08-22 12:02 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 [this message]
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 ` [pve-devel] [RFC pve-storage 7/7] stats: api: cache storage plugin status Lukas Wagner
2023-08-22  8:51   ` 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=wwojtuxonmaw7igbxb4qgbwswqbpmcqjj6fekdny7qlkztzecn@w6koixnfzaxa \
    --to=w.bumiller@proxmox.com \
    --cc=l.wagner@proxmox.com \
    --cc=m.carrara@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 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