diff options
author | Alex Auvolat <alex@adnab.me> | 2020-04-26 19:11:19 +0000 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2020-04-26 19:11:19 +0000 |
commit | 1999c0ae5152917625558c588e71b27f63950f41 (patch) | |
tree | 96b5b7f0d58f336ad4ec84994d62d30c72d8ae96 /src/api | |
parent | 0a283e4e70bbced6e1087df10e661a5a3d33289e (diff) | |
download | garage-1999c0ae5152917625558c588e71b27f63950f41.tar.gz garage-1999c0ae5152917625558c588e71b27f63950f41.zip |
Update delete code
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/s3_put.rs | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/src/api/s3_put.rs b/src/api/s3_put.rs index e6130af6..084af916 100644 --- a/src/api/s3_put.rs +++ b/src/api/s3_put.rs @@ -155,26 +155,30 @@ impl BodyChunker { } pub async fn handle_delete(garage: Arc<Garage>, bucket: &str, key: &str) -> Result<UUID, Error> { - let exists = match garage + let object = match garage .object_table .get(&bucket.to_string(), &key.to_string()) .await? { - None => false, - Some(o) => { - let mut has_active_version = false; - for v in o.versions().iter() { - if v.data != ObjectVersionData::DeleteMarker { - has_active_version = true; - break; - } - } - has_active_version + None => { + // No need to delete + return Ok([0u8; 32].into()); } + Some(o) => o, }; - if !exists { - // No need to delete + let interesting_versions = object.versions().iter().filter(|v| { + v.data != ObjectVersionData::DeleteMarker && v.state != ObjectVersionState::Aborted + }); + + let mut must_delete = false; + let mut timestamp = now_msec(); + for v in interesting_versions { + must_delete = true; + timestamp = std::cmp::max(timestamp, v.timestamp + 1); + } + + if !must_delete { return Ok([0u8; 32].into()); } |