You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2024/07/18 21:32:51 UTC

(couchdb) branch unused-externals-and-local-externals created (now ca9913b8a)

This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a change to branch unused-externals-and-local-externals
in repository https://gitbox.apache.org/repos/asf/couchdb.git


      at ca9913b8a Remove unused external functions and local external calls

This branch includes the following new commits:

     new ca9913b8a Remove unused external functions and local external calls

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(couchdb) 01/01: Remove unused external functions and local external calls

Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch unused-externals-and-local-externals
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit ca9913b8ad6f5b8e0af47e2dfcb7aae6e7b265a7
Author: Nick Vatamaniuc <va...@gmail.com>
AuthorDate: Thu Jul 18 16:02:38 2024 -0400

    Remove unused external functions and local external calls
    
    Local external calls are fairly simple: it's when we use the function in the
    module via the external reference. Previously, with hotcode upgrades that might
    have made sense, but currently it doesn't, maybe even adds a tiny bit of
    overhead on each call. A couple of these were cleaned up in chttpd module.
    
    Unused externals are functions which are exported but not used anywhere.
    
    In some cases we didn't even use the function at all, like in the case of
    stream_init/1,2 or rexi:stream/1,2,3 we can remove their bodies as well.
    
    Since stream_init is removed update the init_stream as per
    https://github.com/apache/couchdb/issues/5122, where we noticed that the newer
    init_stream doesn't actually update the timeout metric, so before cleaning up
    stream_init move that to the init_stream.
---
 src/chttpd/src/chttpd.erl                          | 12 +--
 src/couch/src/couch_emsort.erl                     |  9 +--
 src/couch/src/couch_key_tree.erl                   | 15 ----
 src/couch/src/couch_util.erl                       | 22 +-----
 src/couch_prometheus/src/couch_prometheus_util.erl |  3 +-
 .../src/couch_replicator_api_wrap.erl              | 12 ---
 src/rexi/src/rexi.erl                              | 86 ++--------------------
 src/rexi/src/rexi_utils.erl                        |  2 +-
 8 files changed, 17 insertions(+), 144 deletions(-)

