Browse Source

Rename to unregister_and_register.

Roberto Ostinelli 5 years ago
parent
commit
dfde7c0129
4 changed files with 24 additions and 22 deletions
  1. 6 4
      README.md
  2. 7 7
      src/syn.erl
  3. 6 6
      src/syn_registry.erl
  4. 5 5
      test/syn_registry_SUITE.erl

+ 6 - 4
README.md

@@ -164,11 +164,11 @@ Types:
 To register a previously registered Name with a _different_ Pid:
 To register a previously registered Name with a _different_ Pid:
 
 
 ```erlang
 ```erlang
-syn:force_register(Name, Pid) ->
-    syn:force_register(Name, Pid, undefined).
+syn:unregister_and_register(Name, Pid) ->
+    syn:unregister_and_register(Name, Pid, undefined).
 ```
 ```
 ```erlang
 ```erlang
-syn:force_register(Name, Pid, Meta) -> ok.
+syn:unregister_and_register(Name, Pid, Meta) -> ok.
 
 
 Types:
 Types:
     Name = any()
     Name = any()
@@ -176,7 +176,9 @@ Types:
     Meta = any()
     Meta = any()
 ```
 ```
 
 
-> Force registering is specifically useful if you are force registering a process on a different node from where the process currently registered with `Name` is running on, as `force_register/2,3` will ensure that the registration succeeds and propagates properly. You may otherwise experience a `{error, taken}` response to the registration call if you were to sequentially `unregister/1` and `register/2,3` a process, due to race conditions. Note that the previously registered process will not be killed and will be demonitored, so that the `on_process_exit/4` callback will _not_ be called (even if implemented) when the process dies.
+> Due to Syn being eventually consistent, if you were to sequentially `unregister/1` a name and `register/2,3` a process you might experience a `{error, taken}` response to the latter, since the unregistration may not have yet properly propagated when the registration call is made. This call ensures that the registration succeeds and propagates properly.
+>
+>Note that the previously registered process will not be killed and will be demonitored, so that the `on_process_exit/4` callback will _not_ be called (even if implemented) when the process dies.
 
 
 To retrieve the total count of registered processes running in the cluster:
 To retrieve the total count of registered processes running in the cluster:
 
 

+ 7 - 7
src/syn.erl

@@ -28,7 +28,7 @@
 %% API
 %% API
 -export([start/0, stop/0]).
 -export([start/0, stop/0]).
 -export([register/2, register/3]).
 -export([register/2, register/3]).
--export([force_register/2, force_register/3]).
+-export([unregister_and_register/2, unregister_and_register/3]).
 -export([unregister/1]).
 -export([unregister/1]).
 -export([whereis/1, whereis/2]).
 -export([whereis/1, whereis/2]).
 -export([registry_count/0, registry_count/1]).
 -export([registry_count/0, registry_count/1]).
@@ -68,13 +68,13 @@ register(Name, Pid) ->
 register(Name, Pid, Meta) ->
 register(Name, Pid, Meta) ->
     syn_registry:register(Name, Pid, Meta).
     syn_registry:register(Name, Pid, Meta).
 
 
--spec force_register(Name :: any(), Pid :: pid()) -> ok | {error, Reason :: any()}.
-force_register(Name, Pid) ->
-    syn_registry:force_register(Name, Pid).
+-spec unregister_and_register(Name :: any(), Pid :: pid()) -> ok | {error, Reason :: any()}.
+unregister_and_register(Name, Pid) ->
+    syn_registry:unregister_and_register(Name, Pid).
 
 
--spec force_register(Name :: any(), Pid :: pid(), Meta :: any()) -> ok | {error, Reason :: any()}.
-force_register(Name, Pid, Meta) ->
-    syn_registry:force_register(Name, Pid, Meta).
+-spec unregister_and_register(Name :: any(), Pid :: pid(), Meta :: any()) -> ok | {error, Reason :: any()}.
+unregister_and_register(Name, Pid, Meta) ->
+    syn_registry:unregister_and_register(Name, Pid, Meta).
 
 
 -spec unregister(Name :: any()) -> ok | {error, Reason :: any()}.
 -spec unregister(Name :: any()) -> ok | {error, Reason :: any()}.
 unregister(Name) ->
 unregister(Name) ->

+ 6 - 6
src/syn_registry.erl

@@ -29,7 +29,7 @@
 %% API
 %% API
 -export([start_link/0]).
 -export([start_link/0]).
 -export([register/2, register/3]).
 -export([register/2, register/3]).
--export([force_register/2, force_register/3]).
+-export([unregister_and_register/2, unregister_and_register/3]).
 -export([unregister/1]).
 -export([unregister/1]).
 -export([whereis/1, whereis/2]).
 -export([whereis/1, whereis/2]).
 -export([count/0, count/1]).
 -export([count/0, count/1]).
@@ -72,12 +72,12 @@ register(Name, Pid, Meta) when is_pid(Pid) ->
     Node = node(Pid),
     Node = node(Pid),
     gen_server:call({?MODULE, Node}, {register_on_node, Name, Pid, Meta, false}).
     gen_server:call({?MODULE, Node}, {register_on_node, Name, Pid, Meta, false}).
 
 
