Skip to content

Commit

Permalink
add encode, message, and proto for RpbGetBucketKeyPreflistReq|Resp
Browse files Browse the repository at this point in the history
  • Loading branch information
zeeshanlakhani committed Feb 25, 2015
1 parent 2f0e5bd commit 09586ec
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 66 deletions.
54 changes: 2 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,60 +47,10 @@ In some cases, a client may receive multiple response messages for a
single request. The response message will typically include a boolean
`done` field that signifies the last message in a sequence.

### Riak global Request/Response messages

RpbGetServerInfoReq -> RpbGetServerInfoResp
RpbPingReq -> RpbPingResp
RpbGetBucketReq -> RpbErrorResp | RpbGetBucketResp
RpbPutBucketReq -> RpbErrorResp | RpbPutBucketResp

### Riak KV Request/Response messages

RpbGetClientIdReq -> RpbGetClientIdResp
RpbSetClientIdReq -> RpbSetClientIdResp
RpbGetReq -> RpbErrorResp | RbpGetResp
RpbPutReq -> RpbErrorResp | RpbPutResp
RpbDelReq -> RpbErrorResp | RpbDelResp
RpbListBucketsReq -> RpbErrorResp | RpbListBucketsResp
RpbListKeysReq -> RpbErrorResp | RpbListKeysResp{1,}
RpbMapRedReq -> RpbMapRedResp{1,}
RpbIndexReq -> RpbIndexResp

### Riak Search Request/Response messages

RpbSearchQueryReq -> RpbSearchQueryResp

### Registered Message Codes

