forked from GothenburgBitFactory/taskwarrior
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
598 additions
and
4 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
taskchampion/taskchampion/src/server/cloud/cloudstorage.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.