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 Project: http://git-wip-us.apache.org/repos/asf/couchdb-mem3/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-mem3/commit/32578e40 Tree: http://git-wip-us.apache.org/repos/asf/couchdb-mem3/tree/32578e40 Diff: http://git-wip-us.apache.org/repos/asf/couchdb-mem3/diff/32578e40 Branch: refs/heads/import Commit: 32578e40de6892a9df0b4a078000e444777344ac Parents: d358892 Author: Paul J. Davis <[email protected]> Authored: Tue Sep 25 13:06:45 2012 -0500 Committer: Paul J. Davis <[email protected]> Committed: Tue Sep 25 22:24:58 2012 -0500 ---------------------------------------------------------------------- src/mem3_rep.erl | 1 + src/mem3_sync_security.erl | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-mem3/blob/32578e40/src/mem3_rep.erl ---------------------------------------------------------------------- diff --git a/src/mem3_rep.erl b/src/mem3_rep.erl index cafb1c0..64cf931 100644 --- a/src/mem3_rep.erl +++ b/src/mem3_rep.erl @@ -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 http://git-wip-us.apache.org/repos/asf/couchdb-mem3/blob/32578e40/src/mem3_sync_security.erl ---------------------------------------------------------------------- diff --git a/src/mem3_sync_security.erl b/src/mem3_sync_security.erl index 5a45dbb..c436e56 100644 --- a/src/mem3_sync_security.erl +++ b/src/mem3_sync_security.erl @@ -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. +
