• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MinaProtocol / mina / 353

09 Jul 2025 08:00PM UTC coverage: 31.655% (-29.3%) from 60.949%
353

push

buildkite

web-flow
Merge pull request #17485 from MinaProtocol/brian/more8s

Remove hardcoded state size where previosly missed

2 of 8 new or added lines in 4 files covered. (25.0%)

19023 existing lines in 391 files now uncovered.

22662 of 71591 relevant lines covered (31.65%)

24587.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

8.33
/src/lib/disk_cache/lmdb/disk_cache.ml
1
(* Cache proofs using the lmdb *)
2

6✔
3
open Core
4
open Lmdb_storage.Generic
5

6
module Make (Data : Binable.S) = struct
7
  module F (Db : Db) = struct
8
    type holder = (int, Data.t) Db.t
9

10
    let mk_maps { Db.create } =
UNCOV
11
      create Lmdb_storage.Conv.uint32_be
×
UNCOV
12
        (Lmdb_storage.Conv.bin_prot_conv Data.bin_t)
×
13

14
    let config = { default_config with initial_mmap_size = 256 lsl 20 }
15
  end
16

17
  module Rw = Read_write (F)
18

19
  type t =
20
    { env : Rw.t
21
    ; db : Rw.holder
22
    ; counter : int ref
23
    ; garbage : int Hash_set.t
24
          (** A list of ids that are no longer reachable from OCaml's side *)
25
    }
26

27
  (** How big can the above hashset be before we do a cleanup *)
28
  let garbage_size_limit = 512
29

30
  let initialize path ~logger =
UNCOV
31
    Async.Deferred.Result.map (Disk_cache_utils.initialize_dir path ~logger)
×
32
      ~f:(fun path ->
UNCOV
33
        let env, db = Rw.create path in
×
UNCOV
34
        { env; db; counter = ref 0; garbage = Hash_set.create (module Int) } )
×
35

36
  type id = { idx : int }
37

38
  let get ({ env; db; _ } : t) ({ idx } : id) : Data.t =
UNCOV
39
    Rw.get ~env db idx |> Option.value_exn
×
40

41
  let put ({ env; db; counter; garbage } : t) (x : Data.t) : id =
42
    (* TODO: we may reuse IDs by pulling them from the `garbage` hash set *)
UNCOV
43
    let idx = !counter in
×
44
    incr counter ;
UNCOV
45
    let res = { idx } in
×
46
    (* When this reference is GC'd, delete the file. *)
47
    Gc.Expert.add_finalizer_last_exn res (fun () ->
48
        (* The actual deletion is delayed, as GC maybe triggered in LMDB's
49
           critical section. LMDB critical section then will be re-entered if
50
           it's invoked directly in a GC hook.
51
           This causes mutex double-acquiring and node freezes. *)
UNCOV
52
        Hash_set.add garbage idx ) ;
×
UNCOV
53
    if Hash_set.length garbage >= garbage_size_limit then (
×
UNCOV
54
      Hash_set.iter garbage ~f:(fun to_remove -> Rw.remove ~env db to_remove) ;
×
UNCOV
55
      Hash_set.clear garbage ) ;
×
UNCOV
56
    Rw.set ~env db idx x ;
×
UNCOV
57
    res
×
58

UNCOV
59
  let iteri ({ env; db; _ } : t) ~f = Rw.iter ~env db ~f
×
60

61
  let count ({ env; db; _ } : t) =
UNCOV
62
    let sum = ref 0 in
×
63
    Rw.iter ~env db ~f:(fun _ _ -> incr sum ; `Continue) ;
×
UNCOV
64
    !sum
×
65

UNCOV
66
  let int_of_id { idx } = idx
×
67
end
68

69
let%test_module "disk_cache lmdb" =
70
  ( module struct
71
    include Disk_cache_test_lib.Make_extended (Make)
72

UNCOV
73
    let%test_unit "remove data on gc" = remove_data_on_gc ~gc_strict:false ()
×
74

75
    let%test_unit "simple read/write (with iteration)" =
UNCOV
76
      simple_write_with_iteration ()
×
77

78
    let%test_unit "initialization special cases" =
UNCOV
79
      initialization_special_cases ()
×
80
  end )
12✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc