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/01 11:08:17 UTC

[1/4] ets-lru commit: updated refs/heads/windsor-merge to e9a75fb

Repository: couchdb-ets-lru
Updated Branches:
  refs/heads/windsor-merge [created] e9a75fb72


Fix a bug related to the change in 5aab9df


Project: http://git-wip-us.apache.org/repos/asf/couchdb-ets-lru/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-ets-lru/commit/cd8777bc
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-ets-lru/tree/cd8777bc
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-ets-lru/diff/cd8777bc

Branch: refs/heads/windsor-merge
Commit: cd8777bcc754e32fe64d58d57fbc516934f9738e
Parents: aa817bd
Author: Brian Mitchell <br...@cloudant.com>
Authored: Tue Oct 15 10:02:55 2013 -0400
Committer: Robert Newson <rn...@apache.org>
Committed: Mon Jul 28 17:21:19 2014 +0100

----------------------------------------------------------------------
 src/ets_lru.erl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-ets-lru/blob/cd8777bc/src/ets_lru.erl
----------------------------------------------------------------------
diff --git a/src/ets_lru.erl b/src/ets_lru.erl
index 5880bd5..dc68fb8 100644
--- a/src/ets_lru.erl
+++ b/src/ets_lru.erl
@@ -114,8 +114,8 @@ terminate(_Reason, St) ->
 
 handle_call({lookup, Key}, _From, St) ->
     Reply = case ets:lookup(St#st.objects, Key) of
-        [#entry{val=Val}] ->
-            accessed(St, Key),
+        [#entry{val=Val} | _] ->
+            accessed(Key, St),
             {ok, Val};
         [] ->
             not_found


[3/4] ets-lru commit: updated refs/heads/windsor-merge to e9a75fb

Posted by rn...@apache.org.
set module version to 1


Project: http://git-wip-us.apache.org/repos/asf/couchdb-ets-lru/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-ets-lru/commit/4af7633f
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-ets-lru/tree/4af7633f
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-ets-lru/diff/4af7633f

Branch: refs/heads/windsor-merge
Commit: 4af7633f9288a89f11ae51b4b32d36fd38565f39
Parents: 807c21a
Author: Robert Newson <ro...@cloudant.com>
Authored: Fri Nov 22 16:38:15 2013 +0000
Committer: Robert Newson <rn...@apache.org>
Committed: Mon Jul 28 17:21:42 2014 +0100

----------------------------------------------------------------------
 src/ets_lru.erl | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-ets-lru/blob/4af7633f/src/ets_lru.erl
----------------------------------------------------------------------
diff --git a/src/ets_lru.erl b/src/ets_lru.erl
index 7311081..dbf3402 100644
--- a/src/ets_lru.erl
+++ b/src/ets_lru.erl
@@ -11,7 +11,8 @@
 % the License.
 
 -module(ets_lru).
--behavior(gen_server).
+-behaviour(gen_server).
+-vsn(1).
 
 
 -export([


[2/4] ets-lru commit: updated refs/heads/windsor-merge to e9a75fb

Posted by rn...@apache.org.
Add new match and match_object functions


Project: http://git-wip-us.apache.org/repos/asf/couchdb-ets-lru/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-ets-lru/commit/807c21ad
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-ets-lru/tree/807c21ad
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-ets-lru/diff/807c21ad

Branch: refs/heads/windsor-merge
Commit: 807c21ad4b7236b0c029b0a608ad2bce6a65785d
Parents: cd8777b
Author: Brian Mitchell <br...@cloudant.com>
Authored: Tue Oct 15 10:04:09 2013 -0400
Committer: Robert Newson <rn...@apache.org>
Committed: Mon Jul 28 17:21:28 2014 +0100

----------------------------------------------------------------------
 src/ets_lru.erl | 33 +++++++++++++++++++++++++++++++++
 test/06-match.t | 44 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 77 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-ets-lru/blob/807c21ad/src/ets_lru.erl
----------------------------------------------------------------------
diff --git a/src/ets_lru.erl b/src/ets_lru.erl
index dc68fb8..7311081 100644
--- a/src/ets_lru.erl
+++ b/src/ets_lru.erl
@@ -20,6 +20,8 @@
 
     insert/3,
     lookup/2,
+    match/3,
+    match_object/3,
     remove/2,
     clear/1,
 
@@ -78,6 +80,23 @@ insert(LRU, Key, Val) ->
 remove(LRU, Key) ->
     gen_server:call(LRU, {remove, Key}).
 
+%% @doc match/3 provides an efficient way to retrieve parts of the
+%% keys and values without copying or requiring circumvention of the
+%% ets_lru API. The KeySpec and ValueSpec parameters are used as part
+%% of one larger match spec so keep in mind that all capturing
+%% placeholders will be aliased between the key and value parts.
+-spec match(atom() | pid(), term(), term()) -> [[any()]].
+match(LRU, KeySpec, ValueSpec) ->
+    gen_server:call(LRU, {match, KeySpec, ValueSpec}).
+
+%% @doc match_object/3 provides an efficient way to retrieve multiple
+%% values using match conditions. The KeySpec and ValueSpec parameters
+%% are used as part of one larger match spec so keep in mind that all
+%% capturing placeholders will be aliased between the key and value
+%% parts.
+-spec match_object(atom() | pid(), term(), term()) -> [any()].
+match_object(LRU, KeySpec, ValueSpec) ->
+    gen_server:call(LRU, {match_object, KeySpec, ValueSpec}).
 
 clear(LRU) ->
     gen_server:call(LRU, clear).
@@ -122,6 +141,20 @@ handle_call({lookup, Key}, _From, St) ->
     end,
     {reply, Reply, St, 0};
 
+handle_call({match_object, KeySpec, ValueSpec}, _From, St) ->
+    Pattern = #entry{key=KeySpec, val=ValueSpec, _='_'},
+    Entries = ets:match_object(St#st.objects, Pattern),
+    Values = lists:map(fun(#entry{key=Key,val=Val}) ->
+        accessed(Key, St),
+        Val
+    end, Entries),
+    {reply, Values, St, 0};
+
+handle_call({match, KeySpec, ValueSpec}, _From, St) ->
+    Pattern = #entry{key=KeySpec, val=ValueSpec, _='_'},
+    Values = ets:match(St#st.objects, Pattern),
+    {reply, Values, St, 0};
+
 handle_call({insert, Key, Val}, _From, St) ->
     NewATime = erlang:now(),
     Pattern = #entry{key=Key, atime='$1', _='_'},

http://git-wip-us.apache.org/repos/asf/couchdb-ets-lru/blob/807c21ad/test/06-match.t
----------------------------------------------------------------------
diff --git a/test/06-match.t b/test/06-match.t
new file mode 100644
index 0000000..907ae78
--- /dev/null
+++ b/test/06-match.t
@@ -0,0 +1,44 @@
+#!/usr/bin/env escript
+
+-define(WITH_LRU(F), tutil:with_lru(fun(LRU) -> F(LRU) end)).
+
+main([]) ->
+    code:add_pathz("test"),
+    code:add_pathz("ebin"),
+    tutil:run(6, fun() -> test() end).
+
+test() ->
+    ?WITH_LRU(test_match_zero_values),
+    ?WITH_LRU(test_match_one_value),
+    ?WITH_LRU(test_match_many_values),
+    ?WITH_LRU(test_match_zero_objects),
+    ?WITH_LRU(test_match_one_object),
+    ?WITH_LRU(test_match_many_objects),
+    ok.
+
+test_match_zero_values(LRU) ->
+    etap:is(ets_lru:match(LRU, a, '$1'), [], "Empty match").
+
+test_match_one_value(LRU) ->
+    ets_lru:insert(LRU, b, {x,y}),
+    Values = ets_lru:match(LRU, b, {'$1', '$2'}),
+    etap:is(Values, [[x,y]], "Single match").
+
+test_match_many_values(LRU) ->
+    ets_lru:insert(LRU, boston, {state, "MA"}),
+    ets_lru:insert(LRU, new_york, {state, "NY"}),
+    Values = ets_lru:match(LRU, '_', {state, '$1'}),
+    etap:is(lists:sort(Values), [["MA"],["NY"]], "Multiple match").
+
+test_match_zero_objects(LRU) ->
+    etap:is(ets_lru:match_object(LRU, a, '$1'), [], "Empty match_object").
+
+test_match_one_object(LRU) ->
+    ets_lru:insert(LRU, ans, 42),
+    etap:is(ets_lru:match_object(LRU, ans, '$1'), [42], "Single match_object").
+
+test_match_many_objects(LRU) ->
+    ets_lru:insert(LRU, {color, blue}, a),
+    ets_lru:insert(LRU, {color, red}, b),
+    Values = ets_lru:match_object(LRU, {color, '_'}, '_'),
+    etap:is(lists:sort(Values), [a, b], "Multiple match_object").


[4/4] ets-lru commit: updated refs/heads/windsor-merge to e9a75fb

Posted by rn...@apache.org.
Allow direct access when using a registered process

The match_object API currently takes both atoms and pids.
This change allows the atom case to skip a synchronous call
to the gen_server state. The old path remains to allow pids
to continue to work through the old call path since it
can't easily infer the lru objects table name.

BugzId: 26105


Project: http://git-wip-us.apache.org/repos/asf/couchdb-ets-lru/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-ets-lru/commit/e9a75fb7
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-ets-lru/tree/e9a75fb7
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-ets-lru/diff/e9a75fb7

Branch: refs/heads/windsor-merge
Commit: e9a75fb72400044a04a36441a920016dce4ff84c
Parents: 4af7633
Author: Brian Mitchell <br...@p2p.io>
Authored: Fri Dec 6 11:07:09 2013 -0500
Committer: Robert Newson <rn...@apache.org>
Committed: Mon Jul 28 17:21:49 2014 +0100

----------------------------------------------------------------------
 src/ets_lru.erl | 7 +++++++
 test/06-match.t | 7 +++++--
 2 files changed, 12 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-ets-lru/blob/e9a75fb7/src/ets_lru.erl
----------------------------------------------------------------------
diff --git a/src/ets_lru.erl b/src/ets_lru.erl
index dbf3402..0c94e17 100644
--- a/src/ets_lru.erl
+++ b/src/ets_lru.erl
@@ -96,6 +96,13 @@ match(LRU, KeySpec, ValueSpec) ->
 %% capturing placeholders will be aliased between the key and value
 %% parts.
 -spec match_object(atom() | pid(), term(), term()) -> [any()].
+match_object(Name, KeySpec, ValueSpec) when is_atom(Name) ->
+    Pattern = #entry{key=KeySpec, val=ValueSpec, _='_'},
+    Entries = ets:match_object(obj_table(Name), Pattern),
+    lists:map(fun(#entry{key=Key,val=Val}) ->
+        gen_server:cast(Name, {accessed, Key}),
+        Val
+    end, Entries);
 match_object(LRU, KeySpec, ValueSpec) ->
     gen_server:call(LRU, {match_object, KeySpec, ValueSpec}).
 

http://git-wip-us.apache.org/repos/asf/couchdb-ets-lru/blob/e9a75fb7/test/06-match.t
----------------------------------------------------------------------
diff --git a/test/06-match.t b/test/06-match.t
index 907ae78..c409e8d 100644
--- a/test/06-match.t
+++ b/test/06-match.t
@@ -5,7 +5,7 @@
 main([]) ->
     code:add_pathz("test"),
     code:add_pathz("ebin"),
-    tutil:run(6, fun() -> test() end).
+    tutil:run(7, fun() -> test() end).
 
 test() ->
     ?WITH_LRU(test_match_zero_values),
@@ -35,7 +35,10 @@ test_match_zero_objects(LRU) ->
 
 test_match_one_object(LRU) ->
     ets_lru:insert(LRU, ans, 42),
-    etap:is(ets_lru:match_object(LRU, ans, '$1'), [42], "Single match_object").
+    ViaRegistered = ets_lru:match_object(test_lru, ans, '$1'),
+    etap:is(ViaRegistered, [42], "Single match_object (registered)"),
+    ViaPid = ets_lru:match_object(LRU, ans, '$1'),
+    etap:is(ViaPid, [42], "Single match_object (pid)").
 
 test_match_many_objects(LRU) ->
     ets_lru:insert(LRU, {color, blue}, a),