Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions synapse_auto_compressor/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ pub fn run_compressor_on_room_chunk(
Ok(Some(chunk_stats))
}

#[allow(dead_code)]
pub struct ResultInfo {
pub room_id: String,
pub original_num_rows: usize,
pub new_num_rows: usize,
pub skipped: bool,
}

/// Runs the compressor in chunks on rooms with the lowest uncompressed state group ids
///
/// # Arguments
Expand Down Expand Up @@ -139,7 +147,7 @@ pub fn compress_chunks_of_database(
chunk_size: i64,
default_levels: &[Level],
number_of_chunks: i64,
) -> Result<()> {
) -> Result<Vec<ResultInfo>> {
// connect to the database
let mut client = connect_to_database(db_url)
.with_context(|| format!("Failed to connect to database at {}", db_url))?;
Expand All @@ -149,6 +157,7 @@ pub fn compress_chunks_of_database(
let mut skipped_chunks = 0;
let mut rows_saved = 0;
let mut chunks_processed = 0;
let mut results = vec![];

while chunks_processed < number_of_chunks {
let room_to_compress = get_next_room_to_compress(&mut client)
Expand All @@ -173,22 +182,34 @@ pub fn compress_chunks_of_database(
if chunk_stats.commited {
let savings = chunk_stats.original_num_rows - chunk_stats.new_num_rows;
rows_saved += chunk_stats.original_num_rows - chunk_stats.new_num_rows;
results.push(ResultInfo {
room_id: room_to_compress.clone(),
original_num_rows: chunk_stats.new_num_rows,
new_num_rows: chunk_stats.new_num_rows,
skipped: false,
});
debug!("Saved {} rows for room {}", savings, room_to_compress);
} else {
skipped_chunks += 1;
results.push(ResultInfo {
room_id: room_to_compress.clone(),
original_num_rows: 0,
new_num_rows: 0,
skipped: true,
});
debug!(
"Unable to make savings for room {}, skipping chunk",
room_to_compress
);
}
chunks_processed += 1;
} else {
bail!("Ran the compressor on a room that had no more work to do!")
bail!("Ran the compressor on a room that had no more work to do!");
}
}
info!(
"Finished running compressor. Saved {} rows. Skipped {}/{} chunks",
rows_saved, skipped_chunks, chunks_processed
);
Ok(())
Ok(results)
}
Loading