You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2014/02/13 01:01:14 UTC

[01/12] couch-index commit: updated refs/heads/1994-merge-rcouch to 7c1666b

Updated Branches:
  refs/heads/1994-merge-rcouch 4a5a0e372 -> 7c1666ba7 (forced update)


add supports of view changes in the _changes API

Now when the option `seq_indexed=true` is set in the design doc, the
view filter in _changes will use it to retrieve the results. Compared to
the current way, using a view index will be faster to retrieve changes.
It also gives the possibility to filter changes by key or get changes in
a key range. All the view options can be used.

Note 1: if someone is trying to filter a changes with view options when
the views are not indexed by sequence, a 400 error will be returned.
Note 2: The changes will only be returned when the view is updated if
seq_indexed=true


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/7d713ef6
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/tree/7d713ef6
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/diff/7d713ef6

Branch: refs/heads/1994-merge-rcouch
Commit: 7d713ef6522a0ab939aa357d15a84e34ac80f5a1
Parents: ebb85be
Author: benoitc <bc...@gmail.com>
Authored: Fri Feb 7 15:38:34 2014 +0100
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Wed Feb 12 17:58:22 2014 -0600

----------------------------------------------------------------------
 src/couch_index.erl        | 13 ++++++++++---
 src/couch_index_server.erl |  7 -------
 2 files changed, 10 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/blob/7d713ef6/src/couch_index.erl
----------------------------------------------------------------------
diff --git a/src/couch_index.erl b/src/couch_index.erl
index c48c066..b9ae567 100644
--- a/src/couch_index.erl
+++ b/src/couch_index.erl
@@ -254,12 +254,12 @@ handle_cast(delete, State) ->
     DbName = Mod:get(db_name, IdxState),
     DDocId = Mod:get(idx_name, IdxState),
 
-    ok = Mod:delete(IdxState),
-
     %% notify about the index deletion
     couch_index_event:notify({index_delete,
                               {DbName, DDocId, Mod}}),
 
+    ok = Mod:delete(IdxState),
+
     {stop, normal, State};
 handle_cast(ddoc_updated, State) ->
     #st{mod = Mod, idx_state = IdxState, waiters = Waiters} = State,
