couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject [couchdb] 20/26: FIXUP: Prevent dirty reads from cache
Date Thu, 20 Jul 2017 19:05:33 GMT
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 f3f3510712eac747083537f3516e5fedc0f45d48
Author: Paul J. Davis <paul.joseph.davis@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" <commits@couchdb.apache.org>.

Mime
View raw message