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/11 20:51:54 UTC

[couchdb] branch optimize-ddoc-cache updated: FIXUP: Prevent dirty reads from cache

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


The following commit(s) were added to refs/heads/optimize-ddoc-cache by this push:
     new f9fb65d  FIXUP: Prevent dirty reads from cache
f9fb65d is described below

commit f9fb65ddb85ec130e8d11d5bdcd773f554700a7c
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Tue Jul 11 15:51:35 2017 -0500

    FIXUP: Prevent dirty reads from cache
---
 src/ddoc_cache/src/ddoc_cache_entry.erl | 14 +++++---------
 src/ddoc_cache/src/ddoc_cache_lru.erl   |  7 ++++++-
 2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/ddoc_cache/src/ddoc_cache_entry.erl b/src/ddoc_cache/src/ddoc_cache_entry.erl
index f40ac40..0025904 100644
--- a/src/ddoc_cache/src/ddoc_cache_entry.erl
+++ b/src/ddoc_cache/src/ddoc_cache_entry.erl
@@ -129,7 +129,7 @@ init({Key, Wrapped}) ->
         key = Key,
         val = {open_ok, {ok, Default}},
         opener = start_timer(),
-        waiters = undefined,
+        waiters = [],
         ts = NewTs,
         accessed = 1
     },
@@ -161,7 +161,7 @@ terminate(_Reason, St) ->
     ok.
 
 
-handle_call(open, From, #st{val = undefined} = St) ->
+handle_call(open, From, #st{opener = Pid} = St) when is_pid(Pid) ->
     NewSt = St#st{
         waiters = [From | St#st.waiters]
     },
@@ -234,12 +234,10 @@ handle_info({'DOWN', _, _, Pid, Resp}, #st{key = Key, opener = Pid} = St) ->
             NewSt1 = St#st{
                 val = {open_ok, {ok, Val}},
                 opener = start_timer(),
-                waiters = undefined
+                waiters = []
             },
             NewSt2 = update_lru(NewSt1),
-            if not is_list(St#st.waiters) -> ok; true ->
-                respond(St#st.waiters, {open_ok, {ok, Val}})
-            end,
+            respond(St#st.waiters, {open_ok, {ok, Val}}),
             {noreply, NewSt2};
         {Status, Key, Other} ->
             NewSt = St#st{
@@ -248,9 +246,7 @@ handle_info({'DOWN', _, _, Pid, Resp}, #st{key = Key, opener = Pid} = St) ->
                 waiters = undefined
             },
             remove_from_cache(NewSt),
-            if not is_list(St#st.waiters) -> ok; true ->
-                respond(St#st.waiters, {Status, Other})
-            end,
+            respond(St#st.waiters, {Status, Other}),
             {stop, normal, NewSt}
     end;
 
diff --git a/src/ddoc_cache/src/ddoc_cache_lru.erl b/src/ddoc_cache/src/ddoc_cache_lru.erl
index 12f5d10..2d8a371 100644
--- a/src/ddoc_cache/src/ddoc_cache_lru.erl
+++ b/src/ddoc_cache/src/ddoc_cache_lru.erl
@@ -177,7 +177,12 @@ handle_cast({do_refresh, DbName, DDocIdList}, St) ->
             lists:foreach(fun(DDocId) ->
                 case khash:lookup(DDocIds, DDocId) of
                     {value, Keys} ->
-                        khash:fold(Keys, fun(_, Pid, _) ->
+                        khash:fold(Keys, fun(Key, Pid, _) ->
+                            % We're erasing the value from cache here
+                            % so that new clients will wait for the
+                            % refresh to complete.
+                            Op = [{#entry.val, undefined}],
+                            true = ets:update_element(?CACHE, Key, Op),
                             ddoc_cache_entry:refresh(Pid)
                         end, nil);
                     not_found ->

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