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 2023/04/30 04:20:45 UTC

[couchdb] branch main updated: Make Erlang 24 the minimum version

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 fe445bb95 Make Erlang 24 the minimum version
fe445bb95 is described below

commit fe445bb95c8fc6c0836f31017a98b41736200a71
Author: Nick Vatamaniuc <va...@gmail.com>
AuthorDate: Sat Apr 29 20:05:22 2023 -0400

    Make Erlang 24 the minimum version
    
    We can drop a compat nouveau_maps module. Later we can check the code and see
    if we can replace any maps:map/2 with maps:foreach/2 perhaps.
    
    In smoosh_persist, no need to check for file:delete/2. Later we should probably
    make the delete in couch_file do the same thing to avoid going through the file
    server.
    
    `sha_256_512_supported/0` has been true for a while but the check had been
    broken, the latest crypto module is `crypto:mac/3,4` so we can re-enable these
    tests.
    
    ML discussion: https://lists.apache.org/thread/7nxm16os8dl331034v126kb73jmb7j3x
---
 build-aux/Jenkinsfile.full                |   2 +-
 build-aux/Jenkinsfile.pr                  |   4 +-
 rebar.config.script                       |   2 +-
 src/couch/test/eunit/couch_totp_tests.erl |  37 +++------
 src/docs/src/install/unix.rst             |   2 +-
 src/nouveau/src/nouveau_fabric_info.erl   |   2 +-
 src/nouveau/src/nouveau_fabric_search.erl |   4 +-
 src/nouveau/src/nouveau_httpd.erl         |   2 +-
 src/nouveau/src/nouveau_maps.erl          | 121 ------------------------------
 src/smoosh/src/smoosh_persist.erl         |  11 +--
 10 files changed, 23 insertions(+), 164 deletions(-)

diff --git a/build-aux/Jenkinsfile.full b/build-aux/Jenkinsfile.full
index 8f0e9e31e..b4d9b79a3 100644
--- a/build-aux/Jenkinsfile.full
+++ b/build-aux/Jenkinsfile.full
@@ -18,7 +18,7 @@ ERLANG_VERSION = '24.3.4.10'
 
 // Erlang version used for rebar in release process. CouchDB will not build from
 // the release tarball on Erlang versions older than this
-MINIMUM_ERLANG_VERSION = '23.3.4.18'
+MINIMUM_ERLANG_VERSION = '24.3.4.10'
 
 // We create parallel build / test / package stages for each OS using the metadata
 // in this map. Adding a new OS should ideally only involve adding a new entry here.
