MCPcopy Create free account
hub / github.com/acking-you/static_flow / check_opened_table_and_compact

Function check_opened_table_and_compact

crates/store/src/optimize.rs:266–412  ·  view source on GitHub ↗
(
    table: &Table,
    config: &CompactConfig,
)

Source from the content-addressed store, hash-verified

264}
265
266pub async fn check_opened_table_and_compact(
267 table: &Table,
268 config: &CompactConfig,
269) -> CompactResult {
270 let started = Instant::now();
271 let finalize = |action: CompactAction,
272 small_fragments: usize,
273 max_unindexed_rows: usize,
274 compacted: bool,
275 pruned: bool,
276 index_optimized: bool,
277 error: Option<String>| CompactResult {
278 table: table.name().to_string(),
279 small_fragments,
280 max_unindexed_rows,
281 action,
282 elapsed_ms: started.elapsed().as_millis(),
283 compacted,
284 pruned,
285 index_optimized,
286 error,
287 };
288
289 if !config.enabled {
290 return finalize(CompactAction::CompactionDisabled, 0, 0, false, false, false, None);
291 }
292
293 let small = match count_small_fragments(table).await {
294 Ok(count) => count,
295 Err(err) => {
296 return finalize(
297 CompactAction::StatsFailed,
298 0,
299 0,
300 false,
301 false,
302 false,
303 Some(format!("fragment scan failed: {err}")),
304 )
305 },
306 };
307 let max_unindexed_rows = match max_unindexed_rows(table).await {
308 Ok(count) => count,
309 Err(err) => {
310 return finalize(
311 CompactAction::StatsFailed,
312 small,
313 0,
314 false,
315 false,
316 false,
317 Some(format!("index scan failed: {err}")),
318 )
319 },
320 };
321 if small < config.fragment_threshold {
322 // Even when compaction is skipped, old versions should still be pruned
323 // and lagging indices repaired through the same maintenance entrypoint.

Calls 6

count_small_fragmentsFunction · 0.85
max_unindexed_rowsFunction · 0.85
nameMethod · 0.45

Tested by

no test coverage detected