Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Check security objects during internal replication
If we detect that two shards have different values for a security object
during internal replication we automatically trigger a security object
synchronization.

BugzId: 11602
  • Loading branch information
davisp committed Sep 26, 2012
1 parent d358892 commit 32578e40de6892a9df0b4a078000e444777344ac
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
@@ -26,6 +26,7 @@ go(DbName, Node, Opts) when is_binary(DbName), is_atom(Node) ->
go(#shard{name=DbName, node=node()}, #shard{name=DbName, node=Node}, Opts);

go(#shard{} = Source, #shard{} = Target, Opts) ->
mem3_sync_security:maybe_sync(Source, Target),
BatchSize = case proplists:get_value(batch_size, Opts) of
BS when is_integer(BS), BS > 0 -> BS;
_ -> 100
@@ -14,8 +14,34 @@

-module(mem3_sync_security).

-export([maybe_sync/2, maybe_sync_int/2]).
-export([go/0, go/1]).

-include("mem3.hrl").


maybe_sync(#shard{}=Src, #shard{}=Dst) ->
case is_local(Src#shard.name) of
false ->
erlang:spawn(?MODULE, maybe_sync_int, [Src, Dst]);
true ->
ok
end.

maybe_sync_int(#shard{name=Name}=Src, Dst) ->
DbName = mem3:dbname(Name),
case fabric:get_all_security(DbName, [{shards, [Src, Dst]}]) of
{ok, WorkerObjs} ->
Objs = [Obj || {_Worker, Obj} <- WorkerObjs],
case length(lists:usort(Objs)) of
1 -> ok;
2 -> go(DbName)
end;
Else ->
Args = [DbName, Else],
twig:log(err, "Error checking security objects for ~s :: ~p", Args)
end.

go() ->
{ok, Dbs} = fabric:all_dbs(),
lists:foreach(fun handle_db/1, Dbs).
@@ -73,3 +99,9 @@ is_ok(_, _) ->
% Anything else requires human intervention
broken.


is_local(<<"shards/", _/binary>>) ->
false;
is_local(_) ->
true.

0 comments on commit 32578e4

Please sign in to comment.