From 01bd7cf79c44222567843adfbea74fee78180de4 Mon Sep 17 00:00:00 2001
From: Peter Lemenkov <lemenkov@gmail.com>
Date: Tue, 12 Mar 2019 16:50:18 +0300
Subject: [PATCH] Deprecation: erlang:now/0 -> erlang:timestamp/0
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
diff --git a/src/couch_replicator/src/couch_replicator_manager.erl b/src/couch_replicator/src/couch_replicator_manager.erl
index 4891c4c4c..5ab452e19 100644
--- a/src/couch_replicator/src/couch_replicator_manager.erl
+++ b/src/couch_replicator/src/couch_replicator_manager.erl
@@ -561,7 +561,7 @@ update_rep_doc(RepDb, #doc{body = {RepDocBody}} = RepDoc, KVs) ->
% RFC3339 timestamps.
% Note: doesn't include the time seconds fraction (RFC3339 says it's optional).
timestamp() ->
- {{Year, Month, Day}, {Hour, Min, Sec}} = calendar:now_to_local_time(now()),
+ {{Year, Month, Day}, {Hour, Min, Sec}} = calendar:now_to_local_time(erlang:timestamp()),
UTime = erlang:universaltime(),
LocalTime = calendar:universal_time_to_local_time(UTime),
DiffSecs = calendar:datetime_to_gregorian_seconds(LocalTime) -
diff --git a/src/couch_replicator/src/couch_replicator_worker.erl b/src/couch_replicator/src/couch_replicator_worker.erl
index d66d47805..506565e2c 100644
--- a/src/couch_replicator/src/couch_replicator_worker.erl
+++ b/src/couch_replicator/src/couch_replicator_worker.erl
@@ -72,7 +72,7 @@
start_link(Cp, #db{} = Source, Target, ChangesManager, _MaxConns) ->
Pid = spawn_link(fun() ->
- erlang:put(last_stats_report, now()),
+ erlang:put(last_stats_report, erlang:timestamp()),
queue_fetch_loop(Source, Target, Cp, Cp, ChangesManager)
end),
{ok, Pid};
@@ -88,7 +88,7 @@ init({Cp, Source, Target, ChangesManager, MaxConns}) ->
LoopPid = spawn_link(fun() ->
queue_fetch_loop(Source, Target, Parent, Cp, ChangesManager)
end),
- erlang:put(last_stats_report, now()),
+ erlang:put(last_stats_report, erlang:timestamp()),
State = #state{
cp = Cp,
max_parallel_conns = MaxConns,
@@ -235,7 +235,7 @@ queue_fetch_loop(Source, Target, Parent, Cp, ChangesManager) ->
end,
close_db(Target2),
ok = gen_server:call(Cp, {report_seq_done, ReportSeq, Stats}, infinity),
- erlang:put(last_stats_report, now()),
+ erlang:put(last_stats_report, erlang:timestamp()),
?LOG_DEBUG("Worker reported completion of seq ~p", [ReportSeq]),
queue_fetch_loop(Source, Target, Parent, Cp, ChangesManager)
end.
@@ -375,7 +375,7 @@ spawn_writer(Target, #batch{docs = DocList, size = Size}) ->
after_full_flush(#state{stats = Stats, flush_waiter = Waiter} = State) ->
gen_server:reply(Waiter, {ok, Stats}),
- erlang:put(last_stats_report, now()),
+ erlang:put(last_stats_report, erlang:timestamp()),
State#state{
stats = #rep_stats{},
flush_waiter = nil,
@@ -504,7 +504,7 @@ find_missing(DocInfos, Target) ->
maybe_report_stats(Cp, Stats) ->
- Now = now(),
+ Now = erlang:timestamp(),
case timer:now_diff(erlang:get(last_stats_report), Now) >= ?STATS_DELAY of
true ->
ok = gen_server:call(Cp, {add_stats, Stats}, infinity),
diff --git a/src/couchdb/couch_auth_cache.erl b/src/couchdb/couch_auth_cache.erl
index 42ccd4436..be6b7c4f9 100644
--- a/src/couchdb/couch_auth_cache.erl
+++ b/src/couchdb/couch_auth_cache.erl
@@ -182,7 +182,7 @@ handle_call({fetch, UserName}, _From, State) ->
[] ->
couch_stats_collector:increment({couchdb, auth_cache_misses}),
Creds = get_user_props_from_db(UserName),
- State1 = add_cache_entry(UserName, Creds, erlang:now(), State),
+ State1 = add_cache_entry(UserName, Creds, erlang:timestamp(), State),
{Creds, State1}
end,
{reply, Credentials, NewState};
@@ -261,7 +261,7 @@ free_mru_cache_entry() ->
cache_hit(UserName, Credentials, ATime) ->
- NewATime = erlang:now(),
+ NewATime = erlang:timestamp(),
true = ets:delete(?BY_ATIME, ATime),
true = ets:insert(?BY_ATIME, {NewATime, UserName}),
true = ets:insert(?BY_USER, {UserName, {Credentials, NewATime}}).
diff --git a/src/couchdb/couch_changes.erl b/src/couchdb/couch_changes.erl
index 6edde32db..ac5f27bc0 100644
--- a/src/couchdb/couch_changes.erl
+++ b/src/couchdb/couch_changes.erl
@@ -61,7 +61,7 @@ handle_changes(Args1, Req, Db0) ->
undefined ->
erlang:erase(last_changes_heartbeat);
Val when is_integer(Val); Val =:= true ->
- put(last_changes_heartbeat, now())
+ put(last_changes_heartbeat, erlang:timestamp())
end,
case lists:member(Feed, ["continuous", "longpoll", "eventsource"]) of
@@ -556,7 +556,7 @@ reset_heartbeat() ->
undefined ->
ok;
_ ->
- put(last_changes_heartbeat, now())
+ put(last_changes_heartbeat, erlang:timestamp())
end.
maybe_heartbeat(Timeout, TimeoutFun, Acc) ->
@@ -565,7 +565,7 @@ maybe_heartbeat(Timeout, TimeoutFun, Acc) ->
undefined ->
{ok, Acc};
_ ->
- Now = now(),
+ Now = erlang:timestamp(),
case timer:now_diff(Now, Before) div 1000 >= Timeout of
true ->
Acc2 = TimeoutFun(Acc),
diff --git a/src/couchdb/couch_db_updater.erl b/src/couchdb/couch_db_updater.erl
index c92097f62..3db8e9549 100644
--- a/src/couchdb/couch_db_updater.erl
+++ b/src/couchdb/couch_db_updater.erl
@@ -466,7 +466,7 @@ init_db(DbName, Filepath, Fd, ReaderFd, Header0, Options) ->
{ok, Security} = couch_file:pread_term(Fd, SecurityPtr)
end,
% convert start time tuple to microsecs and store as a binary string
- {MegaSecs, Secs, MicroSecs} = now(),
+ {MegaSecs, Secs, MicroSecs} = erlang:timestamp(),
StartTime = ?l2b(io_lib:format("~p",
[(MegaSecs*1000000*1000000) + (Secs*1000000) + MicroSecs])),
{ok, RefCntr} = couch_ref_counter:start([Fd, ReaderFd]),
diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl
index 9a6bf3ab4..896dde36a 100644
--- a/src/couchdb/couch_httpd.erl
+++ b/src/couchdb/couch_httpd.erl
@@ -232,7 +232,7 @@ handle_request(MochiReq, DefaultFun, UrlHandlers, DbUrlHandlers,
handle_request_int(MochiReq, DefaultFun,
UrlHandlers, DbUrlHandlers, DesignUrlHandlers) ->
- Begin = now(),
+ Begin = erlang:timestamp(),
% for the path, use the raw path with the query string and fragment
% removed, but URL quoting left intact
RawUri = MochiReq:get(raw_path),
@@ -379,7 +379,7 @@ handle_request_int(MochiReq, DefaultFun,
?LOG_INFO("Stacktrace: ~p",[Stack]),
send_error(HttpReq, Error)
end,
- RequestTime = round(timer:now_diff(now(), Begin)/1000),
+ RequestTime = round(timer:now_diff(erlang:timestamp(), Begin)/1000),
couch_stats_collector:record({couchdb, request_time}, RequestTime),
couch_stats_collector:increment({httpd, requests}),
{ok, Resp}.
diff --git a/src/couchdb/couch_httpd_auth.erl b/src/couchdb/couch_httpd_auth.erl
index f7bbb13fe..6001e1392 100644
--- a/src/couchdb/couch_httpd_auth.erl
+++ b/src/couchdb/couch_httpd_auth.erl
@@ -396,7 +396,7 @@ auth_name(String) when is_list(String) ->
?l2b(Name).
make_cookie_time() ->
- {NowMS, NowS, _} = erlang:now(),
+ {NowMS, NowS, _} = erlang:timestamp(),
NowMS * 1000000 + NowS.
cookie_scheme(#httpd{mochi_req=MochiReq}) ->
diff --git a/src/couchdb/couch_os_daemons.erl b/src/couchdb/couch_os_daemons.erl
index cac031a9b..ec3905586 100644
--- a/src/couchdb/couch_os_daemons.erl
+++ b/src/couchdb/couch_os_daemons.erl
@@ -123,7 +123,7 @@ handle_info({Port, {exit_status, Status}}, Table) ->
[D] ->
% Port died for unknown reason. Check to see if it's
% died too many times or if we should boot it back up.
- case should_halt([now() | D#daemon.errors]) of
+ case should_halt([erlang:timestamp() | D#daemon.errors]) of
{true, _} ->
% Halting the process. We won't try and reboot
% until the configuration changes.
@@ -363,7 +363,7 @@ should_halt(Errors) ->
RetryTimeCfg = couch_config:get("os_daemon_settings", "retry_time", "5"),
RetryTime = list_to_integer(RetryTimeCfg),
- Now = now(),
+ Now = erlang:timestamp(),
RecentErrors = lists:filter(fun(Time) ->
timer:now_diff(Now, Time) =< RetryTime * 1000000
end, Errors),
diff --git a/src/couchdb/couch_server.erl b/src/couchdb/couch_server.erl
index 3da4ecf33..a861e8165 100644
--- a/src/couchdb/couch_server.erl
+++ b/src/couchdb/couch_server.erl
@@ -225,7 +225,7 @@ maybe_close_lru_db(#server{dbs_open=NumOpen, max_dbs_open=MaxOpen}=Server)
{ok, Server};
maybe_close_lru_db(#server{dbs_open=NumOpen}=Server) ->
% must free up the lru db.
- case try_close_lru(now()) of
+ case try_close_lru(erlang:timestamp()) of
ok ->
{ok, Server#server{dbs_open=NumOpen - 1}};
Error -> Error
@@ -246,7 +246,7 @@ try_close_lru(StartTime) ->
false ->
% this still has referrers. Go ahead and give it a current lru time
% and try the next one in the table.
- NewLruTime = now(),
+ NewLruTime = erlang:timestamp(),
true = ets:insert(couch_dbs_by_name, {DbName, {opened, MainPid, NewLruTime}}),
true = ets:insert(couch_dbs_by_pid, {MainPid, DbName}),
true = ets:delete(couch_dbs_by_lru, LruTime),
@@ -320,7 +320,7 @@ handle_call({open_result, DbName, {ok, OpenedDbPid}, Options}, _From, Server) ->
gen_server:reply(From,
catch couch_db:open_ref_counted(OpenedDbPid, FromPid))
end, Froms),
- LruTime = now(),
+ LruTime = erlang:timestamp(),
true = ets:insert(couch_dbs_by_name,
{DbName, {opened, OpenedDbPid, LruTime}}),
true = ets:delete(couch_dbs_by_pid, Opener),
@@ -351,7 +351,7 @@ handle_call({open_result, DbName, Error, Options}, _From, Server) ->
end,
{reply, ok, Server#server{dbs_open = DbsOpen}};
handle_call({open, DbName, Options}, {FromPid,_}=From, Server) ->
- LruTime = now(),
+ LruTime = erlang:timestamp(),
case ets:lookup(couch_dbs_by_name, DbName) of
[] ->
open_db(DbName, Server, Options, From);
diff --git a/src/couchdb/couch_stats_aggregator.erl b/src/couchdb/couch_stats_aggregator.erl
index 6090355d5..e86d069de 100644
--- a/src/couchdb/couch_stats_aggregator.erl
+++ b/src/couchdb/couch_stats_aggregator.erl
@@ -139,7 +139,7 @@ handle_call(collect_sample, _, {OldTRef, SampleInterval}) ->
end, couch_stats_collector:all(absolute)),
Values = Incs ++ Abs,
- Now = erlang:now(),
+ Now = erlang:timestamp(),
lists:foreach(fun({{Key, Rate}, Agg}) ->
NewAgg = case proplists:lookup(Key, Values) of
none ->
diff --git a/src/couchdb/couch_task_status.erl b/src/couchdb/couch_task_status.erl
index e23b56089..eed4817b0 100644
--- a/src/couchdb/couch_task_status.erl
+++ b/src/couchdb/couch_task_status.erl
@@ -82,7 +82,7 @@ get(Prop) ->
maybe_persist(TaskProps0) ->
{LastUpdateTime, Frequency} = erlang:get(task_status_update),
- case timer:now_diff(Now = now(), LastUpdateTime) >= Frequency of
+ case timer:now_diff(Now = erlang:timestamp(), LastUpdateTime) >= Frequency of
true ->
put(task_status_update, {Now, Frequency}),
TaskProps = ?set(TaskProps0, updated_on, timestamp(Now)),
@@ -145,7 +145,7 @@ code_change(_OldVsn, State, _Extra) ->
timestamp() ->
- timestamp(now()).
+ timestamp(erlang:timestamp()).
timestamp({Mega, Secs, _}) ->
Mega * 1000000 + Secs.
diff --git a/src/couchdb/couch_uuids.erl b/src/couchdb/couch_uuids.erl
index 581aba97a..082a96526 100644
--- a/src/couchdb/couch_uuids.erl
+++ b/src/couchdb/couch_uuids.erl
@@ -36,7 +36,7 @@ utc_random() ->
utc_suffix(couch_util:to_hex(crypto:strong_rand_bytes(9))).
utc_suffix(Suffix) ->
- Now = {_, _, Micro} = now(),
+ Now = {_, _, Micro} = erlang:timestamp(),
Nowish = calendar:now_to_universal_time(Now),
Nowsecs = calendar:datetime_to_gregorian_seconds(Nowish),
Then = calendar:datetime_to_gregorian_seconds({{1970, 1, 1}, {0, 0, 0}}),
diff --git a/test/couchdb/couchdb_http_proxy_tests.erl b/test/couchdb/couchdb_http_proxy_tests.erl
index 03ceca7c2..2f6e4159e 100644
--- a/test/couchdb/couchdb_http_proxy_tests.erl
+++ b/test/couchdb/couchdb_http_proxy_tests.erl
@@ -467,7 +467,7 @@ recv_body(ReqId, Acc) ->
%% Copy from couch test_util @ master branch
now_us() ->
- {MegaSecs, Secs, MicroSecs} = now(),
+ {MegaSecs, Secs, MicroSecs} = erlang:timestamp(),
(MegaSecs * 1000000 + Secs) * 1000000 + MicroSecs.
stop_sync(Name) ->
diff --git a/test/couchdb/include/couch_eunit.hrl.in b/test/couchdb/include/couch_eunit.hrl.in
index 063b3dbb2..d30fa24bc 100644
--- a/test/couchdb/include/couch_eunit.hrl.in
+++ b/test/couchdb/include/couch_eunit.hrl.in
@@ -25,21 +25,21 @@
-define(tempfile,
fun() ->
- {A, B, C} = erlang:now(),
+ {A, B, C} = erlang:timestamp(),
N = node(),
FileName = lists:flatten(io_lib:format("~p-~p.~p.~p", [N, A, B, C])),
filename:join([?TEMPDIR, FileName])
end).
-define(tempdb,
fun() ->
- Nums = tuple_to_list(erlang:now()),
+ Nums = tuple_to_list(erlang:timestamp()),
Prefix = "eunit-test-db",
Suffix = lists:concat([integer_to_list(Num) || Num <- Nums]),
list_to_binary(Prefix ++ "-" ++ Suffix)
end).
-define(docid,
fun() ->
- {A, B, C} = erlang:now(),
+ {A, B, C} = erlang:timestamp(),
lists:flatten(io_lib:format("~p~p~p", [A, B, C]))
end).