@@ -319,7 +319,14 @@ handle_info(commit, State) ->
             {noreply, State}
     end;
 handle_info({'DOWN', _, _, _Pid, _}, #st{mod=Mod, idx_state=IdxState}=State) ->
-    Args = [Mod:get(db_name, IdxState), Mod:get(idx_name, IdxState)],
+    DbName = Mod:get(db_name, IdxState),
+    DDocId = Mod:get(idx_name, IdxState),
+
+    %% notify to event listeners that the index has been
+    %% updated
+    couch_index_event:notify({index_delete, {DbName, DDocId, Mod}}),
+
+    Args = [DbName, DDocId],
     ?LOG_INFO("Index shutdown by monitor notice for db: ~s idx: ~s", Args),
     catch send_all(State#st.waiters, shutdown),
     {stop, normal, State#st{waiters=[]}}.

http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/blob/7d713ef6/src/couch_index_server.erl
----------------------------------------------------------------------
diff --git a/src/couch_index_server.erl b/src/couch_index_server.erl
index facde14..86791db 100644
--- a/src/couch_index_server.erl
+++ b/src/couch_index_server.erl
@@ -159,8 +159,6 @@ reset_indexes(DbName, Root) ->
         MRef = erlang:monitor(process, Pid),
         gen_server:cast(Pid, delete),
         receive {'DOWN', MRef, _, _, _} -> ok end,
-        couch_index_event:notify({index_delete,
-                                  {DbName, DDocId, couch_mrview_index}}),
         rem_from_ets(DbName, Sig, DDocId, Pid)
     end,
     lists:foreach(Fun, ets:lookup(?BY_DB, DbName)),
@@ -195,11 +193,6 @@ update_notify({ddoc_updated, {DbName, DDocId}}) ->
         fun({_DbName, {_DDocId, Sig}}) ->
             case ets:lookup(?BY_SIG, {DbName, Sig}) of
                 [{_, IndexPid}] ->
-                    %% notify to event listeners that the index has been
-                    %% updated
-                    couch_index_event:notify({index_update,
-                                              {DbName, DDocId,
-                                               couch_mrview_index}}),
                     (catch gen_server:cast(IndexPid, ddoc_updated));
                 [] ->
                     ok


[03/12] couch-index commit: updated refs/heads/1994-merge-rcouch to 7c1666b

Posted by da...@apache.org.
couch_index_sup should be started by the couch application

I had this patch landing in a custommer repository for awhile. Since
couch_index is always dependent of couch it's better to add it to the
couch application supervision rather than on its own.


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/62bddab9
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/tree/62bddab9
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/diff/62bddab9

Branch: refs/heads/1994-merge-rcouch
Commit: 62bddab9c75f4a95a9558dab4890f6eb1637fd35
Parents: 5ae0421
Author: benoitc <be...@apache.org>
Authored: Thu Jan 9 23:29:54 2014 +0100
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Wed Feb 12 17:58:22 2014 -0600

----------------------------------------------------------------------
 src/couch_index.app.src |  3 +--
 src/couch_index_app.erl | 27 ---------------------------
 2 files changed, 1 insertion(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/blob/62bddab9/src/couch_index.app.src
----------------------------------------------------------------------
diff --git a/src/couch_index.app.src b/src/couch_index.app.src
index 6a59e99..921e5d2 100644
--- a/src/couch_index.app.src
+++ b/src/couch_index.app.src
@@ -15,6 +15,5 @@
     {vsn, "1.3.0"},
     {modules, []},
     {registered, [couch_index_server]},
-    {applications, [kernel, stdlib, couch]},
-    {mod, {couch_index_app, []}}
+    {applications, [kernel, stdlib, couch]}
 ]}.

http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/blob/62bddab9/src/couch_index_app.erl
----------------------------------------------------------------------
diff --git a/src/couch_index_app.erl b/src/couch_index_app.erl
deleted file mode 100644
index 6bafdcb..0000000
--- a/src/couch_index_app.erl
+++ /dev/null
@@ -1,27 +0,0 @@
-% Licensed under the Apache License, Version 2.0 (the "License"); you may not
-% use this file except in compliance with the License. You may obtain a copy of
-% the License at
-%
-%   http://www.apache.org/licenses/LICENSE-2.0
-%
-% Unless required by applicable law or agreed to in writing, software
-% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-% License for the specific language governing permissions and limitations under
-% the License.
-
--module(couch_index_app).
-
--behaviour(application).
-
--include_lib("couch/include/couch_db.hrl").
-
--export([start/2, stop/1]).
-
-start(_Type, _Args) ->
-    couch_util:start_app_deps(couch_index),
-    couch_index_sup:start_link().
-
-
-stop(_) ->
-    ok.


[12/12] couch-index commit: updated refs/heads/1994-merge-rcouch to 7c1666b

Posted by da...@apache.org.
couch_index: add background indexing facility

This change add the possibility to trigger a view indexation in
background. The indexation can only work in background if at least one
process acquired it using the `couch_index_server:acquire_index/3`
function. If all the process that acquired it are down or released it
using `couch_index_server:release_indexer/3` then the background task is
stopped.

By default the background indexation will happen every 1s or when 200
docs has been saved in the database. These parameters can be changed
using the options `threshold` and `refresh_interval` in the couch_index
section.

To use it with couch_mrview a new option {refresh, true} has been added
to couch_mrview_changes:handle_changes Also the query parameter
refresh=true is passsed in t the HTTP changes API.


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/814ed50f
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/tree/814ed50f
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/diff/814ed50f

Branch: refs/heads/1994-merge-rcouch
Commit: 814ed50fc48bc4811234a88d1cf9d01b0dc35c27
Parents: 7d713ef
Author: benoitc <be...@apache.org>
Authored: Sat Feb 8 19:55:40 2014 +0100
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Wed Feb 12 17:58:23 2014 -0600

----------------------------------------------------------------------
 src/couch_index.erl         |  35 +++++++-
 src/couch_index_indexer.erl | 189 +++++++++++++++++++++++++++++++++++++++
 src/couch_index_server.erl  |  18 ++++
 3 files changed, 241 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/blob/814ed50f/src/couch_index.erl
----------------------------------------------------------------------
diff --git a/src/couch_index.erl b/src/couch_index.erl
index b9ae567..01483bb 100644
--- a/src/couch_index.erl
+++ b/src/couch_index.erl
@@ -17,6 +17,7 @@
 %% API
 -export([start_link/1, stop/1, get_state/2, get_info/1]).
 -export([compact/1, compact/2, get_compactor_pid/1]).
+-export([acquire_indexer/1, release_indexer/1]).
 -export([config_change/3]).
 
 %% gen_server callbacks
@@ -30,6 +31,7 @@
     idx_state,
     updater,
     compactor,
+    indexer=nil,
     waiters=[],
     commit_delay,
     committed=true,
@@ -68,6 +70,16 @@ compact(Pid, Options) ->
 get_compactor_pid(Pid) ->
     gen_server:call(Pid, get_compactor_pid).
 
+
+acquire_indexer(Pid) ->
+    {ok, IPid} = gen_server:call(Pid, get_indexer_pid),
+    gen_server:call(IPid, {acquire, self()}).
+
+release_indexer(Pid) ->
+    {ok, IPid} = gen_server:call(Pid, get_indexer_pid),
+    gen_server:call(IPid, {release, self()}).
+
+
 config_change("query_server_config", "commit_freq", NewValue) ->
     ok = gen_server:cast(?MODULE, {config_update, NewValue}).
 
@@ -88,6 +100,7 @@ init({Mod, IdxState}) ->
         {ok, NewIdxState} ->
             {ok, UPid} = couch_index_updater:start_link(self(), Mod),
             {ok, CPid} = couch_index_compactor:start_link(self(), Mod),
+
             Delay = couch_config:get("query_server_config", "commit_freq", "5"),
             MsDelay = 1000 * list_to_integer(Delay),
             State = #st{
@@ -196,7 +209,18 @@ handle_call({compacted, NewIdxState}, _From, State) ->
             }};
         _ ->
             {reply, recompact, State}
