@@ -7,6 +7,7 @@ use std::io::{self, BufReader, BufWriter, Seek, Write};
77use std:: path:: { Path , PathBuf } ;
88use std:: time:: Duration ;
99use std:: { fs:: File , io:: Read } ;
10+ use tracing:: error;
1011
1112const INTERNAL_KEY : usize = 32 ;
1213const TOMBSTONE_MARKER : usize = 1 ;
@@ -325,7 +326,7 @@ fn compact_index_file<S: StoreFsManagement>(key_file_path: &Path) -> std::io::Re
325326 let mut original_reader = BufReader :: new ( original_file) ;
326327 let mut temp_writer = SafeWriter :: < S > :: new ( & temp_file_path, true ) . inspect_err ( |_| {
327328 if let Err ( e) = fs:: remove_file ( & lock_file_path) {
328- eprintln ! ( "{}:{}: Failed to remove lock file: {e}" , file!( ) , line!( ) ) ;
329+ error ! ( "{}:{}: Failed to remove lock file: {e}" , file!( ) , line!( ) ) ;
329330 }
330331 } ) ?;
331332
@@ -340,7 +341,7 @@ fn compact_index_file<S: StoreFsManagement>(key_file_path: &Path) -> std::io::Re
340341 } ;
341342 if let Err ( err) = temp_writer. insert_record ( store_key, value) {
342343 if let Err ( e) = fs:: remove_file ( & lock_file_path) {
343- eprintln ! ( "{}:{}: Failed to remove lock file: {e}" , file!( ) , line!( ) ) ;
344+ error ! ( "{}:{}: Failed to remove lock file: {e}" , file!( ) , line!( ) ) ;
344345 }
345346 return Err ( err) ;
346347 }
@@ -356,7 +357,7 @@ fn compact_index_file<S: StoreFsManagement>(key_file_path: &Path) -> std::io::Re
356357 Err ( other) => {
357358 // Handle other errors gracefully
358359 if let Err ( e) = fs:: remove_file ( & lock_file_path) {
359- eprintln ! ( "{}:{}: Failed to remove lock file: {e}" , file!( ) , line!( ) ) ;
360+ error ! ( "{}:{}: Failed to remove lock file: {e}" , file!( ) , line!( ) ) ;
360361 }
361362 return Err ( other) ;
362363 }
@@ -366,30 +367,30 @@ fn compact_index_file<S: StoreFsManagement>(key_file_path: &Path) -> std::io::Re
366367 // Check if any deleted records were found; if not, skip compaction
367368 if !any_deleted {
368369 if let Err ( e) = fs:: remove_file ( & lock_file_path) {
369- eprintln ! ( "{}:{}: Failed to remove lock file: {e}" , file!( ) , line!( ) ) ;
370+ error ! ( "{}:{}: Failed to remove lock file: {e}" , file!( ) , line!( ) ) ;
370371 }
371372 return Ok ( ( ) ) ;
372373 }
373374
374375 // Clean up and finalize the compaction process
375376 if let Err ( e) = temp_writer. flush ( ) {
376377 if let Err ( e) = fs:: remove_file ( & lock_file_path) {
377- eprintln ! ( "{}:{}: Failed to remove lock file: {e}" , file!( ) , line!( ) ) ;
378+ error ! ( "{}:{}: Failed to remove lock file: {e}" , file!( ) , line!( ) ) ;
378379 }
379380 return Err ( e) ;
380381 }
381382
382383 // Replace the original file with the temporary file
383384 if let Err ( e) = fs:: rename ( & temp_file_path, key_file_path) {
384385 if let Err ( e) = fs:: remove_file ( & lock_file_path) {
385- eprintln ! ( "{}:{}: Failed to remove lock file: {e}" , file!( ) , line!( ) ) ;
386+ error ! ( "{}:{}: Failed to remove lock file: {e}" , file!( ) , line!( ) ) ;
386387 }
387388 return Err ( e) ;
388389 }
389390
390391 // Remove the lock file
391392 fs:: remove_file ( & lock_file_path) . map_err ( |e| {
392- eprintln ! ( "{}:{}: Failed to remove lock file: {e}" , file!( ) , line!( ) ) ;
393+ error ! ( "{}:{}: Failed to remove lock file: {e}" , file!( ) , line!( ) ) ;
393394 e
394395 } ) ?;
395396
@@ -589,13 +590,13 @@ mod tests {
589590 create_test_data ( & mut file, & key_file_path, shared_data, i) ;
590591 } else if let Err ( err) = super :: compact_index_file :: < TestStore1 > ( & key_file_path)
591592 {
592- eprintln ! ( "Thread encountered an error during compaction: {err}" ) ;
593+ error ! ( "Thread encountered an error during compaction: {err}" ) ;
593594 return Err ( err) ;
594595 }
595596 barrier. wait ( ) ;
596597 // compact a last time so we know what data to compare against
597598 super :: compact_index_file :: < TestStore1 > ( & key_file_path) . map_err ( |err| {
598- eprintln ! ( "Thread encountered an error during compaction: {err}" ) ;
599+ error ! ( "Thread encountered an error during compaction: {err}" ) ;
599600 err
600601 } )
601602 } )
0 commit comments