KVStore

Struct KVStore 

Source
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>

Source

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: the IP:Port of the registration Server, used for orchestrating the connection of all distributed nodes in the system.
  • my_addr is the IP:Port of this KVStore.
  • blob_sender: is the sending half of an mpsc channel that is passed in by components using this KVStore to facilitate lower level messages. In the case of liquid_ml, it will use the blob_sender to forward the blob to LiquidML. If you are not using LiquidML, you must store the receiving half of the mpsc channel so you may process blobs that are received.
  • kill_notifier: When using the application layer directly, this is passed in for you by the LiquidML struct and is used to perform orderly shutdown when the Client receives Kill messages from the Server
  • num_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 new KVStore.
Source

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

Source

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:

  1. You know that the data was put some microseconds around when wait_and_get was called, but can’t guarantee it happened exactly before wait_and_get is called. In this case, this function can be awaited
  2. The data will be put on this KVStore sometime in the future at an unknown time. In this case, this function should not be awaited but instead given a callback closure via calling and_then on 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.

Source

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

Source

pub async fn send_blob( &self, target_id: usize, blob: Value, ) -> Result<(), LiquidError>

Sends the given blob to the KVStore with the given target_id This provides a lower level interface to facilitate other kinds of messages

Trait Implementations§

Source§

impl<T: Debug> Debug for KVStore<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> !Freeze for KVStore<T>

§

impl<T> !RefUnwindSafe for KVStore<T>

§

impl<T> Send for KVStore<T>
where T: Sync + Send,

§

impl<T> Sync for KVStore<T>
where T: Sync + Send,

§

impl<T> Unpin for KVStore<T>

§

impl<T> !UnwindSafe for KVStore<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V