Permalink
Browse files

Implement get_meta in mccouch

get_meta is similar to get but only returns an item's metadata.

Change-Id: I9575178ef91cff9c2c455647814ac7c43ccedc27
Reviewed-on: http://review.couchbase.org/12212
Reviewed-by: Chiyoung Seo <chiyoung.seo@gmail.com>
Tested-by: Srinivas Vadlamani <srinivas@couchbase.com>
  • Loading branch information...
1 parent 7c1f12d commit 88701cc326bc3dde4ed072bb8441be83adcfb2a5 Srinivas Vadlamani committed Jan 7, 2012
Showing with 26 additions and 1 deletion.
  1. +1 −0 include/mc_constants.hrl
  2. +8 −1 src/mc_couch_kv.erl
  3. +17 −0 src/mc_daemon.erl
View
@@ -44,6 +44,7 @@
-define(RDECR, 16#3b).
-define(RDECRQ, 16#3c).
+-define(GETMETA, 16#a0).
-define(SETQWITHMETA, 16#a3).
-define(DELETEQWITHMETA, 16#a9).
View
@@ -2,7 +2,7 @@
-include("couch_db.hrl").
--export([get/2, grok_doc/1, set/6, delete/2, mk_doc/5, mk_doc/6]).
+-export([get/2, get_meta/2, grok_doc/1, set/6, delete/2, mk_doc/5, mk_doc/6]).
%% ok, Flags, Expiration, Cas, Data
-spec get(_, binary()) -> {ok, integer(), integer(), binary()} | not_found.
@@ -12,6 +12,13 @@ get(Db, Key) ->
_ -> not_found
end.
+get_meta(Db, Key) ->
+ case couch_db:open_doc_int(Db, Key, []) of
+ {ok, Doc} ->
+ {Seqno, <<Cas:64, Len:32, Flags:32>>} = Doc#doc.rev,
+ {Seqno, Cas, Len, Flags};
+ _ -> not_found
+ end.
%% ok, Flags, Expiration, Cas, Data
-spec grok_doc(#doc{}) -> {ok, integer(), integer(), term()}.
View
@@ -92,6 +92,16 @@ handle_get_call(Db, Key) ->
#mc_response{status=1, body="Does not exist"}
end.
+handle_get_meta_call(Db, Key) ->
+ case mc_couch_kv:get_meta(Db, Key) of
+ {Seqno, Cas, Length, Flags} ->
+ #mc_response{extra = <<Flags:32>>,
+ body = <<1:8, 20:8, Seqno:32,
+ Cas:64, Length:32, Flags:32>>};
+ _ ->
+ #mc_response{status=1, body="Does not exist"}
+ end.
+
handle_set_call(Db, Key, Flags, Expiration, Value, JsonMode) ->
NewCas = mc_couch_kv:set(Db,
Key, Flags,
@@ -175,6 +185,13 @@ processing({?GET, VBucket, <<>>, Key, <<>>, _CAS}, _From, State) ->
VBucket, State);
processing({?GET, _, _, _, _, _}, _From, State) ->
{reply, #mc_response{status=?EINVAL}, processing, State};
+processing({?GETMETA, VBucket, <<>>, Key, <<>>, _CAS}, _From, State) ->
+ with_open_db_or_einval(fun(Db) -> {reply, handle_get_meta_call(Db, Key),
+ processing, State}
+ end,
+ VBucket, State);
+processing({?GETMETA, _, _, _, _, _}, _From, State) ->
+ {reply, #mc_response{status=?EINVAL}, processing, State};
processing({?SET, VBucket, <<Flags:32, Expiration:32>>, Key, Value, _CAS},
_From, State) ->
with_open_db_or_einval(fun(Db) -> {reply, handle_set_call(Db, Key, Flags,

0 comments on commit 88701cc

Please sign in to comment.