-    end.
+    end;
+handle_call(get_indexer_pid, _From, #st{mod=Mod, idx_state=IdxState}=State) ->
+    Pid = case State#st.indexer of
+        Pid1 when is_pid(Pid1) ->
+            Pid1;
+        _ ->
+            DbName = Mod:get(db_name, IdxState),
+            {ok, IPid} = couch_index_indexer:start_link(self(), DbName),
+            erlang:monitor(process, IPid),
+            IPid
+    end,
+    {reply, {ok, Pid}, State#st{indexer=Pid}}.
 
 
 handle_cast({config_change, NewDelay}, State) ->
@@ -318,6 +342,15 @@ handle_info(commit, State) ->
             erlang:send_after(Delay, self(), commit),
             {noreply, State}
     end;
+
+handle_info({'DOWN', _, _, Pid, _}, #st{mod=Mod, idx_state=IdxState,
+                                        indexer=Pid}=State) ->
+    Args = [Mod:get(db_name, IdxState),
+            Mod:get(idx_name, IdxState)],
+    ?LOG_INFO("Background indexer shutdown by monitor notice for db: ~s idx: ~s", Args),
+
+    {noreply, State#st{indexer=nil}};
+
 handle_info({'DOWN', _, _, _Pid, _}, #st{mod=Mod, idx_state=IdxState}=State) ->
     DbName = Mod:get(db_name, IdxState),
     DDocId = Mod:get(idx_name, IdxState),

http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/blob/814ed50f/src/couch_index_indexer.erl
----------------------------------------------------------------------
diff --git a/src/couch_index_indexer.erl b/src/couch_index_indexer.erl
new file mode 100644
index 0000000..4af85cf
--- /dev/null
+++ b/src/couch_index_indexer.erl
@@ -0,0 +1,189 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couch_index_indexer).
+
+-export([start_link/2]).
+
+-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
+         terminate/2, code_change/3]).
+
+-record(state, {index,
+                dbname,
+                db_updates=0,
+                tref=nil,
+                notifier=nil,
+                locks}).
+
+
+start_link(Index, DbName) ->
+    gen_server:start_link(?MODULE, {Index, DbName}, []).
+
+init({Index, DbName}) ->
+    process_flag(trap_exit, true),
+    %% delay background index indexing
+    self() ! start_indexing,
+    {ok, #state{index=Index,
+                dbname=DbName,
+                locks=dict:new()}}.
+
+handle_call({acquire, Pid}, _From, #state{locks=Locks}=State) ->
+    NLocks = case dict:find(Pid, Locks) of
+        error ->
+            dict:store(Pid, {erlang:monitor(process, Pid), 1}, Locks);
+        {ok, {MRef, Refc}} ->
+             dict:store(Pid, {MRef, Refc+1}, Locks)
+    end,
+    {reply, ok, State#state{locks=NLocks}};
+
+handle_call({release, Pid}, _From, #state{locks=Locks}=State) ->
+     NLocks = case dict:find(Pid, Locks) of
+        {ok, {MRef, 1}} ->
+            erlang:demonitor(MRef, [flush]),
+            dict:erase(Pid, Locks);
+        {ok, {MRef, Refc}} ->
+            dict:store(Pid, {MRef, Refc-1}, Locks);
+        error ->
+            Locks
+    end,
+
+    NState = State#state{locks=NLocks},
+
+    case should_close() of
+        true -> {stop, normal, ok, NState};
+        false -> {reply, ok, NState}
+    end;
+
+handle_call(stop, _From, State) ->
+    {stop, normal, ok, State}.
+
+handle_cast(updated, #state{index=Index, dbname=DbName,
+                            db_updates=Updates}=State) ->
+    Threshold = get_db_threshold(),
+    NUpdates = Updates + 1,
+
+    %% we only update if the number of updates is greater than the
+    %% threshold.
+    case NUpdates =:= Threshold of
+        true ->
+            refresh_index(DbName, Index),
+            {noreply, State#state{db_updates=0}};
+        false ->
+             {noreply, State#state{db_updates=NUpdates}}
+
+    end;
+
+handle_cast(_Msg, State) ->
+    {noreply, State}.
+
+handle_info(start_indexing, #state{dbname=DbName}=State) ->
+    %% start the db notifier to watch db update events
+    {ok, NotifierPid} = start_db_notifier(DbName),
+
+    %% start the timer
+    R = get_refresh_interval(),
+    TRef = erlang:start_timer(R, self(), refresh_index),
+
+    {noreply, State#state{tref=TRef, notifier=NotifierPid}};
+
+handle_info({timeout, TRef, refresh_index}, #state{index=Index,
+                                                   dbname=DbName,
+                                                   tref=TRef,
+                                                   db_updates=N}=State) ->
+    %% only refresh the index if an update happened
+    case N > 0 of
+        true ->
+            refresh_index(DbName, Index);
+        false ->
+            ok
+    end,
+    {noreply, #state{db_updates=0}=State};
+
+handle_info({'DOWN', MRef, _, Pid, _}, #state{locks=Locks}=State) ->
+    NLocks = case dict:find(Pid, Locks) of
+        {ok, {MRef, _}} ->
+            dict:erase(Pid, Locks);
+        error ->
+            Locks
+    end,
+
+    NState = State#state{locks=NLocks},
+
+    case should_close() of
+        true -> {stop, normal, NState};
+        false -> {noreply, NState}
+    end;
+
+handle_info({'EXIT', Pid, _Reason}, #state{notifier=Pid}=State) ->
+    %% db notifier exited
+    {stop, normal, State#state{notifier=nil}}.
+
+code_change(_OldVsn, State, _Extra) ->
+    {ok, State}.
+
+terminate(_Reason, #state{tref=TRef, notifier=Pid}) ->
+    if TRef /= nil ->
+            erlang:cancel_timer(TRef);
+        true -> ok
+    end,
+
+    case is_pid(Pid) of
+        true -> couch_util:shutdown_sync(Pid);
+        _ -> ok
+    end,
+    ok.
+
+%% refresh the index to trigger updates.
+refresh_index(Db, Index) ->
+    UpdateSeq = couch_util:with_db(Db, fun(WDb) ->
+                    couch_db:get_update_seq(WDb)
+            end),
+
+    case catch couch_index:get_state(Index, UpdateSeq) of
+        {ok, _} -> ok;
+        Error -> {error, Error}
+    end.
+
+%% if none has acquired us, we could stop the server.
+should_close() ->
+    case process_info(self(), monitors) of
+        {monitors, []} ->   true;
+        _ ->                false
+    end.
+
+
+%% number of max updates before refreshing the index. We don't
+%% update the index on each db update. Instead we are waiting for a
+%% minimum. If the minimum is not acchieved, the update will happen
+%% in the next interval.
+get_db_threshold() ->
+    list_to_integer(
+            couch_config:get("couch_index", "threshold", "200")
+    ).
+
+%% refresh interval in ms, the interval in which the index will be
+%% updated
+get_refresh_interval() ->
+    list_to_integer(
+            couch_config:get("couch_index", "refresh_interval", "1000")
+    ).
+
+%% db notifier
+start_db_notifier(DbName) ->
+    Self = self(),
+
+    couch_db_update_notifier:start_link(fun
+            ({updated, Name}) when Name =:= DbName ->
+                gen_server:cast(Self, updated);
+            (_) ->
+                ok
+        end).

http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/blob/814ed50f/src/couch_index_server.erl
----------------------------------------------------------------------
diff --git a/src/couch_index_server.erl b/src/couch_index_server.erl
index 86791db..2c6ebc9 100644
--- a/src/couch_index_server.erl
+++ b/src/couch_index_server.erl
@@ -14,6 +14,7 @@
 -behaviour(gen_server).
 
 -export([start_link/0, get_index/4, get_index/3, get_index/2]).
+-export([acquire_indexer/3, release_indexer/3]).
 -export([config_change/2, update_notify/1]).
 
 -export([init/1, terminate/2, code_change/3]).
@@ -67,6 +68,23 @@ get_index(Module, IdxState) ->
             gen_server:call(?MODULE, {get_index, Args}, infinity)
     end.
 
+acquire_indexer(Module, DbName, DDoc) ->
+    case get_index(Module, DbName, DDoc) of
+        {ok, Pid} ->
+            couch_index:acquire_indexer(Pid);
+        Error ->
+            Error
+    end.
+
+release_indexer(Module, DbName, DDoc) ->
+    case get_index(Module, DbName, DDoc) of
+        {ok, Pid} ->
+            couch_index:release_indexer(Pid);
+        Error ->
+            Error
+    end.
+
+
 
 init([]) ->
     process_flag(trap_exit, true),


[07/12] couch-index commit: updated refs/heads/1994-merge-rcouch to 7c1666b

Posted by da...@apache.org.
remove Makefile.am from apps/ and fix couchspawnkillable


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/ab908352
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/tree/ab908352
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/diff/ab908352

Branch: refs/heads/1994-merge-rcouch
Commit: ab908352c53a84138e3cfd86dceb85fe94ca5fa3
Parents: 0981d12
Author: benoitc <be...@apache.org>
Authored: Tue Jan 7 19:15:43 2014 +0100
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Wed Feb 12 17:58:22 2014 -0600

----------------------------------------------------------------------
 Makefile.am | 40 ----------------------------------------
 1 file changed, 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/blob/ab908352/Makefile.am
----------------------------------------------------------------------
diff --git a/Makefile.am b/Makefile.am
deleted file mode 100644
index 2d4c593..0000000
--- a/Makefile.am
+++ /dev/null
@@ -1,40 +0,0 @@
-## Licensed under the Apache License, Version 2.0 (the "License"); you may not
-## use this file except in compliance with the License. You may obtain a copy of
-## the License at
-##
-##   http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-## WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-## License for the specific language governing permissions and limitations under
-## the License.
-
-couch_indexlibdir = $(localerlanglibdir)/couch_index-0.1
-couch_indexebindir = $(couch_indexlibdir)/ebin
-
-couch_indexebin_DATA = $(compiled_files)
-
-EXTRA_DIST = $(source_files)
-CLEANFILES = $(compiled_files)
-
-source_files = \
-    src/couch_index.erl \
-    src/couch_index_api.erl \
-    src/couch_index.app.src \
-    src/couch_index_compactor.erl \
-    src/couch_index_server.erl \
-    src/couch_index_updater.erl \
-    src/couch_index_util.erl
-
-compiled_files = \
-    ebin/couch_index.beam \
-    ebin/couch_index_compactor.beam \
-    ebin/couch_index_server.beam \
-    ebin/couch_index_updater.beam \
-    ebin/couch_index_util.beam
-
-ebin/%.beam: src/%.erl
-	@mkdir -p ebin/
-	$(ERLC) -I$(top_srcdir)/src/couchdb -o ebin/ $(ERLC_FLAGS) ${TEST} $<;
-


[04/12] couch-index commit: updated refs/heads/1994-merge-rcouch to 7c1666b

Posted by da...@apache.org.
inital move to rebar compilation

- move src/apps
- download dependencies using rebar
- replace ejson by jiffy
- replace couch_drv & couch_ejson_compare by couch_collate


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/9b030c4f
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/tree/9b030c4f
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/diff/9b030c4f

Branch: refs/heads/1994-merge-rcouch
Commit: 9b030c4fdc9e6e4ed1afdebb78529df5e564d927
Parents: 7a61bc8
Author: benoitc <be...@apache.org>
Authored: Mon Jan 6 21:12:45 2014 +0100
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Wed Feb 12 17:58:22 2014 -0600

----------------------------------------------------------------------
 src/couch_index.erl           | 4 +---
 src/couch_index_compactor.erl | 3 +--
 src/couch_index_server.erl    | 2 +-
 src/couch_index_updater.erl   | 2 +-
 src/couch_index_util.erl      | 3 +--
 5 files changed, 5 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/blob/9b030c4f/src/couch_index.erl
----------------------------------------------------------------------
diff --git a/src/couch_index.erl b/src/couch_index.erl
index df004b4..c09a110 100644
--- a/src/couch_index.erl
+++ b/src/couch_index.erl
@@ -23,9 +23,7 @@
 -export([init/1, terminate/2, code_change/3]).
 -export([handle_call/3, handle_cast/2, handle_info/2]).
 
-
--include("couch_db.hrl").
-
+-include_lib("couch/include/couch_db.hrl").
 
 -record(st, {
     mod,

http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/blob/9b030c4f/src/couch_index_compactor.erl
----------------------------------------------------------------------
diff --git a/src/couch_index_compactor.erl b/src/couch_index_compactor.erl
index 72bff51..6e9fb2e 100644
--- a/src/couch_index_compactor.erl
+++ b/src/couch_index_compactor.erl
@@ -22,8 +22,7 @@
 -export([handle_call/3, handle_cast/2, handle_info/2]).
 
 
--include("couch_db.hrl").
-
+-include_lib("couch/include/couch_db.hrl").
 
 -record(st, {
     idx,

http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/blob/9b030c4f/src/couch_index_server.erl
----------------------------------------------------------------------
diff --git a/src/couch_index_server.erl b/src/couch_index_server.erl
index 8e2baf6..7a7bd55 100644
--- a/src/couch_index_server.erl
+++ b/src/couch_index_server.erl
@@ -19,7 +19,7 @@
 -export([init/1, terminate/2, code_change/3]).
 -export([handle_call/3, handle_cast/2, handle_info/2]).
 
--include("couch_db.hrl").
+-include_lib("couch/include/couch_db.hrl").
 
 -define(BY_SIG, couchdb_indexes_by_sig).
 -define(BY_PID, couchdb_indexes_by_pid).

http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/blob/9b030c4f/src/couch_index_updater.erl
----------------------------------------------------------------------
diff --git a/src/couch_index_updater.erl b/src/couch_index_updater.erl
index c6d3059..9f54a56 100644
--- a/src/couch_index_updater.erl
+++ b/src/couch_index_updater.erl
@@ -21,7 +21,7 @@
 -export([init/1, terminate/2, code_change/3]).
 -export([handle_call/3, handle_cast/2, handle_info/2]).
 
--include("couch_db.hrl").
+-include_lib("couch/include/couch_db.hrl").
 
 -record(st, {
     idx,

http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/blob/9b030c4f/src/couch_index_util.erl
----------------------------------------------------------------------
diff --git a/src/couch_index_util.erl b/src/couch_index_util.erl
index 0b833d3..c833920 100644
--- a/src/couch_index_util.erl
+++ b/src/couch_index_util.erl
@@ -15,8 +15,7 @@
 -export([root_dir/0, index_dir/2, index_file/3]).
 -export([load_doc/3, sort_lib/1, hexsig/1]).
 
--include("couch_db.hrl").
-
+-include_lib("couch/include/couch_db.hrl").
 
 root_dir() ->
   couch_config:get("couchdb", "view_index_dir").


[02/12] couch-index commit: updated refs/heads/1994-merge-rcouch to 7c1666b

Posted by da...@apache.org.
add index update events notifications


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/e77ec75c
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/tree/e77ec75c
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/diff/e77ec75c

Branch: refs/heads/1994-merge-rcouch
Commit: e77ec75c51770f79db49d7529491338bf82a6db1
Parents: 62bddab
Author: benoitc <be...@apache.org>
Authored: Thu Jan 30 09:21:06 2014 +0100
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Wed Feb 12 17:58:22 2014 -0600

----------------------------------------------------------------------
 src/couch_index_event.erl     | 65 ++++++++++++++++++++++++++++++++++++++
 src/couch_index_event_sup.erl | 51 ++++++++++++++++++++++++++++++
 src/couch_index_sup.erl       |  7 +++-
 3 files changed, 122 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/blob/e77ec75c/src/couch_index_event.erl
----------------------------------------------------------------------
diff --git a/src/couch_index_event.erl b/src/couch_index_event.erl
new file mode 100644
index 0000000..0cd0a6b
--- /dev/null
+++ b/src/couch_index_event.erl
@@ -0,0 +1,65 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couch_index_event).
+-behaviour(gen_event).
+
+-export([start_link/1]).
+-export([notify/1]).
+-export([stop/1]).
+
+%% gen_event callbacks
+-export([init/1, handle_event/2, handle_call/2, handle_info/2,
+         terminate/2, code_change/3]).
+
+start_link(Consumer) ->
+    HandlerId = {?MODULE, make_ref()},
+    couch_index_event_sup:start_link(couch_index_events, HandlerId,
+                                     Consumer).
+
+notify(Event) ->
+    gen_event:notify(couch_index_events, Event).
+
+stop(Pid) ->
+    couch_index_event_sup:stop(Pid).
+
+
+init(Consumer) ->
+    process_flag(trap_exit, true),
+    {ok, Consumer}.
+
+handle_event(Event, Consumer) ->
+    dispatch_event(Event, Consumer).
+
+handle_call(_Req, Consumer) ->
+    {reply, ok, Consumer}.
+
+handle_info({'EXIT', _, _}, _Consumer) ->
+    remove_handler;
+handle_info(_Info, Consumer)->
+    {ok, Consumer}.
+
+code_change(_OldVsn, Consumer, _Extra) ->
+    {ok, Consumer}.
+
+terminate(_Reason, _consumer) ->
+    ok.
+
+dispatch_event(Event, Fun) when is_function(Fun) ->
+    Fun(Event),
+    {ok, Fun};
+dispatch_event(Event, {Fun, Acc}) when is_function(Fun) ->
+    Acc2 = Fun(Event, Acc),
+    {ok, {Fun, Acc2}};
+dispatch_event(Event, Pid) when is_pid(Pid) ->
+    Pid ! Event,
+    {ok, Pid}.

http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/blob/e77ec75c/src/couch_index_event_sup.erl
----------------------------------------------------------------------
diff --git a/src/couch_index_event_sup.erl b/src/couch_index_event_sup.erl
new file mode 100644
index 0000000..68cba43
--- /dev/null
+++ b/src/couch_index_event_sup.erl
@@ -0,0 +1,51 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couch_index_event_sup).
+
+-export([start_link/3]).
+-export([stop/1]).
+
+%% internal gen_server callbacks
+-export([init/1, terminate/2, handle_call/3, handle_cast/2,
+         handle_info/2,code_change/3]).
+
+start_link(EventMgr, EventHandler, Args) ->
+    gen_server:start_link(?MODULE, {EventMgr, EventHandler, Args}, []).
+
+stop(Pid) ->
+    gen_server:cast(Pid, stop).
+
+init({EventMgr, EventHandler, Args}) ->
+    case gen_event:add_sup_handler(EventMgr, EventHandler, Args) of
+    ok ->
+        {ok, {EventMgr, EventHandler}};
+    {stop, Error} ->
+        {stop, Error}
+    end.
+
+handle_call(_Whatever, _From, State) ->
+    {ok, State}.
+
+handle_cast(stop, State) ->
+    {stop, normal, State}.
+
+handle_info({gen_event_EXIT, _Handler, Reason}, State) ->
+    {stop, Reason, State}.
+
+code_change(_OldVsn, State, _Extra) ->
+    {ok, State}.
+
+terminate(_Reason, _State) ->
+    ok.
+
+

http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/blob/e77ec75c/src/couch_index_sup.erl
----------------------------------------------------------------------
diff --git a/src/couch_index_sup.erl b/src/couch_index_sup.erl
index fd97814..8e69016 100644
--- a/src/couch_index_sup.erl
+++ b/src/couch_index_sup.erl
@@ -26,4 +26,9 @@ start_link() ->
 
 init([]) ->
     Server = ?CHILD(couch_index_server),
-    {ok, {{one_for_one, 10, 3600}, [Server]}}.
+
+    EventSup = {couch_index_events,
+                {gen_event, start_link, [{local, couch_index_events}]},
+                permanent, brutal_kill, worker, dynamic},
+
+    {ok, {{one_for_one, 10, 3600}, [Server, EventSup]}}.


[06/12] couch-index commit: updated refs/heads/1994-merge-rcouch to 7c1666b

Posted by da...@apache.org.
working release


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/0981d127
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/tree/0981d127
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/diff/0981d127

Branch: refs/heads/1994-merge-rcouch
Commit: 0981d127b1aaf572ca89210f1eb27b3704f9196f
Parents: dc6a557
Author: benoitc <be...@apache.org>
Authored: Tue Jan 7 16:14:56 2014 +0100
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Wed Feb 12 17:58:22 2014 -0600

----------------------------------------------------------------------
 src/couch_index.app.src | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/blob/0981d127/src/couch_index.app.src
----------------------------------------------------------------------
diff --git a/src/couch_index.app.src b/src/couch_index.app.src
index 687a2e2..6a59e99 100644
--- a/src/couch_index.app.src
+++ b/src/couch_index.app.src
@@ -12,7 +12,7 @@
 
 {application, couch_index, [
     {description, "CouchDB Secondary Index Manager"},
-    {vsn, "@version@"},
+    {vsn, "1.3.0"},
     {modules, []},
     {registered, [couch_index_server]},
     {applications, [kernel, stdlib, couch]},


[05/12] couch-index commit: updated refs/heads/1994-merge-rcouch to 7c1666b

Posted by da...@apache.org.
make couch_index a standalone erlang app

With this change couch_index will be started by the release instead of
letting couchdb to start it. It also has its own supervision now.


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/dc6a557b
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/tree/dc6a557b
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/diff/dc6a557b

Branch: refs/heads/1994-merge-rcouch
Commit: dc6a557b13e38d64d77696aa4d0ecde1c85bc22c
Parents: 9b030c4
Author: benoitc <be...@apache.org>
Authored: Mon Jan 6 23:47:49 2014 +0100
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Wed Feb 12 17:58:22 2014 -0600

----------------------------------------------------------------------
 src/couch_index.app.src |  8 +++-----
 src/couch_index_app.erl | 27 +++++++++++++++++++++++++++
 src/couch_index_sup.erl | 30 ++++++++++++++++++++++++++++++
 3 files changed, 60 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/blob/dc6a557b/src/couch_index.app.src
----------------------------------------------------------------------
diff --git a/src/couch_index.app.src b/src/couch_index.app.src
index 141ed9d..687a2e2 100644
--- a/src/couch_index.app.src
+++ b/src/couch_index.app.src
@@ -13,10 +13,8 @@
 {application, couch_index, [
     {description, "CouchDB Secondary Index Manager"},
     {vsn, "@version@"},
-    {modules, [
-        couch_index,
-        couch_index_server
-    ]},
+    {modules, []},
     {registered, [couch_index_server]},
-    {applications, [kernel, stdlib]}
+    {applications, [kernel, stdlib, couch]},
+    {mod, {couch_index_app, []}}
 ]}.

http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/blob/dc6a557b/src/couch_index_app.erl
----------------------------------------------------------------------
diff --git a/src/couch_index_app.erl b/src/couch_index_app.erl
new file mode 100644
index 0000000..6bafdcb
--- /dev/null
+++ b/src/couch_index_app.erl
@@ -0,0 +1,27 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couch_index_app).
+
+-behaviour(application).
+
+-include_lib("couch/include/couch_db.hrl").
+
+-export([start/2, stop/1]).
+
+start(_Type, _Args) ->
+    couch_util:start_app_deps(couch_index),
+    couch_index_sup:start_link().
+
+
+stop(_) ->
+    ok.

http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/blob/dc6a557b/src/couch_index_sup.erl
----------------------------------------------------------------------
diff --git a/src/couch_index_sup.erl b/src/couch_index_sup.erl
new file mode 100644
index 0000000..d7b1033
--- /dev/null
+++ b/src/couch_index_sup.erl
@@ -0,0 +1,30 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couch_index_sup).
+-behaviour(supervisor).
+
+-export([start_link/0]).
+-export([init/1]).
+
+
+%% Helper macro for declaring children of supervisor
+-define(CHILD(I), {I, {I, start_link, []}, permanent, 5000, worker, [I]}).
+
+start_link() ->
+    supervisor:start_link({local, ?MODULE}, ?MODULE, []).
+
+
+init([]) ->
+    Server = ?CHILD(couch_index_server),
+    {ok, {{one_for_one, 10, 3600}, [Server]}}.
+


[09/12] couch-index commit: updated refs/heads/1994-merge-rcouch to 7c1666b

Posted by da...@apache.org.
couch_mrview: couch_mrview_changes:handle_changes

Similar to couch_changes:handle_changes but for view changes. It add
support for longpolling, normal and continuous stream The API differs
from the one for doc by beeing independant from the transport: the
support of HTTP will be added on top for example.

This API will be also used to replace the view filter in the current _changes
API.

Also add unittests.


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/c1e96031
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/tree/c1e96031
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/diff/c1e96031

Branch: refs/heads/1994-merge-rcouch
Commit: c1e960318253d51de74cadab7d049858e8d4ec8c
Parents: e77ec75
Author: benoitc <be...@apache.org>
Authored: Fri Jan 31 13:13:23 2014 +0100
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Wed Feb 12 17:58:22 2014 -0600

----------------------------------------------------------------------
 src/couch_index_server.erl | 7 +++++++
 1 file changed, 7 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/blob/c1e96031/src/couch_index_server.erl
----------------------------------------------------------------------
diff --git a/src/couch_index_server.erl b/src/couch_index_server.erl
index 86791db..facde14 100644
--- a/src/couch_index_server.erl
+++ b/src/couch_index_server.erl
@@ -159,6 +159,8 @@ reset_indexes(DbName, Root) ->
         MRef = erlang:monitor(process, Pid),
         gen_server:cast(Pid, delete),
         receive {'DOWN', MRef, _, _, _} -> ok end,
+        couch_index_event:notify({index_delete,
+                                  {DbName, DDocId, couch_mrview_index}}),
         rem_from_ets(DbName, Sig, DDocId, Pid)
     end,
     lists:foreach(Fun, ets:lookup(?BY_DB, DbName)),
@@ -193,6 +195,11 @@ update_notify({ddoc_updated, {DbName, DDocId}}) ->
         fun({_DbName, {_DDocId, Sig}}) ->
             case ets:lookup(?BY_SIG, {DbName, Sig}) of
                 [{_, IndexPid}] ->
+                    %% notify to event listeners that the index has been
+                    %% updated
+                    couch_index_event:notify({index_update,
+                                              {DbName, DDocId,
+                                               couch_mrview_index}}),
                     (catch gen_server:cast(IndexPid, ddoc_updated));
                 [] ->
                     ok


[11/12] couch-index commit: updated refs/heads/1994-merge-rcouch to 7c1666b

Posted by da...@apache.org.
couch_index: don't try to get the config each time in the indexer

Rather than fetching the threshold and refresh interval settings each
time we need them, register the process to couch_config events so we can
update the config only when needed.


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/7c1666ba
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/tree/7c1666ba
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/diff/7c1666ba

Branch: refs/heads/1994-merge-rcouch
Commit: 7c1666ba73641efd0a8eab76399f1794082085e2
Parents: 814ed50
Author: benoitc <be...@apache.org>
Authored: Sun Feb 9 09:47:24 2014 +0100
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Wed Feb 12 17:58:23 2014 -0600

----------------------------------------------------------------------
 src/couch_index_indexer.erl | 38 +++++++++++++++++++++++++++++++++++---
 1 file changed, 35 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/blob/7c1666ba/src/couch_index_indexer.erl
----------------------------------------------------------------------
diff --git a/src/couch_index_indexer.erl b/src/couch_index_indexer.erl
index 4af85cf..727c8dd 100644
--- a/src/couch_index_indexer.erl
+++ b/src/couch_index_indexer.erl
@@ -19,6 +19,8 @@
 
 -record(state, {index,
                 dbname,
+                threshold,
+                refresh_interval,
                 db_updates=0,
                 tref=nil,
                 notifier=nil,
@@ -30,10 +32,25 @@ start_link(Index, DbName) ->
 
 init({Index, DbName}) ->
     process_flag(trap_exit, true),
+    %% register to config events
+    Self = self(),
+    ok  = couch_config:register(fun
+                ("couch_index", "threshold") ->
+                    gen_server:cast(Self, config_threshold);
+                ("couch_index", "refresh_interval") ->
+                    gen_server:cast(Self, config_refresh)
+            end),
+
+    %% get defaults
+    Threshold = get_db_threshold(),
+    Refresh = get_refresh_interval(),
+
     %% delay background index indexing
     self() ! start_indexing,
     {ok, #state{index=Index,
                 dbname=DbName,
+                threshold=Threshold,
+                refresh_interval=Refresh,
                 locks=dict:new()}}.
 
 handle_call({acquire, Pid}, _From, #state{locks=Locks}=State) ->
@@ -66,9 +83,24 @@ handle_call({release, Pid}, _From, #state{locks=Locks}=State) ->
 handle_call(stop, _From, State) ->
     {stop, normal, ok, State}.
 
+
+handle_cast(config_threshold, State) ->
+    Threshold = get_db_threshold(),
+    {noreply, State#state{threshold=Threshold}};
+handle_cast(config_refresh, #state{tref=TRef}=State) ->
+    R = get_refresh_interval(),
+    %% stop the old timee
+    if TRef /= nil ->
+            erlang:cancel_timer(TRef);
+        true -> ok
+    end,
+    %% start the new timer
+    NTRef = erlang:start_timer(R, self(), refresh_index),
+    {noreply, State#state{refresh_interval=R, tref=NTRef}};
+
 handle_cast(updated, #state{index=Index, dbname=DbName,
+                            threshold=Threshold,
                             db_updates=Updates}=State) ->
-    Threshold = get_db_threshold(),
     NUpdates = Updates + 1,
 
     %% we only update if the number of updates is greater than the
@@ -85,12 +117,12 @@ handle_cast(updated, #state{index=Index, dbname=DbName,
 handle_cast(_Msg, State) ->
     {noreply, State}.
 
-handle_info(start_indexing, #state{dbname=DbName}=State) ->
+handle_info(start_indexing, #state{dbname=DbName,
+                                   refresh_interval=R}=State) ->
     %% start the db notifier to watch db update events
     {ok, NotifierPid} = start_db_notifier(DbName),
 
     %% start the timer
-    R = get_refresh_interval(),
     TRef = erlang:start_timer(R, self(), refresh_index),
 
     {noreply, State#state{tref=TRef, notifier=NotifierPid}};


[10/12] couch-index commit: updated refs/heads/1994-merge-rcouch to 7c1666b

Posted by da...@apache.org.
add `make test` target . all erlang test pass

note: from time to time there is a timing issue on 200- test that need
to be fixed. It is most probably due to the way the indexer is
supervised.


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/5ae0421f
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/tree/5ae0421f
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/diff/5ae0421f

Branch: refs/heads/1994-merge-rcouch
Commit: 5ae0421fa3ea720e42b113f0ee4dddd9285e7447
Parents: ab90835
Author: benoitc <be...@apache.org>
Authored: Thu Jan 9 16:24:32 2014 +0100
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Wed Feb 12 17:58:22 2014 -0600

----------------------------------------------------------------------
 src/couch_index_server.erl | 12 +++++++-----
 src/couch_index_sup.erl    |  1 -
 2 files changed, 7 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/blob/5ae0421f/src/couch_index_server.erl
----------------------------------------------------------------------
diff --git a/src/couch_index_server.erl b/src/couch_index_server.erl
index 7a7bd55..86791db 100644
--- a/src/couch_index_server.erl
+++ b/src/couch_index_server.erl
@@ -26,7 +26,8 @@
 -define(BY_DB, couchdb_indexes_by_db).
 
 
--record(st, {root_dir}).
+-record(st, {root_dir,
+             notifier_pid}).
 
 start_link() ->
     gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
@@ -73,10 +74,13 @@ init([]) ->
     ets:new(?BY_SIG, [protected, set, named_table]),
     ets:new(?BY_PID, [private, set, named_table]),
     ets:new(?BY_DB, [protected, bag, named_table]),
-    couch_db_update_notifier:start_link(fun ?MODULE:update_notify/1),
+
+    {ok, NotifierPid} = couch_db_update_notifier:start_link(
+            fun ?MODULE:update_notify/1),
     RootDir = couch_index_util:root_dir(),
     couch_file:init_delete_dir(RootDir),
-    {ok, #st{root_dir=RootDir}}.
+    {ok, #st{root_dir=RootDir,
+             notifier_pid=NotifierPid}}.
 
 
 terminate(_Reason, _State) ->
@@ -117,7 +121,6 @@ handle_cast({reset_indexes, DbName}, State) ->
     reset_indexes(DbName, State#st.root_dir),
     {noreply, State}.
 
-
 handle_info({'EXIT', Pid, Reason}, Server) ->
     case ets:lookup(?BY_PID, Pid) of
         [{Pid, {DbName, Sig}}] ->
@@ -198,4 +201,3 @@ update_notify({ddoc_updated, {DbName, DDocId}}) ->
         ets:match_object(?BY_DB, {DbName, {DDocId, '$1'}}));
 update_notify(_) ->
     ok.
-

http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/blob/5ae0421f/src/couch_index_sup.erl
----------------------------------------------------------------------
diff --git a/src/couch_index_sup.erl b/src/couch_index_sup.erl
index d7b1033..fd97814 100644
--- a/src/couch_index_sup.erl
+++ b/src/couch_index_sup.erl
@@ -27,4 +27,3 @@ start_link() ->
 init([]) ->
     Server = ?CHILD(couch_index_server),
     {ok, {{one_for_one, 10, 3600}, [Server]}}.
-


[08/12] couch-index commit: updated refs/heads/1994-merge-rcouch to 7c1666b

Posted by da...@apache.org.
extract couch_httpd changes API in its own module


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/ebb85be3
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/tree/ebb85be3
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/diff/ebb85be3

Branch: refs/heads/1994-merge-rcouch
Commit: ebb85be335c84c23178285142bcd09576c33c1d7
Parents: c1e9603
Author: benoitc <bc...@gmail.com>
Authored: Sun Feb 2 19:54:01 2014 +0100
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Wed Feb 12 17:58:22 2014 -0600

----------------------------------------------------------------------
 src/couch_index.erl | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-index/blob/ebb85be3/src/couch_index.erl
----------------------------------------------------------------------
diff --git a/src/couch_index.erl b/src/couch_index.erl
index c09a110..c48c066 100644
--- a/src/couch_index.erl
+++ b/src/couch_index.erl
@@ -219,9 +219,18 @@ handle_cast({new_state, NewIdxState}, State) ->
     } = State,
     assert_signature_match(Mod, OldIdxState, NewIdxState),
     CurrSeq = Mod:get(update_seq, NewIdxState),
+
+    DbName = Mod:get(db_name, NewIdxState),
+    DDocId = Mod:get(idx_name, NewIdxState),
+
+    %% notify to event listeners that the index has been
+    %% updated
+    couch_index_event:notify({index_update,
+                              {DbName, DDocId,
+                               Mod}}),
     Args = [
-        Mod:get(db_name, NewIdxState),
-        Mod:get(idx_name, NewIdxState),
+        DbName,
+        DDocId,
         CurrSeq
     ],
     ?LOG_DEBUG("Updated index for db: ~s idx: ~s seq: ~B", Args),
@@ -242,12 +251,27 @@ handle_cast(stop, State) ->
     {stop, normal, State};
 handle_cast(delete, State) ->
     #st{mod=Mod, idx_state=IdxState} = State,
+    DbName = Mod:get(db_name, IdxState),
+    DDocId = Mod:get(idx_name, IdxState),
+
     ok = Mod:delete(IdxState),
+
+    %% notify about the index deletion
+    couch_index_event:notify({index_delete,
+                              {DbName, DDocId, Mod}}),
+
     {stop, normal, State};
 handle_cast(ddoc_updated, State) ->
     #st{mod = Mod, idx_state = IdxState, waiters = Waiters} = State,
     DbName = Mod:get(db_name, IdxState),
     DDocId = Mod:get(idx_name, IdxState),
+
+    %% notify to event listeners that the index has been
+    %% updated
+    couch_index_event:notify({index_update,
+                              {DbName, DDocId,
+                               Mod}}),
+
     Shutdown = couch_util:with_db(DbName, fun(Db) ->
         case couch_db:open_doc(Db, DDocId, [ejson_body]) of
             {not_found, deleted} ->