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/08/19 18:22:25 UTC

(couchdb) branch main updated: Remove compat couch_rand module

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

vatamane pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/main by this push:
     new aca60ddf1 Remove compat couch_rand module
aca60ddf1 is described below

commit aca60ddf147811547b11cf5e8fd10bcfbe3c053e
Author: Nick Vatamaniuc <va...@gmail.com>
AuthorDate: Mon Aug 19 13:47:29 2024 -0400

    Remove compat couch_rand module
    
    It's not needed any longer as `rand` is in all the currently supported Erlang
    releases.
---
 src/couch/src/couch_debug.erl                      |  2 +-
 src/couch/src/couch_multidb_changes.erl            |  2 +-
 src/couch/src/couch_rand.erl                       | 24 ----------------------
 src/couch/src/couch_uuids.erl                      |  2 +-
 src/couch/src/test_util.erl                        |  2 +-
 src/couch/test/eunit/couch_btree_tests.erl         |  8 ++++----
 src/couch/test/eunit/couch_file_tests.erl          |  6 +++---
 src/couch/test/eunit/couch_key_tree_tests.erl      |  2 +-
 src/couch/test/eunit/json_stream_parse_tests.erl   |  2 +-
 src/couch_log/test/eunit/couch_log_test.erl        |  2 +-
 .../src/couch_replicator_doc_processor.erl         |  6 +++---
 src/couch_replicator/src/couch_replicator_docs.erl |  2 +-
 .../src/couch_replicator_scheduler_job.erl         |  2 +-
 src/ddoc_cache/test/eunit/ddoc_cache_lru_test.erl  |  2 +-
 src/ioq/src/ioq.erl                                |  2 +-
 src/mem3/src/mem3.erl                              |  2 +-
 16 files changed, 22 insertions(+), 46 deletions(-)

diff --git a/src/couch/src/couch_debug.erl b/src/couch/src/couch_debug.erl
index fb33044b4..4c654ef67 100644
--- a/src/couch/src/couch_debug.erl
+++ b/src/couch/src/couch_debug.erl
@@ -1137,7 +1137,7 @@ random_processes(Acc, Depth) ->
     end.
 
 oneof(Options) ->
-    lists:nth(couch_rand:uniform(length(Options)), Options).
+    lists:nth(rand:uniform(length(Options)), Options).
 
 tree() ->
     [InitialPid | _] = Processes = random_processes(5),
diff --git a/src/couch/src/couch_multidb_changes.erl b/src/couch/src/couch_multidb_changes.erl
index 004f47064..5f9ba69e1 100644
--- a/src/couch/src/couch_multidb_changes.erl
+++ b/src/couch/src/couch_multidb_changes.erl
@@ -373,7 +373,7 @@ notify_fold(DbName, {Server, DbSuffix, Count}) ->
 % number of shards back to back during startup.
 jitter(N) ->
     Range = min(2 * N * ?AVG_DELAY_MSEC, ?MAX_DELAY_MSEC),
-    couch_rand:uniform(Range).
+    rand:uniform(Range).
 
 scan_local_db(Server, DbSuffix) when is_pid(Server) ->
     case couch_server:exists(DbSuffix) of
diff --git a/src/couch/src/couch_rand.erl b/src/couch/src/couch_rand.erl
deleted file mode 100644
index bc30956a4..000000000
--- a/src/couch/src/couch_rand.erl
+++ /dev/null
@@ -1,24 +0,0 @@
-% Licensed under the Apache License, Version 2.0 (the "License"); you may not
-% use this file except in compliance with the License. You may obtain a copy of
-% the License at
-%
-%   http://www.apache.org/licenses/LICENSE-2.0
-%
-% Unless required by applicable law or agreed to in writing, software
-% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-% License for the specific language governing permissions and limitations under
-% the License.
-
--module(couch_rand).
-
--export([
-    uniform/0,
-    uniform/1
-]).
-
-uniform() ->
-    rand:uniform().
-
-uniform(N) ->
-    rand:uniform(N).
diff --git a/src/couch/src/couch_uuids.erl b/src/couch/src/couch_uuids.erl
index 7a04f3026..588136159 100644
--- a/src/couch/src/couch_uuids.erl
+++ b/src/couch/src/couch_uuids.erl
@@ -88,7 +88,7 @@ new_prefix() ->
     couch_util:to_hex((crypto:strong_rand_bytes(13))).
 
 inc() ->
