Skip to content

Commit 30b5612

Browse files
ngorogiannisfacebook-github-bot
authored andcommitted
[sqlite] use checkpointing instead of vacuum
Summary: `VACUUM` is used to shrink the size of DBs destined for caching (eg in buck), as well as to "canonicalise" their content into something deterministic. VACUUM does two things: 1. it incorporates the WAL log into the main DB file. 2. it compacts the DB by combining half-empty pages and generally moving things around. (2) is quite costly. In addition, it doesn't achieve byte-determinism (for instance, `VACUUM` is not idempotent wrt `md5sum`). This diff replaces `VACUUM` with `PRAGMA wal_checkpoint` which only aims at doing (1). This saves considerable time on large DBs. Reviewed By: skcho Differential Revision: D32758493 fbshipit-source-id: a3688b13d5
1 parent 7e2d161 commit 30b5612

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

infer/src/base/DBWriter.ml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ module Implementation = struct
169169

170170

171171
let canonicalize () =
172-
ResultsDatabase.get_database () |> SqliteUtils.exec ~log:"running VACUUM" ~stmt:"VACUUM"
172+
ResultsDatabase.get_database ()
173+
|> SqliteUtils.exec ~log:"checkpointing" ~stmt:"PRAGMA wal_checkpoint"
173174

174175

175176
let reset_capture_tables () =
@@ -242,6 +243,7 @@ module Command = struct
242243
; tenv: Sqlite3.Data.t
243244
; integer_type_widths: Sqlite3.Data.t
244245
; proc_names: Sqlite3.Data.t }
246+
| Checkpoint
245247
| DeleteAllSpecs
246248
| DeleteSpec of {proc_uid: string}
247249
| Handshake
@@ -262,11 +264,12 @@ module Command = struct
262264
; callees: Sqlite3.Data.t }
263265
| ResetCaptureTables
264266
| Terminate
265-
| Vacuum
266267

267268
let to_string = function
268269
| AddSourceFile _ ->
269270
"AddSourceFile"
271+
| Checkpoint ->
272+
"Checkpoint"
270273
| DeleteAllSpecs ->
271274
"DeleteAllSpecs"
272275
| DeleteSpec _ ->
@@ -285,15 +288,15 @@ module Command = struct
285288
"StoreSpec"
286289
| Terminate ->
287290
"Terminate"
288-
| Vacuum ->
289-
"Vacuum"
290291

291292

292293
let pp fmt cmd = F.pp_print_string fmt (to_string cmd)
293294

294295
let execute = function
295296
| AddSourceFile {source_file; tenv; integer_type_widths; proc_names} ->
296297
Implementation.add_source_file ~source_file ~tenv ~integer_type_widths ~proc_names
298+
| Checkpoint ->
299+
Implementation.canonicalize ()
297300
| DeleteAllSpecs ->
298301
Implementation.delete_all_specs ()
299302
| DeleteSpec {proc_uid} ->
@@ -314,8 +317,6 @@ module Command = struct
314317
Implementation.reset_capture_tables ()
315318
| Terminate ->
316319
Implementation.log_specs_overwrite_counts ()
317-
| Vacuum ->
318-
Implementation.canonicalize ()
319320
end
320321

321322
type response = Ack | Error of (string * Caml.Printexc.raw_backtrace)
@@ -442,7 +443,7 @@ let mark_all_source_files_stale () = perform MarkAllSourceFilesStale
442443

443444
let merge ~infer_deps_file = perform (Merge {infer_deps_file})
444445

445-
let canonicalize () = perform Vacuum
446+
let canonicalize () = perform Checkpoint
446447

447448
let reset_capture_tables () = perform ResetCaptureTables
448449

0 commit comments

Comments
 (0)