aboutsummaryrefslogtreecommitdiff
path: root/src/core/object_table.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-04-26 18:55:13 +0000
committerAlex Auvolat <alex@adnab.me>2020-04-26 18:55:13 +0000
commit9cb870f950504b142e2954d2e1eb76929aaf689f (patch)
treef63d8039ec33644f061add4dcf046717e0be2a75 /src/core/object_table.rs
parentea7e4748edb32bcbcf737dcf35322eb6496b3439 (diff)
downloadgarage-9cb870f950504b142e2954d2e1eb76929aaf689f.tar.gz
garage-9cb870f950504b142e2954d2e1eb76929aaf689f.zip
Prepare for multipart uploads
Diffstat (limited to 'src/core/object_table.rs')
-rw-r--r--src/core/object_table.rs43
1 files changed, 32 insertions, 11 deletions
diff --git a/src/core/object_table.rs b/src/core/object_table.rs
index e4c78524..98e8d636 100644
--- a/src/core/object_table.rs
+++ b/src/core/object_table.rs
@@ -61,11 +61,31 @@ pub struct ObjectVersion {
pub mime_type: String,
pub size: u64,
- pub is_complete: bool,
+ pub state: ObjectVersionState,
pub data: ObjectVersionData,
}
+#[derive(PartialEq, Clone, Copy, Debug, Serialize, Deserialize)]
+pub enum ObjectVersionState {
+ Uploading,
+ Complete,
+ Aborted,
+}
+
+impl ObjectVersionState {
+ fn max(self, other: Self) -> Self {
+ use ObjectVersionState::*;
+ if self == Aborted || other == Aborted {
+ Aborted
+ } else if self == Complete || other == Complete {
+ Complete
+ } else {
+ Uploading
+ }
+ }
+}
+
#[derive(PartialEq, Clone, Debug, Serialize, Deserialize)]
pub enum ObjectVersionData {
DeleteMarker,
@@ -74,8 +94,14 @@ pub enum ObjectVersionData {
}
impl ObjectVersion {
- fn cmp_key(&self) -> (u64, &UUID) {
- (self.timestamp, &self.uuid)
+ fn cmp_key(&self) -> (u64, UUID) {
+ (self.timestamp, self.uuid)
+ }
+ pub fn is_complete(&self) -> bool {
+ self.state == ObjectVersionState::Complete
+ }
+ pub fn is_data(&self) -> bool {
+ self.state == ObjectVersionState::Complete && self.data != ObjectVersionData::DeleteMarker
}
}
@@ -98,9 +124,7 @@ impl Entry<String, String> for Object {
if other_v.size > v.size {
v.size = other_v.size;
}
- if other_v.is_complete && !v.is_complete {
- v.is_complete = true;
- }
+ v.state = v.state.max(other_v.state);
}
Err(i) => {
self.versions.insert(i, other_v.clone());
@@ -112,7 +136,7 @@ impl Entry<String, String> for Object {
.iter()
.enumerate()
.rev()
- .filter(|(_, v)| v.is_complete)
+ .filter(|(_, v)| v.is_complete())
.next()
.map(|(vi, _)| vi);
@@ -159,9 +183,6 @@ impl TableSchema for ObjectTable {
}
fn matches_filter(entry: &Self::E, _filter: &Self::Filter) -> bool {
- entry
- .versions
- .iter()
- .any(|x| x.is_complete && x.data != ObjectVersionData::DeleteMarker)
+ entry.versions.iter().any(|v| v.is_data())
}
}