Merge pull request #116 from ixmatus/parnell/fix-gc-bug

gc.rs: `LIMIT` number of `orphan_chunks`, fixes #115
This commit is contained in:
Zhaofeng Li 2024-06-01 08:13:20 -06:00 committed by GitHub
commit 3907b31157
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -158,6 +158,15 @@ async fn run_reap_orphan_chunks(state: &State) -> Result<()> {
let db = state.database().await?;
let storage = state.storage().await?;
let orphan_chunk_limit = match db.get_database_backend() {
// Arbitrarily chosen sensible value since there's no good default to choose from for MySQL
sea_orm::DatabaseBackend::MySql => 1000,
// Panic limit set by sqlx for postgresql: https://github.com/launchbadge/sqlx/issues/671#issuecomment-687043510
sea_orm::DatabaseBackend::Postgres => u64::from(u16::MAX),
// Default statement limit imposed by sqlite: https://www.sqlite.org/limits.html#max_variable_number
sea_orm::DatabaseBackend::Sqlite => 500,
};
// find all orphan chunks...
let orphan_chunk_ids = Query::select()
.from(Chunk)
@ -190,6 +199,7 @@ async fn run_reap_orphan_chunks(state: &State) -> Result<()> {
let orphan_chunks: Vec<chunk::Model> = Chunk::find()
.filter(chunk::Column::State.eq(ChunkState::Deleted))
.limit(orphan_chunk_limit)
.all(db)
.await?;