Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added gproc_dist:sync()

  • Loading branch information...
commit c16d33932e24e5991032b2d35ce2588b2b3f8ab4 1 parent e73a7f3
Ulf Wiger authored
View
26 doc/gproc_dist.md
@@ -35,7 +35,7 @@ Class = n - unique name
| p - non-unique property
| c - counter
| a - aggregated counter
-Scope = l | g (global or local).</td></tr><tr><td valign="top"><a href="#set_value-2">set_value/2</a></td><td></td></tr><tr><td valign="top"><a href="#start_link-0">start_link/0</a></td><td></td></tr><tr><td valign="top"><a href="#start_link-1">start_link/1</a></td><td></td></tr><tr><td valign="top"><a href="#surrendered-3">surrendered/3</a></td><td></td></tr><tr><td valign="top"><a href="#terminate-2">terminate/2</a></td><td></td></tr><tr><td valign="top"><a href="#unreg-1">unreg/1</a></td><td></td></tr><tr><td valign="top"><a href="#update_counter-2">update_counter/2</a></td><td></td></tr></table>
+Scope = l | g (global or local).</td></tr><tr><td valign="top"><a href="#set_value-2">set_value/2</a></td><td></td></tr><tr><td valign="top"><a href="#start_link-0">start_link/0</a></td><td></td></tr><tr><td valign="top"><a href="#start_link-1">start_link/1</a></td><td></td></tr><tr><td valign="top"><a href="#surrendered-3">surrendered/3</a></td><td></td></tr><tr><td valign="top"><a href="#sync-0">sync/0</a></td><td>Synchronize with the gproc leader.</td></tr><tr><td valign="top"><a href="#terminate-2">terminate/2</a></td><td></td></tr><tr><td valign="top"><a href="#unreg-1">unreg/1</a></td><td></td></tr><tr><td valign="top"><a href="#update_counter-2">update_counter/2</a></td><td></td></tr></table>
@@ -220,8 +220,7 @@ Class = n - unique name
| p - non-unique property
| c - counter
| a - aggregated counter
-Scope = l | g (global or local)
-<a name="set_value-2"></a>
+Scope = l | g (global or local)<a name="set_value-2"></a>
<h3>set_value/2</h3>
@@ -261,7 +260,26 @@ Scope = l | g (global or local)
`surrendered(S, X2, E) -> any()`
-<a name="terminate-2"></a>
+<a name="sync-0"></a>
+
+<h3>sync/0</h3>
+
+
+
+
+
+<pre>sync() -> true</pre>
+<br></br>
+
+
+
+
+
+
+Synchronize with the gproc leader
+
+This function can be used to ensure that data has been replicated from the
+leader to the current node.<a name="terminate-2"></a>
<h3>terminate/2</h3>
View
2  src/gproc.app.src
@@ -5,7 +5,7 @@
{application, gproc,
[
{description, "GPROC"},
- {vsn, "0.2.2"},
+ {vsn, "0.2.3"},
{id, "GPROC"},
{registered, [ ] },
%% NOTE: do not list applications which are load-only!
View
21 src/gproc_dist.erl
@@ -29,7 +29,9 @@
give_away/2,
update_counter/2]).
--export([leader_call/1, leader_cast/1]).
+-export([leader_call/1,
+ leader_cast/1,
+ sync/0]).
%%% internal exports
-export([init/1,
@@ -82,7 +84,7 @@ reg(Key) ->
%%% | c - counter
%%% | a - aggregated counter
%%% Scope = l | g (global or local)
-%%%
+%%% @end
reg({_,g,_} = Key, Value) ->
%% anything global
leader_call({reg, Key, Value, self()});
@@ -121,7 +123,15 @@ update_counter({c,g,_} = Key, Incr) when is_integer(Incr) ->
update_counter(_, _) ->
erlang:error(badarg).
-
+%% @spec sync() -> true
+%% @doc Synchronize with the gproc leader
+%%
+%% This function can be used to ensure that data has been replicated from the
+%% leader to the current node.
+%% @end
+%%
+sync() ->
+ leader_call(sync).
%%% ==========================================================
@@ -184,6 +194,8 @@ handle_DOWN(Node, S, _E) ->
%% ets:select_delete(?TAB, [{Head, Gs, [true]}]),
%% {ok, [{delete, Globs}], S}.
+handle_leader_call(sync, _From, S, _E) ->
+ {reply, true, sync, S};
handle_leader_call({reg, {C,g,Name} = K, Value, Pid}, _From, S, _E) ->
case gproc_lib:insert_reg(K, Value, Pid, g) of
false ->
@@ -354,7 +366,8 @@ terminate(_Reason, _S) ->
-
+from_leader(sync, S, _E) ->
+ {ok, S};
from_leader(Ops, S, _E) ->
lists:foreach(
fun({delete, Globals}) ->
View
11 test/gproc_dist_tests.erl
@@ -28,7 +28,8 @@ dist_test_() ->
Ns = start_slaves([dist_test_n1, dist_test_n2]),
?assertMatch({[ok,ok],[]},
rpc:multicall(Ns, application, start, [gproc])),
- ?debugVal(Ns)
+%% ?debugVal(Ns)
+ Ns
end,
fun(Ns) ->
[rpc:call(N, init, stop, []) || N <- Ns]
@@ -51,6 +52,9 @@ dist_test_() ->
end,
fun() ->
?debugVal(t_give_away(Ns))
+ end,
+ fun() ->
+ ?debugVal(t_sync(Ns))
end
]
},
@@ -126,6 +130,11 @@ t_give_away([A,B|_] = Ns) ->
?assertMatch(ok, t_call(Pa, die)),
?assertMatch(ok, t_call(Pb, die)).
+t_sync(Ns) ->
+ %% Don't really know how to test this...
+ [?assertMatch(true, rpc:call(N, gproc_dist, sync, []))
+ || N <- Ns].
+
t_fail_node([A,B|_] = Ns) ->
Na = ?T_NAME,
Nb = ?T_NAME,
Please sign in to comment.
Something went wrong with that request. Please try again.