package octez-libs

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file env.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
(*****************************************************************************)
(*                                                                           *)
(* Open Source License                                                       *)
(* Copyright (c) 2018-2022 Tarides <contact@tarides.com>                     *)
(*                                                                           *)
(* Permission is hereby granted, free of charge, to any person obtaining a   *)
(* copy of this software and associated documentation files (the "Software"),*)
(* to deal in the Software without restriction, including without limitation *)
(* the rights to use, copy, modify, merge, publish, distribute, sublicense,  *)
(* and/or sell copies of the Software, and to permit persons to whom the     *)
(* Software is furnished to do so, subject to the following conditions:      *)
(*                                                                           *)
(* The above copyright notice and this permission notice shall be included   *)
(* in all copies or substantial portions of the Software.                    *)
(*                                                                           *)
(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)
(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  *)
(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL   *)
(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)
(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING   *)
(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER       *)
(* DEALINGS IN THE SOFTWARE.                                                 *)
(*                                                                           *)
(*****************************************************************************)

(* Determines the policy used to determine whether to add new
   objects to Irmin's index whenever they are exported to the
   data file. *)
type indexing_strategy =
  [ `Minimal (* only newly-exported commit objects are added to the index *)
  | `Always (* all newly-exported objects are added to the index *) ]

type t = {
  verbosity : [`Default | `Info | `Debug];
  index_log_size : int;
  lru_size : int;
  auto_flush : int;
  indexing_strategy : indexing_strategy;
}

(* Caps the number of entries stored in the Irmin's index. As a
   trade-off, increasing this value will delay index merges, and thus,
   make them more expensive in terms of disk usage, memory usage and
   computation time.*)
let index_log_size = 2_500_000

(* Caps the number of entries stored in the Irmin's LRU cache. As a
   trade-off, increasing this value will increase the memory
   consumption.*)
let lru_size = 15_000

(* This limit ensures that no trees with more than [auto_flush]
   mutations can exist in memory, bounding the memory usage of a
   single commit performed by a read-write process. As a trade-off,
   the intermediate flushed trees to the store might be unused and
   will have to be garbage collected later on to save space. *)
let auto_flush = 10_000

let default =
  {
    verbosity = `Default;
    index_log_size;
    lru_size;
    auto_flush;
    indexing_strategy = `Minimal;
  }

let max_verbosity a b =
  match (a, b) with
  | `Debug, _ | _, `Debug -> `Debug
  | `Info, _ | _, `Info -> `Info
  | _ -> `Default

let v =
  match Unix.getenv "TEZOS_CONTEXT" with
  | exception Not_found -> default
  | v ->
      List.fold_left
        (fun acc s ->
          match String.trim s with
          | "v" | "verbose" ->
              {acc with verbosity = max_verbosity acc.verbosity `Info}
          | "vv" -> {acc with verbosity = `Debug}
          | v -> (
              match String.split '=' v |> List.map String.trim with
              | ["index-log-size"; n] -> (
                  match int_of_string_opt n with
                  | None ->
                      Fmt.epr
                        "[WARNING] Trying to convert %s into an integer for \
                         index-log-size, but the conversion failed. Using \
                         default settings."
                        n ;
                      acc
                  | Some v -> {acc with index_log_size = v})
              | ["lru-size"; n] -> (
                  match int_of_string_opt n with
                  | None ->
                      Fmt.epr
                        "[WARNING] Trying to convert %s into an integer for \
                         lru-size, but the conversion failed. Using default \
                         settings."
                        n ;
                      acc
                  | Some v -> {acc with lru_size = v})
              | ["auto-flush"; n] -> (
                  match int_of_string_opt n with
                  | None ->
                      Fmt.epr
                        "[WARNING] Trying to convert %s into an integer for \
                         auto-flush, but the conversion failed. Using default \
                         settings."
                        n ;
                      acc
                  | Some v -> {acc with auto_flush = v})
              | ["indexing-strategy"; n] -> (
                  match n with
                  | "always" -> {acc with indexing_strategy = `Always}
                  | "minimal" -> {acc with indexing_strategy = `Minimal}
                  | x ->
                      Fmt.epr
                        "[WARNING]  Unable to parse indexing strategy '%s'. \
                         Expected one of { 'always', 'minimal' }."
                        x ;
                      acc)
              | unknown :: _ ->
                  Fmt.epr
                    "[WARNING] Unknow option %s detected in the environment \
                     variable TEZOS_CONTEXT."
                    unknown ;
                  acc
              | [] ->
                  Fmt.epr
                    "[WARNING] Empty string detected in the environment \
                     variable TEZOS_CONTEXT." ;
                  acc))
        default
        (String.split ',' v)
OCaml

Innovation. Community. Security.