Merge remote-tracking branch 'aeternity/uw-avoid-set_env' into mas-pr231-review
This commit is contained in:
commit
90574122c9
11 changed files with 140 additions and 33 deletions
|
@ -1063,9 +1063,8 @@ init([Opts]) ->
|
|||
{InkerOpts, PencillerOpts} = set_options(Opts),
|
||||
|
||||
LogLevel = proplists:get_value(log_level, Opts),
|
||||
ok = application:set_env(leveled, log_level, LogLevel),
|
||||
ForcedLogs = proplists:get_value(forced_logs, Opts),
|
||||
ok = application:set_env(leveled, forced_logs, ForcedLogs),
|
||||
leveled_log:save(LogLevel, ForcedLogs),
|
||||
|
||||
OverrideFunctions = proplists:get_value(override_functions, Opts),
|
||||
SetFun =
|
||||
|
|
|
@ -498,10 +498,11 @@ generate_orderedkeys(_Seqn, 0, Acc, _BucketLow, _BucketHigh) ->
|
|||
Acc;
|
||||
generate_orderedkeys(Seqn, Count, Acc, BucketLow, BucketHigh) ->
|
||||
BNumber = Seqn div (BucketHigh - BucketLow),
|
||||
BucketExt = string:right(integer_to_list(BucketLow + BNumber), 4, $0),
|
||||
BucketExt = leveled_util:string_right(
|
||||
integer_to_list(BucketLow + BNumber), 4, $0),
|
||||
KNumber = Seqn * 100 + leveled_rand:uniform(100),
|
||||
KeyExt =
|
||||
string:right(integer_to_list(KNumber), 8, $0),
|
||||
leveled_util:string_right(integer_to_list(KNumber), 8, $0),
|
||||
LK = leveled_codec:to_ledgerkey("Bucket" ++ BucketExt, "Key" ++ KeyExt, o),
|
||||
Chunk = leveled_rand:rand_bytes(16),
|
||||
{_B, _K, MV, _H, _LMs} =
|
||||
|
|
|
@ -140,7 +140,7 @@
|
|||
%% @doc
|
||||
%% Generate a new clerk
|
||||
clerk_new(InkerClerkOpts) ->
|
||||
gen_server:start_link(?MODULE, [InkerClerkOpts], []).
|
||||
gen_server:start_link(?MODULE, [leveled_log:get_opts(), InkerClerkOpts], []).
|
||||
|
||||
-spec clerk_compact(pid(), pid(),
|
||||
fun(), fun(), fun(),
|
||||
|
@ -170,7 +170,8 @@ clerk_trim(Pid, Inker, PersistedSQN) ->
|
|||
%% of the hastable in the CDB file - so that the file is not blocked during
|
||||
%% this calculation
|
||||
clerk_hashtablecalc(HashTree, StartPos, CDBpid) ->
|
||||
{ok, Clerk} = gen_server:start_link(?MODULE, [#iclerk_options{}], []),
|
||||
{ok, Clerk} = gen_server:start_link(?MODULE, [leveled_log:get_opts(),
|
||||
#iclerk_options{}], []),
|
||||
gen_server:cast(Clerk, {hashtable_calc, HashTree, StartPos, CDBpid}).
|
||||
|
||||
-spec clerk_stop(pid()) -> ok.
|
||||
|
@ -183,7 +184,8 @@ clerk_stop(Pid) ->
|
|||
%%% gen_server callbacks
|
||||
%%%============================================================================
|
||||
|
||||
init([IClerkOpts]) ->
|
||||
init([LogOpts, IClerkOpts]) ->
|
||||
leveled_log:save(LogOpts),
|
||||
ReloadStrategy = IClerkOpts#iclerk_options.reload_strategy,
|
||||
CDBopts = IClerkOpts#iclerk_options.cdb_options,
|
||||
WP = CDBopts#cdb_options.waste_path,
|
||||
|
|
|
@ -174,13 +174,13 @@
|
|||
%% The inker will need to know what the reload strategy is, to inform the
|
||||
%% clerk about the rules to enforce during compaction.
|
||||
ink_start(InkerOpts) ->
|
||||
gen_server:start_link(?MODULE, [InkerOpts], []).
|
||||
gen_server:start_link(?MODULE, [leveled_log:get_opts(), InkerOpts], []).
|
||||
|
||||
-spec ink_snapstart(inker_options()) -> {ok, pid()}.
|
||||
%% @doc
|
||||
%% Don't link on startup as snapshot
|
||||
ink_snapstart(InkerOpts) ->
|
||||
gen_server:start(?MODULE, [InkerOpts], []).
|
||||
gen_server:start(?MODULE, [leveled_log:get_opts(), InkerOpts], []).
|
||||
|
||||
-spec ink_put(pid(),
|
||||
leveled_codec:ledger_key(),
|
||||
|
@ -451,7 +451,8 @@ ink_checksqn(Pid, LedgerSQN) ->
|
|||
%%% gen_server callbacks
|
||||
%%%============================================================================
|
||||
|
||||
init([InkerOpts]) ->
|
||||
init([LogOpts, InkerOpts]) ->
|
||||
leveled_log:save(LogOpts),
|
||||
leveled_rand:seed(),
|
||||
case {InkerOpts#inker_options.root_path,
|
||||
InkerOpts#inker_options.start_snapshot} of
|
||||
|
@ -1401,7 +1402,8 @@ compact_journal_testto(WRP, ExpectedFiles) ->
|
|||
timer:sleep(1000),
|
||||
CompactedManifest2 = ink_getmanifest(Ink1),
|
||||
lists:foreach(fun({_SQN, FN, _P, _LK}) ->
|
||||
?assertMatch(0, string:str(FN, ?COMPACT_FP))
|
||||
?assertMatch(0, leveled_util:string_str(
|
||||
FN, ?COMPACT_FP))
|
||||
end,
|
||||
CompactedManifest2),
|
||||
?assertMatch(2, length(CompactedManifest2)),
|
||||
|
|
|
@ -9,9 +9,14 @@
|
|||
|
||||
-export([log/2,
|
||||
log_timer/3,
|
||||
log_randomtimer/4]).
|
||||
log_randomtimer/4]).
|
||||
|
||||
-define(LOG_LEVELS, [debug, info, warn, error, critical]).
|
||||
-export([save/1, save/2,
|
||||
get_opts/0]).
|
||||
|
||||
-type log_level() :: debug | info | warn | error | critical.
|
||||
-type log_levels() :: [log_level()].
|
||||
-define(LOG_LEVELS, [debug, info, warn, error, critical]).
|
||||
|
||||
-define(DEFAULT_LOG_LEVEL, error).
|
||||
|
||||
|
@ -375,6 +380,28 @@
|
|||
{warn, "Error ~w caught when safe reading a file to length ~w"}}
|
||||
]).
|
||||
|
||||
-record(log_options,
|
||||
{log_level = info :: leveled_log:log_levels(),
|
||||
forced_logs = [] :: [string()]}).
|
||||
|
||||
save(LogLevel, ForcedLogs) when is_list(ForcedLogs), is_atom(LogLevel) ->
|
||||
save(#log_options{log_level = LogLevel,
|
||||
forced_logs = ForcedLogs}).
|
||||
|
||||
save(#log_options{} = LO) ->
|
||||
put('$leveled_log_options', LO),
|
||||
ok.
|
||||
|
||||
get_opts() ->
|
||||
case get('$leveled_log_options') of
|
||||
undefined ->
|
||||
LogLevel = application:get_env(leveled, log_level, ?DEFAULT_LOG_LEVEL),
|
||||
ForcedLogs = application:get_env(leveled, forced_logs, []),
|
||||
#log_options{log_level = LogLevel,
|
||||
forced_logs = ForcedLogs};
|
||||
#log_options{} = LO ->
|
||||
LO
|
||||
end.
|
||||
|
||||
log(LogReference, Subs) ->
|
||||
log(LogReference, Subs, ?LOG_LEVELS).
|
||||
|
@ -396,15 +423,15 @@ log(LogRef, Subs, SupportedLogLevels) ->
|
|||
end.
|
||||
|
||||
should_i_log(LogLevel, Levels, LogRef) ->
|
||||
ForcedLogs = application:get_env(leveled, forced_logs, []),
|
||||
#log_options{log_level = CurLevel, forced_logs = ForcedLogs} = get_opts(),
|
||||
case lists:member(LogRef, ForcedLogs) of
|
||||
true ->
|
||||
true;
|
||||
false ->
|
||||
case application:get_env(leveled, log_level, ?DEFAULT_LOG_LEVEL) of
|
||||
LogLevel ->
|
||||
if CurLevel == LogLevel ->
|
||||
true;
|
||||
CurLevel ->
|
||||
true;
|
||||
true ->
|
||||
is_active_level(Levels, CurLevel, LogLevel)
|
||||
end
|
||||
end.
|
||||
|
@ -499,4 +526,18 @@ shouldilog_test() ->
|
|||
ok = application:set_env(leveled, log_level, info),
|
||||
?assertMatch(false, should_i_log(debug, ?LOG_LEVELS, "D0001")).
|
||||
|
||||
shouldilog2_test() ->
|
||||
ok = save(unsupported, []),
|
||||
?assertMatch(false, should_i_log(info, ?LOG_LEVELS, "G0001")),
|
||||
?assertMatch(false, should_i_log(inform, ?LOG_LEVELS, "G0001")),
|
||||
ok = save(debug, []),
|
||||
?assertMatch(true, should_i_log(info, ?LOG_LEVELS, "G0001")),
|
||||
ok = save(info, []),
|
||||
?assertMatch(true, should_i_log(info, ?LOG_LEVELS, "G0001")),
|
||||
ok = save(error, ["G0001"]),
|
||||
?assertMatch(true, should_i_log(info, ?LOG_LEVELS, "G0001")),
|
||||
?assertMatch(false, should_i_log(info, ?LOG_LEVELS, "G0002")),
|
||||
ok = save(info, []),
|
||||
?assertMatch(false, should_i_log(debug, ?LOG_LEVELS, "D0001")).
|
||||
|
||||
-endif.
|
||||
|
|
|
@ -60,7 +60,8 @@
|
|||
clerk_new(Owner, Manifest, CompressionMethod) ->
|
||||
{ok, Pid} =
|
||||
gen_server:start_link(?MODULE,
|
||||
[{compression_method, CompressionMethod}],
|
||||
[leveled_log:get_opts(),
|
||||
{compression_method, CompressionMethod}],
|
||||
[]),
|
||||
ok = gen_server:call(Pid, {load, Owner, Manifest}, infinity),
|
||||
leveled_log:log("PC001", [Pid, Owner]),
|
||||
|
@ -82,7 +83,8 @@ clerk_close(Pid) ->
|
|||
%%% gen_server callbacks
|
||||
%%%============================================================================
|
||||
|
||||
init([{compression_method, CompressionMethod}]) ->
|
||||
init([LogOpts, {compression_method, CompressionMethod}]) ->
|
||||
leveled_log:save(LogOpts),
|
||||
{ok, #state{compression_method = CompressionMethod}}.
|
||||
|
||||
handle_call({load, Owner, RootPath}, _From, State) ->
|
||||
|
@ -263,9 +265,11 @@ generate_randomkeys(Count, BucketRangeLow, BucketRangeHigh) ->
|
|||
generate_randomkeys(0, Acc, _BucketLow, _BucketHigh) ->
|
||||
Acc;
|
||||
generate_randomkeys(Count, Acc, BucketLow, BRange) ->
|
||||
BNumber = string:right(integer_to_list(BucketLow + leveled_rand:uniform(BRange)),
|
||||
4, $0),
|
||||
KNumber = string:right(integer_to_list(leveled_rand:uniform(1000)), 4, $0),
|
||||
BNumber = leveled_util:string_right(
|
||||
integer_to_list(BucketLow + leveled_rand:uniform(BRange)),
|
||||
4, $0),
|
||||
KNumber = leveled_util:string_right(
|
||||
integer_to_list(leveled_rand:uniform(1000)), 4, $0),
|
||||
K = {o, "Bucket" ++ BNumber, "Key" ++ KNumber, null},
|
||||
RandKey = {K, {Count + 1,
|
||||
{active, infinity},
|
||||
|
|
|
@ -318,13 +318,13 @@
|
|||
%% query is run against the level zero space and just the query results are
|
||||
%5 copied into the clone.
|
||||
pcl_start(PCLopts) ->
|
||||
gen_server:start_link(?MODULE, [PCLopts], []).
|
||||
gen_server:start_link(?MODULE, [leveled_log:get_opts(), PCLopts], []).
|
||||
|
||||
-spec pcl_snapstart(penciller_options()) -> {ok, pid()}.
|
||||
%% @doc
|
||||
%% Don't link to the bookie - this is a snpashot
|
||||
pcl_snapstart(PCLopts) ->
|
||||
gen_server:start(?MODULE, [PCLopts], []).
|
||||
gen_server:start(?MODULE, [leveled_log:get_opts(), PCLopts], []).
|
||||
|
||||
-spec pcl_pushmem(pid(), bookies_memory()) -> ok|returned.
|
||||
%% @doc
|
||||
|
@ -601,7 +601,8 @@ pcl_checkforwork(Pid) ->
|
|||
%%% gen_server callbacks
|
||||
%%%============================================================================
|
||||
|
||||
init([PCLopts]) ->
|
||||
init([LogOpts, PCLopts]) ->
|
||||
leveled_log:save(LogOpts),
|
||||
leveled_rand:seed(),
|
||||
case {PCLopts#penciller_options.root_path,
|
||||
PCLopts#penciller_options.start_snapshot,
|
||||
|
|
|
@ -262,9 +262,11 @@ generate_randomkeys(Seqn, Count, BucketRangeLow, BucketRangeHigh) ->
|
|||
generate_randomkeys(_Seqn, 0, Acc, _BucketLow, _BucketHigh) ->
|
||||
Acc;
|
||||
generate_randomkeys(Seqn, Count, Acc, BucketLow, BRange) ->
|
||||
BNumber = string:right(integer_to_list(BucketLow + leveled_rand:uniform(BRange)),
|
||||
4, $0),
|
||||
KNumber = string:right(integer_to_list(leveled_rand:uniform(1000)), 4, $0),
|
||||
BNumber = leveled_util:string_right(
|
||||
integer_to_list(BucketLow + leveled_rand:uniform(BRange)),
|
||||
4, $0),
|
||||
KNumber = leveled_util:string_right(
|
||||
integer_to_list(leveled_rand:uniform(1000)), 4, $0),
|
||||
{K, V} = {{o, "Bucket" ++ BNumber, "Key" ++ KNumber, null},
|
||||
{Seqn, {active, infinity}, null}},
|
||||
generate_randomkeys(Seqn + 1,
|
||||
|
|
|
@ -2490,8 +2490,10 @@ generate_randomkeys(_Seqn, 0, Acc, _BucketLow, _BucketHigh) ->
|
|||
Acc;
|
||||
generate_randomkeys(Seqn, Count, Acc, BucketLow, BRange) ->
|
||||
BRand = leveled_rand:uniform(BRange),
|
||||
BNumber = string:right(integer_to_list(BucketLow + BRand), 4, $0),
|
||||
KNumber = string:right(integer_to_list(leveled_rand:uniform(1000)), 6, $0),
|
||||
BNumber = leveled_util:string_right(
|
||||
integer_to_list(BucketLow + BRand), 4, $0),
|
||||
KNumber = leveled_util:string_right(
|
||||
integer_to_list(leveled_rand:uniform(1000)), 6, $0),
|
||||
LK = leveled_codec:to_ledgerkey("Bucket" ++ BNumber, "Key" ++ KNumber, o),
|
||||
Chunk = leveled_rand:rand_bytes(64),
|
||||
{_B, _K, MV, _H, _LMs} =
|
||||
|
|
|
@ -581,8 +581,10 @@ generate_randomkeys(_Seqn, 0, Acc, _BucketLow, _BucketHigh) ->
|
|||
Acc;
|
||||
generate_randomkeys(Seqn, Count, Acc, BucketLow, BRange) ->
|
||||
BRand = leveled_rand:uniform(BRange),
|
||||
BNumber = string:right(integer_to_list(BucketLow + BRand), 4, $0),
|
||||
KNumber = string:right(integer_to_list(leveled_rand:uniform(1000)), 4, $0),
|
||||
BNumber = leveled_util:string_right(
|
||||
integer_to_list(BucketLow + BRand), 4, $0),
|
||||
KNumber = leveled_util:string_right(
|
||||
integer_to_list(leveled_rand:uniform(1000)), 4, $0),
|
||||
{K, V} = {{o, "Bucket" ++ BNumber, "Key" ++ KNumber, null},
|
||||
{Seqn, {active, infinity}, null}},
|
||||
generate_randomkeys(Seqn + 1,
|
||||
|
|
|
@ -16,6 +16,18 @@
|
|||
integer_time/1,
|
||||
magic_hash/1]).
|
||||
|
||||
-export([string_right/3,
|
||||
string_str/2]).
|
||||
|
||||
-ifdef(OTP_RELEASE).
|
||||
|
||||
-if(?OTP_RELEASE >= 21).
|
||||
-else.
|
||||
-define(LEGACY_OTP, true).
|
||||
-endif.
|
||||
|
||||
-endif. % (OTP_RELEASE)
|
||||
|
||||
|
||||
-spec generate_uuid() -> list().
|
||||
%% @doc
|
||||
|
@ -64,8 +76,47 @@ hash1(H, <<B:8/integer, Rest/bytes>>) ->
|
|||
H2 = H1 bxor B,
|
||||
hash1(H2, Rest).
|
||||
|
||||
%% A number of string functions have become deprecated in OTP 21
|
||||
%%
|
||||
-ifdef(LEGACY_OTP).
|
||||
|
||||
string_right(String, Len, Char) ->
|
||||
string:right(String, Len, Char).
|
||||
|
||||
string_str(S, Sub) ->
|
||||
string:str(S, Sub).
|
||||
|
||||
-else.
|
||||
|
||||
string_right(String, Len, Char) when is_list(String), is_integer(Char) ->
|
||||
Slen = length(String),
|
||||
if
|
||||
Slen > Len -> lists:nthtail(Slen-Len, String);
|
||||
Slen < Len -> chars(Char, Len-Slen, String);
|
||||
Slen =:= Len -> String
|
||||
end.
|
||||
|
||||
chars(C, N, Tail) when N > 0 ->
|
||||
chars(C, N-1, [C|Tail]);
|
||||
chars(C, 0, Tail) when is_integer(C) ->
|
||||
Tail.
|
||||
|
||||
|
||||
string_str(S, Sub) when is_list(Sub) -> str(S, Sub, 1).
|
||||
|
||||
str([C|S], [C|Sub], I) ->
|
||||
case l_prefix(Sub, S) of
|
||||
true -> I;
|
||||
false -> str(S, [C|Sub], I+1)
|
||||
end;
|
||||
str([_|S], Sub, I) -> str(S, Sub, I+1);
|
||||
str([], _Sub, _I) -> 0.
|
||||
|
||||
l_prefix([C|Pre], [C|String]) -> l_prefix(Pre, String);
|
||||
l_prefix([], String) when is_list(String) -> true;
|
||||
l_prefix(Pre, String) when is_list(Pre), is_list(String) -> false.
|
||||
|
||||
-endif.
|
||||
|
||||
%%%============================================================================
|
||||
%%% Test
|
||||
|
@ -88,4 +139,4 @@ magichashperf_test() ->
|
|||
{TimeMH2, _HL1} = timer:tc(lists, map, [fun(K) -> magic_hash(K) end, KL]),
|
||||
io:format(user, "1000 keys magic hashed in ~w microseconds~n", [TimeMH2]).
|
||||
|
||||
-endif.
|
||||
-endif.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue