Skip to content

Commit

Permalink
Use set_with_meta instead of add_with_meta for new items
Browse files Browse the repository at this point in the history
Even for an add through xdcr, ep-engine creates a temp item and
returns its CAS, which is supposed to be used while issuing the add
later. This is similar to issuing a set_with_meta command. Hence,
add_with_meta is redundant and can be removed.

Change-Id: Ic7339c74f7c2dd09f5b5e0516809e93085015567
Reviewed-on: http://review.couchbase.org/13658
Tested-by: Srinivas Vadlamani <srinivas@couchbase.com>
Tested-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
Reviewed-by: Aliaksey Kandratsenka <alkondratenko@gmail.com>
  • Loading branch information
Srinivas Vadlamani authored and alk committed Mar 8, 2012
1 parent 053dcde commit 1723bd9
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions src/capi_replication.erl
Expand Up @@ -199,14 +199,14 @@ do_update_replicated_doc_loop(Bucket, VBucket, DocId,
DocValue, DocDeleted) ->
RV =
case capi_utils:get_meta(Bucket, VBucket, DocId) of
{error, enoent, _CAS} ->
{error, enoent, CAS} ->
case DocDeleted of
true ->
%% TODO: we must preserve source revision here
ok;
false ->
do_add_with_meta(Bucket, DocId,
VBucket, DocValue, DocRev)
do_set_with_meta(Bucket, DocId, VBucket, DocValue,
DocRev, CAS)
end;
{error, not_my_vbucket} ->
{error, {bad_request, not_my_vbucket}};
Expand Down Expand Up @@ -245,26 +245,14 @@ do_update_replicated_doc_loop(Bucket, VBucket, DocId,
RV
end.

do_add_with_meta(Bucket, DocId, VBucket, DocValue, DocRev) ->
case ns_memcached:add_with_meta(Bucket, DocId, VBucket,
DocValue, {revid, DocRev}) of
{ok, _, _} ->
ok;
{memcached_error, key_eexists, _} ->
retry;
{memcached_error, not_my_vbucket, _} ->
{error, {bad_request, not_my_vbucket}};
{memcached_error, einval, _} ->
%% this is most likely an invalid revision
{error, {bad_request, einval}}
end.

do_set_with_meta(Bucket, DocId, VBucket, DocValue, DocRev, CAS) ->
case ns_memcached:set_with_meta(Bucket, DocId,
VBucket, DocValue,
{revid, DocRev}, CAS) of
{ok, _, _} ->
ok;
{memcached_error, key_enoent, _} ->
retry;
{memcached_error, key_eexists, _} ->
retry;
{memcached_error, not_my_vbucket, _} ->
Expand Down

0 comments on commit 1723bd9

Please sign in to comment.