Skip to content

Commit

Permalink
hibari >> GH51 - Update for Erlang/OTP 18
Browse files Browse the repository at this point in the history
- Add "18" to require_otp_vsn of rebar.config.
- Replace deprecated erlang:now/0 with gmt_time_otp18 functions
  such as monotonic_time/0 and erlang_system_time/1.
- Replace deprecated httpd_conf:clean/1 with string:strip/1.
  • Loading branch information
tatsuya6502 committed Nov 10, 2015
1 parent 41a3648 commit 8344276
Show file tree
Hide file tree
Showing 18 changed files with 108 additions and 78 deletions.
2 changes: 1 addition & 1 deletion include/brick_admin.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
-define(BKEY_MIGRATION_STATE, migration_state).

-record(hevent, {
time :: brick_bp:nowtime(), % now()
time :: brick_bp:nowtime(), % erlang:timestamp()
what :: atom(), % term()
detail :: atom(), % term()
props = [] :: brick_bp:proplist() % proplist()
Expand Down
3 changes: 1 addition & 2 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
%%% -*- mode: erlang -*-

%% Require OTP version R16 and 17
{require_otp_vsn, "R16|17"}.
{require_otp_vsn, "R16|17|18"}.

%% Depends
{deps_dir, "../"}.
Expand Down
18 changes: 10 additions & 8 deletions src/brick_admin.erl
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@

-include("brick_specs.hrl").

-define(TIME, gmt_time_otp18).

-define(S3_TABLE, 'tab1').

%% API
Expand Down Expand Up @@ -149,7 +151,7 @@
-record(state, {
schema = undefined, % dict:new()
mig_mons = undefined, % migration monitor 2-tuples
start_time = undefined, % now()
start_time = undefined, % erlang:timestamp()
extra_term = undefined, % term()
mbox_highwater = undefined
}).
Expand Down Expand Up @@ -808,7 +810,7 @@ handle_info({finish_init_tasks, BootstrapFile}, State) ->
{ok, MboxHigh} = application:get_env(gdss_admin, brick_admin_mbox_high_water),
%% Cross-app dependency: we need the partition_detector app running.
%% If not, complain loudly.
StartTime = now(),
StartTime = ?TIME:timestamp(),
ExtraStarting = {brick_admin, {starting, StartTime, node(), self()}},
ExtraRunning = {brick_admin, {running, StartTime, node(), self()}},
case (catch partition_detector_server:is_active()) of
Expand Down Expand Up @@ -1681,7 +1683,7 @@ do_start_migration(TableName, NewLH, Options, S) ->
NewGH_0 = brick_hash:init_global_hash_state(
true, pre, OldGH#g_hash_r.current_rev,
CurLH, CurChainList, NewLH, NewChainList, false),
Cookie = now(),
Cookie = ?TIME:timestamp(),
NewGH_1 = NewGH_0#g_hash_r{cookie = Cookie,
minor_rev = OldGH#g_hash_r.minor_rev+1},
NewGH_2 = lists:foldl(
Expand Down Expand Up @@ -1966,7 +1968,7 @@ check_for_other_admin_server_beacons(Intervals, MyStartTime, FailUSecs) ->
running_admin_beacons_p(USecs, MyStartTime) ->
Bs0 = partition_detector_server:get_last_beacons(),
%% io:format("Bs0 ~p\n", [Bs0]),
Now = now(),
Now = ?TIME:timestamp(),
Bs = lists:filter(fun(B) ->
%% io:format("Diff ~p ~p\n", [timer:now_diff(Now, B#beacon.time), B]),
timer:now_diff(Now, B#beacon.time) < USecs
Expand Down Expand Up @@ -2372,10 +2374,10 @@ start_throttle_server_maybe(Node, Opts) ->
%% @doc Start throttle server under the brick_admin_sup supervisor.

start_throttle_server(Node, Opts) ->
BwThrottle = proplists:get_value(throttle_bytes, Opts, 999*1000*1000),
Hour = 1*60*60*1000,
Spec = {now(), {brick_ticket, start_link,
[undefined, BwThrottle, 1000, Hour]},
BwThrottle = proplists:get_value(throttle_bytes, Opts, 999 * 1000 * 1000),
Hour = 1 * 60 * 60 * 1000,
Spec = {?TIME:timestamp(), {brick_ticket, start_link,
[undefined, BwThrottle, 1000, Hour]},
temporary, 2000, worker, [brick_ticket]},
{ok, ThrottlePid} =
supervisor:start_child({brick_admin_sup, Node}, Spec),
Expand Down
3 changes: 2 additions & 1 deletion src/brick_admin_cinfo.erl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ bootstrap_config(C) ->
cluster_info:send(C, Bin).

history_dump(C) ->
Tmp = lists:flatten(io_lib:format("/tmp/history.~p", [now()])),
Tmp = lists:flatten(io_lib:format("/tmp/history.~p",
[gmt_time_otp18:system_time(micro_seconds)])),
Res = try
ok = mod_admin:dump_history(Tmp),
{ok, Out} = file:read_file(Tmp),
Expand Down
6 changes: 4 additions & 2 deletions src/brick_bp.erl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
, sleep_random :: integer() % sleep random for check_status
}).

-define(TIME, gmt_time_otp18).

%%====================================================================
%% API
%%====================================================================
Expand Down Expand Up @@ -144,7 +146,7 @@ state(Pid) ->
%% initialize.
%%--------------------------------------------------------------------
init([_Name, Brick, Node, BrickOptions] = _Arg) ->
_ = random:seed(now()),
_ = random:seed(?TIME:monotonic_time(), ?TIME:unique_integer(), ?TIME:time_offset()),
{ok, Time} = application:get_env(gdss_admin, admin_server_brick_poll),
{ok, TRef} = brick_itimer:send_interval(Time, check_status),
{ok, SleepRnd} = application:get_env(gdss_admin, admin_server_brick_pinger_sleep_random),
Expand Down Expand Up @@ -264,7 +266,7 @@ handle_event(check_status, StateName, State) ->
?E_ERROR(
"Brick {~w,~w}: killed asynchronously from StateName ~p",
[State#state.brick, State#state.node, StateName]),
Report = [{killed, now()},
Report = [{killed, ?TIME:timestamp()},
{old_state, StateName},
{info, "Attempted transition back "
"to 'ok' but brick has not been "
Expand Down
13 changes: 8 additions & 5 deletions src/brick_chainmon.erl
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@

%% For opconf_r record, see brick_admin.hrl

-define(TIME, gmt_time_otp18).

%%====================================================================
%% API
%%====================================================================
Expand Down Expand Up @@ -214,7 +216,7 @@ state(ServerRef) ->
%%--------------------------------------------------------------------
init([Chain, Bricks]) ->
self() ! finish_init_tasks,
_ = random:seed(now()),
_ = random:seed(?TIME:monotonic_time(), ?TIME:unique_integer(), ?TIME:time_offset()),
{ok, Time} = application:get_env(gdss_admin, admin_server_chain_poll),
{ok, TRef} = brick_itimer:send_interval(Time, check_status),
SBPid = brick_sb:sb_pid(),
Expand Down Expand Up @@ -487,12 +489,12 @@ calculate_best_first_brick(S) ->
%% <ul>
%% <li> Brick has never been in 'ok' state. We assign the atom
%% never_been_up as the last up "time" for this brick. Any
%% atom will sort before any tuple (i.e. a legit erlang:now() 3-tuple)
%% atom will sort before any tuple (i.e. a legit erlang:timestamp() 3-tuple)
%% or a binary.</li>
%% <li> A brick has been in an 'ok' state, but then it changed to a non-ok
%% state, e.g. 'unknown'. After the last 'ok' event, it's the
%% first state transition <b>after that</b> that tells us when the
%% last time the brick had up-to-date data. So we use the erlang:now()
%% last time the brick had up-to-date data. So we use the erlang:timestamp()
%% 3-tuple for our sorting. </li>
%% <li> A brick has been in an 'ok' state, but the history does not include
%% any non-ok state afterward. So, as far as we know, that brick has
Expand Down Expand Up @@ -1542,15 +1544,16 @@ add_repair_brick_to_end({NewTail, NewTailNode} = _NewTailBrick, S) ->
-spec poll_for_full_sync(brick_name(), node(), integer()) -> ok | {poll_for_full_sync, timeout, integer(), integer()}.
poll_for_full_sync(Brick, Node, TimeLimit_0) ->
TimeLimit = TimeLimit_0 * 1000, % Convert to usec.
Start = now(),
Start = ?TIME:monotonic_time(),
SyncPoll =
fun(Acc) ->
case brick_server:chain_get_downstream_serials(Brick, Node) of
{X, X} ->
%%io:format("p11 ~p ~p\n", [X, X]),
{false, Acc};
{X, Y} when is_integer(X), is_integer(Y) ->
case timer:now_diff(now(), Start) of
End = ?TIME:monotonic_time(),
case ?TIME:convert_time_unit(End - Start, native, micro_seconds) of
D when D > TimeLimit ->
{false, {poll_for_full_sync, timeout, X, Y}};
_ ->
Expand Down
9 changes: 6 additions & 3 deletions src/brick_migmon.erl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
options = []
}).

-define(TIME, gmt_time_otp18).

%%%----------------------------------------------------------------------
%%% API
%%%----------------------------------------------------------------------
Expand Down Expand Up @@ -75,7 +77,7 @@ init([T, Options]) ->
chains_starting(trigger, S) when is_record(S, state) ->
?ELOG_INFO("Migration monitor: ~w: chains starting",
[(S#state.tab)#table_r.name]),
Start = now(),
Start = ?TIME:monotonic_time(),
T = S#state.tab,
GH = T#table_r.ghash,

Expand All @@ -97,8 +99,9 @@ chains_starting(trigger, S) when is_record(S, state) ->
end, x)
end, AllChains),
gen_fsm:send_event(self(), trigger),
case timer:now_diff(now(), Start) of
N when N < 1*1000*1000 ->
End = ?TIME:monotonic_time(),
case ?TIME:convert_time_unit(End - Start, native, milli_seconds) of
N when N < 1 * 1000 ->
?ELOG_INFO("Migration monitor: ~w: sweeps starting",
[(S#state.tab)#table_r.name]),
{next_state, migrating, S};
Expand Down
16 changes: 10 additions & 6 deletions src/brick_sb.erl
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@

%% History event record, 'hevent', moved to brick_admin.hrl

-define(TIME, gmt_time_otp18).

%%====================================================================
%% API
%%====================================================================
Expand Down Expand Up @@ -365,13 +367,13 @@ squorum_multiset(Bricks, KVs) ->
Ops = [brick_server:make_set(term_to_binary(K),
term_to_binary(V, [{compressed,1}])) ||
{K, V} <- KVs],
Start = now(),
Start = ?TIME:monotonic_time(),
Res = brick_squorum:multiset(Bricks, Ops),
End = now(),
case timer:now_diff(End, Start) of
N when N > 100*1000 ->
End = ?TIME:monotonic_time(),
case ?TIME:convert_time_unit(End - Start, native, milli_seconds) of
N when N > 100 ->
?E_INFO("~s:squorum_set(ops len ~p) was ~p msec\n",
[?MODULE, length(KVs), N div 1000]);
[?MODULE, length(KVs), N]);
_ ->
ok
end,
Expand Down Expand Up @@ -414,7 +416,9 @@ make_status_report_op({report_status, {Type, Name} = Key,
true ->
State#state.status
end,
HEvent = #hevent{time = now(), what = What, detail = Status,
HEvent = #hevent{time = ?TIME:timestamp(),
what = What,
detail = Status,
props = PropList},
NewHList = [HEvent|OldHList],
NewHistory = dict:store(Key, NewHList, State#state.history),
Expand Down
8 changes: 4 additions & 4 deletions src/mod_admin.erl
Original file line number Diff line number Diff line change
Expand Up @@ -118,24 +118,24 @@ do2(ModData) ->
%% {error, term()}
%% @doc EWSAPI config callback.
load("AdminOptFoo " ++ AuthArg, [])->
case catch list_to_atom(httpd_conf:clean(AuthArg)) of
case catch list_to_atom(string:strip(AuthArg)) of
true ->
{ok, [], {admin_opt_foo, true}};
false ->
{ok, [], {admin_opt_foo, false}};
_ ->
{error, ?NICE(httpd_conf:clean(AuthArg) ++ " is an invalid AdminOptFoo directive")}
{error, ?NICE(string:strip(AuthArg) ++ " is an invalid AdminOptFoo directive")}

end;

load("AdminOptBar " ++ AuthArg, [])->
case catch list_to_atom(httpd_conf:clean(AuthArg)) of
case catch list_to_atom(string:strip(AuthArg)) of
true ->
{ok, [], {admin_opt_bar, true}};
false ->
{ok, [], {admin_opt_bar, false}};
_ ->
{error, ?NICE(httpd_conf:clean(AuthArg) ++ " is an invalid AdminOptBar directive")}
{error, ?NICE(string:strip(AuthArg) ++ " is an invalid AdminOptBar directive")}

end.

Expand Down
8 changes: 5 additions & 3 deletions test/eqc/simple_eqc_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ initial_state() ->

-spec initial_state(proplist()) -> #state{}.
initial_state(_Options) ->
QQQ = now(),
QQQ = gmt_time_otp18:timestamp(),
gmt_loop:do_while(
fun(_Acc) ->
try
Expand Down Expand Up @@ -632,8 +632,10 @@ key_prefix() ->

-spec make_exp(state()) -> exp_time().
make_exp(S) ->
{MSec, Sec, USec} = now(),
NowX = (MSec * 1000000 * 1000000) + (Sec * 1000000) + USec,
NowX = gmt_time_otp18:erlang_system_time(micro_seconds),
%% TODO: FIXME: This should read (NowX div 1000) or
%% just NowX with erlang_system_time(milli_seconds).
%% https://github.com/hibari/gdss-admin/issues/11
(NowX * 1000) + S#state.step.

-spec apply_exp_time_directive([op_flag()],
Expand Down
7 changes: 4 additions & 3 deletions test/eqc/simple_update_counter_eqc_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
%% Timeout.

update_counter(Tab, Key, Incr, Timeout) when is_integer(Incr) ->
update_counter2(Tab, Key, Incr, Timeout, erlang:now());
update_counter2(Tab, Key, Incr, Timeout, gmt_time_otp18:monotonic_time());
update_counter(_Tab, _Key, _Incr, _Timeout) ->
invalid_arg_present.

Expand All @@ -72,8 +72,9 @@ update_counter(_Tab, _Key, _Incr, _Timeout) ->
%%====================================================================

update_counter1(Tab, Key, Incr, Timeout, Expires) ->
case timer:now_diff(erlang:now(), Expires) of
TDiff when TDiff > Timeout*1000 ->
Now = gmt_time_otp18:monotonic_time(),
case gmt_time_otp18:convert_time_unit(Now - Expires, native, milli_seconds) of
TDiff when TDiff > Timeout ->
exit(timeout);
_ ->
update_counter2(Tab, Key, Incr, Timeout, Expires)
Expand Down
8 changes: 5 additions & 3 deletions test/eqc/squorum_eqc_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ common1_prop(F_check, Env) ->
%% Called in symbolic context.

initial_state() ->
QQQ = now(),
QQQ = gmt_time_otp18:timestamp(),
gmt_loop:do_while(
fun(_Acc) ->
try
Expand Down Expand Up @@ -372,8 +372,10 @@ key_prefix() ->
"/foo/bar/".

make_exp(S) ->
{MSec, Sec, USec} = now(),
NowX = (MSec * 1000000 * 1000000) + (Sec * 1000000) + USec,
NowX = gmt_time_otp18:erlang_system_time(micro_seconds),
%% TODO: FIXME: This should read (NowX div 1000) or
%% just NowX with erlang_system_time(milli_seconds).
%% https://github.com/hibari/gdss-admin/issues/11
(NowX * 1000) + S#state.step.

random_val() ->
Expand Down
4 changes: 3 additions & 1 deletion test/eunit/brick_ets_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
-compile(export_all).
-include_lib("eunit/include/eunit.hrl").

-define(TIME, gmt_time_otp18).

-define(MAXKEYS,5000).

-define(KILLTIME,30000).
Expand Down Expand Up @@ -55,7 +57,7 @@ test_teardown(X) ->
ok.

test_data_integrity() ->
random:seed(erlang:now()),
random:seed(?TIME:monotonic_time(), ?TIME:unique_integer(), ?TIME:time_offset()),
[ ok = test_data_integrity(T,10) || {T,[],true} <- all_tables()].

test_data_integrity(_T,0) ->
Expand Down
4 changes: 3 additions & 1 deletion test/eunit/brick_eunit_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

-define(MYNODE, 'gdss_eunit@localhost').

-define(TIME, gmt_time_otp18).


%%%----------------------------------------------------------------------
%%% TEST UTILS
Expand Down Expand Up @@ -54,7 +56,7 @@ setup(Verbose) ->
true ->
error_logger:delete_report_handler(error_logger_tty_h)
end,
random:seed(erlang:now()),
random:seed(?TIME:monotonic_time(), ?TIME:unique_integer(), ?TIME:time_offset()),
ok.

setup_and_bootstrap() ->
Expand Down
6 changes: 4 additions & 2 deletions test/eunit/brick_replace_rename_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ test_simple_rename1() ->

-spec make_exp(non_neg_integer()) -> exp_time().
make_exp(StepMillis) ->
{MSec, Sec, USec} = now(),
NowX = (MSec * 1000000 * 1000000) + (Sec * 1000000) + USec,
NowX = gmt_time_otp18:erlang_system_time(micro_seconds),
%% TODO: FIXME: This should read (NowX div 1000) or
%% just NowX with erlang_system_time(milli_seconds).
%% https://github.com/hibari/gdss-admin/issues/11
(NowX * 1000) + StepMillis.

0 comments on commit 8344276

Please sign in to comment.