pub struct KVStore<T> { /* private fields */ }Expand description
A distributed Key, Value store which is generic for type T. Since
this is a distributed KVStore, Keys know which node the values
‘belong’ to.
Internally KVStores store their data in memory as serialized blobs
(Vec<u8>). The KVStore caches deserialized Values into their type
T on a least-recently used basis. There is a hard limit on the cache size
that is set to 1/3 the total memory of the machine.
Implementations§
Source§impl<T: Serialize + DeserializeOwned + Sync + Send + PartialEq + DeepSizeOf + 'static> KVStore<T>
impl<T: Serialize + DeserializeOwned + Sync + Send + PartialEq + DeepSizeOf + 'static> KVStore<T>
Sourcepub async fn new(
server_addr: String,
my_addr: String,
blob_sender: Sender<Value>,
num_clients: usize,
) -> Arc<Self>
pub async fn new( server_addr: String, my_addr: String, blob_sender: Sender<Value>, num_clients: usize, ) -> Arc<Self>
Creates a new distributed KVStore. Note that you likely do not
want to use a KVStore directly, and instead would have a much
easier time using the application layer directly via the LiquidML
struct.
§Parameters
server_addr: theIP:Portof the registrationServer, used for orchestrating the connection of all distributed nodes in the system.my_addris theIP:Portof thisKVStore.blob_sender: is the sending half of anmpscchannel that is passed in by components using thisKVStoreto facilitate lower level messages. In the case ofliquid_ml, it will use theblob_senderto forward the blob toLiquidML. If you are not usingLiquidML, you must store the receiving half of thempscchannel so you may process blobs that are received.kill_notifier: When using the application layer directly, this is passed in for you by theLiquidMLstruct and is used to perform orderly shutdown when theClientreceivesKillmessages from theServernum_clients: the number of nodes in the distributed system, including this one.wait_for_all_clients: whether or not to wait for all other nodes to connect to this one before returning the newKVStore.
Sourcepub async fn get(&self, key: &Key) -> Result<Arc<T>, LiquidError>
pub async fn get(&self, key: &Key) -> Result<Arc<T>, LiquidError>
Used to retrieve the deserialized Value associated with the given
key if the data is held locally on this node in either the cache or
the store itself.
The difference between get and wait_and_get is that get
returns an error if the data is not owned by this KVStore or if it
is not owned by this KVStore and it is not in its cache.
§Errors
If key is not in this KVStores cache or is not owned by this
KVStore, then the error LiquidError::NotPresent is returned
Sourcepub async fn wait_and_get(&self, key: &Key) -> Result<Arc<T>, LiquidError>
pub async fn wait_and_get(&self, key: &Key) -> Result<Arc<T>, LiquidError>
Get the data for the given key. If the key belongs on a different
node then the data will be requested from the node that owns the key
and awaiting this method will block until that node responds with the
data.
Make sure that you use this function in only one of the two following ways:
- You know that the data was
putsome microseconds around whenwait_and_getwas called, but can’t guarantee it happened exactly beforewait_and_getis called. In this case, this function can beawaited - The data will be
puton thisKVStoresometime in the future at an unknown time. In this case, this function should not beawaited but instead given a callback closure via callingand_thenon the returned future
If you do not do that, for example in the second case you await
despite our warning, then you will waste a lot of time waiting for the
data to be transferred over the network.
Sourcepub async fn put(
&self,
key: Key,
value: T,
) -> Result<Option<Value>, LiquidError>
pub async fn put( &self, key: Key, value: T, ) -> Result<Option<Value>, LiquidError>
Puts the data held in value to the KVStore with the id in
key.home.
§If key belongs to this KVStore
If this KVStore did not have this key present, Ok(None) is
returned.
If this KVStore does have this key present, the associated
Value is updated, and Ok(Some<Value>) of the old Value is
returned. The key is not updated, though; this matters for types that
can be == without being identical.
§If key belongs to another KVStore
Ok(None) is returned after the value was successfully sent
Trait Implementations§
Auto Trait Implementations§
impl<T> !Freeze for KVStore<T>
impl<T> !RefUnwindSafe for KVStore<T>
impl<T> Send for KVStore<T>
impl<T> Sync for KVStore<T>
impl<T> Unpin for KVStore<T>
impl<T> !UnwindSafe for KVStore<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more