1
0
Fork 0
mirror of https://github.com/zhaofengli/attic.git synced 2025-03-05 16:27:06 +00:00

fix chunk deletion bug

fetch all deleted chunks, not just the ones that just transitioned
This commit is contained in:
Travis Staton 2023-06-24 12:31:38 -04:00
parent 4fedffe6a1
commit 91d8bd5cdc
No known key found for this signature in database
GPG key ID: 431DD911A00DAE49

View file

@ -177,16 +177,21 @@ async fn run_reap_orphan_chunks(state: &State) -> Result<()> {
// ... and transition their state to Deleted // ... and transition their state to Deleted
// //
// Deleted chunks are essentially invisible from our normal queries // Deleted chunks are essentially invisible from our normal queries
let change_state = Query::update() let transition_statement = {
.table(Chunk) let change_state = Query::update()
.value(chunk::Column::State, ChunkState::Deleted) .table(Chunk)
.and_where(chunk::Column::Id.in_subquery(orphan_chunk_ids)) .value(chunk::Column::State, ChunkState::Deleted)
.returning_all() .and_where(chunk::Column::Id.in_subquery(orphan_chunk_ids))
.to_owned(); .to_owned();
db.get_database_backend().build(&change_state)
};
let stmt = db.get_database_backend().build(&change_state); db.execute(transition_statement).await?;
let orphan_chunks = chunk::Model::find_by_statement(stmt).all(db).await?; let orphan_chunks: Vec<chunk::Model> = Chunk::find()
.filter(chunk::Column::State.eq(ChunkState::Deleted))
.all(db)
.await?;
if orphan_chunks.is_empty() { if orphan_chunks.is_empty() {
return Ok(()); return Ok(());