Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add interface for pb bucket key active preflist #75

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/riak_api_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
%% because it is started before riak_api.
{riak_core_pb_bucket, 19, 22},
{riak_core_pb_bucket, 29, 30},
{riak_core_pb_bucket_type, 31, 33}
{riak_core_pb_bucket_type, 31, 32},
{riak_core_pb_bucket_key_apl, 33, 34}
]).

%% @doc The application:start callback.
Expand Down
4 changes: 3 additions & 1 deletion src/riak_core_pb_bucket.erl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
decode/2,
encode/1,
process/2,
process_stream/3]).
process_stream/3,
maybe_create_bucket_type/2,
bucket_type/2]).

-include_lib("riak_pb/include/riak_pb.hrl").

Expand Down
82 changes: 82 additions & 0 deletions src/riak_core_pb_bucket_key_apl.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
%% --------------------------------------------------------------------------
%%
%% riak_core_pb_bucket_key_apl: Expose Core active preflist functionality to
%% Protocol Buffers
%%
%% Copyright (c) 2015 Basho Technologies, Inc.
%%
%% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file
%% except in compliance with the License. You may obtain
%% a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing,
%% software distributed under the License is distributed on an
%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
%% KIND, either express or implied. See the License for the
%% specific language governing permissions and limitations
%% under the License.
%%
%% --------------------------------------------------------------------------

%% @doc <p>The Bucket-Key Preflist (Primaries & Fallbacks) PB service
%% for Riak Core. This service covers the following request messages in the
%% original protocol:</p>
%%
%% <pre>
%% 33 - RpbGetBucketKeyPreflistReq
%% </pre>
%%
%% <p>This service produces the following responses:</p>
%%
%% <pre>
%% 34 - RpbGetBucketKeyPreflistResp
%% </pre>
%%
%% @end
-module(riak_core_pb_bucket_key_apl).

-behaviour(riak_api_pb_service).

-export([init/0,
decode/2,
encode/1,
process/2,
process_stream/3]).

-include_lib("riak_pb/include/riak_pb.hrl").

init() ->
undefined.

%% @doc decode/2 callback. Decodes an incoming message.
decode(Code, Bin) when Code == 33 ->
Msg = riak_pb_codec:decode(Code, Bin),
case Msg of
#rpbgetbucketkeypreflistreq{type =T, bucket =B, key =Key} ->
Bucket = riak_core_pb_bucket:bucket_type(T, B),
{ok, Msg, {"riak_core.get_preflist", {Bucket, Key}}}
end.

%% @doc encode/1 callback. Encodes an outgoing response message.
encode(Message) ->
{ok, riak_pb_codec:encode(Message)}.

%% Get bucket-key preflist primaries
process(#rpbgetbucketkeypreflistreq{type=T, bucket=B0, key =K}, State) ->
B = riak_core_pb_bucket:maybe_create_bucket_type(T, B0),
Preflist = riak_core_apl:get_apl_ann_with_pnum({B, K}),
case Preflist of
[] ->
{error, {format,
"No preflist for bucket '~s' and key '~s'",
[B, K]}, State};
P ->
PbPreflist = riak_pb_codec:encode_apl_ann(P),
{reply, #rpbgetbucketkeypreflistresp{preflist=PbPreflist}, State}
end.

process_stream(_, _, State) ->
{ignore, State}.