diff --git a/src/chttpd/src/chttpd_auth_request.erl b/src/chttpd/src/chttpd_auth_request.erl index 9110ed6bc4a..f85eb9722aa 100644 --- a/src/chttpd/src/chttpd_auth_request.erl +++ b/src/chttpd/src/chttpd_auth_request.erl @@ -70,6 +70,8 @@ authorize_request_int(#httpd{path_parts=[_DbName, <<"_compact">>|_]}=Req) -> require_db_admin(Req); authorize_request_int(#httpd{path_parts=[_DbName, <<"_view_cleanup">>]}=Req) -> require_db_admin(Req); +authorize_request_int(#httpd{path_parts=[_DbName, <<"_sync_shards">>]}=Req) -> + require_admin(Req); authorize_request_int(#httpd{path_parts=[_DbName|_]}=Req) -> db_authorization_check(Req). diff --git a/src/mem3/src/mem3_httpd.erl b/src/mem3/src/mem3_httpd.erl index 571f0637025..c922141b1c7 100644 --- a/src/mem3/src/mem3_httpd.erl +++ b/src/mem3/src/mem3_httpd.erl @@ -12,7 +12,8 @@ -module(mem3_httpd). --export([handle_membership_req/1, handle_shards_req/2]). +-export([handle_membership_req/1, handle_shards_req/2, + handle_sync_req/2]). %% includes -include_lib("mem3/include/mem3.hrl"). @@ -52,6 +53,16 @@ handle_shards_req(#httpd{path_parts=[_DbName, <<"_shards">>]}=Req, _Db) -> handle_shards_req(#httpd{path_parts=[_DbName, <<"_shards">>, _DocId]}=Req, _Db) -> chttpd:send_method_not_allowed(Req, "GET"). +handle_sync_req(#httpd{method='POST', + path_parts=[_DbName, <<"_sync_shards">>]} = Req, Db) -> + DbName = mem3:dbname(couch_db:name(Db)), + ShardList = [S#shard.name || S <- mem3:ushards(DbName)], + [ sync_shard(S) || S <- ShardList ], + chttpd:send_json(Req, 202, {[{ok, true}]}); +handle_sync_req(Req, _) -> + chttpd:send_method_not_allowed(Req, "POST"). + + %% %% internal %% @@ -64,3 +75,10 @@ json_shards([#shard{node=Node, range=[B,E]} | Rest], AccIn) -> HexEnd = couch_util:to_hex(<>), Range = list_to_binary(HexBeg ++ "-" ++ HexEnd), json_shards(Rest, dict:append(Range, Node, AccIn)). + +sync_shard(ShardName) -> + Shards = mem3_shards:for_shard_name(ShardName), + [rpc:call(S1#shard.node, mem3_sync, push, [S1, S2#shard.node]) || + S1 <- Shards, S2 <- Shards, S1 =/= S2], + ok. + diff --git a/src/mem3/src/mem3_httpd_handlers.erl b/src/mem3/src/mem3_httpd_handlers.erl index d8e138c15f7..7cbd9fe5f20 100644 --- a/src/mem3/src/mem3_httpd_handlers.erl +++ b/src/mem3/src/mem3_httpd_handlers.erl @@ -18,6 +18,7 @@ url_handler(<<"_membership">>) -> fun mem3_httpd:handle_membership_req/1; url_handler(_) -> no_match. db_handler(<<"_shards">>) -> fun mem3_httpd:handle_shards_req/2; +db_handler(<<"_sync_shards">>) -> fun mem3_httpd:handle_sync_req/2; db_handler(_) -> no_match. design_handler(_) -> no_match.