couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fdman...@apache.org
Subject svn commit: r992994 - /couchdb/branches/new_replicator/src/couchdb/couch_replicate.erl
Date Mon, 06 Sep 2010 11:03:00 GMT
Author: fdmanana
Date: Mon Sep  6 11:03:00 2010
New Revision: 992994

URL: http://svn.apache.org/viewvc?rev=992994&view=rev
Log:
New replicator: importing couch_util's get_value/2 and get_value/3 to reduce code size.

Modified:
    couchdb/branches/new_replicator/src/couchdb/couch_replicate.erl

Modified: couchdb/branches/new_replicator/src/couchdb/couch_replicate.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_replicate.erl?rev=992994&r1=992993&r2=992994&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_replicate.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_replicate.erl Mon Sep  6 11:03:00 2010
@@ -23,6 +23,11 @@
 -include("couch_db.hrl").
 -include("couch_api_wrap.hrl").
 
+-import(couch_util, [
+    get_value/2,
+    get_value/3
+]).
+
 % Can't be greater than the maximum number of child restarts specified
 % in couch_rep_sup.erl.
 -define(MAX_RESTARTS, 3).
@@ -67,7 +72,7 @@
 
 
 replicate(#rep{id = RepId, options = Options} = Rep) ->
-    case couch_util:get_value(cancel, Options, false) of
+    case get_value(cancel, Options, false) of
     true ->
         end_replication(RepId);
     false ->
@@ -79,8 +84,8 @@ replicate(#rep{id = RepId, options = Opt
 
 
 do_replication_loop(#rep{options = Options, source = Src} = Rep) ->
-    DocIds = couch_util:get_value(doc_ids, Options),
-    Continuous = couch_util:get_value(continuous, Options, false),
+    DocIds = get_value(doc_ids, Options),
+    Continuous = get_value(continuous, Options, false),
     Seq = case {DocIds, Continuous} of
     {undefined, false} ->
         last_seq(Src);
@@ -92,7 +97,7 @@ do_replication_loop(#rep{options = Optio
 do_replication_loop(#rep{id = {BaseId,_} = Id, options = Options} = Rep, Seq) ->
     case start_replication(Rep) of
     {ok, _Pid} ->
-        case couch_util:get_value(continuous, Options, false) of
+        case get_value(continuous, Options, false) of
         true ->
             {ok, {continuous, ?l2b(BaseId)}};
         false ->
@@ -107,7 +112,7 @@ do_replication_loop(#rep{id = {BaseId,_}
 maybe_retry(RepResult, _Rep, undefined) ->
     RepResult;
 maybe_retry({ok, {Props}} = Result, Rep, Seq) ->
-    case couch_util:get_value(source_last_seq, Props) >= Seq of
+    case get_value(source_last_seq, Props) >= Seq of
     true ->
         Result;
     false ->
@@ -121,9 +126,8 @@ last_seq(DbName) ->
     {ok, Db} = couch_api_wrap:db_open(
         DbName, [{user_ctx, #user_ctx{roles = [<<"_admin">>]}}]),
     {ok, DbInfo} = couch_api_wrap:get_db_info(Db),
-    Seq = couch_util:get_value(update_seq, DbInfo),
     couch_api_wrap:db_close(Db),
-    Seq.
+    get_value(update_seq, DbInfo).
 
 
 start_replication(#rep{id = {BaseId, Extension}} = Rep) ->
@@ -223,7 +227,7 @@ do_init(#rep{options = Options} = Rep) -
     {ok, MissingRevsQueue} = couch_work_queue:new(
         [{max_size, 100000}, {max_items, 500}, {multi_workers, true}]),
 
-    case couch_util:get_value(doc_ids, Options) of
+    case get_value(doc_ids, Options) of
     undefined ->
         {ok, ChangesQueue} = couch_work_queue:new(
             [{max_size, 100000}, {max_items, 500}]),
@@ -262,7 +266,7 @@ do_init(#rep{options = Options} = Rep) -
             changes_reader = ChangesReader,
             missing_revs_finder = MissingRevsFinder,
             doc_copiers = DocCopiers,
-            is_successor_seq = couch_util:get_value(is_successor_seq, Options,
+            is_successor_seq = get_value(is_successor_seq, Options,
                 fun(Seq, NextSeq) -> (Seq + 1) =:= NextSeq end)
         }
     }.
@@ -376,7 +380,7 @@ handle_info({'EXIT', Pid, Reason}, #rep_
 
 handle_info({'EXIT', Pid, Reason}, State) ->
     #rep_state{doc_copiers = DocCopiers} = State,
-    case couch_util:get_value(Pid, DocCopiers) of
+    case get_value(Pid, DocCopiers) of
     undefined ->
         cancel_timer(State),
         {stop, {unknown_process_died, Pid, Reason}, State};
@@ -430,7 +434,7 @@ terminate_cleanup(#rep_state{source = So
 
 
 start_timer(#rep_state{rep_details = #rep{options = Options}} = State) ->
-    case couch_util:get_value(doc_ids, Options) of
+    case get_value(doc_ids, Options) of
     undefined ->
         After = checkpoint_interval(State),
         case timer:apply_after(After, gen_server, cast, [self(), checkpoint]) of
@@ -452,7 +456,7 @@ cancel_timer(#rep_state{timer = Timer}) 
 
 
 get_result(#rep_state{stats = Stats, rep_details = Rep} = State) ->
-    case couch_util:get_value(doc_ids, Rep#rep.options) of
+    case get_value(doc_ids, Rep#rep.options) of
     undefined ->
         State#rep_state.checkpoint_history;
     _DocIdList ->
@@ -474,7 +478,7 @@ init_state(Rep) ->
     } = Rep,
     {ok, Source} = couch_api_wrap:db_open(Src, [{user_ctx, UserCtx}]),
     {ok, Target} = couch_api_wrap:db_open(Tgt, [{user_ctx, UserCtx}],
-        couch_util:get_value(create_target, Options, false)),
+        get_value(create_target, Options, false)),
 
     {ok, SourceInfo} = couch_api_wrap:get_db_info(Source),
     {ok, TargetInfo} = couch_api_wrap:get_db_info(Target),
@@ -504,8 +508,8 @@ init_state(Rep) ->
         source_log = SourceLog,
         target_log = TargetLog,
         rep_starttime = httpd_util:rfc1123_date(),
-        src_starttime = couch_util:get_value(instance_start_time, SourceInfo),
-        tgt_starttime = couch_util:get_value(instance_start_time, TargetInfo)
+        src_starttime = get_value(instance_start_time, SourceInfo),
+        tgt_starttime = get_value(instance_start_time, TargetInfo)
     },
     State#rep_state{timer = start_timer(State)}.
 
@@ -753,17 +757,17 @@ commit_to_both(Source, Target) ->
 compare_replication_logs(SrcDoc, TgtDoc) ->
     #doc{body={RepRecProps}} = SrcDoc,
     #doc{body={RepRecPropsTgt}} = TgtDoc,
-    case couch_util:get_value(<<"session_id">>, RepRecProps) ==
-            couch_util:get_value(<<"session_id">>, RepRecPropsTgt) of
+    case get_value(<<"session_id">>, RepRecProps) ==
+            get_value(<<"session_id">>, RepRecPropsTgt) of
     true ->
         % if the records have the same session id,
         % then we have a valid replication history
-        OldSeqNum = couch_util:get_value(<<"source_last_seq">>, RepRecProps,
0),
-        OldHistory = couch_util:get_value(<<"history">>, RepRecProps, []),
+        OldSeqNum = get_value(<<"source_last_seq">>, RepRecProps, 0),
+        OldHistory = get_value(<<"history">>, RepRecProps, []),
         {OldSeqNum, OldHistory};
     false ->
-        SourceHistory = couch_util:get_value(<<"history">>, RepRecProps, []),
-        TargetHistory = couch_util:get_value(<<"history">>, RepRecPropsTgt, []),
+        SourceHistory = get_value(<<"history">>, RepRecProps, []),
+        TargetHistory = get_value(<<"history">>, RepRecPropsTgt, []),
         ?LOG_INFO("Replication records differ. "
                 "Scanning histories to find a common ancestor.", []),
         ?LOG_DEBUG("Record on source:~p~nRecord on target:~p~n",
@@ -775,18 +779,18 @@ compare_rep_history(S, T) when S =:= [] 
     ?LOG_INFO("no common ancestry -- performing full replication", []),
     {0, []};
 compare_rep_history([{S} | SourceRest], [{T} | TargetRest] = Target) ->
-    SourceId = couch_util:get_value(<<"session_id">>, S),
+    SourceId = get_value(<<"session_id">>, S),
     case has_session_id(SourceId, Target) of
     true ->
-        RecordSeqNum = couch_util:get_value(<<"recorded_seq">>, S, 0),
+        RecordSeqNum = get_value(<<"recorded_seq">>, S, 0),
         ?LOG_INFO("found a common replication record with source_seq ~p",
             [RecordSeqNum]),
         {RecordSeqNum, SourceRest};
     false ->
-        TargetId = couch_util:get_value(<<"session_id">>, T),
+        TargetId = get_value(<<"session_id">>, T),
         case has_session_id(TargetId, SourceRest) of
         true ->
-            RecordSeqNum = couch_util:get_value(<<"recorded_seq">>, T, 0),
+            RecordSeqNum = get_value(<<"recorded_seq">>, T, 0),
             ?LOG_INFO("found a common replication record with source_seq ~p",
                 [RecordSeqNum]),
             {RecordSeqNum, TargetRest};
@@ -799,7 +803,7 @@ compare_rep_history([{S} | SourceRest], 
 has_session_id(_SessionId, []) ->
     false;
 has_session_id(SessionId, [{Props} | Rest]) ->
-    case couch_util:get_value(<<"session_id">>, Props, nil) of
+    case get_value(<<"session_id">>, Props, nil) of
     SessionId ->
         true;
     _Else ->



Mime
View raw message