aboutsummaryrefslogtreecommitdiff
path: root/apps/dreki/src/dreki_config.erl
blob: 457f55986074a647c4cae5b917bf15192557460c (plain) (blame)
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
-module(dreki_config).
-include_lib("kernel/include/logger.hrl").
-include_lib("partisan/include/partisan.hrl").
-include("dreki_plum.hrl").
-include("dreki_otel.hrl").

-compile({no_auto_import,[get/0]}).


-export([init/1]).
-export([get/1]).
-export([set/2]).

-define(CONFIG, [
    %% All stolen from bondy as partisan isn't that well documented, eh.
    {partisan, [
        {broadcast_mods, [plum_db, partisan_plumtree_backend]},
        {channels, [data, rpc, membership]},
        {connect_disterl, false},
        {exchange_tick_period, timer:minutes(1)},
        {lazy_tick_period, timer:seconds(5)},
        {parallelism, 4},
        {membership_strategy, partisan_full_membership_strategy},
        {partisan_peer_service_manager,
            partisan_pluggable_peer_service_manager},
        {pid_encoding, false},
        {ref_encoding, false},
        {binary_padding, false},
        {disable_fast_forward, false},
        %% Broadcast options
        {broadcast, false},
        {tree_refresh, 1000},
        {relay_ttl, 5}
    ]},

   %% Same!
   {plum_db, [
       {aae_enabled, true},
       {wait_for_aae_exchange, true},
       {store_open_retries_delay, 2000},
       {store_open_retry_limit, 30},
       {data_exchange_timeout, 60000},
       {hashtree_timer, 10000},
       {data_dir, "data/plumdb"},
       {partitions, 8},
       {prefixes, ?PLUM_DB_PREFIXES}
   ]}
]).

-define(PT, dreki_config_cache).

init(_Args) ->
    persistent_term:put(?PT, [{dreki, application:get_all_env(dreki)},
                             {dreki_web, application:get_all_env(dreki_web)
                             }]),
    ok = set_app_configs(?CONFIG),
    ?LOG_NOTICE(#{message => "Configured Dreki and dependencies"}),
    ok = partisan_config:init(),
    ok.

get() ->
    persistent_term:get(?PT).

get(Key) ->
    ?with_span(?FUN_NAME, #{}, fun (_) -> key_value:get(Key, get()) end).

set(Key, Value) ->
    ?with_span(?FUN_NAME, #{},
               fun (_) ->
                       persistent_term:put(?PT, key_value:put(Key, Value, get())),
                       ok
               end).

set_app_configs(Configs) ->
   lists:foreach(fun ({App, Params}) ->
       [application:set_env(App, Key, Value) || {Key, Value} <- Params]
   end, Configs),
   ok.