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/05/23 16:37:00 UTC

[couchdb] branch use-faster-sets created (now 6dde2abb1)

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

vatamane pushed a change to branch use-faster-sets
in repository https://gitbox.apache.org/repos/asf/couchdb.git


      at 6dde2abb1 Use a faster sets implementation available since OTP 24

This branch includes the following new commits:

     new 6dde2abb1 Use a faster sets implementation available since OTP 24

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: Use a faster sets implementation available since OTP 24

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

vatamane pushed a commit to branch use-faster-sets
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 6dde2abb1fcb8ecffde6fc57926f41d3a5a677a8
Author: Nick Vatamaniuc <va...@gmail.com>
AuthorDate: Tue May 23 12:19:40 2023 -0400

    Use a faster sets implementation available since OTP 24
    
    Since OTP 24 a version of sets implemented using maps is available [1]
    
    Replace a few case where we use sets with the new implementation.
    
    [1] https://www.erlang.org/doc/man/sets.html
---
 src/global_changes/src/global_changes_listener.erl | 6 +++---
 src/global_changes/src/global_changes_server.erl   | 6 +++---
 src/mem3/src/mem3_sync_event_listener.erl          | 6 +++---
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/global_changes/src/global_changes_listener.erl b/src/global_changes/src/global_changes_listener.erl
index 71d14e274..924071ee1 100644
--- a/src/global_changes/src/global_changes_listener.erl
+++ b/src/global_changes/src/global_changes_listener.erl
@@ -55,7 +55,7 @@ init(_) ->
     State = #state{
         update_db = UpdateDb,
         pending_update_count = 0,
-        pending_updates = sets:new(),
+        pending_updates = sets:new([{version, 2}]),
         max_event_delay = MaxEventDelay,
         dbname = global_changes_util:get_dbname()
     },
@@ -99,7 +99,7 @@ handle_cast({set_update_db, Boolean}, State0) ->
             {false, true} ->
                 State0#state{
                     update_db = Boolean,
-                    pending_updates = sets:new(),
+                    pending_updates = sets:new([{version, 2}]),
                     pending_update_count = 0,
                     last_update_time = undefined
                 };
@@ -141,7 +141,7 @@ maybe_send_updates(#state{update_db = true} = State) ->
                         0
                     ),
                     State1 = State#state{
-                        pending_updates = sets:new(),
+                        pending_updates = sets:new([{version, 2}]),
                         pending_update_count = 0,
                         last_update_time = undefined
                     },
diff --git a/src/global_changes/src/global_changes_server.erl b/src/global_changes/src/global_changes_server.erl
index e9a9c5fb4..0e4cea14e 100644
--- a/src/global_changes/src/global_changes_server.erl
+++ b/src/global_changes/src/global_changes_server.erl
@@ -69,7 +69,7 @@ init([]) ->
     State = #state{
         update_db = UpdateDb,
         pending_update_count = 0,
-        pending_updates = sets:new(),
+        pending_updates = sets:new([{version, 2}]),
         max_write_delay = MaxWriteDelay,
         dbname = GlobalChangesDbName,
         handler_ref = erlang:monitor(process, Handler)
@@ -106,7 +106,7 @@ handle_cast({set_update_db, Boolean}, State0) ->
             {false, true} ->
                 State0#state{
                     update_db = Boolean,
-                    pending_updates = sets:new(),
+                    pending_updates = sets:new([{version, 2}]),
                     pending_update_count = 0
                 };
             _ ->
@@ -177,7 +177,7 @@ flush_updates(State) ->
         0
     ),
     {noreply, State#state{
-        pending_updates = sets:new(),
+        pending_updates = sets:new([{version, 2}]),
         pending_update_count = 0
     }}.
 
diff --git a/src/mem3/src/mem3_sync_event_listener.erl b/src/mem3/src/mem3_sync_event_listener.erl
index a01921f85..4389291a3 100644
--- a/src/mem3/src/mem3_sync_event_listener.erl
+++ b/src/mem3/src/mem3_sync_event_listener.erl
@@ -63,7 +63,7 @@ init(_) ->
     ok = subscribe_for_config(),
     Delay = config:get_integer("mem3", "sync_delay", 5000),
     Frequency = config:get_integer("mem3", "sync_frequency", 500),
-    Buckets = lists:duplicate(Delay div Frequency + 1, sets:new()),
+    Buckets = lists:duplicate(Delay div Frequency + 1, sets:new([{version, 2}])),
     St = #state{
         nodes = mem3_sync:nodes_db(),
         shards = mem3_sync:shards_db(),
@@ -163,7 +163,7 @@ rebucket_shards(Frequency, Delay, Buckets0) ->
             [sets:union([B | ToMerge]) | Buckets1];
         M ->
             %% Extend the number of buckets by M
-            lists:duplicate(M, sets:new()) ++ Buckets0
+            lists:duplicate(M, sets:new([{version, 2}])) ++ Buckets0
     end.
 
 %% To ensure that mem3_sync:push/2 is indeed called with roughly the frequency
@@ -180,7 +180,7 @@ maybe_push_shards(St) ->
     case Delta > Frequency of
         true ->
             {Buckets1, [ToPush]} = lists:split(length(Buckets0) - 1, Buckets0),
-            Buckets2 = [sets:new() | Buckets1],
+            Buckets2 = [sets:new([{version, 2}]) | Buckets1],
             %% There's no sets:map/2!
             sets:fold(
                 fun(ShardName, _) -> push_shard(ShardName) end,