You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ns...@apache.org on 2016/07/23 07:53:40 UTC

[2/4] thrift git commit: THRIFT-3820 Erlang: Detect OTP >= 18 to use new time correction

THRIFT-3820 Erlang: Detect OTP >= 18 to use new time correction

erlang:now/0 is deprecated BIF.
See the "Time and Time Correction in Erlang" chapter of the ERTS User's Guide for more information.

This closes #1000


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/8ab38b6b
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/8ab38b6b
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/8ab38b6b

Branch: refs/heads/master
Commit: 8ab38b6b955ceba6106c615287c04abecdfb3c77
Parents: 5871d2c
Author: \u0412\u0435\u0441\u0435\u043b\u043e\u0432 \u0410\u043d\u0434\u0440\u0435\u0439 <gi...@hotmail.com>
Authored: Fri Apr 29 13:12:05 2016 +0300
Committer: Nobuaki Sukegawa <ns...@apache.org>
Committed: Sat Jul 23 15:12:42 2016 +0900

----------------------------------------------------------------------
 lib/erl/rebar.config.script                |  7 +++++++
 lib/erl/src/thrift_reconnecting_client.erl | 19 +++++++++++++++++--
 2 files changed, 24 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/8ab38b6b/lib/erl/rebar.config.script
----------------------------------------------------------------------
diff --git a/lib/erl/rebar.config.script b/lib/erl/rebar.config.script
new file mode 100644
index 0000000..c733823
--- /dev/null
+++ b/lib/erl/rebar.config.script
@@ -0,0 +1,7 @@
+Def0 = case not erlang:is_builtin(erlang, monotonic_time, 0) of
+           true -> [];
+           false -> [{d, time_correction}]
+       end,
+Defs = Def0,
+lists:keystore(erl_opts, 1, CONFIG,
+               {erl_opts, proplists:get_value(erl_opts, CONFIG, []) ++ Defs}).

http://git-wip-us.apache.org/repos/asf/thrift/blob/8ab38b6b/lib/erl/src/thrift_reconnecting_client.erl
----------------------------------------------------------------------
diff --git a/lib/erl/src/thrift_reconnecting_client.erl b/lib/erl/src/thrift_reconnecting_client.erl
index 6731eab..468c38b 100644
--- a/lib/erl/src/thrift_reconnecting_client.erl
+++ b/lib/erl/src/thrift_reconnecting_client.erl
@@ -115,9 +115,9 @@ handle_call( { call, Op, Args },
              _From,
              State=#state{ client = Client } ) ->
 
-  Start = now(),
+  Timer = timer_fun(),
   Result = ( catch thrift_client:call( Client, Op, Args) ),
-  Time = timer:now_diff( now(), Start ),
+  Time = Timer(),
 
   case Result of
     { C, { ok, Reply } } ->
@@ -217,6 +217,21 @@ reconn_time( #state{ reconn_max = ReconnMax, reconn_time = R } ) ->
     false -> Backoff
   end.
 
+-ifdef(time_correction).
+timer_fun() ->
+  T1 = erlang:monotonic_time(),
+  fun() ->
+    T2 = erlang:monotonic_time(),
+    erlang:convert_time_unit(T2 - T1, native, micro_seconds)
+  end.
+-else.
+timer_fun() ->
+  T1 = erlang:now(),
+  fun() ->
+    T2 = erlang:now(),
+    timer:now_diff(T2, T1)
+  end.
+-endif.
 
 incr_stats( Op, Result, Time,
             State = #state{ op_cnt_dict  = OpCntDict,