[sql] clean up temp files after running

Summary:
Despite what the sqlite manual says, it looks like it's possible for sqlite not
to remove the -shm and -wal files after a successful termination.

Close the database and clean them up in Buck mode so that they do not perturb
the cache.

Reviewed By: martinoluca

Differential Revision: D5953967

fbshipit-source-id: 9068b01
master
Jules Villard 8 years ago committed by Facebook Github Bot
parent 1b6c77b624
commit 97efcd426f

@ -126,7 +126,7 @@ let delete_capture_and_analysis_data () =
in in
List.iter ~f:Utils.rmtree dirs_to_delete ; List.iter ~f:Unix.mkdir_p dirs_to_delete ; () List.iter ~f:Utils.rmtree dirs_to_delete ; List.iter ~f:Unix.mkdir_p dirs_to_delete ; ()
let canonicalize_db () = let db_canonicalize () =
let db = get_database () in let db = get_database () in
SqliteUtils.exec db ~log:"running VACUUM" ~stmt:"VACUUM" SqliteUtils.exec db ~log:"running VACUUM" ~stmt:"VACUUM"

@ -33,9 +33,12 @@ val new_database_connection : unit -> unit
val delete_capture_and_analysis_data : unit -> unit val delete_capture_and_analysis_data : unit -> unit
(** delete all results from the capture and the analysis *) (** delete all results from the capture and the analysis *)
val canonicalize_db : unit -> unit val db_canonicalize : unit -> unit
(** put the database on disk in deterministic form *) (** put the database on disk in deterministic form *)
val db_close : unit -> unit
(** close the current connection to the database *)
val register_statement : ('a, unit, string, (unit -> Sqlite3.stmt)) Base.format4 -> 'a val register_statement : ('a, unit, string, (unit -> Sqlite3.stmt)) Base.format4 -> 'a
(** Return a function unit -> Sqlite3.stmt that can be called (once the DB has been initialized) to (** Return a function unit -> Sqlite3.stmt that can be called (once the DB has been initialized) to
get the prepared statement corresponding to the current DB connection. Use this to prepare get the prepared statement corresponding to the current DB connection. Use this to prepare

@ -114,6 +114,12 @@ let clean_compilation_command mode =
(* Clean up the results dir to select only what's relevant to go in the Buck cache. In particular, (* Clean up the results dir to select only what's relevant to go in the Buck cache. In particular,
get rid of non-deterministic outputs.*) get rid of non-deterministic outputs.*)
let clean_results_dir () = let clean_results_dir () =
if not Config.flavors then
(* we do not need to keep the capture data in Buck/Java mode *)
ResultsDir.reset_attributes_table () ;
ResultsDir.db_canonicalize () ;
(* make sure we are done with the database *)
ResultsDir.db_close () ;
(* In Buck flavors mode we keep all capture data, but in Java mode we keep only the tenv *) (* In Buck flavors mode we keep all capture data, but in Java mode we keep only the tenv *)
let should_delete_dir = let should_delete_dir =
let dirs_to_delete = let dirs_to_delete =
@ -127,7 +133,12 @@ let clean_results_dir () =
List.mem ~equal:String.equal dirs_to_delete List.mem ~equal:String.equal dirs_to_delete
in in
let should_delete_file = let should_delete_file =
let files_to_delete = [Config.log_file] in let files_to_delete =
[ Config.log_file
; (* some versions of sqlite do not clean up after themselves *)
(ResultsDir.database_filename ^ "-shm")
; (ResultsDir.database_filename ^ "-wal") ]
in
let suffixes_to_delete = let suffixes_to_delete =
".txt" :: ".csv" :: ".json" :: (if Config.flavors then [] else [".cfg"; ".cg"]) ".txt" :: ".csv" :: ".json" :: (if Config.flavors then [] else [".cfg"; ".cg"])
in in
@ -160,11 +171,7 @@ let clean_results_dir () =
| exception Unix.Unix_error (Unix.ENOENT, _, _) | exception Unix.Unix_error (Unix.ENOENT, _, _)
-> () -> ()
in in
delete_temp_results Config.results_dir ; delete_temp_results Config.results_dir
if not Config.flavors then
(* we do not need to keep the capture data in Buck/Java mode *)
ResultsDir.reset_attributes_table () ;
ResultsDir.canonicalize_db ()
let check_captured_empty mode = let check_captured_empty mode =
let clean_command_opt = clean_compilation_command mode in let clean_command_opt = clean_compilation_command mode in

Loading…
Cancel
Save