You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2014/08/28 14:17:43 UTC
[01/10] ddoc-cache commit: updated refs/heads/master to 4ffc6b0
Repository: couchdb-ddoc-cache
Updated Branches:
refs/heads/master f17c21fb6 -> 4ffc6b000
Update to use new couch_event application
Project: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/commit/41d82533
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/tree/41d82533
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/diff/41d82533
Branch: refs/heads/master
Commit: 41d82533aa59ca271619e822f4542faa5f3d028c
Parents: f17c21f
Author: Paul J. Davis <pa...@gmail.com>
Authored: Tue Apr 23 17:05:55 2013 -0500
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 11:26:06 2014 +0100
----------------------------------------------------------------------
src/ddoc_cache.app.src | 1 +
src/ddoc_cache_opener.erl | 24 +++++++++++++-----------
2 files changed, 14 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/blob/41d82533/src/ddoc_cache.app.src
----------------------------------------------------------------------
diff --git a/src/ddoc_cache.app.src b/src/ddoc_cache.app.src
index 55a108f..7d03bdf 100644
--- a/src/ddoc_cache.app.src
+++ b/src/ddoc_cache.app.src
@@ -28,6 +28,7 @@
kernel,
stdlib,
crypto,
+ couch_event,
ets_lru,
mem3,
fabric,
http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/blob/41d82533/src/ddoc_cache_opener.erl
----------------------------------------------------------------------
diff --git a/src/ddoc_cache_opener.erl b/src/ddoc_cache_opener.erl
index 0a0198e..c0a85b4 100644
--- a/src/ddoc_cache_opener.erl
+++ b/src/ddoc_cache_opener.erl
@@ -37,7 +37,7 @@
]).
-export([
- evictor/1
+ handle_db_event/3
]).
@@ -63,7 +63,9 @@ start_link() ->
init(_) ->
process_flag(trap_exit, true),
ets:new(?OPENING, [set, protected, named_table, {keypos, #opener.key}]),
- {ok, Evictor} = couch_db_update_notifier:start_link(fun ?MODULE:evictor/1),
+ {ok, Evictor} = couch_event:link_listener(
+ ?MODULE, handle_db_event, nil, [all_dbs]
+ ),
{ok, #st{
evictor = Evictor
}}.
@@ -127,7 +129,7 @@ handle_cast(Msg, St) ->
handle_info({'EXIT', Pid, Reason}, #st{evictor=Pid}=St) ->
couch_log:error("ddoc_cache_opener evictor died ~w", [Reason]),
- {ok, Evictor} = couch_db_update_notifier:start_link(fun ?MODULE:evictor/1),
+ {ok, Evictor} = couch_event:link_listener(?MODULE, evictor, nil, [all_dbs]),
{noreply, St#st{evictor=Evictor}};
handle_info({'EXIT', _Pid, {open_ok, Key, Resp}}, St) ->
@@ -157,14 +159,14 @@ code_change(_OldVsn, State, _Extra) ->
{ok, State}.
-evictor({created, ShardDbName}) ->
- DbName = mem3:dbname(ShardDbName),
- gen_server:cast(?MODULE, {evict, DbName});
-evictor({deleted, ShardDbName}) ->
- DbName = mem3:dbname(ShardDbName),
- gen_server:cast(?MODULE, {evict, DbName});
-evictor(_) ->
- ok.
+handle_db_event(ShardDbName, created, St) ->
+ gen_server:cast(?MODULE, {evict, mem3:dbname(ShardDbName)}),
+ {ok, St};
+handle_db_event(ShardDbName, deleted, St) ->
+ gen_server:cast(?MODULE, {evict, mem3:dbname(ShardDbName)}),
+ {ok, St};
+handle_db_event(_DbName, _Event, St) ->
+ {ok, St}.
open_ddoc({DbName, validation_funs}=Key) ->
[03/10] ddoc-cache commit: updated refs/heads/master to 4ffc6b0
Posted by rn...@apache.org.
Add a simple dialyzer task
This fixes a number of dialyzer warnings as well. Mostly for simple
missing matches. I'm not sure it's worth covering all of these cases
just yet but it wasn't hard for this code.
I've also included the ets_lru module in the dialyzer source to help
ensure that the new match APIs are used correctly. It will skip it
if it's not found on the default path or at ETS_LRU_PATH.
Project: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/commit/72f6af53
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/tree/72f6af53
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/diff/72f6af53
Branch: refs/heads/master
Commit: 72f6af5329f115a18b290b8b0c7031f0ad82520c
Parents: 6219808
Author: Brian Mitchell <br...@cloudant.com>
Authored: Thu Oct 10 16:50:38 2013 -0400
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 11:50:34 2014 +0100
----------------------------------------------------------------------
src/ddoc_cache_opener.erl | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/blob/72f6af53/src/ddoc_cache_opener.erl
----------------------------------------------------------------------
diff --git a/src/ddoc_cache_opener.erl b/src/ddoc_cache_opener.erl
index 56bfa7d..e949f60 100644
--- a/src/ddoc_cache_opener.erl
+++ b/src/ddoc_cache_opener.erl
@@ -43,6 +43,9 @@
-define(OPENING, ddoc_cache_opening).
+-type dbname() :: iodata().
+-type docid() :: iodata().
+-type revision() :: {integer(), binary()}.
-record(opener, {
key,
@@ -62,7 +65,7 @@ start_link() ->
init(_) ->
process_flag(trap_exit, true),
- ets:new(?OPENING, [set, protected, named_table, {keypos, #opener.key}]),
+ _ = ets:new(?OPENING, [set, protected, named_table, {keypos, #opener.key}]),
{ok, Evictor} = couch_event:link_listener(
?MODULE, handle_db_event, nil, [all_dbs]
),
@@ -144,7 +147,7 @@ handle_info({'EXIT', Pid, Reason}, St) ->
Pattern = #opener{pid=Pid, _='_'},
case ets:match_object(?OPENING, Pattern) of
[#opener{key=Key, clients=Clients}] ->
- [gen_server:reply(C, {error, Reason}) || C <- Clients],
+ _ = [gen_server:reply(C, {error, Reason}) || C <- Clients],
ets:delete(?OPENING, Key),
{noreply, St};
[] ->
@@ -169,6 +172,7 @@ handle_db_event(_DbName, _Event, St) ->
{ok, St}.
+-spec open_ddoc({dbname(), validation_funs | docid()}) -> no_return().
open_ddoc({DbName, validation_funs}=Key) ->
{ok, DDocs} = fabric:design_docs(mem3:dbname(DbName)),
Funs = lists:flatmap(fun(DDoc) ->
@@ -194,5 +198,5 @@ open_ddoc({DbName, DDocId}=Key) ->
respond(Key, Resp) ->
[#opener{clients=Clients}] = ets:lookup(?OPENING, Key),
- [gen_server:reply(C, Resp) || C <- Clients],
+ _ = [gen_server:reply(C, Resp) || C <- Clients],
ets:delete(?OPENING, Key).
[06/10] ddoc-cache commit: updated refs/heads/master to 4ffc6b0
Posted by rn...@apache.org.
Add support for keying the cache by revision
This patch splits up the code paths between ddoc_cache and
ddoc_cache_opener a bit more clearly, keeping the gen_server
implementation details "mostly" in one place. The overloaded
open function has been replaced with more explicit function
names. I've left the old open to support old code during the
upgrade process but it should be removed after the next release.
The opener lookup keys are a bit mismatched from the LRU keys so
I've renamed those variables to make it clear when we're talking
about the openers rather than the cache itself. It could be
argued that the revision oblivious doc lookup could reuse the
result of any pending revision specific lookup on the same id
but it seems a bit too optimistic here so I've left them as
separate opener keys.
Project: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/commit/41589453
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/tree/41589453
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/diff/41589453
Branch: refs/heads/master
Commit: 4158945359493733d0e7e94ca388146f145fcd53
Parents: 8ab9683
Author: Brian Mitchell <br...@cloudant.com>
Authored: Tue Oct 15 17:05:55 2013 -0400
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 11:56:44 2014 +0100
----------------------------------------------------------------------
src/ddoc_cache.erl | 86 ++++++++----------
src/ddoc_cache_opener.erl | 200 +++++++++++++++++++++++++++++------------
2 files changed, 181 insertions(+), 105 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/blob/41589453/src/ddoc_cache.erl
----------------------------------------------------------------------
diff --git a/src/ddoc_cache.erl b/src/ddoc_cache.erl
index e862667..6c54c36 100644
--- a/src/ddoc_cache.erl
+++ b/src/ddoc_cache.erl
@@ -12,70 +12,60 @@
-module(ddoc_cache).
+-include_lib("couch/include/couch_db.hrl").
--export([
- start/0,
- stop/0,
-
- open/2,
- evict/2
-]).
+-export([start/0, stop/0]).
+% public API
+-export([open_doc/2, open_doc/3, open_validation_funs/1, evict/2]).
--define(CACHE, ddoc_cache_lru).
--define(OPENER, ddoc_cache_opener).
-
+% deprecated API
+-export([open/2]).
start() ->
application:start(ddoc_cache).
-
stop() ->
application:stop(ddoc_cache).
+open_doc(DbName, DocId) ->
+ Key = {DbName, DocId, '_'},
+ case ddoc_cache_opener:match_newest(Key) of
+ {ok, _} = Resp ->
+ Resp;
+ missing ->
+ ddoc_cache_opener:open_doc(DbName, DocId);
+ recover ->
+ ddoc_cache_opener:recover_doc(DbName, DocId)
+ end.
-open(DbName, validation_funs) ->
- open({DbName, validation_funs});
-open(DbName, <<"_design/", _/binary>>=DDocId) when is_binary(DbName) ->
- open({DbName, DDocId});
-open(DbName, DDocId) when is_binary(DDocId) ->
- open({DbName, <<"_design/", DDocId/binary>>}).
-
-
-open(Key) ->
- try ets_lru:lookup_d(?CACHE, Key) of
+open_doc(DbName, DocId, RevId) ->
+ Key = {DbName, DocId, RevId},
+ case ddoc_cache_opener:lookup(Key) of
{ok, _} = Resp ->
Resp;
- _ ->
- case gen_server:call(?OPENER, {open, Key}, infinity) of
- {open_ok, Resp} ->
- Resp;
- {open_error, throw, Error} ->
- throw(Error);
- {open_error, error, Error} ->
- erlang:error(Error);
- {open_error, exit, Error} ->
- exit(Error)
- end
- catch
- error:badarg ->
- recover(Key)
+ missing ->
+ ddoc_cache_opener:open_doc(DbName, DocId, RevId);
+ recover ->
+ ddoc_cache_opener:recover_doc(DbName, DocId, RevId)
end.
+open_validation_funs(DbName) ->
+ Key = {DbName, validation_funs},
+ case ddoc_cache_opener:lookup(Key) of
+ {ok, _} = Resp ->
+ Resp;
+ missing ->
+ ddoc_cache_opener:open_validation_funs(DbName);
+ recover ->
+ ddoc_cache_opener:recover_validation_funs(DbName)
+ end.
evict(ShardDbName, DDocIds) ->
DbName = mem3:dbname(ShardDbName),
- gen_server:cast(?OPENER, {evict, DbName, DDocIds}).
-
+ ddoc_cache_opener:evict_docs(DbName, DDocIds).
-recover({DbName, validation_funs}) ->
- {ok, DDocs} = fabric:design_docs(mem3:dbname(DbName)),
- Funs = lists:flatmap(fun(DDoc) ->
- case couch_doc:get_validate_doc_fun(DDoc) of
- nil -> [];
- Fun -> [Fun]
- end
- end, DDocs),
- {ok, Funs};
-recover({DbName, DDocId}) ->
- fabric:open_doc(DbName, DDocId, [ejson_body]).
+open(DbName, validation_funs) ->
+ open_validation_funs(DbName);
+open(DbName, DocId) ->
+ open_doc(DbName, DocId).
http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/blob/41589453/src/ddoc_cache_opener.erl
----------------------------------------------------------------------
diff --git a/src/ddoc_cache_opener.erl b/src/ddoc_cache_opener.erl
index b34359f..780f9dd 100644
--- a/src/ddoc_cache_opener.erl
+++ b/src/ddoc_cache_opener.erl
@@ -13,38 +13,49 @@
-module(ddoc_cache_opener).
-behaviour(gen_server).
+-include_lib("couch/include/couch_db.hrl").
-include_lib("mem3/include/mem3.hrl").
--export([
- start_link/0
-]).
+% worker API
+-export([start_link/0]).
+% public API
-export([
- open_ddoc/1
+ open_doc/2,
+ open_doc/3,
+ open_validation_funs/1,
+ evict_docs/2,
+ lookup/1,
+ match_newest/1,
+ recover_doc/2,
+ recover_doc/3,
+ recover_validation_funs/1
]).
+% couch_event listener callback
+-export([handle_db_event/3]).
+
+% gen_server behavior
-export([
init/1,
terminate/2,
-
handle_call/3,
handle_cast/2,
handle_info/2,
-
code_change/3
]).
+% sub-process spawn API
-export([
- handle_db_event/3
+ fetch_doc_data/1
]).
-
-define(CACHE, ddoc_cache_lru).
-define(OPENING, ddoc_cache_opening).
-type dbname() :: iodata().
-type docid() :: iodata().
--type revision() :: {integer(), binary()}.
+-type revision() :: {pos_integer(), <<_:128>>}.
-record(opener, {
key,
@@ -57,10 +68,78 @@
evictor
}).
-
start_link() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
+-spec open_doc(dbname(), docid()) -> {ok, #doc{}}.
+open_doc(DbName, DocId) ->
+ Resp = gen_server:call(?MODULE, {open, {DbName, DocId}}, infinity),
+ handle_open_response(Resp).
+
+-spec open_doc(dbname(), docid(), revision()) -> {ok, #doc{}}.
+open_doc(DbName, DocId, RevId) ->
+ Resp = gen_server:call(?MODULE, {open, {DbName, DocId, RevId}}, infinity),
+ handle_open_response(Resp).
+
+-spec open_validation_funs(dbname()) -> {ok, [fun()]}.
+open_validation_funs(DbName) ->
+ Resp = gen_server:call(?MODULE, {open, {DbName, validation_funs}}, infinity),
+ handle_open_response(Resp).
+
+-spec evict_docs(dbname(), [docid()]) -> ok.
+evict_docs(DbName, DocIds) ->
+ gen_server:cast(?MODULE, {evict, DbName, DocIds}).
+
+lookup(Key) ->
+ try ets_lru:lookup_d(?CACHE, Key) of
+ {ok, _} = Resp ->
+ Resp;
+ _ ->
+ missing
+ catch
+ error:badarg ->
+ recover
+ end.
+
+match_newest(Key) ->
+ try ets_lru:match_object(?CACHE, Key, '_') of
+ [] ->
+ missing;
+ Docs ->
+ Sorted = lists:sort(fun (#doc{revs=L}, #doc{revs=R}) ->
+ L >= R
+ end, Docs),
+ {ok, hd(Sorted)}
+ catch
+ error:badarg ->
+ recover
+ end.
+
+recover_doc(DbName, DDocId) ->
+ fabric:open_doc(DbName, DDocId, []).
+
+recover_doc(DbName, DDocId, RevId) ->
+ {ok, [Resp]} = fabric:open_revs(DbName, DDocId, [RevId], []),
+ Resp.
+
+recover_validation_funs(DbName) ->
+ {ok, DDocs} = fabric:design_docs(mem3:dbname(DbName)),
+ Funs = lists:flatmap(fun(DDoc) ->
+ case couch_doc:get_validate_doc_fun(DDoc) of
+ nil -> [];
+ Fun -> [Fun]
+ end
+ end, DDocs),
+ {ok, Funs}.
+
+handle_db_event(ShardDbName, created, St) ->
+ gen_server:cast(?MODULE, {evict, mem3:dbname(ShardDbName)}),
+ {ok, St};
+handle_db_event(ShardDbName, deleted, St) ->
+ gen_server:cast(?MODULE, {evict, mem3:dbname(ShardDbName)}),
+ {ok, St};
+handle_db_event(_DbName, _Event, St) ->
+ {ok, St}.
init(_) ->
process_flag(trap_exit, true),
@@ -72,7 +151,6 @@ init(_) ->
evictor = Evictor
}}.
-
terminate(_Reason, St) ->
case is_pid(St#st.evictor) of
true -> exit(St#st.evictor, kill);
@@ -80,15 +158,14 @@ terminate(_Reason, St) ->
end,
ok.
-
-handle_call({open, {_DbName, _DDocId}=Key}, From, St) ->
- case ets:lookup(?OPENING, Key) of
+handle_call({open, OpenerKey}, From, St) ->
+ case ets:lookup(?OPENING, OpenerKey) of
[#opener{clients=Clients}=O] ->
ets:insert(?OPENING, O#opener{clients=[From | Clients]}),
{noreply, St};
[] ->
- Pid = spawn_link(?MODULE, open_ddoc, [Key]),
- ets:insert(?OPENING, #opener{key=Key, pid=Pid, clients=[From]}),
+ Pid = spawn_link(?MODULE, fetch_doc_data, [OpenerKey]),
+ ets:insert(?OPENING, #opener{key=OpenerKey, pid=Pid, clients=[From]}),
{noreply, St}
end;
@@ -105,39 +182,41 @@ handle_cast({evict, DbName, DDocIds}, St) ->
{noreply, St};
handle_cast({do_evict, DbName}, St) ->
- DDocIds = ets_lru:match(?CACHE, {DbName, '$1'}, '_'),
+ DDocIds = lists:flatten(ets_lru:match(?CACHE, {DbName, '$1', '_'}, '_')),
handle_cast({do_evict, DbName, DDocIds}, St);
handle_cast({do_evict, DbName, DDocIds}, St) ->
ets_lru:remove(?CACHE, {DbName, validation_funs}),
lists:foreach(fun(DDocId) ->
- ets_lru:remove(?CACHE, {DbName, DDocId})
+ RevIds = ets_lru:match(?CACHE, {DbName, DDocId, '$1'}, '_'),
+ lists:foreach(fun([RevId]) ->
+ ets_lru:remove(?CACHE, {DbName, DDocId, RevId})
+ end, RevIds)
end, DDocIds),
{noreply, St};
handle_cast(Msg, St) ->
{stop, {invalid_cast, Msg}, St}.
-
handle_info({'EXIT', Pid, Reason}, #st{evictor=Pid}=St) ->
couch_log:error("ddoc_cache_opener evictor died ~w", [Reason]),
{ok, Evictor} = couch_event:link_listener(?MODULE, handle_db_event, nil, [all_dbs]),
{noreply, St#st{evictor=Evictor}};
-handle_info({'EXIT', _Pid, {open_ok, Key, Resp}}, St) ->
- respond(Key, {open_ok, Resp}),
+handle_info({'EXIT', _Pid, {open_ok, OpenerKey, Resp}}, St) ->
+ respond(OpenerKey, {open_ok, Resp}),
{noreply, St};
-handle_info({'EXIT', _Pid, {open_error, Key, Type, Error}}, St) ->
- respond(Key, {open_error, Type, Error}),
+handle_info({'EXIT', _Pid, {open_error, OpenerKey, Type, Error}}, St) ->
+ respond(OpenerKey, {open_error, Type, Error}),
{noreply, St};
handle_info({'EXIT', Pid, Reason}, St) ->
Pattern = #opener{pid=Pid, _='_'},
case ets:match_object(?OPENING, Pattern) of
- [#opener{key=Key, clients=Clients}] ->
+ [#opener{key=OpenerKey, clients=Clients}] ->
_ = [gen_server:reply(C, {error, Reason}) || C <- Clients],
- ets:delete(?OPENING, Key),
+ ets:delete(?OPENING, OpenerKey),
{noreply, St};
[] ->
{stop, {unknown_pid_died, {Pid, Reason}}, St}
@@ -146,46 +225,53 @@ handle_info({'EXIT', Pid, Reason}, St) ->
handle_info(Msg, St) ->
{stop, {invalid_info, Msg}, St}.
-
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
-
-handle_db_event(ShardDbName, created, St) ->
- gen_server:cast(?MODULE, {evict, mem3:dbname(ShardDbName)}),
- {ok, St};
-handle_db_event(ShardDbName, deleted, St) ->
- gen_server:cast(?MODULE, {evict, mem3:dbname(ShardDbName)}),
- {ok, St};
-handle_db_event(_DbName, _Event, St) ->
- {ok, St}.
-
-
--spec open_ddoc({dbname(), validation_funs | docid()}) -> no_return().
-open_ddoc({DbName, validation_funs}=Key) ->
- {ok, DDocs} = fabric:design_docs(mem3:dbname(DbName)),
- Funs = lists:flatmap(fun(DDoc) ->
- case couch_doc:get_validate_doc_fun(DDoc) of
- nil -> [];
- Fun -> [Fun]
- end
- end, DDocs),
- ok = ets_lru:insert(?CACHE, {DbName, validation_funs}, Funs),
- exit({open_ok, Key, {ok, Funs}});
-open_ddoc({DbName, DDocId}=Key) ->
- try fabric:open_doc(DbName, DDocId, [ejson_body]) of
+-spec fetch_doc_data({dbname(), validation_funs}) -> no_return();
+ ({dbname(), docid()}) -> no_return();
+ ({dbname(), docid(), revision()}) -> no_return().
+fetch_doc_data({DbName, validation_funs}) ->
+ OpenerKey = {DbName, validation_funs},
+ {ok, Funs} = recover_validation_funs(DbName),
+ ok = ets_lru:insert(?CACHE, OpenerKey, Funs),
+ exit({open_ok, OpenerKey, {ok, Funs}});
+fetch_doc_data({DbName, DocId}) ->
+ OpenerKey = {DbName, DocId},
+ try recover_doc(DbName, DocId) of
{ok, Doc} ->
- ok = ets_lru:insert(?CACHE, {DbName, DDocId}, Doc),
- exit({open_ok, Key, {ok, Doc}});
+ {RevCount, [RevHash| _]} = Doc#doc.revs,
+ RevId = {RevCount, RevHash},
+ ok = ets_lru:insert(?CACHE, {DbName, DocId, RevId}, Doc),
+ exit({open_ok, OpenerKey, {ok, Doc}});
Else ->
- exit({open_ok, Key, Else})
+ exit({open_ok, OpenerKey, Else})
catch
Type:Reason ->
- exit({open_error, Key, Type, Reason})
+ exit({open_error, OpenerKey, Type, Reason})
+ end;
+fetch_doc_data({DbName, DocId, RevId}) ->
+ OpenerKey = {DbName, DocId, RevId},
+ try recover_doc(DbName, DocId, RevId) of
+ {ok, Doc} ->
+ ok = ets_lru:insert(?CACHE, {DbName, DocId, RevId}, Doc),
+ exit({open_ok, OpenerKey, {ok, Doc}});
+ Else ->
+ exit({open_ok, OpenerKey, Else})
+ catch
+ Type:Reason ->
+ exit({open_error, OpenerKey, Type, Reason})
end.
+handle_open_response(Resp) ->
+ case Resp of
+ {open_ok, Value} -> Value;
+ {open_error, throw, Error} -> throw(Error);
+ {open_error, error, Error} -> erlang:error(Error);
+ {open_error, exit, Error} -> exit(Error)
+ end.
-respond(Key, Resp) ->
- [#opener{clients=Clients}] = ets:lookup(?OPENING, Key),
+respond(OpenerKey, Resp) ->
+ [#opener{clients=Clients}] = ets:lookup(?OPENING, OpenerKey),
_ = [gen_server:reply(C, Resp) || C <- Clients],
- ets:delete(?OPENING, Key).
+ ets:delete(?OPENING, OpenerKey).
[08/10] ddoc-cache commit: updated refs/heads/master to 4ffc6b0
Posted by rn...@apache.org.
set module version to 1
Project: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/commit/64bab939
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/tree/64bab939
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/diff/64bab939
Branch: refs/heads/master
Commit: 64bab93937b2df855027da5d75ff565268eae631
Parents: 5f5c289
Author: Robert Newson <ro...@cloudant.com>
Authored: Fri Nov 22 16:38:03 2013 +0000
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 11:57:08 2014 +0100
----------------------------------------------------------------------
src/ddoc_cache_opener.erl | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/blob/64bab939/src/ddoc_cache_opener.erl
----------------------------------------------------------------------
diff --git a/src/ddoc_cache_opener.erl b/src/ddoc_cache_opener.erl
index 2563cc2..168b455 100644
--- a/src/ddoc_cache_opener.erl
+++ b/src/ddoc_cache_opener.erl
@@ -12,6 +12,7 @@
-module(ddoc_cache_opener).
-behaviour(gen_server).
+-vsn(1).
-include_lib("couch/include/couch_db.hrl").
-include_lib("mem3/include/mem3.hrl").
[07/10] ddoc-cache commit: updated refs/heads/master to 4ffc6b0
Posted by rn...@apache.org.
Address code review feedback
Summary:
* removed the useless include inside ddoc_cache
* revised the export listing style and removed confusing comments
* added guards back to older ddoc_cache:open/2 API
* clarified a type declaration, still strict until it's moved
* replaced match_newest sort with the canonical comparison rule
* simplified setting of the OpenerKey in some clauses
* renamed Rev* variables for correctness
* added back precious whitespace in some places
Project: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/commit/5f5c289f
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/tree/5f5c289f
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/diff/5f5c289f
Branch: refs/heads/master
Commit: 5f5c289fd75843faaf9a8f5d05739f4e7eeb6e68
Parents: 4158945
Author: Brian Mitchell <br...@p2p.io>
Authored: Wed Oct 23 23:02:00 2013 -0400
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 11:56:58 2014 +0100
----------------------------------------------------------------------
src/ddoc_cache.erl | 25 +++++++++-----
src/ddoc_cache_opener.erl | 75 ++++++++++++++++++++----------------------
2 files changed, 52 insertions(+), 48 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/blob/5f5c289f/src/ddoc_cache.erl
----------------------------------------------------------------------
diff --git a/src/ddoc_cache.erl b/src/ddoc_cache.erl
index 6c54c36..40d9467 100644
--- a/src/ddoc_cache.erl
+++ b/src/ddoc_cache.erl
@@ -12,15 +12,20 @@
-module(ddoc_cache).
--include_lib("couch/include/couch_db.hrl").
+-export([
+ start/0,
+ stop/0
+]).
--export([start/0, stop/0]).
+-export([
+ open_doc/2,
+ open_doc/3,
+ open_validation_funs/1,
+ evict/2,
-% public API
--export([open_doc/2, open_doc/3, open_validation_funs/1, evict/2]).
-
-% deprecated API
--export([open/2]).
+ %% deprecated
+ open/2
+]).
start() ->
application:start(ddoc_cache).
@@ -67,5 +72,7 @@ evict(ShardDbName, DDocIds) ->
open(DbName, validation_funs) ->
open_validation_funs(DbName);
-open(DbName, DocId) ->
- open_doc(DbName, DocId).
+open(DbName, <<"_design/", _/binary>>=DDocId) when is_binary(DbName) ->
+ open_doc(DbName, DDocId);
+open(DbName, DDocId) when is_binary(DDocId) ->
+ open_doc(DbName, <<"_design/", DDocId/binary>>).
http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/blob/5f5c289f/src/ddoc_cache_opener.erl
----------------------------------------------------------------------
diff --git a/src/ddoc_cache_opener.erl b/src/ddoc_cache_opener.erl
index 780f9dd..2563cc2 100644
--- a/src/ddoc_cache_opener.erl
+++ b/src/ddoc_cache_opener.erl
@@ -16,10 +16,20 @@
-include_lib("couch/include/couch_db.hrl").
-include_lib("mem3/include/mem3.hrl").
-% worker API
--export([start_link/0]).
+-export([
+ start_link/0
+]).
+-export([
+ init/1,
+ terminate/2,
+
+ handle_call/3,
+ handle_cast/2,
+ handle_info/2,
+
+ code_change/3
+]).
-% public API
-export([
open_doc/2,
open_doc/3,
@@ -31,21 +41,9 @@
recover_doc/3,
recover_validation_funs/1
]).
-
-% couch_event listener callback
--export([handle_db_event/3]).
-
-% gen_server behavior
-export([
- init/1,
- terminate/2,
- handle_call/3,
- handle_cast/2,
- handle_info/2,
- code_change/3
+ handle_db_event/3
]).
-
-% sub-process spawn API
-export([
fetch_doc_data/1
]).
@@ -55,7 +53,8 @@
-type dbname() :: iodata().
-type docid() :: iodata().
--type revision() :: {pos_integer(), <<_:128>>}.
+-type doc_hash() :: <<_:128>>.
+-type revision() :: {pos_integer(), doc_hash()}.
-record(opener, {
key,
@@ -77,8 +76,8 @@ open_doc(DbName, DocId) ->
handle_open_response(Resp).
-spec open_doc(dbname(), docid(), revision()) -> {ok, #doc{}}.
-open_doc(DbName, DocId, RevId) ->
- Resp = gen_server:call(?MODULE, {open, {DbName, DocId, RevId}}, infinity),
+open_doc(DbName, DocId, Rev) ->
+ Resp = gen_server:call(?MODULE, {open, {DbName, DocId, Rev}}, infinity),
handle_open_response(Resp).
-spec open_validation_funs(dbname()) -> {ok, [fun()]}.
@@ -106,9 +105,10 @@ match_newest(Key) ->
[] ->
missing;
Docs ->
- Sorted = lists:sort(fun (#doc{revs=L}, #doc{revs=R}) ->
- L >= R
- end, Docs),
+ Sorted = lists:sort(
+ fun (#doc{deleted=DelL, revs=L}, #doc{deleted=DelR, revs=R}) ->
+ {not DelL, L} > {not DelR, R}
+ end, Docs),
{ok, hd(Sorted)}
catch
error:badarg ->
@@ -118,8 +118,8 @@ match_newest(Key) ->
recover_doc(DbName, DDocId) ->
fabric:open_doc(DbName, DDocId, []).
-recover_doc(DbName, DDocId, RevId) ->
- {ok, [Resp]} = fabric:open_revs(DbName, DDocId, [RevId], []),
+recover_doc(DbName, DDocId, Rev) ->
+ {ok, [Resp]} = fabric:open_revs(DbName, DDocId, [Rev], []),
Resp.
recover_validation_funs(DbName) ->
@@ -188,10 +188,10 @@ handle_cast({do_evict, DbName}, St) ->
handle_cast({do_evict, DbName, DDocIds}, St) ->
ets_lru:remove(?CACHE, {DbName, validation_funs}),
lists:foreach(fun(DDocId) ->
- RevIds = ets_lru:match(?CACHE, {DbName, DDocId, '$1'}, '_'),
- lists:foreach(fun([RevId]) ->
- ets_lru:remove(?CACHE, {DbName, DDocId, RevId})
- end, RevIds)
+ Revs = ets_lru:match(?CACHE, {DbName, DDocId, '$1'}, '_'),
+ lists:foreach(fun([Rev]) ->
+ ets_lru:remove(?CACHE, {DbName, DDocId, Rev})
+ end, Revs)
end, DDocIds),
{noreply, St};
@@ -231,18 +231,16 @@ code_change(_OldVsn, State, _Extra) ->
-spec fetch_doc_data({dbname(), validation_funs}) -> no_return();
({dbname(), docid()}) -> no_return();
({dbname(), docid(), revision()}) -> no_return().
-fetch_doc_data({DbName, validation_funs}) ->
- OpenerKey = {DbName, validation_funs},
+fetch_doc_data({DbName, validation_funs}=OpenerKey) ->
{ok, Funs} = recover_validation_funs(DbName),
ok = ets_lru:insert(?CACHE, OpenerKey, Funs),
exit({open_ok, OpenerKey, {ok, Funs}});
-fetch_doc_data({DbName, DocId}) ->
- OpenerKey = {DbName, DocId},
+fetch_doc_data({DbName, DocId}=OpenerKey) ->
try recover_doc(DbName, DocId) of
{ok, Doc} ->
- {RevCount, [RevHash| _]} = Doc#doc.revs,
- RevId = {RevCount, RevHash},
- ok = ets_lru:insert(?CACHE, {DbName, DocId, RevId}, Doc),
+ {RevDepth, [RevHash| _]} = Doc#doc.revs,
+ Rev = {RevDepth, RevHash},
+ ok = ets_lru:insert(?CACHE, {DbName, DocId, Rev}, Doc),
exit({open_ok, OpenerKey, {ok, Doc}});
Else ->
exit({open_ok, OpenerKey, Else})
@@ -250,11 +248,10 @@ fetch_doc_data({DbName, DocId}) ->
Type:Reason ->
exit({open_error, OpenerKey, Type, Reason})
end;
-fetch_doc_data({DbName, DocId, RevId}) ->
- OpenerKey = {DbName, DocId, RevId},
- try recover_doc(DbName, DocId, RevId) of
+fetch_doc_data({DbName, DocId, Rev}=OpenerKey) ->
+ try recover_doc(DbName, DocId, Rev) of
{ok, Doc} ->
- ok = ets_lru:insert(?CACHE, {DbName, DocId, RevId}, Doc),
+ ok = ets_lru:insert(?CACHE, {DbName, DocId, Rev}, Doc),
exit({open_ok, OpenerKey, {ok, Doc}});
Else ->
exit({open_ok, OpenerKey, Else})
[09/10] ddoc-cache commit: updated refs/heads/master to 4ffc6b0
Posted by rn...@apache.org.
Load design docs with an ejson body
Project: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/commit/d9bc36ff
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/tree/d9bc36ff
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/diff/d9bc36ff
Branch: refs/heads/master
Commit: d9bc36ff4c32711ab128e3b6491ade0ae8ed415d
Parents: 64bab93
Author: Paul J. Davis <pa...@gmail.com>
Authored: Thu Aug 14 12:47:51 2014 -0500
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Thu Aug 14 12:47:51 2014 -0500
----------------------------------------------------------------------
src/ddoc_cache_opener.erl | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/blob/d9bc36ff/src/ddoc_cache_opener.erl
----------------------------------------------------------------------
diff --git a/src/ddoc_cache_opener.erl b/src/ddoc_cache_opener.erl
index 168b455..1ef3ec8 100644
--- a/src/ddoc_cache_opener.erl
+++ b/src/ddoc_cache_opener.erl
@@ -117,10 +117,10 @@ match_newest(Key) ->
end.
recover_doc(DbName, DDocId) ->
- fabric:open_doc(DbName, DDocId, []).
+ fabric:open_doc(DbName, DDocId, [ejson_body]).
recover_doc(DbName, DDocId, Rev) ->
- {ok, [Resp]} = fabric:open_revs(DbName, DDocId, [Rev], []),
+ {ok, [Resp]} = fabric:open_revs(DbName, DDocId, [Rev], [ejson_body]),
Resp.
recover_validation_funs(DbName) ->
[02/10] ddoc-cache commit: updated refs/heads/master to 4ffc6b0
Posted by rn...@apache.org.
Fix name of event listener callback
Project: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/commit/62198081
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/tree/62198081
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/diff/62198081
Branch: refs/heads/master
Commit: 62198081464835bb1c88bbea9ac7e5c2e69aa042
Parents: 41d8253
Author: Adam Kocoloski <ad...@cloudant.com>
Authored: Fri May 24 14:32:04 2013 -0400
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 11:27:05 2014 +0100
----------------------------------------------------------------------
src/ddoc_cache_opener.erl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/blob/62198081/src/ddoc_cache_opener.erl
----------------------------------------------------------------------
diff --git a/src/ddoc_cache_opener.erl b/src/ddoc_cache_opener.erl
index c0a85b4..56bfa7d 100644
--- a/src/ddoc_cache_opener.erl
+++ b/src/ddoc_cache_opener.erl
@@ -129,7 +129,7 @@ handle_cast(Msg, St) ->
handle_info({'EXIT', Pid, Reason}, #st{evictor=Pid}=St) ->
couch_log:error("ddoc_cache_opener evictor died ~w", [Reason]),
- {ok, Evictor} = couch_event:link_listener(?MODULE, evictor, nil, [all_dbs]),
+ {ok, Evictor} = couch_event:link_listener(?MODULE, handle_db_event, nil, [all_dbs]),
{noreply, St#st{evictor=Evictor}};
handle_info({'EXIT', _Pid, {open_ok, Key, Resp}}, St) ->
[05/10] ddoc-cache commit: updated refs/heads/master to 4ffc6b0
Posted by rn...@apache.org.
Simplify pulling out all design document ids from the cache
This allows the code to avoid copying the entire ets entries into
code from a separate module for both efficiency and modularity
purposes. This requires the new ets_lru match code to function.
It currently uses match which is dispatched to the gen_server.
It might be wise to make it direct since the match code does not
update access times (or if it did, we could make that a cast).
Project: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/commit/8ab96835
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/tree/8ab96835
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/diff/8ab96835
Branch: refs/heads/master
Commit: 8ab968359919a42279603a52ea98a061d4037079
Parents: 4b1c758
Author: Brian Mitchell <br...@cloudant.com>
Authored: Fri Oct 11 12:25:34 2013 -0400
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 11:50:55 2014 +0100
----------------------------------------------------------------------
src/ddoc_cache_opener.erl | 12 +-----------
1 file changed, 1 insertion(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/blob/8ab96835/src/ddoc_cache_opener.erl
----------------------------------------------------------------------
diff --git a/src/ddoc_cache_opener.erl b/src/ddoc_cache_opener.erl
index 258b5fc..b34359f 100644
--- a/src/ddoc_cache_opener.erl
+++ b/src/ddoc_cache_opener.erl
@@ -105,17 +105,7 @@ handle_cast({evict, DbName, DDocIds}, St) ->
{noreply, St};
handle_cast({do_evict, DbName}, St) ->
- % Bit of hack to introspect the ets_lru ETS tables directly
- % but I think this is better than having to manage our own
- % DbName -> DDocIdList table
- DDocIds = ets:foldl(fun(Obj, Acc) ->
- entry = element(1, Obj), % assert this is an entry record
- {EntryDbName, EntryDDocId} = element(2, Obj),
- case EntryDbName == DbName of
- true -> [EntryDDocId | Acc];
- false -> Acc
- end
- end, [], ddoc_cache_lru_objects),
+ DDocIds = ets_lru:match(?CACHE, {DbName, '$1'}, '_'),
handle_cast({do_evict, DbName, DDocIds}, St);
handle_cast({do_evict, DbName, DDocIds}, St) ->
[10/10] ddoc-cache commit: updated refs/heads/master to 4ffc6b0
Posted by rn...@apache.org.
Update to use couch_stats
Project: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/commit/4ffc6b00
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/tree/4ffc6b00
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/diff/4ffc6b00
Branch: refs/heads/master
Commit: 4ffc6b00031a1dea42bd8b549fc32d6918c41396
Parents: d9bc36f
Author: Paul J. Davis <pa...@gmail.com>
Authored: Thu Aug 21 01:49:43 2014 -0500
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Thu Aug 21 01:49:43 2014 -0500
----------------------------------------------------------------------
priv/stats_descriptions.cfg | 12 ++++++++++++
src/ddoc_cache.app.src | 3 ++-
src/ddoc_cache.erl | 9 +++++++++
3 files changed, 23 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/blob/4ffc6b00/priv/stats_descriptions.cfg
----------------------------------------------------------------------
diff --git a/priv/stats_descriptions.cfg b/priv/stats_descriptions.cfg
new file mode 100644
index 0000000..f769a97
--- /dev/null
+++ b/priv/stats_descriptions.cfg
@@ -0,0 +1,12 @@
+{[ddoc_cache, hit], [
+ {type, counter},
+ {desc, <<"number of design doc cache hits">>}
+]}.
+{[ddoc_cache, miss], [
+ {type, counter},
+ {desc, <<"number of design doc cache misses">>}
+]}.
+{[ddoc_cache, recovery], [
+ {type, counter},
+ {desc, <<"number of design doc cache recoveries">>}
+]}.
http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/blob/4ffc6b00/src/ddoc_cache.app.src
----------------------------------------------------------------------
diff --git a/src/ddoc_cache.app.src b/src/ddoc_cache.app.src
index 7d03bdf..a64b2f5 100644
--- a/src/ddoc_cache.app.src
+++ b/src/ddoc_cache.app.src
@@ -32,7 +32,8 @@
ets_lru,
mem3,
fabric,
- couch_log
+ couch_log,
+ couch_stats
]},
{mod, {ddoc_cache_app, []}},
{env, [
http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/blob/4ffc6b00/src/ddoc_cache.erl
----------------------------------------------------------------------
diff --git a/src/ddoc_cache.erl b/src/ddoc_cache.erl
index 40d9467..6aa3efd 100644
--- a/src/ddoc_cache.erl
+++ b/src/ddoc_cache.erl
@@ -37,10 +37,13 @@ open_doc(DbName, DocId) ->
Key = {DbName, DocId, '_'},
case ddoc_cache_opener:match_newest(Key) of
{ok, _} = Resp ->
+ couch_stats:increment_counter([ddoc_cache, hit]),
Resp;
missing ->
+ couch_stats:increment_counter([ddoc_cache, miss]),
ddoc_cache_opener:open_doc(DbName, DocId);
recover ->
+ couch_stats:increment_counter([ddoc_cache, recovery]),
ddoc_cache_opener:recover_doc(DbName, DocId)
end.
@@ -48,10 +51,13 @@ open_doc(DbName, DocId, RevId) ->
Key = {DbName, DocId, RevId},
case ddoc_cache_opener:lookup(Key) of
{ok, _} = Resp ->
+ couch_stats:increment_counter([ddoc_cache, hit]),
Resp;
missing ->
+ couch_stats:increment_counter([ddoc_cache, miss]),
ddoc_cache_opener:open_doc(DbName, DocId, RevId);
recover ->
+ couch_stats:increment_counter([ddoc_cache, recovery]),
ddoc_cache_opener:recover_doc(DbName, DocId, RevId)
end.
@@ -59,10 +65,13 @@ open_validation_funs(DbName) ->
Key = {DbName, validation_funs},
case ddoc_cache_opener:lookup(Key) of
{ok, _} = Resp ->
+ couch_stats:increment_counter([ddoc_cache, hit]),
Resp;
missing ->
+ couch_stats:increment_counter([ddoc_cache, mis]),
ddoc_cache_opener:open_validation_funs(DbName);
recover ->
+ couch_stats:increment_counter([ddoc_cache, recovery]),
ddoc_cache_opener:recover_validation_funs(DbName)
end.
[04/10] ddoc-cache commit: updated refs/heads/master to 4ffc6b0
Posted by rn...@apache.org.
Define a macro for the LRU cache name
Project: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/commit/4b1c758b
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/tree/4b1c758b
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/diff/4b1c758b
Branch: refs/heads/master
Commit: 4b1c758b58da9615eb10320add30a4628002b23f
Parents: 72f6af5
Author: Brian Mitchell <br...@cloudant.com>
Authored: Fri Oct 11 11:04:00 2013 -0400
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 11:50:47 2014 +0100
----------------------------------------------------------------------
src/ddoc_cache_opener.erl | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-ddoc-cache/blob/4b1c758b/src/ddoc_cache_opener.erl
----------------------------------------------------------------------
diff --git a/src/ddoc_cache_opener.erl b/src/ddoc_cache_opener.erl
index e949f60..258b5fc 100644
--- a/src/ddoc_cache_opener.erl
+++ b/src/ddoc_cache_opener.erl
@@ -13,10 +13,8 @@
-module(ddoc_cache_opener).
-behaviour(gen_server).
-
-include_lib("mem3/include/mem3.hrl").
-
-export([
start_link/0
]).
@@ -41,6 +39,7 @@
]).
+-define(CACHE, ddoc_cache_lru).
-define(OPENING, ddoc_cache_opening).
-type dbname() :: iodata().
@@ -120,9 +119,9 @@ handle_cast({do_evict, DbName}, St) ->
handle_cast({do_evict, DbName, DDocIds}, St);
handle_cast({do_evict, DbName, DDocIds}, St) ->
- ets_lru:remove(ddoc_cache_lru, {DbName, validation_funs}),
+ ets_lru:remove(?CACHE, {DbName, validation_funs}),
lists:foreach(fun(DDocId) ->
- ets_lru:remove(ddoc_cache_lru, {DbName, DDocId})
+ ets_lru:remove(?CACHE, {DbName, DDocId})
end, DDocIds),
{noreply, St};
@@ -181,12 +180,12 @@ open_ddoc({DbName, validation_funs}=Key) ->
Fun -> [Fun]
end
end, DDocs),
- ok = ets_lru:insert(ddoc_cache_lru, {DbName, validation_funs}, Funs),
+ ok = ets_lru:insert(?CACHE, {DbName, validation_funs}, Funs),
exit({open_ok, Key, {ok, Funs}});
open_ddoc({DbName, DDocId}=Key) ->
try fabric:open_doc(DbName, DDocId, [ejson_body]) of
{ok, Doc} ->
- ok = ets_lru:insert(ddoc_cache_lru, {DbName, DDocId}, Doc),
+ ok = ets_lru:insert(?CACHE, {DbName, DDocId}, Doc),
exit({open_ok, Key, {ok, Doc}});
Else ->
exit({open_ok, Key, Else})