--spec force_register(Name :: any(), Pid :: pid()) -> ok | {error, Reason :: any()}.
-force_register(Name, Pid) ->
-    force_register(Name, Pid, undefined).
+-spec unregister_and_register(Name :: any(), Pid :: pid()) -> ok | {error, Reason :: any()}.
+unregister_and_register(Name, Pid) ->
+    unregister_and_register(Name, Pid, undefined).
 
 
--spec force_register(Name :: any(), Pid :: pid(), Meta :: any()) -> ok | {error, Reason :: any()}.
-force_register(Name, Pid, Meta) when is_pid(Pid) ->
+-spec unregister_and_register(Name :: any(), Pid :: pid(), Meta :: any()) -> ok | {error, Reason :: any()}.
+unregister_and_register(Name, Pid, Meta) when is_pid(Pid) ->
     Node = node(Pid),
     Node = node(Pid),
     gen_server:call({?MODULE, Node}, {register_on_node, Name, Pid, Meta, true}).
     gen_server:call({?MODULE, Node}, {register_on_node, Name, Pid, Meta, true}).
 
 

+ 5 - 5
test/syn_registry_SUITE.erl

@@ -52,7 +52,7 @@
     two_nodes_registration_race_condition_conflict_resolution_when_process_died/1,
     two_nodes_registration_race_condition_conflict_resolution_when_process_died/1,
     two_nodes_registry_full_cluster_sync_on_boot_node_added_later/1,
     two_nodes_registry_full_cluster_sync_on_boot_node_added_later/1,
     two_nodes_registry_full_cluster_sync_on_boot_syn_started_later/1,
     two_nodes_registry_full_cluster_sync_on_boot_syn_started_later/1,
-    two_nodes_force_register/1
+    two_nodes_unregister_and_register/1
 ]).
 ]).
 -export([
 -export([
     three_nodes_partial_netsplit_consistency/1,
     three_nodes_partial_netsplit_consistency/1,
@@ -129,7 +129,7 @@ groups() ->
             two_nodes_registration_race_condition_conflict_resolution_when_process_died,
             two_nodes_registration_race_condition_conflict_resolution_when_process_died,
             two_nodes_registry_full_cluster_sync_on_boot_node_added_later,
             two_nodes_registry_full_cluster_sync_on_boot_node_added_later,
             two_nodes_registry_full_cluster_sync_on_boot_syn_started_later,
             two_nodes_registry_full_cluster_sync_on_boot_syn_started_later,
-            two_nodes_force_register
+            two_nodes_unregister_and_register
         ]},
         ]},
         {three_nodes_process_registration, [shuffle], [
         {three_nodes_process_registration, [shuffle], [
             three_nodes_partial_netsplit_consistency,
             three_nodes_partial_netsplit_consistency,
@@ -666,7 +666,7 @@ two_nodes_registry_full_cluster_sync_on_boot_syn_started_later(Config) ->
     Pid = syn:whereis(<<"proc">>),
     Pid = syn:whereis(<<"proc">>),
     Pid = rpc:call(SlaveNode, syn, whereis, [<<"proc">>]).
     Pid = rpc:call(SlaveNode, syn, whereis, [<<"proc">>]).
 
 
-two_nodes_force_register(Config) ->
+two_nodes_unregister_and_register(Config) ->
     Name = "common name",
     Name = "common name",
     %% get slave
     %% get slave
     SlaveNode = proplists:get_value(slave_node, Config),
     SlaveNode = proplists:get_value(slave_node, Config),
@@ -687,11 +687,11 @@ two_nodes_force_register(Config) ->
     {PidRemote, {pid_remote, TestPid}} = syn:whereis(Name, with_meta),
     {PidRemote, {pid_remote, TestPid}} = syn:whereis(Name, with_meta),
     {PidRemote, {pid_remote, TestPid}} = rpc:call(SlaveNode, syn, whereis, [Name, with_meta]),
     {PidRemote, {pid_remote, TestPid}} = rpc:call(SlaveNode, syn, whereis, [Name, with_meta]),
     %% force
     %% force
-    ok = syn:force_register(Name, PidLocal, {pid_local, TestPid}),
+    ok = syn:unregister_and_register(Name, PidLocal, {pid_local, TestPid}),
     timer:sleep(1000),
     timer:sleep(1000),
     {PidLocal, {pid_local, TestPid}} = syn:whereis(Name, with_meta),
     {PidLocal, {pid_local, TestPid}} = syn:whereis(Name, with_meta),
     {PidLocal, {pid_local, TestPid}} = rpc:call(SlaveNode, syn, whereis, [Name, with_meta]),
     {PidLocal, {pid_local, TestPid}} = rpc:call(SlaveNode, syn, whereis, [Name, with_meta]),
-    ok = rpc:call(SlaveNode, syn, force_register, [Name, PidRemote, {pid_remote, TestPid}]),
+    ok = rpc:call(SlaveNode, syn, unregister_and_register, [Name, PidRemote, {pid_remote, TestPid}]),
     timer:sleep(1000),
     timer:sleep(1000),
     {PidRemote, {pid_remote, TestPid}} = syn:whereis(Name, with_meta),
     {PidRemote, {pid_remote, TestPid}} = syn:whereis(Name, with_meta),
     {PidRemote, {pid_remote, TestPid}} = rpc:call(SlaveNode, syn, whereis, [Name, with_meta]),
     {PidRemote, {pid_remote, TestPid}} = rpc:call(SlaveNode, syn, whereis, [Name, with_meta]),