diff --git a/build-aux/Jenkinsfile.pr b/build-aux/Jenkinsfile.pr
index 46c5e47a0..4f8c281f2 100644
--- a/build-aux/Jenkinsfile.pr
+++ b/build-aux/Jenkinsfile.pr
@@ -50,7 +50,7 @@ pipeline {
     // Search for ERLANG_VERSION
     // see https://issues.jenkins.io/browse/JENKINS-61047 for why this cannot
     // be done parametrically
-    LOW_ERLANG_VER = '23.3.4.18'
+    LOW_ERLANG_VER = '24.3.4.10'
   }
 
   options {
@@ -247,7 +247,7 @@ pipeline {
         axes {
           axis {
             name 'ERLANG_VERSION'
-            values '23.3.4.18', '24.3.4.10', '25.3'
+            values '24.3.4.10', '25.3'
           }
           axis {
             name 'SM_VSN'
diff --git a/rebar.config.script b/rebar.config.script
index 7c8ee3fd7..7853514d6 100644
--- a/rebar.config.script
+++ b/rebar.config.script
@@ -187,7 +187,7 @@ end.
 AddConfig = [
     {cover_enabled, true},
     {cover_print_enabled, true},
-    {require_otp_vsn, "23|24|25|26"},
+    {require_otp_vsn, "24|25|26"},
     {deps_dir, "src"},
     {deps, lists:map(MakeDep, DepDescs ++ OptionalDeps)},
     {sub_dirs, SubDirs},
diff --git a/src/couch/test/eunit/couch_totp_tests.erl b/src/couch/test/eunit/couch_totp_tests.erl
index 6817a092a..3c831365f 100644
--- a/src/couch/test/eunit/couch_totp_tests.erl
+++ b/src/couch/test/eunit/couch_totp_tests.erl
@@ -25,31 +25,18 @@ totp_sha_test() ->
 
 totp_sha256_test() ->
     Key = <<"12345678901234567890123456789012">>,
-    case sha_256_512_supported() of
-        true ->
-            ?assertEqual(46119246, couch_totp:generate(sha256, Key, 59, 30, 8)),
-            ?assertEqual(68084774, couch_totp:generate(sha256, Key, 1111111109, 30, 8)),
-            ?assertEqual(67062674, couch_totp:generate(sha256, Key, 1111111111, 30, 8)),
-            ?assertEqual(91819424, couch_totp:generate(sha256, Key, 1234567890, 30, 8)),
-            ?assertEqual(90698825, couch_totp:generate(sha256, Key, 2000000000, 30, 8)),
-            ?assertEqual(77737706, couch_totp:generate(sha256, Key, 20000000000, 30, 8));
-        false ->
-            ?debugMsg("sha256 not supported, tests skipped")
-    end.
+    ?assertEqual(46119246, couch_totp:generate(sha256, Key, 59, 30, 8)),
+    ?assertEqual(68084774, couch_totp:generate(sha256, Key, 1111111109, 30, 8)),
+    ?assertEqual(67062674, couch_totp:generate(sha256, Key, 1111111111, 30, 8)),
+    ?assertEqual(91819424, couch_totp:generate(sha256, Key, 1234567890, 30, 8)),
+    ?assertEqual(90698825, couch_totp:generate(sha256, Key, 2000000000, 30, 8)),
+    ?assertEqual(77737706, couch_totp:generate(sha256, Key, 20000000000, 30, 8)).
 
 totp_sha512_test() ->
     Key = <<"1234567890123456789012345678901234567890123456789012345678901234">>,
-    case sha_256_512_supported() of
-        true ->
-            ?assertEqual(90693936, couch_totp:generate(sha512, Key, 59, 30, 8)),
-            ?assertEqual(25091201, couch_totp:generate(sha512, Key, 1111111109, 30, 8)),
-            ?assertEqual(99943326, couch_totp:generate(sha512, Key, 1111111111, 30, 8)),
-            ?assertEqual(93441116, couch_totp:generate(sha512, Key, 1234567890, 30, 8)),
-            ?assertEqual(38618901, couch_totp:generate(sha512, Key, 2000000000, 30, 8)),
-            ?assertEqual(47863826, couch_totp:generate(sha512, Key, 20000000000, 30, 8));
-        false ->
-            ?debugMsg("sha512 not supported, tests skipped")
-    end.
-
-sha_256_512_supported() ->
-    erlang:function_exported(crypto, hmac, 3).
+    ?assertEqual(90693936, couch_totp:generate(sha512, Key, 59, 30, 8)),
+    ?assertEqual(25091201, couch_totp:generate(sha512, Key, 1111111109, 30, 8)),
+    ?assertEqual(99943326, couch_totp:generate(sha512, Key, 1111111111, 30, 8)),
+    ?assertEqual(93441116, couch_totp:generate(sha512, Key, 1234567890, 30, 8)),
+    ?assertEqual(38618901, couch_totp:generate(sha512, Key, 2000000000, 30, 8)),
+    ?assertEqual(47863826, couch_totp:generate(sha512, Key, 20000000000, 30, 8)).
diff --git a/src/docs/src/install/unix.rst b/src/docs/src/install/unix.rst
index c4c05070d..a8728fecd 100644
--- a/src/docs/src/install/unix.rst
+++ b/src/docs/src/install/unix.rst
@@ -142,7 +142,7 @@ Dependencies
 
 You should have the following installed:
 
-* `Erlang OTP (23.x, 24.x, 25.x) <http://erlang.org/>`_
+* `Erlang OTP (24.x, 25.x)      <http://erlang.org/>`_
 * `ICU                          <http://icu-project.org/>`_
 * `OpenSSL                      <http://www.openssl.org/>`_
 * `Mozilla SpiderMonkey (1.8.5, 60, 68, 78, 91) <https://spidermonkey.dev/>`_
diff --git a/src/nouveau/src/nouveau_fabric_info.erl b/src/nouveau/src/nouveau_fabric_info.erl
index b5f928075..59e47094f 100644
--- a/src/nouveau/src/nouveau_fabric_info.erl
+++ b/src/nouveau/src/nouveau_fabric_info.erl
@@ -70,7 +70,7 @@ handle_message({ok, Info}, Worker, {Counters, Acc0}) ->
         nil ->
             C1 = fabric_dict:store(Worker, ok, Counters),
             C2 = fabric_view:remove_overlapping_shards(Worker, C1),
-            Acc1 = nouveau_maps:merge_with(fun merge_info/3, Info, Acc0),
+            Acc1 = maps:merge_with(fun merge_info/3, Info, Acc0),
             case fabric_dict:any(nil, C2) of
                 true ->
                     {ok, {C2, Acc1}};
diff --git a/src/nouveau/src/nouveau_fabric_search.erl b/src/nouveau/src/nouveau_fabric_search.erl
index 5212bf620..d11b55670 100644
--- a/src/nouveau/src/nouveau_fabric_search.erl
+++ b/src/nouveau/src/nouveau_fabric_search.erl
@@ -217,8 +217,8 @@ merge_facets(FacetsA, null, _Limit) ->
 merge_facets(null, FacetsB, _Limit) ->
     FacetsB;
 merge_facets(FacetsA, FacetsB, _Limit) ->
-    Combiner = fun(_, V1, V2) -> nouveau_maps:merge_with(fun(_, V3, V4) -> V3 + V4 end, V1, V2) end,
-    nouveau_maps:merge_with(Combiner, FacetsA, FacetsB).
+    Combiner = fun(_, V1, V2) -> maps:merge_with(fun(_, V3, V4) -> V3 + V4 end, V1, V2) end,
+    maps:merge_with(Combiner, FacetsA, FacetsB).
 
 get_shards(DbName, #{partition := Partition}) when is_binary(Partition) ->
     PartitionId = couch_partition:shard_key(Partition),
diff --git a/src/nouveau/src/nouveau_httpd.erl b/src/nouveau/src/nouveau_httpd.erl
index 5cb50de6a..e60d7e440 100644
--- a/src/nouveau/src/nouveau_httpd.erl
+++ b/src/nouveau/src/nouveau_httpd.erl
@@ -206,7 +206,7 @@ validate_query_arg(sort, Sort) ->
 validate_query_arg(ranges, undefined) ->
     null;
 validate_query_arg(ranges, {json, Ranges}) when is_map(Ranges) ->
-    nouveau_maps:foreach(fun is_valid_range/2, Ranges),
+    maps:foreach(fun is_valid_range/2, Ranges),
     Ranges;
 validate_query_arg(ranges, Ranges) ->
     validate_query_arg(ranges, {json, ?JSON_DECODE(Ranges, [return_maps])});
diff --git a/src/nouveau/src/nouveau_maps.erl b/src/nouveau/src/nouveau_maps.erl
deleted file mode 100644
index 81a145557..000000000
--- a/src/nouveau/src/nouveau_maps.erl
+++ /dev/null
@@ -1,121 +0,0 @@
-%%
-%%
-%% %CopyrightBegin%
-%%
-%% Copyright Ericsson AB 2013-2021. All Rights Reserved.
-%%
-%% 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.
-%%
-%% %CopyrightEnd%
-%%
-
-%% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*-
-
-%% backport of OTP 24 map functions not present in 23.
-
--module(nouveau_maps).
-
--export([merge_with/3, foreach/2]).
-
--if(?OTP_RELEASE >= 24).
-merge_with(Combiner, Map1, Map2) ->
-    maps:merge_with(Combiner, Map1, Map2).
-
-foreach(Fun, MapOrIter) ->
-    maps:foreach(Fun, MapOrIter).
-
--else.
-
-merge_with(Combiner, Map1, Map2) when
-    is_map(Map1),
-    is_map(Map2),
-    is_function(Combiner, 3)
-->
-    case map_size(Map1) > map_size(Map2) of
-        true ->
-            Iterator = maps:iterator(Map2),
-            merge_with_1(
-                maps:next(Iterator),
-                Map1,
-                Map2,
-                Combiner
-            );
-        false ->
-            Iterator = maps:iterator(Map1),
-            merge_with_1(
-                maps:next(Iterator),
-                Map2,
-                Map1,
-                fun(K, V1, V2) -> Combiner(K, V2, V1) end
-            )
-    end;
-merge_with(Combiner, Map1, Map2) ->
-    error_with_info(
-        error_type_merge_intersect(Map1, Map2, Combiner),
-        [Combiner, Map1, Map2]
-    ).
-
-merge_with_1({K, V2, Iterator}, Map1, Map2, Combiner) ->
-    case Map1 of
-        #{K := V1} ->
-            NewMap1 = Map1#{K := Combiner(K, V1, V2)},
-            merge_with_1(maps:next(Iterator), NewMap1, Map2, Combiner);
-        #{} ->
-            merge_with_1(maps:next(Iterator), maps:put(K, V2, Map1), Map2, Combiner)
-    end;
-merge_with_1(none, Result, _, _) ->
-    Result.
-
-foreach(Fun, MapOrIter) when is_function(Fun, 2) ->
-    Iter =
-        if
-            is_map(MapOrIter) -> maps:iterator(MapOrIter);
-            true -> MapOrIter
-        end,
-    try maps:next(Iter) of
-        Next ->
-            foreach_1(Fun, Next)
-    catch
-        error:_ ->
-            error_with_info({badmap, MapOrIter}, [Fun, MapOrIter])
-    end;
-foreach(Pred, Map) ->
-    badarg_with_info([Pred, Map]).
-
-foreach_1(Fun, {K, V, Iter}) ->
-    Fun(K, V),
-    foreach_1(Fun, maps:next(Iter));
-foreach_1(_Fun, none) ->
-    ok.
-
-%% We must inline these functions so that the stacktrace points to
-%% the correct function.
--compile({inline, [badarg_with_info/1, error_with_info/2]}).
-
-badarg_with_info(Args) ->
-    erlang:error(badarg, Args, [{error_info, #{module => erl_stdlib_errors}}]).
-
-error_with_info(Reason, Args) ->
-    erlang:error(Reason, Args, [{error_info, #{module => erl_stdlib_errors}}]).
-
-error_type_two_maps(M1, M2) when is_map(M1) ->
-    {badmap, M2};
-error_type_two_maps(M1, _M2) ->
-    {badmap, M1}.
-
-error_type_merge_intersect(M1, M2, Combiner) when is_function(Combiner, 3) ->
-    error_type_two_maps(M1, M2);
-error_type_merge_intersect(_M1, _M2, _Combiner) ->
-    badarg.
-
--endif.
diff --git a/src/smoosh/src/smoosh_persist.erl b/src/smoosh/src/smoosh_persist.erl
index 68d8a418d..886f18e04 100644
--- a/src/smoosh/src/smoosh_persist.erl
+++ b/src/smoosh/src/smoosh_persist.erl
@@ -93,12 +93,12 @@ check_setup(true) ->
         ok -> ok;
         {error, Error2} -> throw({fail, "write", Error2})
     end,
-    delete_file(Path).
+    file:delete(Path, [raw]).
 
 write(#{} = QData, Path) when is_list(Path), map_size(QData) == 0 ->
     % Save a few bytes by deleting the persisted queue data if
     % there are no waiting/starting or active jobs
-    delete_file(Path);
+    file:delete(Path, [raw]);
 write(#{} = QData, Path) when is_list(Path) ->
     Bin = term_to_binary(QData, [compressed, {minor_version, 2}]),
     TmpPath = tmp_path(Path),
@@ -133,13 +133,6 @@ state_dir() ->
     Dir = config:get("smoosh", "state_dir", "."),
     filename:absname(Dir).
 
-delete_file(Path) ->
-    % On Erlang 24+ we can avoid using the file server
-    case erlang:function_exported(file, delete, 2) of
-        true -> file:delete(Path, [raw]);
-        false -> file:delete(Path)
-    end.
-
 -ifdef(TEST).
 
 -include_lib("couch/include/couch_eunit.hrl").