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

Function check_and_compact

crates/store/src/optimize.rs:208–264  ·  view source on GitHub ↗
(db: &Connection, name: &str, config: &CompactConfig)

Source from the content-addressed store, hash-verified

206}
207
208async fn check_and_compact(db: &Connection, name: &str, config: &CompactConfig) -> CompactResult {
209 let started = Instant::now();
210 let finalize = |action: CompactAction,
211 small_fragments: usize,
212 max_unindexed_rows: usize,
213 compacted: bool,
214 pruned: bool,
215 index_optimized: bool,
216 error: Option<String>| CompactResult {
217 table: name.to_string(),
218 small_fragments,
219 max_unindexed_rows,
220 action,
221 elapsed_ms: started.elapsed().as_millis(),
222 compacted,
223 pruned,
224 index_optimized,
225 error,
226 };
227
228 if !config.enabled {
229 return finalize(CompactAction::CompactionDisabled, 0, 0, false, false, false, None);
230 }
231
232 let lock_path = local_table_rewrite_lock_path(db.uri(), name);
233 let _file_guard =
234 match acquire_table_access_file_lock(&lock_path, TableAccessMode::Exclusive).await {
235 Ok(guard) => guard,
236 Err(err) => {
237 return finalize(
238 CompactAction::CompactFailed,
239 0,
240 0,
241 false,
242 false,
243 false,
244 Some(format!("table lock failed: {err}")),
245 )
246 },
247 };
248
249 let table = match db.open_table(name).execute().await {
250 Ok(t) => t,
251 Err(err) => {
252 return finalize(
253 CompactAction::OpenFailed,
254 0,
255 0,
256 false,
257 false,
258 false,
259 Some(format!("open failed: {err:#}")),
260 )
261 },
262 };
263 check_opened_table_and_compact(&table, config).await
264}
265

Calls 5

executeMethod · 0.80
open_tableMethod · 0.45

Tested by

no test coverage detected