Commits

Anonymous committed 38e7534

PBC support for default bucket r/w/dw values (closes #83)

Comments (0)

Files changed (2)

apps/riak_kv/src/riak_kv_pb_socket.erl

 
 process_message(#rpbgetreq{bucket=B, key=K, r=R0}, 
                 #state{client=C} = State) ->
-    R = case R0 of 
-        ?RIAKC_RW_ONE -> one;
-        ?RIAKC_RW_QUORUM -> quorum;
-        ?RIAKC_RW_ALL -> all;
-        Other  -> Other
-        end,
+    R = normalize_rw_value(R0),
     case C:get(B, K, default_r(R)) of
         {ok, O} ->
             PbContent = riakc_pb:pbify_rpbcontents(riak_object:get_contents(O), []),
     O1 = update_rpbcontent(O0, RpbContent),
     O  = update_pbvc(O1, PbVC),
     % erlang_protobuffs encodes as 1/0/undefined
-    W = case W0 of
-            ?RIAKC_RW_ONE -> one;
-            ?RIAKC_RW_ALL -> all;
-            ?RIAKC_RW_QUORUM -> quorum;
-            Other  -> Other
-        end,
-    DW = case DW0 of
-            ?RIAKC_RW_ONE -> one;
-            ?RIAKC_RW_ALL -> all;
-            ?RIAKC_RW_QUORUM -> quorum;
-            Other1 -> Other1
-        end,
+    W = normalize_rw_value(W0),
+    DW = normalize_rw_value(DW0),
     Options = case ReturnBody of 1 -> [returnbody]; _ -> [] end,
     case C:put(O, default_w(W), default_dw(DW), default_timeout(), Options) of
         ok ->
 
 process_message(#rpbdelreq{bucket=B, key=K, rw=RW0}, 
                 #state{client=C} = State) ->
-    RW = case RW0 of 
-        ?RIAKC_RW_ONE -> one;
-        ?RIAKC_RW_QUORUM -> quorum;
-        ?RIAKC_RW_ALL -> all;
-        Other -> Other
-        end,    
+    RW = normalize_rw_value(RW0),
     case C:delete(B, K, default_rw(RW)) of
         ok ->
             send_msg(rpbdelresp, State);
 %% Set default values in the options record if none are provided.
 %% Erlang protobuffs does not support default, so have to do it here.
 default_r(undefined) ->
-    2;
+    default;
 default_r(R) ->
     R.
 
 default_w(undefined) ->
-    2;
+    default;
 default_w(W) ->
     W.
 
 default_dw(undefined) ->
-    0;
+    default;
 default_dw(DW) ->
     DW.
 
 default_rw(undefined) ->
-    2;
+    default;
 default_rw(RW) ->
     RW.
 
 encode_mapred_phase(_Res, ContentType) ->
     {error, {unknown_content_type, ContentType}}.
 
+normalize_rw_value(?RIAKC_RW_ONE) -> one;
+normalize_rw_value(?RIAKC_RW_QUORUM) -> quorum;
+normalize_rw_value(?RIAKC_RW_ALL) -> all;
+normalize_rw_value(?RIAKC_RW_DEFAULT) -> default;
+normalize_rw_value(V) -> V.
+    
+    
         {webmachine, "1.7.0", {hg, "http://bitbucket.org/basho/webmachine",
                                "tip"}},
         {riakc, "0.2.0", {hg, "http://bitbucket.org/basho/riak-erlang-client",
-                          "tip"}},
+                          "65"}},
         {bitcask, "1.0.1", {hg, "http://bitbucket.org/basho/bitcask",
                             "tip"}},
         {ebloom, ".*", {hg, "http://bitbucket.org/basho/ebloom",