-    couch_rand:uniform(16#ffd).
+    rand:uniform(16#ffd).
 
 state() ->
     AlgoStr = config:get("uuids", "algorithm", "sequential"),
diff --git a/src/couch/src/test_util.erl b/src/couch/src/test_util.erl
index e53b11149..430c54788 100644
--- a/src/couch/src/test_util.erl
+++ b/src/couch/src/test_util.erl
@@ -487,7 +487,7 @@ random_rev() ->
     couch_util:to_hex_bin(crypto:strong_rand_bytes(16)).
 
 shuffle(List) ->
-    Paired = [{couch_rand:uniform(), I} || I <- List],
+    Paired = [{rand:uniform(), I} || I <- List],
     Sorted = lists:sort(Paired),
     [I || {_, I} <- Sorted].
 
diff --git a/src/couch/test/eunit/couch_btree_tests.erl b/src/couch/test/eunit/couch_btree_tests.erl
index 1c9ba7771..1ec92818b 100644
--- a/src/couch/test/eunit/couch_btree_tests.erl
+++ b/src/couch/test/eunit/couch_btree_tests.erl
@@ -86,7 +86,7 @@ btree_open_test_() ->
 
 sorted_kvs_test_() ->
     Funs = kvs_test_funs(),
-    Sorted = [{Seq, couch_rand:uniform()} || Seq <- lists:seq(1, ?ROWS)],
+    Sorted = [{Seq, rand:uniform()} || Seq <- lists:seq(1, ?ROWS)],
     {
         "BTree with sorted keys",
         {
@@ -103,7 +103,7 @@ sorted_kvs_test_() ->
     }.
 
 rsorted_kvs_test_() ->
-    Sorted = [{Seq, couch_rand:uniform()} || Seq <- lists:seq(1, ?ROWS)],
+    Sorted = [{Seq, rand:uniform()} || Seq <- lists:seq(1, ?ROWS)],
     Funs = kvs_test_funs(),
     Reversed = Sorted,
     {
@@ -123,7 +123,7 @@ rsorted_kvs_test_() ->
 
 shuffled_kvs_test_() ->
     Funs = kvs_test_funs(),
-    Sorted = [{Seq, couch_rand:uniform()} || Seq <- lists:seq(1, ?ROWS)],
+    Sorted = [{Seq, rand:uniform()} || Seq <- lists:seq(1, ?ROWS)],
     Shuffled = shuffle(Sorted),
     {
         "BTree with shuffled keys",
@@ -579,7 +579,7 @@ randomize(T, List) ->
     ).
 
 randomize(List) ->
-    D = lists:map(fun(A) -> {couch_rand:uniform(), A} end, List),
+    D = lists:map(fun(A) -> {rand:uniform(), A} end, List),
     {_, D1} = lists:unzip(lists:keysort(1, D)),
     D1.
 
diff --git a/src/couch/test/eunit/couch_file_tests.erl b/src/couch/test/eunit/couch_file_tests.erl
index 673795121..177d5c3b6 100644
--- a/src/couch/test/eunit/couch_file_tests.erl
+++ b/src/couch/test/eunit/couch_file_tests.erl
@@ -340,14 +340,14 @@ check_header_recovery(CheckFun) ->
     ok.
 
 write_random_data(Fd) ->
-    write_random_data(Fd, 100 + couch_rand:uniform(1000)).
+    write_random_data(Fd, 100 + rand:uniform(1000)).
 
 write_random_data(Fd, 0) ->
     {ok, Bytes} = couch_file:bytes(Fd),
     {ok, (1 + Bytes div ?BLOCK_SIZE) * ?BLOCK_SIZE};
 write_random_data(Fd, N) ->
     Choices = [foo, bar, <<"bizzingle">>, "bank", ["rough", stuff]],
-    Term = lists:nth(couch_rand:uniform(4) + 1, Choices),
+    Term = lists:nth(rand:uniform(4) + 1, Choices),
     {ok, _, _} = couch_file:append_term(Fd, Term),
     write_random_data(Fd, N - 1).
 
@@ -466,7 +466,7 @@ nuke_dir_test_() ->
                     File0 = ?tempfile() ++ ".couch",
                     RootDir = filename:dirname(File0),
                     BaseName = filename:basename(File0),
-                    Seed = couch_rand:uniform(8999999999) + 999999999,
+                    Seed = rand:uniform(8999999999) + 999999999,
                     DDocDir = io_lib:format("db.~b_design", [Seed]),
                     ViewDir = filename:join([RootDir, DDocDir]),
                     file:make_dir(ViewDir),
diff --git a/src/couch/test/eunit/couch_key_tree_tests.erl b/src/couch/test/eunit/couch_key_tree_tests.erl
index a277a5652..b7c1a9771 100644
--- a/src/couch/test/eunit/couch_key_tree_tests.erl
+++ b/src/couch/test/eunit/couch_key_tree_tests.erl
@@ -360,7 +360,7 @@ should_find_missing_leaves_large_test() ->
         Seed = {1647, 841737, 351137},
         {_, Tree} = test_util:revtree_generate(1000, 0.2, 5, Seed),
         Seq = lists:seq(1, 1000),
-        Revs1 = [{couch_rand:uniform(1000), test_util:random_rev()} || _ <- Seq],
+        Revs1 = [{rand:uniform(1000), test_util:random_rev()} || _ <- Seq],
         Revs2 = couch_key_tree:find_missing(Tree, Revs1),
         ?assertEqual(lists:sort(Revs1), lists:sort(Revs2))
     end).
diff --git a/src/couch/test/eunit/json_stream_parse_tests.erl b/src/couch/test/eunit/json_stream_parse_tests.erl
index ab26be725..3bb8b2462 100644
--- a/src/couch/test/eunit/json_stream_parse_tests.erl
+++ b/src/couch/test/eunit/json_stream_parse_tests.erl
@@ -142,7 +142,7 @@ single_byte_data_fun([H | T]) ->
 multiple_bytes_data_fun([]) ->
     done;
 multiple_bytes_data_fun(L) ->
-    N = couch_rand:uniform(7) - 1,
+    N = rand:uniform(7) - 1,
     {Part, Rest} = split(L, N),
     {list_to_binary(Part), fun() -> multiple_bytes_data_fun(Rest) end}.
 
diff --git a/src/couch_log/test/eunit/couch_log_test.erl b/src/couch_log/test/eunit/couch_log_test.erl
index 1538934b3..817724cc0 100644
--- a/src/couch_log/test/eunit/couch_log_test.erl
+++ b/src/couch_log/test/eunit/couch_log_test.erl
@@ -72,5 +72,5 @@ check_levels(TestLevel, [CfgLevel | RestLevels]) ->
     check_levels(TestLevel, RestLevels).
 
 new_msg() ->
-    Bin = list_to_binary([couch_rand:uniform(255) || _ <- lists:seq(1, 16)]),
+    Bin = list_to_binary([rand:uniform(255) || _ <- lists:seq(1, 16)]),
     couch_util:to_hex(Bin).
diff --git a/src/couch_replicator/src/couch_replicator_doc_processor.erl b/src/couch_replicator/src/couch_replicator_doc_processor.erl
index ecb2cca51..286076195 100644
--- a/src/couch_replicator/src/couch_replicator_doc_processor.erl
+++ b/src/couch_replicator/src/couch_replicator_doc_processor.erl
@@ -410,7 +410,7 @@ error_backoff(ErrCnt) ->
     % ErrCnt is the exponent here. The reason 64 is used is to start at
     % 64 (about a minute) max range. Then first backoff would be 30 sec
     % on average. Then 1 minute and so on.
-    couch_rand:uniform(?INITIAL_BACKOFF_EXPONENT bsl Exp).
+    rand:uniform(?INITIAL_BACKOFF_EXPONENT bsl Exp).
 
 -spec filter_backoff() -> seconds().
 filter_backoff() ->
@@ -419,10 +419,10 @@ filter_backoff() ->
     % wait is longer, but not more than a day (?TS_DAY_SEC). If there are just
     % few, wait is shorter, starting at about 30 seconds. `2 *` is used since
     % the expected wait would then be 0.5 * Range so it is easier to see the
-    % average wait. `1 +` is used because couch_rand:uniform only
+    % average wait. `1 +` is used because rand:uniform only
     % accepts >= 1 values and crashes otherwise.
     Range = 1 + min(2 * (Total / 10), ?TS_DAY_SEC),
-    ?MIN_FILTER_DELAY_SEC + couch_rand:uniform(round(Range)).
+    ?MIN_FILTER_DELAY_SEC + rand:uniform(round(Range)).
 
 % Replication was usurped - move it to the not_owner state
 % and try to kill running jobs if there are any.
diff --git a/src/couch_replicator/src/couch_replicator_docs.erl b/src/couch_replicator/src/couch_replicator_docs.erl
index 85baa1c3e..a041e274a 100644
--- a/src/couch_replicator/src/couch_replicator_docs.erl
+++ b/src/couch_replicator/src/couch_replicator_docs.erl
@@ -155,7 +155,7 @@ update_rep_doc(RepDbName, RepDocId, KVs, Wait) when is_binary(RepDocId) ->
         throw:conflict ->
             Msg = "Conflict when updating replication doc `~s`. Retrying.",
             couch_log:error(Msg, [RepDocId]),
-            ok = timer:sleep(couch_rand:uniform(erlang:min(128, Wait)) * 100),
+            ok = timer:sleep(rand:uniform(erlang:min(128, Wait)) * 100),
             update_rep_doc(RepDbName, RepDocId, KVs, Wait * 2)
     end;
 update_rep_doc(RepDbName, #doc{body = {RepDocBody}} = RepDoc, KVs, _Try) ->
diff --git a/src/couch_replicator/src/couch_replicator_scheduler_job.erl b/src/couch_replicator/src/couch_replicator_scheduler_job.erl
index a8a465059..544c5602a 100644
--- a/src/couch_replicator/src/couch_replicator_scheduler_job.erl
+++ b/src/couch_replicator/src/couch_replicator_scheduler_job.erl
@@ -520,7 +520,7 @@ startup_jitter() ->
         "startup_jitter",
         ?STARTUP_JITTER_DEFAULT
     ),
-    couch_rand:uniform(erlang:max(1, Jitter)).
+    rand:uniform(erlang:max(1, Jitter)).
 
 headers_strip_creds([], Acc) ->
     lists:reverse(Acc);
diff --git a/src/ddoc_cache/test/eunit/ddoc_cache_lru_test.erl b/src/ddoc_cache/test/eunit/ddoc_cache_lru_test.erl
index cc812d284..81285e855 100644
--- a/src/ddoc_cache/test/eunit/ddoc_cache_lru_test.erl
+++ b/src/ddoc_cache/test/eunit/ddoc_cache_lru_test.erl
@@ -28,7 +28,7 @@ recover(<<"pause", _/binary>>) ->
     end,
     {ok, paused};
 recover(<<"big", _/binary>>) ->
-    {ok, [couch_rand:uniform() || _ <- lists:seq(1, 8192)]};
+    {ok, [rand:uniform() || _ <- lists:seq(1, 8192)]};
 recover(DbName) ->
     {ok, DbName}.
 
diff --git a/src/ioq/src/ioq.erl b/src/ioq/src/ioq.erl
index bcb99b291..586a75084 100644
--- a/src/ioq/src/ioq.erl
+++ b/src/ioq/src/ioq.erl
@@ -207,7 +207,7 @@ make_next_request(#state{} = State) ->
         {false, true} ->
             choose_next_request(#state.background, State);
         {false, false} ->
-            case couch_rand:uniform() < State#state.ratio of
+            case rand:uniform() < State#state.ratio of
                 true ->
                     choose_next_request(#state.background, State);
                 false ->
diff --git a/src/mem3/src/mem3.erl b/src/mem3/src/mem3.erl
index 28fc49a0f..c0d64d7e4 100644
--- a/src/mem3/src/mem3.erl
+++ b/src/mem3/src/mem3.erl
@@ -275,7 +275,7 @@ choose_shards(DbName, Nodes, Options) ->
     mem3_util:create_partition_map(DbName, N, Q, RotatedNodes, Suffix).
 
 rotate_rand(Nodes) ->
-    {A, B} = lists:split(couch_rand:uniform(length(Nodes)), Nodes),
+    {A, B} = lists:split(rand:uniform(length(Nodes)), Nodes),
     B ++ A.
 
 get_placement(Options) ->