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/13 17:59:47 UTC
[couchdb] 16/24: FIXUP: Crash the LRU if its evictor dies
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 3682de14fb8caf79ebeff3cf531aa11aa91db6cf
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Jul 10 13:24:15 2017 -0500
FIXUP: Crash the LRU if its evictor dies
The time between the process death and restart is a window where we
could miss eviction events which would lead to a temporarily inconsitent
cache. Given that we expect this to happen basically never we'll just
reuse the restart the world approach to maintaining consistency.
---
src/ddoc_cache/src/ddoc_cache_lru.erl | 9 +++------
src/ddoc_cache/test/ddoc_cache_coverage_test.erl | 18 ++++++++----------
2 files changed, 11 insertions(+), 16 deletions(-)
diff --git a/src/ddoc_cache/src/ddoc_cache_lru.erl b/src/ddoc_cache/src/ddoc_cache_lru.erl
index 2764959..ff70342 100644
--- a/src/ddoc_cache/src/ddoc_cache_lru.erl
+++ b/src/ddoc_cache/src/ddoc_cache_lru.erl
@@ -89,6 +89,7 @@ init(_) ->
{ok, Evictor} = couch_event:link_listener(
?MODULE, handle_db_event, nil, [all_dbs]
),
+ ?EVENT(lru_init, nil),
{ok, #st{
pids = Pids,
dbs = Dbs,
@@ -191,12 +192,8 @@ handle_cast(Msg, St) ->
{stop, {invalid_cast, Msg}, St}.
-handle_info({'EXIT', Pid, _Reason}, #st{evictor = Pid} = St) ->
- ?EVENT(evictor_died, Pid),
- {ok, Evictor} = couch_event:link_listener(
- ?MODULE, handle_db_event, nil, [all_dbs]
- ),
- {noreply, St#st{evictor=Evictor}};
+handle_info({'EXIT', Pid, Reason}, #st{evictor = Pid} = St) ->
+ {stop, Reason, St};
handle_info({'EXIT', Pid, normal}, St) ->
% This clause handles when an entry starts
diff --git a/src/ddoc_cache/test/ddoc_cache_coverage_test.erl b/src/ddoc_cache/test/ddoc_cache_coverage_test.erl
index 91182ca..57959f5 100644
--- a/src/ddoc_cache/test/ddoc_cache_coverage_test.erl
+++ b/src/ddoc_cache/test/ddoc_cache_coverage_test.erl
@@ -26,7 +26,7 @@ coverage_test_() ->
[
fun restart_lru/0,
fun restart_tables/0,
- fun restart_evictor/0
+ fun stop_on_evictor_death/0
]
}.
@@ -43,22 +43,20 @@ restart_tables() ->
?assertEqual({ok, foo}, ddoc_cache_tables:code_change(1, foo, [])).
-restart_evictor() ->
+stop_on_evictor_death() ->
meck:new(ddoc_cache_ev, [passthrough]),
try
- State = sys:get_state(ddoc_cache_lru),
+ Lru = whereis(ddoc_cache_lru),
+ State = sys:get_state(Lru),
Evictor = element(4, State),
- Ref = erlang:monitor(process, Evictor),
+ Ref = erlang:monitor(process, Lru),
exit(Evictor, shutdown),
receive
{'DOWN', Ref, _, _, Reason} ->
- couch_log:error("MONITOR: ~p", [Reason]),
- ok
+ ?assertEqual(shutdown, Reason)
end,
- meck:wait(ddoc_cache_ev, event, [evictor_died, '_'], 1000),
- NewState = sys:get_state(ddoc_cache_lru),
- NewEvictor = element(4, NewState),
- ?assertNotEqual(Evictor, NewEvictor)
+ meck:wait(ddoc_cache_ev, event, [lru_init, '_'], 1000),
+ ?assert(whereis(ddoc_cache_lru) /= Lru)
after
meck:unload()
end.
--
To stop receiving notification emails like this one, please contact
"commits@couchdb.apache.org" <co...@couchdb.apache.org>.