Packages
ra
2.6.3
3.1.9
3.1.8
3.1.7
3.1.6
3.1.5
3.1.4
3.1.3
3.1.2
3.1.1
3.1.0
3.0.2
3.0.1
3.0.0
3.0.0-beta.1
2.17.3
2.17.2
2.17.1
2.17.0
2.16.13
2.16.12
2.16.11
2.16.10
2.16.9
2.16.8
2.16.7
2.16.6
2.16.5
2.16.4
2.16.3
2.16.2
2.16.1
2.16.0
2.16.0-pre.12
2.16.0-pre.11
2.16.0-pre.10
2.16.0-pre.9
2.16.0-pre.8
2.16.0-pre.7
2.16.0-pre.6
2.16.0-pre.5
2.16.0-pre.4
2.16.0-pre.3
2.16.0-pre.2
2.16.0-pre.1
2.15.4
2.15.3
2.15.2
2.15.1
2.15.0
2.14.0
2.13.6
2.13.5
2.13.4
2.13.3
2.13.2
2.13.1
2.13.0
2.13.0-pre.1
2.12.0
2.11.0
2.11.0-pre.1
2.10.2-pre.2
2.10.2-pre.1
2.10.1
2.10.0
2.10.0-pre.3
2.10.0-pre.2
2.10.0-pre.1
2.9.10-pre.1
2.9.1
2.9.1-pre.2
2.9.1-pre.1
2.9.0
2.8.0
retired
2.7.3
2.7.2
2.7.1
2.7.0
2.7.0-pre.3
2.7.0-pre.2
2.7.0-pre.1
2.6.3
2.6.2
2.6.1
2.6.0-pre.1
2.5.1
2.5.1-pre.1
2.5.0
2.4.9
2.4.8
2.4.7
2.4.6
2.4.5
2.4.4
2.4.3
2.4.2
retired
2.4.1
2.4.0
2.3.0
2.2.0
2.1.0
2.0.13
2.0.12
2.0.11
2.0.10
2.0.9
2.0.8
2.0.7
2.0.6
2.0.5
2.0.4
2.0.3
2.0.2
2.0.1
2.0.0
1.1.9
1.1.8
1.1.7
1.1.6
1.1.5
1.1.4
1.1.3
1.1.2
1.1.1
1.1.0
1.0.8
1.0.7
1.0.6
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0
0.9.6
0.9.5
0.9.4
0.9.2
0.3.3
retired
0.3.2
retired
0.3.1
retired
Raft library
Current section
Files
Jump to
Current section
Files
src/ra_log_sup.erl
%% This Source Code Form is subject to the terms of the Mozilla Public
%% License, v. 2.0. If a copy of the MPL was not distributed with this
%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
%%
%% Copyright (c) 2017-2022 VMware, Inc. or its affiliates. All rights reserved.
%%
%% @hidden
-module(ra_log_sup).
-behaviour(supervisor).
-include("ra.hrl").
%% API functions
-export([start_link/1]).
%% Supervisor callbacks
-export([init/1]).
-spec start_link(ra_system:config()) ->
{ok, pid()} | ignore | {error, term()}.
start_link(#{names := #{log_sup := Name}} = Cfg) ->
supervisor:start_link({local, Name}, ?MODULE, [Cfg]).
init([#{data_dir := DataDir,
name := System,
names := #{wal := _WalName,
segment_writer := SegWriterName} = _Names} = Cfg]) ->
%% TODO: make unnamed
PreInit = #{id => ra_log_pre_init,
start => {ra_log_pre_init, start_link, [System]}},
Meta = #{id => ra_log_meta,
start => {ra_log_meta, start_link, [Cfg]}},
SegmentMaxEntries = maps:get(segment_max_entries, Cfg, ?SEGMENT_MAX_ENTRIES),
SegmentMaxPending = maps:get(segment_max_pending, Cfg, ?SEGMENT_MAX_PENDING),
SegmentComputeChecksums = maps:get(segment_compute_checksums, Cfg, true),
SegWriterConf = #{name => SegWriterName,
system => System,
data_dir => DataDir,
segment_conf =>
#{max_count => SegmentMaxEntries,
max_pending => SegmentMaxPending,
compute_checksums => SegmentComputeChecksums}},
SegWriter = #{id => ra_log_segment_writer,
start => {ra_log_segment_writer, start_link,
[SegWriterConf]}},
WalConf = make_wal_conf(Cfg),
SupFlags = #{strategy => one_for_all, intensity => 5, period => 5},
WalSup = #{id => ra_log_wal_sup,
type => supervisor,
start => {ra_log_wal_sup, start_link, [WalConf]}},
{ok, {SupFlags, [PreInit, Meta, SegWriter, WalSup]}}.
make_wal_conf(#{data_dir := DataDir,
name := _System,
names := #{wal := WalName,
segment_writer := SegWriterName} = Names} = Cfg) ->
WalDir = case Cfg of
#{wal_data_dir := D} -> D;
_ -> DataDir
end,
MaxSizeBytes = maps:get(wal_max_size_bytes, Cfg,
?WAL_DEFAULT_MAX_SIZE_BYTES),
ComputeChecksums = maps:get(wal_compute_checksums, Cfg, true),
MaxBatchSize = maps:get(wal_max_batch_size, Cfg,
?WAL_DEFAULT_MAX_BATCH_SIZE),
MaxEntries = maps:get(wal_max_entries, Cfg, undefined),
Strategy = maps:get(wal_write_strategy, Cfg, default),
SyncMethod = maps:get(wal_sync_method, Cfg, datasync),
HibAfter = maps:get(wal_hibernate_after, Cfg, undefined),
Gc = maps:get(wal_garbage_collect, Cfg, false),
PreAlloc = maps:get(wal_pre_allocate, Cfg, false),
MinBinVheapSize = maps:get(wal_min_bin_vheap_size, Cfg,
?MIN_BIN_VHEAP_SIZE),
CompressMemTables = maps:get(compress_mem_tables, Cfg, false),
#{name => WalName,
names => Names,
dir => WalDir,
segment_writer => SegWriterName,
compute_checksums => ComputeChecksums,
write_strategy => Strategy,
max_size_bytes => MaxSizeBytes,
max_entries => MaxEntries,
sync_method => SyncMethod,
max_batch_size => MaxBatchSize,
hibernate_after => HibAfter,
garbage_collect => Gc,
pre_allocate => PreAlloc,
min_bin_vheap_size => MinBinVheapSize,
compress_mem_tables => CompressMemTables
}.