aboutsummaryrefslogtreecommitdiff
path: root/src/object_table.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-04-09 23:45:07 +0200
committerAlex Auvolat <alex@adnab.me>2020-04-09 23:45:07 +0200
commitd66c0d6833ddbeb61e34ee222dde92a5363bda1f (patch)
tree0e2da23fb32a6bf62a205fdf5f90d986ac14ad0c /src/object_table.rs
parenta3eb88e6013e70238e7ddd66b4644f138b3d1b93 (diff)
downloadgarage-d66c0d6833ddbeb61e34ee222dde92a5363bda1f.tar.gz
garage-d66c0d6833ddbeb61e34ee222dde92a5363bda1f.zip
Why is it not Sync??
Diffstat (limited to 'src/object_table.rs')
-rw-r--r--src/object_table.rs35
1 files changed, 16 insertions, 19 deletions
diff --git a/src/object_table.rs b/src/object_table.rs
index 092dddf8..37b9fc0a 100644
--- a/src/object_table.rs
+++ b/src/object_table.rs
@@ -8,16 +8,20 @@ use crate::table::*;
use crate::server::Garage;
-#[derive(Clone, Debug, Serialize, Deserialize)]
+#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
pub struct Object {
+ // Primary key
pub bucket: String,
+
+ // Sort key
pub key: String,
- pub versions: Vec<Box<Version>>,
+ // Data
+ pub versions: Vec<Box<ObjectVersion>>,
}
-#[derive(Clone, Debug, Serialize, Deserialize)]
-pub struct Version {
+#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
+pub struct ObjectVersion {
pub uuid: UUID,
pub timestamp: u64,
@@ -25,20 +29,16 @@ pub struct Version {
pub size: u64,
pub is_complete: bool,
- pub data: VersionData,
+ pub data: ObjectVersionData,
}
-#[derive(Clone, Debug, Serialize, Deserialize)]
-pub enum VersionData {
+#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
+pub enum ObjectVersionData {
DeleteMarker,
Inline(#[serde(with="serde_bytes")] Vec<u8>),
FirstBlock(Hash),
}
-pub struct ObjectTable {
- pub garage: RwLock<Option<Arc<Garage>>>,
-}
-
impl Entry<String, String> for Object {
fn partition_key(&self) -> &String {
&self.bucket
@@ -47,25 +47,20 @@ impl Entry<String, String> for Object {
&self.key
}
- fn merge(&mut self, other: &Self) -> bool {
- let mut has_change = false;
-
+ fn merge(&mut self, other: &Self) {
for other_v in other.versions.iter() {
match self.versions.binary_search_by(|v| (v.timestamp, &v.uuid).cmp(&(other_v.timestamp, &other_v.uuid))) {
Ok(i) => {
let mut v = &mut self.versions[i];
if other_v.size > v.size {
v.size = other_v.size;
- has_change = true;
}
if other_v.is_complete && !v.is_complete {
v.is_complete = true;
- has_change = true;
}
}
Err(i) => {
self.versions.insert(i, other_v.clone());
- has_change = true;
}
}
}
@@ -78,11 +73,13 @@ impl Entry<String, String> for Object {
if let Some(last_vi) = last_complete {
self.versions = self.versions.drain(last_vi..).collect::<Vec<_>>();
}
-
- has_change
}
}
+pub struct ObjectTable {
+ pub garage: RwLock<Option<Arc<Garage>>>,
+}
+
#[async_trait]
impl TableFormat for ObjectTable {
type P = String;