This is an automated email from the ASF dual-hosted git repository. vatamane pushed a commit to branch prototype/fdb-replicator in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 88334abf6d002efeff1f8d2c480ecab72a48e7e3 Author: Nick Vatamaniuc <[email protected]> AuthorDate: Mon Jul 20 17:10:17 2020 -0400 [wip] replace state maps fields with defines --- src/couch_replicator/src/couch_replicator.erl | 10 +++++----- src/couch_replicator/src/couch_replicator.hrl | 16 +++++++++++----- src/couch_replicator/src/couch_replicator_filters.erl | 2 +- src/couch_replicator/src/couch_replicator_ids.erl | 14 +++++++------- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/couch_replicator/src/couch_replicator.erl b/src/couch_replicator/src/couch_replicator.erl index 69bbb2f..3a27692 100644 --- a/src/couch_replicator/src/couch_replicator.erl +++ b/src/couch_replicator/src/couch_replicator.erl @@ -54,8 +54,8 @@ no_return(). replicate(PostBody, #user_ctx{name = UserName}) -> {ok, Rep0} = couch_replicator_utils:parse_rep_doc(PostBody, UserName), - Rep = Rep0#{<<"start_time">> => erlang:system_time()}, - #{<<"id">> := RepId, <<"options">> := Options} = Rep, + Rep = Rep0#{?START_TIME => erlang:system_time()}, + #{?REP_ID := RepId, ?OPTIONS := Options} = Rep, case maps:get(<<"cancel">>, Options, false) of true -> CancelRepId = case maps:get(<<"id">>, Options, nil) of @@ -122,10 +122,10 @@ cancel_replication(RepId) when is_binary(RepId) -> case couch_jobs:get_job_data(undefined, ?REP_JOBS, RepId) of {error_not, found} -> {error, not_found}; - #{<<"rep">> := #{<<"db_name">> := null}} -> + #{?REP := #{?DB_NAME := null}} -> couch_jobs:remove(undefined, ?REP_JOBS, RepId) {ok, {cancelled, ?l2b(FullRepId)}}; - #{<<"rep">> := #{}} -> + #{?REP := #{}} -> % Job was started from a replicator doc canceling via _replicate % doesn't quite make sense, instead replicator should be deleted. {error, not_found} @@ -286,7 +286,7 @@ check_authorization(RepId, #user_ctx{name = Name} = Ctx) -> case couch_jobs:get_job_data(undefined, ?REP_JOBS, RePid) of {error_not, found} -> not_found; - #{<<"rep">> := {<<"user">> := Name}} -> + #{?REP := {?REP_USER := Name}} -> ok; #{} -> couch_httpd:verify_is_server_admin(Ctx) diff --git a/src/couch_replicator/src/couch_replicator.hrl b/src/couch_replicator/src/couch_replicator.hrl index d94c3eb..80ab48f 100644 --- a/src/couch_replicator/src/couch_replicator.hrl +++ b/src/couch_replicator/src/couch_replicator.hrl @@ -13,8 +13,8 @@ -define(REP_ID_VERSION, 4). % Couch jobs types and timeouts --define(REP_DOCS, <<"repdocs">>). --define(REP_JOBS, <<"repjobs">>). +-define(REP_DOCS, <<"rep_docs">>). +-define(REP_JOBS, <<"rep_jobs">>). -define(REP_DOCS_TIMEOUT_MSEC, 17000). -define(REP_JOBS_TIMEOUT_MSEC, 33000). @@ -29,6 +29,9 @@ -define(URL, <<"url">>). -define(AUTH, <<"auth">>). -define(HEADERS, <<"headers">>). +-define(PROXY, <<"proxy">>). +-define(SOURCE_PROXY, <<"source_proxy">>). +-define(TARGET_PROXY, <<"target_proxy">>). % Replication states -define(ST_ERROR, <<"error">>). @@ -42,14 +45,18 @@ -define(ST_TRIGGERED, <<"triggered">>). % Some fields from a rep object --define(REP_ID, <<"id">>). +-define(REP_ID, <<"rep_id">>). +-define(BASE_ID, <<"base_id">>). -define(DB_NAME, <<"db_name">>). -define(DOC_ID, <<"doc_id">>). +-define(REP_USER, <<"rep_user">>). -define(START_TIME, <<"start_time">>). +-define(OPTIONS, <<"options">>). -% Fields couch job data objects +% Fields for couch job data objects -define(REP, <<"rep">>). -define(REP_PARSE_ERROR, <<"rep_parse_error">>). +-defene(REP_STATS, <<"rep_stats">>). -define(STATE, <<"state">>). -define(STATE_INFO, <<"state_info">>). -define(DOC_STATE, <<"doc_state">>). @@ -58,7 +65,6 @@ -define(ERROR_COUNT, <<"error_count">>). -define(LAST_UPDATED, <<"last_updated">>). -define(HISTORY, <<"history">>). --define(VER, <<"ver">>). % Accepted job message tag -define(ACCEPTED_JOB, accepted_job). diff --git a/src/couch_replicator/src/couch_replicator_filters.erl b/src/couch_replicator/src/couch_replicator_filters.erl index fe785a2..0e80773 100644 --- a/src/couch_replicator/src/couch_replicator_filters.erl +++ b/src/couch_replicator/src/couch_replicator_filters.erl @@ -90,7 +90,7 @@ fetch(DDocName, FilterName, Source) -> % Get replication type and view (if any) from replication document props -spec view_type(#{}, [_]) -> {binary(), #{}} | {error, binary()}. -view_type(#{<<"filter">> := <<"_view">>}, Options) -> +view_type(#{?FILTER := <<"_view">>}, Options) -> {QP} = couch_util:get_value(query_params, Options, {[]}), ViewParam = couch_util:get_value(<<"view">>, QP), case re:split(ViewParam, <<"/">>) of diff --git a/src/couch_replicator/src/couch_replicator_ids.erl b/src/couch_replicator/src/couch_replicator_ids.erl index a3f6220..d3b3c00 100644 --- a/src/couch_replicator/src/couch_replicator_ids.erl +++ b/src/couch_replicator/src/couch_replicator_ids.erl @@ -30,7 +30,7 @@ % {filter_fetch_error, Error} exception. % -replication_id(#{<<"options">> := Options} = Rep) -> +replication_id(#{?OPTIONS := Options} = Rep) -> BaseId = replication_id(Rep, ?REP_ID_VERSION), UseOpts = [<<"continuous">>, <<"create_target">>] {BaseId, maybe_append_options(UseOpts, Options)}. @@ -40,19 +40,19 @@ replication_id(#{<<"options">> := Options} = Rep) -> % If a change is made to how replications are identified, % please add a new clause and increase ?REP_ID_VERSION. -replication_id(#{<<"source">> := Src, <<"target">> := Tgt} = Rep, 4) -> +replication_id(#{?SOURCE := Src, ?TARGET := Tgt} = Rep, 4) -> UUID = couch_server:get_uuid(), SrcInfo = get_v4_endpoint(Src), TgtInfo = get_v4_endpoint(Tgt), maybe_append_filters([UUID, SrcInfo, TgtInfo], Rep); -replication_id(#{<<"source">> := Src0, <<"target">> := Tgt0} = Rep, 3) -> +replication_id(#{?SOURCE := Src0, ?TARGET := Tgt0} = Rep, 3) -> UUID = couch_server:get_uuid(), Src = get_rep_endpoint(Src0), Tgt = get_rep_endpoint(Tgt0), maybe_append_filters([UUID, Src, Tgt], Rep); -replication_id(#{<<"source">> := Src0, <<"target">> := Tgt0} = Rep, 2) -> +replication_id(#{?SOURCE := Src0, ?TARGET := Tgt0} = Rep, 2) -> {ok, HostName} = inet:gethostname(), Port = case (catch mochiweb_socket_server:get(couch_httpd, port)) of P when is_number(P) -> @@ -69,7 +69,7 @@ replication_id(#{<<"source">> := Src0, <<"target">> := Tgt0} = Rep, 2) -> Tgt = get_rep_endpoint(Tgt0), maybe_append_filters([HostName, Port, Src, Tgt], Rep); -replication_id(#{<<"source">> := Src0, <<"target">> := Tgt0} = Rep, 1) -> +replication_id(#{?SOURCE := Src0, ?TARGET := Tgt0} = Rep, 1) -> {ok, HostName} = inet:gethostname(), Src = get_rep_endpoint(Src0), Tgt = get_rep_endpoint(Tgt0), @@ -98,8 +98,8 @@ convert({BaseId, Ext} = Id) when is_binary(BaseId), is_binary(Ext) -> maybe_append_filters(Base, #{} = Rep) -> #{ - <<"source">> := Source, - <<"options">> := Options + ?SOURCE := Source, + ?OPTIONS := Options } = Rep, Base2 = Base ++ case couch_replicator_filters:parse(Options) of