diff --git a/src/chttpd/src/chttpd.erl b/src/chttpd/src/chttpd.erl
index ab8e1e9a3..0c1380862 100644
--- a/src/chttpd/src/chttpd.erl
+++ b/src/chttpd/src/chttpd.erl
@@ -515,7 +515,7 @@ maybe_log(_HttpReq, #httpd_resp{should_log = false}) ->
 %% aren't sharded. So for now when a local db is specified as the source or
 %% the target, it's hacked to make it a full url and treated as a remote.
 possibly_hack(#httpd{path_parts = [<<"_replicate">>]} = Req) ->
-    {Props0} = chttpd:json_body_obj(Req),
+    {Props0} = json_body_obj(Req),
     Props1 = fix_uri(Req, Props0, <<"source">>),
     Props2 = fix_uri(Req, Props1, <<"target">>),
     Req#httpd{req_body = {Props2}};
@@ -824,7 +824,7 @@ etag_match(Req, CurrentEtag) when is_binary(CurrentEtag) ->
     etag_match(Req, binary_to_list(CurrentEtag));
 etag_match(Req, CurrentEtag) ->
     EtagsToMatch0 = string:tokens(
-        chttpd:header_value(Req, "If-None-Match", ""), ", "
+        header_value(Req, "If-None-Match", ""), ", "
     ),
     EtagsToMatch = lists:map(fun strip_weak_prefix/1, EtagsToMatch0),
     lists:member(CurrentEtag, EtagsToMatch).
@@ -839,7 +839,7 @@ etag_respond(Req, CurrentEtag, RespFun) ->
         true ->
             % the client has this in their cache.
             Headers = [{"ETag", CurrentEtag}],
-            chttpd:send_response(Req, 304, Headers, <<>>);
+            send_response(Req, 304, Headers, <<>>);
         false ->
             % Run the function.
             RespFun()
@@ -970,7 +970,7 @@ send_delayed_error(#delayed_resp{resp = Resp, req = Req}, Reason) ->
 close_delayed_json_object(Resp, Buffer, Terminator, 0) ->
     % Use a separate chunk to close the streamed array to maintain strict
     % compatibility with earlier versions. See COUCHDB-2724
-    {ok, R1} = chttpd:send_delayed_chunk(Resp, Buffer),
+    {ok, R1} = send_delayed_chunk(Resp, Buffer),
     send_delayed_chunk(R1, Terminator);
 close_delayed_json_object(Resp, Buffer, Terminator, _Threshold) ->
     send_delayed_chunk(Resp, [Buffer | Terminator]).
@@ -1020,7 +1020,7 @@ start_delayed_response(#delayed_resp{} = DelayedResp) ->
     {ok, DelayedResp}.
 
 buffer_response(Req) ->
-    case chttpd:qs_value(Req, "buffer_response") of
+    case qs_value(Req, "buffer_response") of
         "false" ->
             false;
         "true" ->
@@ -1350,7 +1350,7 @@ send_chunked_error(Resp, Error) ->
     send_chunk(Resp, []).
 
 send_redirect(Req, Path) ->
-    Headers = [{"Location", chttpd:absolute_uri(Req, Path)}],
+    Headers = [{"Location", absolute_uri(Req, Path)}],
     send_response(Req, 301, Headers, <<>>).
 
 server_header() ->
diff --git a/src/couch/src/couch_emsort.erl b/src/couch/src/couch_emsort.erl
index 9dcc08d67..4250b45e9 100644
--- a/src/couch/src/couch_emsort.erl
+++ b/src/couch/src/couch_emsort.erl
@@ -130,7 +130,7 @@
 %
 
 -export([open/1, open/2, get_fd/1, get_state/1]).
--export([add/2, merge/1, merge/2, sort/1, iter/1, next/1]).
+-export([add/2, merge/2, iter/1, next/1]).
 -export([num_kvs/1, num_merges/1]).
 
 -record(ems, {
@@ -188,13 +188,6 @@ add(Ems, KVs) ->
         num_bb = Ems#ems.num_bb + 1
     }}.
 
-sort(#ems{} = Ems) ->
-    {ok, Ems1} = merge(Ems),
-    iter(Ems1).
-
-merge(Ems) ->
-    merge(Ems, fun(_) -> ok end).
-
 merge(#ems{root = undefined} = Ems, _Reporter) ->
     {ok, Ems};
 merge(#ems{} = Ems, Reporter) ->
diff --git a/src/couch/src/couch_key_tree.erl b/src/couch/src/couch_key_tree.erl
index db04d250e..87504c78c 100644
--- a/src/couch/src/couch_key_tree.erl
+++ b/src/couch/src/couch_key_tree.erl
@@ -57,7 +57,6 @@
     get_full_key_paths/2,
     get_key_leafs/2,
     map/2,
-    map_leafs/2,
     mapfold/3,
     multi_merge/2,
     merge/2,
@@ -475,20 +474,6 @@ mapfold_simple(Fun, Acc, Pos, [{Key, Value, SubTree} | RestTree]) ->
     {RestTree2, Acc4} = mapfold_simple(Fun, Acc3, Pos, RestTree),
     {[{Key, Value2, SubTree2} | RestTree2], Acc4}.
 
-map_leafs(_Fun, []) ->
-    [];
-map_leafs(Fun, [{Pos, Tree} | Rest]) ->
-    [NewTree] = map_leafs_simple(Fun, Pos, [Tree]),
-    [{Pos, NewTree} | map_leafs(Fun, Rest)].
-
-map_leafs_simple(_Fun, _Pos, []) ->
-    [];
-map_leafs_simple(Fun, Pos, [{Key, Value, []} | RestTree]) ->
-    Value2 = Fun({Pos, Key}, Value),
-    [{Key, Value2, []} | map_leafs_simple(Fun, Pos, RestTree)];
-map_leafs_simple(Fun, Pos, [{Key, Value, SubTree} | RestTree]) ->
-    [{Key, Value, map_leafs_simple(Fun, Pos + 1, SubTree)} | map_leafs_simple(Fun, Pos, RestTree)].
-
 stem(Trees, Limit) ->
     try
         {_, Branches} = lists:foldl(
diff --git a/src/couch/src/couch_util.erl b/src/couch/src/couch_util.erl
index 739df28e5..18faa9695 100644
--- a/src/couch/src/couch_util.erl
+++ b/src/couch/src/couch_util.erl
@@ -19,10 +19,10 @@
 -export([encodeBase64Url/1, decodeBase64Url/1]).
 -export([validate_utf8/1, to_hex/1, to_hex_bin/1, parse_term/1, dict_find/3]).
 -export([get_nested_json_value/2, json_user_ctx/1]).
--export([proplist_apply_field/2, json_apply_field/2]).
+-export([json_apply_field/2]).
 -export([to_binary/1, to_integer/1, to_list/1, url_encode/1]).
 -export([json_encode/1, json_decode/1, json_decode/2]).
--export([verify/2, simple_call/2, shutdown_sync/1]).
+-export([verify/2, shutdown_sync/1]).
 -export([get_value/2, get_value/3, set_value/3]).
 -export([reorder_results/2, reorder_results/3]).
 -export([url_strip_password/1]).
@@ -157,20 +157,6 @@ shutdown_sync(Pid) ->
         erlang:demonitor(MRef, [flush])
     end.
 
-simple_call(Pid, Message) ->
-    MRef = erlang:monitor(process, Pid),
-    try
-        Pid ! {self(), Message},
-        receive
-            {Pid, Result} ->
-                Result;
-            {'DOWN', MRef, _, _, Reason} ->
-                exit(Reason)
-        end
-    after
-        erlang:demonitor(MRef, [flush])
-    end.
-
 validate_utf8(Data) when is_list(Data) ->
     validate_utf8(?l2b(Data));
 validate_utf8(Bin) when is_binary(Bin) ->
@@ -276,10 +262,6 @@ get_nested_json_value(Value, []) ->
 get_nested_json_value(_NotJSONObj, _) ->
     throw({not_found, json_mismatch}).
 
-proplist_apply_field(H, L) ->
-    {R} = json_apply_field(H, {L}),
-    R.
-
 json_apply_field(H, {L}) ->
     json_apply_field(H, L, []).
 json_apply_field({Key, NewValue}, [{Key, _OldVal} | Headers], Acc) ->
diff --git a/src/couch_prometheus/src/couch_prometheus_util.erl b/src/couch_prometheus/src/couch_prometheus_util.erl
index 633bb036d..3cfc0994f 100644
--- a/src/couch_prometheus/src/couch_prometheus_util.erl
+++ b/src/couch_prometheus/src/couch_prometheus_util.erl
@@ -16,8 +16,7 @@
     couch_to_prom/3,
     to_bin/1,
     to_prom/4,
-    to_prom/2,
-    to_prom_summary/2
+    to_prom/2
 ]).
 
 couch_to_prom([couch_log, level, alert], Info, _All) ->
diff --git a/src/couch_replicator/src/couch_replicator_api_wrap.erl b/src/couch_replicator/src/couch_replicator_api_wrap.erl
index 3dac826a0..ce22ceb64 100644
--- a/src/couch_replicator/src/couch_replicator_api_wrap.erl
+++ b/src/couch_replicator/src/couch_replicator_api_wrap.erl
@@ -28,7 +28,6 @@
     db_close/1,
     get_db_info/1,
     get_pending_count/2,
-    get_view_info/3,
     update_doc/3,
     update_doc/4,
     update_docs/3,
@@ -154,17 +153,6 @@ get_pending_count(#httpdb{} = Db, Seq) ->
         {ok, couch_util:get_value(<<"pending">>, Props, null)}
     end).
 
-get_view_info(#httpdb{} = Db, DDocId, ViewName) ->
-    Path = io_lib:format("~s/_view/~s/_info", [DDocId, ViewName]),
-    send_req(
-        Db,
-        [{path, Path}],
-        fun(200, _, {Props}) ->
-            {VInfo} = couch_util:get_value(<<"view_index">>, Props, {[]}),
-            {ok, VInfo}
-        end
-    ).
-
 ensure_full_commit(#httpdb{} = Db) ->
     send_req(
         Db,
diff --git a/src/rexi/src/rexi.erl b/src/rexi/src/rexi.erl
index 77830996e..9cc33d786 100644
--- a/src/rexi/src/rexi.erl
+++ b/src/rexi/src/rexi.erl
@@ -11,26 +11,15 @@
 % the License.
 
 -module(rexi).
--export([start/0, stop/0, restart/0]).
+
 -export([cast/2, cast/3, cast/4, kill/2, kill_all/1]).
--export([reply/1, sync_reply/1, sync_reply/2]).
+-export([reply/1]).
 -export([async_server_call/2, async_server_call/3]).
--export([stream_init/0, stream_init/1]).
 -export([stream_start/1, stream_cancel/1]).
--export([stream/1, stream/2, stream/3, stream_ack/1, stream_ack/2]).
--export([stream2/1, stream2/2, stream2/3, stream_last/1, stream_last/2]).
+-export([stream_ack/1]).
+-export([stream2/1, stream_last/1, stream_last/2]).
 -export([ping/0]).
 
-start() ->
-    application:start(rexi).
-
-stop() ->
-    application:stop(rexi).
-
-restart() ->
-    stop(),
-    start().
-
 %% @equiv cast(Node, self(), MFA)
 -spec cast(node(), {atom(), atom(), list()}) -> reference().
 cast(Node, MFA) ->
@@ -131,10 +120,6 @@ reply(Reply) ->
     {Caller, Ref} = get(rexi_from),
     erlang:send(Caller, {Ref, Reply}).
 
-%% @equiv sync_reply(Reply, 300000)
-sync_reply(Reply) ->
-    sync_reply(Reply, 300000).
-
 %% @doc convenience function to reply to caller and wait for response.  Message
 %% is of the form {OriginalRef, {self(),reference()}, Reply}, which enables the
 %% original caller to respond back.
@@ -150,33 +135,6 @@ sync_reply(Reply, Timeout) ->
         timeout
     end.
 
-%% @equiv stream_init(300000)
-stream_init() ->
-    stream_init(300000).
-
-%% @doc Initialize an RPC stream that involves sending multiple
-%% messages back to the coordinator.
-%%
-%% This should be called by rexi workers. It blocks until the
-%% coordinator responds with whether this worker should proceed.
-%% This function will either return with `ok` or call
-%% `erlang:exit/1`.
--spec stream_init(pos_integer()) -> ok.
-stream_init(Timeout) ->
-    case sync_reply(rexi_STREAM_INIT, Timeout) of
-        rexi_STREAM_START ->
-            ok;
-        rexi_STREAM_CANCEL ->
-            exit(normal);
-        timeout ->
-            couch_stats:increment_counter(
-                [rexi, streams, timeout, init_stream]
-            ),
-            exit(timeout);
-        Else ->
-            exit({invalid_stream_message, Else})
-    end.
-
 %% @doc Start a worker stream
 %%
 %% If a coordinator wants to continue using a streaming worker it
@@ -197,38 +155,9 @@ stream_start({Pid, _Tag} = From) when is_pid(Pid) ->
 stream_cancel({Pid, _Tag} = From) when is_pid(Pid) ->
     gen_server:reply(From, rexi_STREAM_CANCEL).
 
-%% @equiv stream(Msg, 100, 300000)
-stream(Msg) ->
-    stream(Msg, 10, 300000).
-
-%% @equiv stream(Msg, Limit, 300000)
-stream(Msg, Limit) ->
-    stream(Msg, Limit, 300000).
-
-%% @doc convenience function to stream messages to caller while blocking when
-%% a specific number of messages are outstanding. Message is of the form
-%% {OriginalRef, self(), Reply}, which enables the original caller to ack.
--spec stream(any(), integer(), pos_integer() | infinity) -> any().
-stream(Msg, Limit, Timeout) ->
-    try maybe_wait(Limit, Timeout) of
-        {ok, Count} ->
-            put(rexi_unacked, Count + 1),
-            {Caller, Ref} = get(rexi_from),
-            erlang:send(Caller, {Ref, self(), Msg}),
-            ok
-    catch
-        throw:timeout ->
-            couch_stats:increment_counter([rexi, streams, timeout, stream]),
-            exit(timeout)
-    end.
-
 %% @equiv stream2(Msg, 5, 300000)
 stream2(Msg) ->
     Limit = config:get_integer("rexi", "stream_limit", 5),
-    stream2(Msg, Limit).
-
-%% @equiv stream2(Msg, Limit, 300000)
-stream2(Msg, Limit) ->
     stream2(Msg, Limit, 300000).
 
 %% @doc Stream a message back to the coordinator. It limits the
@@ -263,14 +192,10 @@ stream_last(Msg, Timeout) ->
     rexi:reply(Msg),
     ok.
 
-%% @equiv stream_ack(Client, 1)
+%% @doc Ack streamed messages
 stream_ack(Client) ->
     erlang:send(Client, {rexi_ack, 1}).
 
-%% @doc Ack streamed messages
-stream_ack(Client, N) ->
-    erlang:send(Client, {rexi_ack, N}).
-
 %% Sends a ping message to the coordinator. This is for long running
 %% operations on a node that could exceed the rexi timeout
 ping() ->
@@ -297,6 +222,7 @@ init_stream(Timeout) ->
         rexi_STREAM_CANCEL ->
             exit(normal);
         timeout ->
+            couch_stats:increment_counter([rexi, streams, timeout, init_stream]),
             exit(timeout);
         Else ->
             exit({invalid_stream_message, Else})
diff --git a/src/rexi/src/rexi_utils.erl b/src/rexi/src/rexi_utils.erl
index d59c5ea0f..7e7518e67 100644
--- a/src/rexi/src/rexi_utils.erl
+++ b/src/rexi/src/rexi_utils.erl
@@ -12,7 +12,7 @@
 
 -module(rexi_utils).
 
--export([server_id/1, server_pid/1, send/2, recv/6]).
+-export([server_pid/1, send/2, recv/6]).
 
 %% @doc Return a rexi_server id for the given node.
 server_id(Node) ->