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 2017/07/20 20:17:34 UTC

[couchdb] branch optimize-ddoc-cache updated (ee00280 -> bc8ddc1)

This is an automated email from the ASF dual-hosted git repository.

davisp pushed a change to branch optimize-ddoc-cache
in repository https://gitbox.apache.org/repos/asf/couchdb.git.


    omit ee00280  FIXUP: Process processes in the process of dying
     new bc8ddc1  FIXUP: Process processes in the process of dying

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (ee00280)
            \
             N -- N -- N   refs/heads/optimize-ddoc-cache (bc8ddc1)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/ddoc_cache/src/ddoc_cache_entry.erl       |  5 +++-
 src/ddoc_cache/test/ddoc_cache_entry_test.erl | 35 ++++++++++++++-------------
 2 files changed, 22 insertions(+), 18 deletions(-)

-- 
To stop receiving notification emails like this one, please contact
['"commits@couchdb.apache.org" <co...@couchdb.apache.org>'].

[couchdb] 01/01: FIXUP: Process processes in the process of dying

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch optimize-ddoc-cache
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit bc8ddc1a3c55f8d5ec82b05ba495d60006e7dcb7
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Thu Jul 20 14:02:57 2017 -0500

    FIXUP: Process processes in the process of dying
    
    Turns out we could go to evict an entry just after it had decided to
    leave the cache (i.e., its ddoc was just deleted). When that happens
    ddoc_cache_lru would die trying to shut the process down becuase the
    process died normal earlier than expected.
---
 src/ddoc_cache/src/ddoc_cache_entry.erl       | 23 ++++++++++++++++++-----
 src/ddoc_cache/test/ddoc_cache_entry_test.erl | 18 ++++++++++++++++++
 2 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/src/ddoc_cache/src/ddoc_cache_entry.erl b/src/ddoc_cache/src/ddoc_cache_entry.erl
index 63a2efa..ef6868e 100644
--- a/src/ddoc_cache/src/ddoc_cache_entry.erl
+++ b/src/ddoc_cache/src/ddoc_cache_entry.erl
@@ -45,6 +45,9 @@
 -include("ddoc_cache.hrl").
 
 
+-define(ENTRY_SHUTDOWN_TIMEOUT, 5000).
+
+
 -record(st, {
     key,
     val,
@@ -77,7 +80,17 @@ start_link(Key, Default) ->
 
 
 shutdown(Pid) ->
-    ok = gen_server:call(Pid, shutdown).
+    Ref = erlang:monitor(process, Pid),
+    ok = gen_server:cast(Pid, shutdown),
+    receive
+        {'DOWN', Ref, process, Pid, normal} ->
+            ok;
+        {'DOWN', Ref, process, Pid, Reason} ->
+            erlang:exit(Reason)
+    after ?ENTRY_SHUTDOWN_TIMEOUT ->
+        erlang:demonitor(Ref, [flush]),
+        erlang:exit({timeout, {entry_shutdown, Pid}})
+    end.
 
 
 open(Pid, Key) ->
@@ -170,10 +183,6 @@ handle_call(open, From, #st{opener = Pid} = St) when is_pid(Pid) ->
 handle_call(open, _From, St) ->
     {reply, St#st.val, St};
 
-handle_call(shutdown, _From, St) ->
-    remove_from_cache(St),
-    {stop, normal, ok, St};
-
 handle_call(Msg, _From, St) ->
     {stop, {bad_call, Msg}, {bad_call, Msg}, St}.
 
@@ -227,6 +236,10 @@ handle_cast(refresh, #st{opener = Pid} = St) when is_pid(Pid) ->
     },
     {noreply, NewSt};
 
+handle_cast(shutdown, St) ->
+    remove_from_cache(St),
+    {stop, normal, St};
+
 handle_cast(Msg, St) ->
     {stop, {bad_cast, Msg}, St}.
 
diff --git a/src/ddoc_cache/test/ddoc_cache_entry_test.erl b/src/ddoc_cache/test/ddoc_cache_entry_test.erl
index 381185c..49b24a9 100644
--- a/src/ddoc_cache/test/ddoc_cache_entry_test.erl
+++ b/src/ddoc_cache/test/ddoc_cache_entry_test.erl
@@ -137,3 +137,21 @@ handles_bad_messages(_) ->
 handles_code_change(_) ->
     CCExpect = {ok, bar},
     ?assertEqual(CCExpect, ddoc_cache_entry:code_change(foo, bar, baz)).
+
+
+handles_bad_shutdown_test_() ->
+    {timeout, 10, ?_test(begin
+        ErrorPid = spawn(fun() ->
+            receive
+               _ -> exit(bad_shutdown)
+            end
+        end),
+        ?assertExit(bad_shutdown, ddoc_cache_entry:shutdown(ErrorPid)),
+        NotDeadYetPid = spawn(fun() ->
+            timer:sleep(infinity)
+        end),
+        ?assertExit(
+                {timeout, {entry_shutdown, NotDeadYetPid}},
+                ddoc_cache_entry:shutdown(NotDeadYetPid)
+            )
+    end)}.

-- 
To stop receiving notification emails like this one, please contact
"commits@couchdb.apache.org" <co...@couchdb.apache.org>.