forked from Deuxfleurs/garage
properly delete multipart uploads after completion
This commit is contained in:
parent
e645bbd3ce
commit
3d477906d4
1 changed files with 34 additions and 20 deletions
|
@ -397,34 +397,20 @@ impl TableSchema for ObjectTable {
|
||||||
|
|
||||||
// 2. Enqueue propagation deletions to version table
|
// 2. Enqueue propagation deletions to version table
|
||||||
if let (Some(old_v), Some(new_v)) = (old, new) {
|
if let (Some(old_v), Some(new_v)) = (old, new) {
|
||||||
// Propagate deletion of old versions
|
|
||||||
for v in old_v.versions.iter() {
|
for v in old_v.versions.iter() {
|
||||||
let newly_deleted = match new_v
|
let new_v_id = new_v
|
||||||
.versions
|
.versions
|
||||||
.binary_search_by(|nv| nv.cmp_key().cmp(&v.cmp_key()))
|
.binary_search_by(|nv| nv.cmp_key().cmp(&v.cmp_key()));
|
||||||
{
|
|
||||||
|
// Propagate deletion of old versions to the Version table
|
||||||
|
let delete_version = match new_v_id {
|
||||||
Err(_) => true,
|
Err(_) => true,
|
||||||
Ok(i) => {
|
Ok(i) => {
|
||||||
new_v.versions[i].state == ObjectVersionState::Aborted
|
new_v.versions[i].state == ObjectVersionState::Aborted
|
||||||
&& v.state != ObjectVersionState::Aborted
|
&& v.state != ObjectVersionState::Aborted
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if newly_deleted {
|
if delete_version {
|
||||||
if let ObjectVersionState::Uploading {
|
|
||||||
multipart: true, ..
|
|
||||||
} = &v.state
|
|
||||||
{
|
|
||||||
let deleted_mpu =
|
|
||||||
MultipartUpload::new(v.uuid, old_v.bucket_id, old_v.key.clone(), true);
|
|
||||||
let res = self.mpu_table.queue_insert(tx, &deleted_mpu);
|
|
||||||
if let Err(e) = db::unabort(res)? {
|
|
||||||
error!(
|
|
||||||
"Unable to enqueue multipart upload deletion propagation: {}. A repair will be needed.",
|
|
||||||
e
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let deleted_version = Version::new(
|
let deleted_version = Version::new(
|
||||||
v.uuid,
|
v.uuid,
|
||||||
VersionBacklink::Object {
|
VersionBacklink::Object {
|
||||||
|
@ -441,6 +427,34 @@ impl TableSchema for ObjectTable {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// After abortion or completion of multipart uploads, delete MPU table entry
|
||||||
|
if matches!(
|
||||||
|
v.state,
|
||||||
|
ObjectVersionState::Uploading {
|
||||||
|
multipart: true,
|
||||||
|
..
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
let delete_mpu = match new_v_id {
|
||||||
|
Err(_) => true,
|
||||||
|
Ok(i) => !matches!(
|
||||||
|
new_v.versions[i].state,
|
||||||
|
ObjectVersionState::Uploading { .. }
|
||||||
|
),
|
||||||
|
};
|
||||||
|
if delete_mpu {
|
||||||
|
let deleted_mpu =
|
||||||
|
MultipartUpload::new(v.uuid, old_v.bucket_id, old_v.key.clone(), true);
|
||||||
|
let res = self.mpu_table.queue_insert(tx, &deleted_mpu);
|
||||||
|
if let Err(e) = db::unabort(res)? {
|
||||||
|
error!(
|
||||||
|
"Unable to enqueue multipart upload deletion propagation: {}. A repair will be needed.",
|
||||||
|
e
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue