Skip to content

Commit

Permalink
WIP cloudstorage
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche committed Dec 23, 2023
1 parent 9c00598 commit a4711db
Show file tree
Hide file tree
Showing 6 changed files with 598 additions and 4 deletions.
30 changes: 30 additions & 0 deletions taskchampion/taskchampion/src/server/cloud/cloudstorage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use crate::errors::Result;

/// An abstraction of a cloud-storage service.
///
/// The underlying cloud storage is assumed to be a map from object names to object values,
/// similar to a HashMap, with the addition of a compare-and-swap operation. Object names
/// are always simple strings from the character set `[a-zA-Z0-9-]`, no more than 100 characters
/// in length.
pub(in crate::server::cloud) trait CloudStorage {
/// Put an object into cloud storage. If the object exists, it is overwritten.
fn put(&mut self, name: &[u8], value: &[u8]) -> Result<()>;

/// Get an object from cloud storage, or None if the object does not exist.
fn get(&mut self, name: &[u8]) -> Result<Option<Vec<u8>>>;

/// Delete an object. Does nothing if the object does not exist.
fn del(&mut self, name: &[u8]) -> Result<()>;

/// Enumerate objects with the given prefix.
fn list<'a>(&'a mut self, prefix: &'a [u8]) -> Result<Box<dyn Iterator<Item = &'a [u8]> + 'a>>;

/// Compare the existing object with `existing_value`, and replace with `new_value` only if the
/// values match. Returns true if the replacement occurred.
fn compare_and_swap(
&mut self,
name: &[u8],
existing_value: Option<Vec<u8>>,
new_value: Vec<u8>,
) -> Result<bool>;
}
11 changes: 11 additions & 0 deletions taskchampion/taskchampion/src/server/cloud/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*!
* Support for cloud-storage-backed sync.
*
* All of these operate using a similar approach, with specific patterns of object names. The
* process of adding a new version requires a compare-and-swap operation that sets a new version
* as the "latest" only if the existing "latest" has the expected value. This ensures a continuous
* chain of versions, even if multiple replicas attempt to sync at the same time.
*/

mod cloudstorage;
mod server;
Loading

0 comments on commit a4711db

Please sign in to comment.