0 - RpbErrorResp
1 - RpbPingReq - 0 length
2 - RpbPingResp (pong) - 0 length
3 - RpbGetClientIdReq
4 - RpbGetClientIdResp
5 - RpbSetClientIdReq
6 - RpbSetClientIdResp
7 - RpbGetServerInfoReq
8 - RpbGetServerInfoResp
9 - RpbGetReq
10 - RpbGetResp
11 - RpbPutReq
12 - RpbPutResp - 0 length
13 - RpbDelReq
14 - RpbDelResp
15 - RpbListBucketsReq
16 - RpbListBucketsResp
17 - RpbListKeysReq
18 - RpbListKeysResp{1,}
19 - RpbGetBucketReq
20 - RpbGetBucketResp
21 - RpbSetBucketReq
22 - RpbSetBucketResp
23 - RpbMapRedReq
24 - RpbMapRedResp{1,}
25 - RpbIndexReq
26 - RpbIndexResp
27 - RpbSearchQueryReq
28 - RbpSearchQueryResp
[Message codes](http://docs.basho.com/riak/latest/dev/references/protocol-buffers/#Message-Codes) and documentation can be found in the protocol-buffers
[section](http://docs.basho.com/riak/latest/dev/references/protocol-buffers/) of the online docs.

## Contributing

Expand Down
24 changes: 13 additions & 11 deletions dialyzer.ignore-warnings
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ riak_dt_pb.erl:86: The pattern <FNum, 'repeated_packed', Data, Type, _> can neve
riak_dt_pb.erl:222: The pattern <Types, [{Fnum, Bytes} | Tail], Acc> can never match the type <_,[],[{_,_}]>
riak_kv_pb.erl:47: Guard test is_list(Records::tuple()) can never succeed
riak_kv_pb.erl:74: The pattern <_, 'repeated_packed', 'undefined', _, _> can never match the type <1..255,'optional' | 'repeated' | 'required',_,atom(),[[binary() | maybe_improper_list(any(),binary() | [])]]>
riak_pb.erl:74: The pattern <_, 'repeated_packed', 'undefined', _, _> can never match the type <1..255,'optional' | 'repeated' | 'required',_,'bool' | 'bytes' | 'int64' | 'rpbbucketprops' | 'rpbbucketprops_rpbreplmode' | 'rpbcommithook' | 'rpbmodfun' | 'uint32',[[binary() | maybe_improper_list(any(),binary() | [])]]>
riak_kv_pb.erl:75: The pattern <_, 'repeated_packed', [], _, _> can never match the type <1..255,'optional' | 'repeated' | 'required',_,atom(),[[binary() | maybe_improper_list(any(),binary() | [])]]>
riak_pb.erl:75: The pattern <_, 'repeated_packed', [], _, _> can never match the type <1..255,'optional' | 'repeated' | 'required',_,'bool' | 'bytes' | 'int64' | 'rpbbucketprops' | 'rpbbucketprops_rpbreplmode' | 'rpbcommithook' | 'rpbmodfun' | 'uint32',[[binary() | maybe_improper_list(any(),binary() | [])]]>
riak_kv_pb.erl:86: The pattern <FNum, 'repeated_packed', Data, Type, _> can never match the type <1..255,'optional' | 'repeated' | 'required',_,atom(),[[binary() | maybe_improper_list(any(),binary() | [])]]>
riak_kv_pb.erl:222: The pattern <Types, [{Fnum, Bytes} | Tail], Acc> can never match the type <_,[],[{_,_}]>
riak_pb.erl:47: Guard test is_list(Records::tuple()) can never succeed
riak_pb.erl:74: The pattern <_, 'repeated_packed', 'undefined', _, _> can never match the type <1..255,'optional' | 'repeated' | 'required',_,'bool' | 'bytes' | 'rpbbucketprops' | 'rpbbucketprops_rpbreplmode' | 'rpbcommithook' | 'rpbmodfun' | 'uint32',[[binary() | maybe_improper_list(any(),binary() | [])]]>
riak_pb.erl:75: The pattern <_, 'repeated_packed', [], _, _> can never match the type <1..255,'optional' | 'repeated' | 'required',_,'bool' | 'bytes' | 'rpbbucketprops' | 'rpbbucketprops_rpbreplmode' | 'rpbcommithook' | 'rpbmodfun' | 'uint32',[[binary() | maybe_improper_list(any(),binary() | [])]]>
riak_pb.erl:86: The pattern <FNum, 'repeated_packed', Data, Type, _> can never match the type <1..255,'optional' | 'repeated' | 'required',_,'bool' | 'bytes' | 'rpbbucketprops' | 'rpbbucketprops_rpbreplmode' | 'rpbcommithook' | 'rpbmodfun' | 'uint32',[[binary() | maybe_improper_list(any(),binary() | [])]]>
riak_pb.erl:202: The pattern <Binary, 'string'> can never match the type <_,'bool' | 'bytes' | 'rpbbucketprops' | 'rpbbucketprops_rpbreplmode' | 'rpbcommithook' | 'rpbmodfun' | 'uint32'>
riak_pb.erl:86: The pattern <FNum, 'repeated_packed', Data, Type, _> can never match the type <1..255,'optional' | 'repeated' | 'required',_,'bool' | 'bytes' | 'int64' | 'rpbbucketprops' | 'rpbbucketprops_rpbreplmode' | 'rpbcommithook' | 'rpbmodfun' | 'uint32',[[binary() | maybe_improper_list(any(),binary() | [])]]>
riak_pb.erl:202: The pattern <Binary, 'string'> can never match the type <_,'bool' | 'bytes' | 'int64' | 'rpbbucketprops' | 'rpbbucketprops_rpbreplmode' | 'rpbcommithook' | 'rpbmodfun' | 'uint32'>
riak_pb.erl:222: The pattern <Types, [{Fnum, Bytes} | Tail], Acc> can never match the type <_,[],[{_,_}]>
riak_search_pb.erl:47: Guard test is_list(Records::tuple()) can never succeed
riak_search_pb.erl:74: The pattern <_, 'repeated_packed', 'undefined', _, _> can never match the type <1..255,'optional' | 'repeated' | 'required',_,'bool' | 'bytes' | 'float' | 'rpbbucketprops' | 'rpbbucketprops_rpbreplmode' | 'rpbcommithook' | 'rpbmodfun' | 'rpbpair' | 'rpbsearchdoc' | 'uint32',[[binary() | maybe_improper_list(any(),binary() | [])]]>
Expand All @@ -39,16 +40,17 @@ riak_kv_pb.erl:74: The pattern <_, 'repeated_packed', [], _, _> can never match
riak_kv_pb.erl:85: The pattern <FNum, 'repeated_packed', Data, Type, _> can never match the type <1..255,'optional' | 'repeated' | 'required',_,atom(),[[binary() | maybe_improper_list(any(),binary() | [])]]>
riak_kv_pb.erl:221: The pattern <Types, [{Fnum, Bytes} | Tail], Acc> can never match the type <_,[],[{_,_}]>
riak_pb.erl:46: Guard test is_list(Records::tuple()) can never succeed
riak_pb.erl:73: The pattern <_, 'repeated_packed', 'undefined', _, _> can never match the type <1..255,'optional' | 'repeated' | 'required',_,'bool' | 'bytes' | 'rpbbucketprops' | 'rpbbucketprops_rpbreplmode' | 'rpbcommithook' | 'rpbmodfun' | 'uint32',[[binary() | maybe_improper_list(any(),binary() | [])]]>
riak_pb.erl:74: The pattern <_, 'repeated_packed', [], _, _> can never match the type <1..255,'optional' | 'repeated' | 'required',_,'bool' | 'bytes' | 'rpbbucketprops' | 'rpbbucketprops_rpbreplmode' | 'rpbcommithook' | 'rpbmodfun' | 'uint32',[[binary() | maybe_improper_list(any(),binary() | [])]]>
riak_pb.erl:85: The pattern <FNum, 'repeated_packed', Data, Type, _> can never match the type <1..255,'optional' | 'repeated' | 'required',_,'bool' | 'bytes' | 'rpbbucketprops' | 'rpbbucketprops_rpbreplmode' | 'rpbcommithook' | 'rpbmodfun' | 'uint32',[[binary() | maybe_improper_list(any(),binary() | [])]]>
riak_pb.erl:74: The pattern <_, 'repeated_packed', 'undefined', _, _> can never match the type <1..255,'optional' | 'repeated' | 'required',_,'bool' | 'bytes' | 'int64' | 'rpbbucketkeypreflistitem' | 'rpbbucketprops' | 'rpbbucketprops_rpbreplmode' | 'rpbcommithook' | 'rpbmodfun' | 'uint32',[[binary() | maybe_improper_list(any(),binary() | [])]]>
riak_pb.erl:75: The pattern <_, 'repeated_packed', [], _, _> can never match the type <1..255,'optional' | 'repeated' | 'required',_,'bool' | 'bytes' | 'int64' | 'rpbbucketkeypreflistitem' | 'rpbbucketprops' | 'rpbbucketprops_rpbreplmode' | 'rpbcommithook' | 'rpbmodfun' | 'uint32',[[binary() | maybe_improper_list(any(),binary() | [])]]>
riak_pb.erl:86: The pattern <FNum, 'repeated_packed', Data, Type, _> can never match the type <1..255,'optional' | 'repeated' | 'required',_,'bool' | 'bytes' | 'int64' | 'rpbbucketkeypreflistitem' | 'rpbbucketprops' | 'rpbbucketprops_rpbreplmode' | 'rpbcommithook' | 'rpbmodfun' | 'uint32',[[binary() | maybe_improper_list(any(),binary() | [])]]>
riak_pb.erl:202: The pattern <Binary, 'string'> can never match the type <_,'bool' | 'bytes' | 'int64' | 'rpbbucketkeypreflistitem' | 'rpbbucketprops' | 'rpbbucketprops_rpbreplmode' | 'rpbcommithook' | 'rpbmodfun' | 'uint32'>
riak_pb.erl:201: The pattern <Binary, 'string'> can never match the type <_,'bool' | 'bytes' | 'rpbbucketprops' | 'rpbbucketprops_rpbreplmode' | 'rpbcommithook' | 'rpbmodfun' | 'uint32'>
riak_pb.erl:221: The pattern <Types, [{Fnum, Bytes} | Tail], Acc> can never match the type <_,[],[{_,_}]>
riak_search_pb.erl:46: Guard test is_list(Records::tuple()) can never succeed
riak_search_pb.erl:73: The pattern <_, 'repeated_packed', 'undefined', _, _> can never match the type <1..255,'optional' | 'repeated' | 'required',_,'bool' | 'bytes' | 'float' | 'rpbbucketprops' | 'rpbbucketprops_rpbreplmode' | 'rpbcommithook' | 'rpbmodfun' | 'rpbpair' | 'rpbsearchdoc' | 'uint32',[[binary() | maybe_improper_list(any(),binary() | [])]]>
riak_search_pb.erl:74: The pattern <_, 'repeated_packed', [], _, _> can never match the type <1..255,'optional' | 'repeated' | 'required',_,'bool' | 'bytes' | 'float' | 'rpbbucketprops' | 'rpbbucketprops_rpbreplmode' | 'rpbcommithook' | 'rpbmodfun' | 'rpbpair' | 'rpbsearchdoc' | 'uint32',[[binary() | maybe_improper_list(any(),binary() | [])]]>
riak_search_pb.erl:85: The pattern <FNum, 'repeated_packed', Data, Type, _> can never match the type <1..255,'optional' | 'repeated' | 'required',_,'bool' | 'bytes' | 'float' | 'rpbbucketprops' | 'rpbbucketprops_rpbreplmode' | 'rpbcommithook' | 'rpbmodfun' | 'rpbpair' | 'rpbsearchdoc' | 'uint32',[[binary() | maybe_improper_list(any(),binary() | [])]]>
riak_search_pb.erl:201: The pattern <Binary, 'string'> can never match the type <_,'bool' | 'bytes' | 'float' | 'rpbbucketprops' | 'rpbbucketprops_rpbreplmode' | 'rpbcommithook' | 'rpbmodfun' | 'rpbpair' | 'rpbsearchdoc' | 'uint32'>
riak_search_pb.erl:74: The pattern <_, 'repeated_packed', 'undefined', _, _> can never match the type <1..255,'optional' | 'repeated' | 'required',_,'bool' | 'bytes' | 'float' | 'int64' | 'rpbbucketkeypreflistitem' | 'rpbbucketprops' | 'rpbbucketprops_rpbreplmode' | 'rpbcommithook' | 'rpbmodfun' | 'rpbpair' | 'rpbsearchdoc' | 'uint32',[[binary() | maybe_improper_list(any(),binary() | [])]]>
riak_search_pb.erl:75: The pattern <_, 'repeated_packed', [], _, _> can never match the type <1..255,'optional' | 'repeated' | 'required',_,'bool' | 'bytes' | 'float' | 'int64' | 'rpbbucketkeypreflistitem' | 'rpbbucketprops' | 'rpbbucketprops_rpbreplmode' | 'rpbcommithook' | 'rpbmodfun' | 'rpbpair' | 'rpbsearchdoc' | 'uint32',[[binary() | maybe_improper_list(any(),binary() | [])]]>
riak_search_pb.erl:86: The pattern <FNum, 'repeated_packed', Data, Type, _> can never match the type <1..255,'optional' | 'repeated' | 'required',_,'bool' | 'bytes' | 'float' | 'int64' | 'rpbbucketkeypreflistitem' | 'rpbbucketprops' | 'rpbbucketprops_rpbreplmode' | 'rpbcommithook' | 'rpbmodfun' | 'rpbpair' | 'rpbsearchdoc' | 'uint32',[[binary() | maybe_improper_list(any(),binary() | [])]]>
riak_search_pb.erl:202: The pattern <Binary, 'string'> can never match the type <_,'bool' | 'bytes' | 'float' | 'int64' | 'rpbbucketkeypreflistitem' | 'rpbbucketprops' | 'rpbbucketprops_rpbreplmode' | 'rpbcommithook' | 'rpbmodfun' | 'rpbpair' | 'rpbsearchdoc' | 'uint32'>
riak_search_pb.erl:221: The pattern <Types, [{Fnum, Bytes} | Tail], Acc> can never match the type <_,[],[{_,_}]>
riak_yokozuna_pb.erl:46: Guard test is_list(Records::tuple()) can never succeed
riak_yokozuna_pb.erl:73: The pattern <_, 'repeated_packed', 'undefined', _, _> can never match the type <1 | 2 | 3,'optional' | 'repeated' | 'required',_,'bytes' | 'rpbyokozunaindex' | 'rpbyokozunaschema' | 'uint32',[[binary() | maybe_improper_list(any(),binary() | [])]]>
Expand All @@ -60,6 +62,6 @@ riak_yokozuna_pb.erl:102: The pattern <'pikachu', 'value'> can never match the t
riak_yokozuna_pb.erl:201: The pattern <Binary, 'string'> can never match the type <_,'bytes' | 'rpbyokozunaindex' | 'rpbyokozunaschema' | 'uint32'>
riak_yokozuna_pb.erl:221: The pattern <Types, [{Fnum, Bytes} | Tail], Acc> can never match the type <_,[],[{_,_}]>
## Insufficient typing on record in generated code
riak_pb_codec.erl:345: Invalid type specification for function riak_pb_codec:decode_commit_hooks/1. The success typing is ([any()]) -> [{atom(),atom() | [any(),...]} | {'modfun',atom(),atom() | [any(),...]}]
riak_pb_codec.erl:354: Invalid type specification for function riak_pb_codec:decode_commit_hooks/1. The success typing is ([any()]) -> [{atom(),atom() | [any(),...]} | {'modfun',atom(),atom() | [any(),...]}]
## Internal calls only pass empty-list, but calls from other libraries pass proplists
riak_pb_dt_codec.erl:181: The pattern {AtomType, _} can never match the type 'false'
21 changes: 20 additions & 1 deletion src/riak_kv.proto
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ message RpbDelReq {

// Delete response - not defined, will return a RpbDelResp on success or RpbErrorResp on failure

// List buckets request
// List buckets request
message RpbListBucketsReq {
optional uint32 timeout = 1;
optional bool stream = 2;
Expand Down Expand Up @@ -272,3 +272,22 @@ message RpbCounterGetReq {
message RpbCounterGetResp {
optional sint64 value = 1;
}

// Get bucket-key preflist request
message RpbGetBucketKeyPreflistReq {
required bytes bucket = 1;
required bytes key = 2;
optional bytes type = 3;
}

// Get bucket-key preflist response
message RpbGetBucketKeyPreflistResp {
repeated RpbBucketKeyPreflistItem preflist = 1;
}

// Preflist item
message RpbBucketKeyPreflistItem {
required int64 partition = 1;
required bytes node = 2;
required bool primary = 3;
}
2 changes: 1 addition & 1 deletion src/riak_pb_codec.erl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ msg_type(Int) -> riak_pb_messages:msg_type(Int).
%% @doc Converts a symbolic message name into a message code. Replaces
%% `riakc_pb:msg_code/1'.
-spec msg_code(atom()) -> integer().
msg_code(Atom) -> riak_pb_messages:msg_code(Atom).
msg_code(Atom) -> riak_pb_messages:msg_code(Atom).

%% @doc Selects the appropriate PB decoder for a message code.
-spec decoder_for(pos_integer()) -> module().
Expand Down
52 changes: 51 additions & 1 deletion src/riak_pb_kv_codec.erl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
-include("riak_kv_pb.hrl").
-include("riak_pb_kv_codec.hrl").

-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
-endif.

-export([encode_contents/1, %% riakc_pb:pbify_rpbcontents
decode_contents/1, %% riakc_pb:erlify_rpbcontents
encode_content/1, %% riakc_pb:pbify_rpbcontent
Expand All @@ -42,7 +46,8 @@
encode_link/1, %% riakc_pb:pbify_rpblink
decode_link/1, %% riakc_pb:erlify_rpblink
encode_quorum/1,
decode_quorum/1 %% riak_kv_pb_socket:normalize_rw_value
decode_quorum/1, %% riak_kv_pb_socket:normalize_rw_value
encode_apl_ann/1
]).

-export_type([quorum/0]).
Expand All @@ -58,6 +63,10 @@

-type contents() :: [{metadata(), value()}].

%% @doc Annotated preflist type
-type preflist_with_pnum_ann() :: [{{non_neg_integer(), node()}, primary|fallback}].


%% @doc Convert a list of object {MetaData,Value} pairs to protocol
%% buffers messages.
-spec encode_contents(contents()) -> [#rpbcontent{}].
Expand Down Expand Up @@ -231,3 +240,44 @@ decode_quorum(?RIAKPB_RW_ALL) -> all;
decode_quorum(?RIAKPB_RW_DEFAULT) -> default;
decode_quorum(undefined) -> undefined;
decode_quorum(I) when is_integer(I), I >= 0 -> I.

%% @doc Convert preflist to RpbBucketKeyPreflist.
-spec encode_apl_ann(preflist_with_pnum_ann()) ->
PBPreflist::[#rpbbucketkeypreflistitem{}].
encode_apl_ann(Preflist) ->
[encode_apl_item({PartitionNumber, Node}, T) ||
{{PartitionNumber, Node}, T} <- Preflist].

-spec encode_apl_item({non_neg_integer(), node()}, primary|fallback) ->
#rpbbucketkeypreflistitem{}.
encode_apl_item({PartitionNumber, Node}, primary) ->
#rpbbucketkeypreflistitem{partition=PartitionNumber,
node=riak_pb_codec:to_binary(Node),
primary=riak_pb_codec:encode_bool(true)};
encode_apl_item({PartitionNumber, Node}, fallback) ->
#rpbbucketkeypreflistitem{partition=PartitionNumber,
node=riak_pb_codec:to_binary(Node),
primary=riak_pb_codec:encode_bool(false)}.


-ifdef(TEST).

encode_apl_ann_test() ->
Encoded = encode_apl_ann([{{1,
'dev5@127.0.0.1'},
primary},
{{2,
'dev6@127.0.0.1'},
primary},
{{3,
'dev3@127.0.0.1'},
fallback}]),
?assertEqual(Encoded,
[{rpbbucketkeypreflistitem,
1,<<"dev5@127.0.0.1">>,true},
{rpbbucketkeypreflistitem,
2,<<"dev6@127.0.0.1">>,true},
{rpbbucketkeypreflistitem,
3,<<"dev3@127.0.0.1">>,false}]).

-endif.
2 changes: 2 additions & 0 deletions src/riak_pb_messages.csv
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
30,RpbResetBucketResp,riak
31,RpbGetBucketTypeReq,riak
32,RpbSetBucketTypeReq,riak
33,Rpbgetbucketkeypreflistreq,riak
34,Rpbgetbucketkeypreflistresp,riak
40,RpbCSBucketReq,riak_kv
41,RpbCSBucketResp,riak_kv
50,RpbCounterUpdateReq,riak_kv
Expand Down

0 comments on commit 09586ec

Please # to comment.