Merge branch 'ku/config-system' into tmp
This commit is contained in:
commit
d2b1c7512a
5 changed files with 58 additions and 13 deletions
|
@ -18,10 +18,9 @@
|
||||||
%%
|
%%
|
||||||
%% -------------------------------------------------------------------
|
%% -------------------------------------------------------------------
|
||||||
|
|
||||||
-define(MAX_FILE_SIZE, 256*1024*1024). % 256 MBytes
|
%% @doc Now 4GiBytes, could be up to 64bit due to PB message limit of
|
||||||
-define(MAX_CHUNK_SIZE, ((1 bsl 32) - 1)).
|
%% chunk size
|
||||||
%% -define(DATA_DIR, "/Volumes/SAM1/seq-tests/data").
|
-define(DEFAULT_MAX_FILE_SIZE, ((1 bsl 32) - 1)).
|
||||||
-define(DATA_DIR, "./data").
|
|
||||||
-define(MINIMUM_OFFSET, 1024).
|
-define(MINIMUM_OFFSET, 1024).
|
||||||
|
|
||||||
%% 0th draft of checksum typing with 1st byte.
|
%% 0th draft of checksum typing with 1st byte.
|
||||||
|
@ -39,4 +38,5 @@
|
||||||
-define(PB_MAX_MSG_SIZE, (33*1024*1024)).
|
-define(PB_MAX_MSG_SIZE, (33*1024*1024)).
|
||||||
-define(PB_PACKET_OPTS, [{packet, 4}, {packet_size, ?PB_MAX_MSG_SIZE}]).
|
-define(PB_PACKET_OPTS, [{packet, 4}, {packet_size, ?PB_MAX_MSG_SIZE}]).
|
||||||
|
|
||||||
|
%% TODO: it's used in flu_sup and elsewhere, change this to suitable name
|
||||||
-define(TEST_ETS_TABLE, test_ets_table).
|
-define(TEST_ETS_TABLE, test_ets_table).
|
||||||
|
|
|
@ -4,6 +4,7 @@ if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then
|
||||||
echo '$TRAVIS_PULL_REQUEST is false, skipping tests'
|
echo '$TRAVIS_PULL_REQUEST is false, skipping tests'
|
||||||
exit 0
|
exit 0
|
||||||
else
|
else
|
||||||
echo '$TRAVIS_PULL_REQUEST is not false, running tests'
|
echo '$TRAVIS_PULL_REQUEST is not false ($TRAVIS_PULL_REQUEST), running tests'
|
||||||
make test
|
make test
|
||||||
|
make dialyzer
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -5,9 +5,6 @@
|
||||||
{mod,{machi_app,[]}},
|
{mod,{machi_app,[]}},
|
||||||
{registered, []},
|
{registered, []},
|
||||||
{env, [
|
{env, [
|
||||||
{flu_list,
|
%% Don't use this static env for defaults, or we will fall into config hell.
|
||||||
[
|
|
||||||
%%%%%% {flu_a, 32900, "./data.flu_a"}
|
|
||||||
]}
|
|
||||||
]}
|
]}
|
||||||
]}.
|
]}.
|
||||||
|
|
43
src/machi_config.erl
Normal file
43
src/machi_config.erl
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
%% -------------------------------------------------------------------
|
||||||
|
%%
|
||||||
|
%% Copyright (c) 2007-2015 Basho Technologies, Inc. All Rights Reserved.
|
||||||
|
%%
|
||||||
|
%% This file is provided to you under the Apache License,
|
||||||
|
%% Version 2.0 (the "License"); you may not use this file
|
||||||
|
%% except in compliance with the License. You may obtain
|
||||||
|
%% a copy of the License at
|
||||||
|
%%
|
||||||
|
%% http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
%%
|
||||||
|
%% Unless required by applicable law or agreed to in writing,
|
||||||
|
%% software distributed under the License is distributed on an
|
||||||
|
%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
%% KIND, either express or implied. See the License for the
|
||||||
|
%% specific language governing permissions and limitations
|
||||||
|
%% under the License.
|
||||||
|
%%
|
||||||
|
%% -------------------------------------------------------------------
|
||||||
|
|
||||||
|
%% @doc Configuration consulting utilities. Some conventions:
|
||||||
|
%% - The function name should match with exact configuration
|
||||||
|
%% name in `app.config' or `advanced.config' of `machi' section.
|
||||||
|
%% - The default value of that configuration is expected to be in
|
||||||
|
%% cuttlefish schema file. Otherwise some macro in headers may
|
||||||
|
%% be chosen.
|
||||||
|
%% - Documentation of the configuration is supposed to be written
|
||||||
|
%% in cuttlefish schema file, rather than @doc section of the function.
|
||||||
|
%% - spec of the function should be written.
|
||||||
|
%% - Returning `undefined' is strongly discouraged. Return some default
|
||||||
|
%% value instead.
|
||||||
|
%% - `application:get_env/3' is recommended. See `max_file_size/0' for
|
||||||
|
%% example.
|
||||||
|
|
||||||
|
-module(machi_config).
|
||||||
|
|
||||||
|
-include("machi.hrl").
|
||||||
|
|
||||||
|
-export([max_file_size/0]).
|
||||||
|
|
||||||
|
-spec max_file_size() -> pos_integer().
|
||||||
|
max_file_size() ->
|
||||||
|
application:get_env(machi, max_file_size, ?DEFAULT_MAX_FILE_SIZE).
|
|
@ -87,6 +87,7 @@
|
||||||
data_filehandle :: file:io_device(),
|
data_filehandle :: file:io_device(),
|
||||||
csum_table :: machi_csum_table:table(),
|
csum_table :: machi_csum_table:table(),
|
||||||
eof_position = 0 :: non_neg_integer(),
|
eof_position = 0 :: non_neg_integer(),
|
||||||
|
max_file_size = ?DEFAULT_MAX_FILE_SIZE :: pos_integer(),
|
||||||
tref :: reference(), %% timer ref
|
tref :: reference(), %% timer ref
|
||||||
ticks = 0 :: non_neg_integer(), %% ticks elapsed with no new operations
|
ticks = 0 :: non_neg_integer(), %% ticks elapsed with no new operations
|
||||||
ops = 0 :: non_neg_integer(), %% sum of all ops
|
ops = 0 :: non_neg_integer(), %% sum of all ops
|
||||||
|
@ -222,7 +223,8 @@ init({Filename, DataDir}) ->
|
||||||
data_filehandle = FHd,
|
data_filehandle = FHd,
|
||||||
csum_table = CsumTable,
|
csum_table = CsumTable,
|
||||||
tref = Tref,
|
tref = Tref,
|
||||||
eof_position = Eof},
|
eof_position = Eof,
|
||||||
|
max_file_size = machi_config:max_file_size()},
|
||||||
lager:debug("Starting file proxy ~p for filename ~p, state = ~p, Eof = ~p",
|
lager:debug("Starting file proxy ~p for filename ~p, state = ~p, Eof = ~p",
|
||||||
[self(), Filename, St, Eof]),
|
[self(), Filename, St, Eof]),
|
||||||
{ok, St}.
|
{ok, St}.
|
||||||
|
@ -281,7 +283,8 @@ handle_call({read, Offset, Length, Opts}, _From,
|
||||||
State = #state{filename = F,
|
State = #state{filename = F,
|
||||||
data_filehandle = FH,
|
data_filehandle = FH,
|
||||||
csum_table = CsumTable,
|
csum_table = CsumTable,
|
||||||
reads = {T, Err}}) ->
|
reads = {T, Err}
|
||||||
|
}) ->
|
||||||
NoChecksum = proplists:get_value(no_checksum, Opts, false),
|
NoChecksum = proplists:get_value(no_checksum, Opts, false),
|
||||||
NoChunk = proplists:get_value(no_chunk, Opts, false),
|
NoChunk = proplists:get_value(no_chunk, Opts, false),
|
||||||
NeedsMerge = proplists:get_value(needs_trimmed, Opts, false),
|
NeedsMerge = proplists:get_value(needs_trimmed, Opts, false),
|
||||||
|
@ -384,9 +387,10 @@ handle_cast(Cast, State) ->
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
||||||
% @private
|
% @private
|
||||||
handle_info(tick, State = #state{eof_position = Eof}) when Eof >= ?MAX_FILE_SIZE ->
|
handle_info(tick, State = #state{eof_position = Eof,
|
||||||
|
max_file_size = MaxFileSize}) when Eof >= MaxFileSize ->
|
||||||
lager:notice("Eof position ~p >= max file size ~p. Shutting down.",
|
lager:notice("Eof position ~p >= max file size ~p. Shutting down.",
|
||||||
[Eof, ?MAX_FILE_SIZE]),
|
[Eof, MaxFileSize]),
|
||||||
{stop, file_rollover, State};
|
{stop, file_rollover, State};
|
||||||
|
|
||||||
%% XXX Is this a good idea? Need to think this through a bit.
|
%% XXX Is this a good idea? Need to think this through a bit.
|
||||||
|
|
Loading…
Reference in a new issue