couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [4/4] ets-lru commit: updated refs/heads/windsor-merge to e9a75fb
Date Fri, 01 Aug 2014 09:08:20 GMT
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 <brian@p2p.io>
Authored: Fri Dec 6 11:07:09 2013 -0500
Committer: Robert Newson <rnewson@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),


Mime
View raw message