Update delete code
This commit is contained in:
parent
0a283e4e70
commit
1999c0ae51
1 changed files with 17 additions and 13 deletions
|
@ -155,26 +155,30 @@ impl BodyChunker {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn handle_delete(garage: Arc<Garage>, bucket: &str, key: &str) -> Result<UUID, Error> {
|
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
|
.object_table
|
||||||
.get(&bucket.to_string(), &key.to_string())
|
.get(&bucket.to_string(), &key.to_string())
|
||||||
.await?
|
.await?
|
||||||
{
|
{
|
||||||
None => false,
|
None => {
|
||||||
Some(o) => {
|
// No need to delete
|
||||||
let mut has_active_version = false;
|
return Ok([0u8; 32].into());
|
||||||
for v in o.versions().iter() {
|
|
||||||
if v.data != ObjectVersionData::DeleteMarker {
|
|
||||||
has_active_version = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
has_active_version
|
|
||||||
}
|
}
|
||||||
|
Some(o) => o,
|
||||||
};
|
};
|
||||||
|
|
||||||
if !exists {
|
let interesting_versions = object.versions().iter().filter(|v| {
|
||||||
// No need to delete
|
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());
|
return Ok([0u8; 32].into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue