couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From iil...@apache.org
Subject [1/4] couch-index commit: updated refs/heads/master to aa8e6f9
Date Tue, 24 May 2016 18:30:26 GMT
Repository: couchdb-couch-index
Updated Branches:
  refs/heads/master 8ec83cf48 -> aa8e6f957


Extract commit_compacted function


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/commit/b8bfca7f
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/tree/b8bfca7f
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/diff/b8bfca7f

Branch: refs/heads/master
Commit: b8bfca7ff0edb6790c57f5d082e296865ff7ff52
Parents: 8ec83cf
Author: ILYA Khlopotov <iilyak@ca.ibm.com>
Authored: Fri May 13 08:22:55 2016 -0700
Committer: ILYA Khlopotov <iilyak@ca.ibm.com>
Committed: Tue May 17 11:47:30 2016 -0700

----------------------------------------------------------------------
 src/couch_index.erl | 46 +++++++++++++++++++++++++---------------------
 1 file changed, 25 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/blob/b8bfca7f/src/couch_index.erl
----------------------------------------------------------------------
diff --git a/src/couch_index.erl b/src/couch_index.erl
index 2b19cca..25fc62a 100644
--- a/src/couch_index.erl
+++ b/src/couch_index.erl
@@ -191,9 +191,7 @@ handle_call(get_compactor_pid, _From, State) ->
 handle_call({compacted, NewIdxState}, _From, State) ->
     #st{
         mod=Mod,
-        idx_state=OldIdxState,
-        updater=Updater,
-        commit_delay=Delay
+        idx_state=OldIdxState
     } = State,
     assert_signature_match(Mod, OldIdxState, NewIdxState),
     NewSeq = Mod:get(update_seq, NewIdxState),
@@ -202,26 +200,10 @@ handle_call({compacted, NewIdxState}, _From, State) ->
     % up to date with the current index. Otherwise indexes could roll back
     % (perhaps considerably) to previous points in history.
     case NewSeq >= OldSeq of
-        true ->
-            {ok, NewIdxState1} = Mod:swap_compacted(OldIdxState, NewIdxState),
-            % Restart the indexer if it's running.
-            case couch_index_updater:is_running(Updater) of
-                true -> ok = couch_index_updater:restart(Updater, NewIdxState1);
-                false -> ok
-            end,
-            case State#st.committed of
-                true -> erlang:send_after(Delay, self(), commit);
-                false -> ok
-            end,
-            {reply, ok, State#st{
-                idx_state=NewIdxState1,
-                committed=false
-            }};
-        _ ->
-            {reply, recompact, State}
+        true -> {reply, ok, commit_compacted(NewIdxState, State)};
+        false -> {reply, recompact, State}
     end.
 
-
 handle_cast({config_change, NewDelay}, State) ->
     MsDelay = 1000 * list_to_integer(NewDelay),
     {noreply, State#st{commit_delay=MsDelay}};
@@ -407,3 +389,25 @@ assert_signature_match(Mod, OldIdxState, NewIdxState) ->
         {Sig, Sig} -> ok;
         _ -> erlang:error(signature_mismatch)
     end.
+
+commit_compacted(NewIdxState, State) ->
+    #st{
+        mod=Mod,
+        idx_state=OldIdxState,
+        updater=Updater,
+        commit_delay=Delay
+    } = State,
+    {ok, NewIdxState1} = Mod:swap_compacted(OldIdxState, NewIdxState),
+    % Restart the indexer if it's running.
+    case couch_index_updater:is_running(Updater) of
+        true -> ok = couch_index_updater:restart(Updater, NewIdxState1);
+        false -> ok
+    end,
+    case State#st.committed of
+        true -> erlang:send_after(Delay, self(), commit);
+        false -> ok
+    end,
+    State#st{
+        idx_state=NewIdxState1,
+        committed=false
+     }.


Mime
View raw message