From 1723bd9cb36eeefc29481179c6b382dc27da95fe Mon Sep 17 00:00:00 2001 From: Srinivas Vadlamani Date: Wed, 1 Feb 2012 01:54:19 -0800 Subject: [PATCH] Use set_with_meta instead of add_with_meta for new items 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 Tested-by: Aliaksey Kandratsenka Reviewed-by: Aliaksey Kandratsenka --- src/capi_replication.erl | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/src/capi_replication.erl b/src/capi_replication.erl index 9a1c11f14c..812173f374 100644 --- a/src/capi_replication.erl +++ b/src/capi_replication.erl @@ -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}}; @@ -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, _} ->