|
| 1 | +%% ------------------------------------------------------------------- |
| 2 | +%% |
| 3 | +%% basho_bench: Benchmarking Suite |
| 4 | +%% |
| 5 | +%% Copyright (c) 2009-2010 Basho Techonologies |
| 6 | +%% |
| 7 | +%% This file is provided to you under the Apache License, |
| 8 | +%% Version 2.0 (the "License"); you may not use this file |
| 9 | +%% except in compliance with the License. You may obtain |
| 10 | +%% a copy of the License at |
| 11 | +%% |
| 12 | +%% http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | +%% |
| 14 | +%% Unless required by applicable law or agreed to in writing, |
| 15 | +%% software distributed under the License is distributed on an |
| 16 | +%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 17 | +%% KIND, either express or implied. See the License for the |
| 18 | +%% specific language governing permissions and limitations |
| 19 | +%% under the License. |
| 20 | +%% |
| 21 | +%% ------------------------------------------------------------------- |
| 22 | +-module(basho_bench_driver_kv_backend). |
| 23 | + |
| 24 | +-export([new/1, |
| 25 | + run/4]). |
| 26 | + |
| 27 | +-include("basho_bench.hrl"). |
| 28 | + |
| 29 | +-record(state, { |
| 30 | + backend :: atom(), |
| 31 | + bucket :: binary(), |
| 32 | + uses_r_object :: boolean(), |
| 33 | + be_state :: term() |
| 34 | + }). |
| 35 | + |
| 36 | +%% ==================================================================== |
| 37 | +%% API |
| 38 | +%% ==================================================================== |
| 39 | + |
| 40 | +%% @doc new |
| 41 | +%% |
| 42 | +%% Config items: |
| 43 | +%% - be_backend_mod :: atom() |
| 44 | +%% - be_disable_uses_r_object :: boolean() |
| 45 | +%% - be_config :: proplist(), passed to start/2 |
| 46 | + |
| 47 | +new(_Id) -> |
| 48 | + Backend = basho_bench_config:get(be_backend_mod, riak_kv_yessir_backend), |
| 49 | + io:format("DBG ~p\n", [Backend]), |
| 50 | + Bucket = <<"Oh, shouldn't matter much">>, |
| 51 | + {ok, Caps} = Backend:capabilities(x), |
| 52 | + UsesRObj = proplists:get_value(uses_r_object, Caps, false), |
| 53 | + RObjDisabled = basho_bench_config:get(be_disable_uses_r_object, false), |
| 54 | + Use = UsesRObj andalso not RObjDisabled, |
| 55 | + {ok, BE} = Backend:start(0, basho_bench_config:get(be_config, [])), |
| 56 | + |
| 57 | + {ok, #state{backend=Backend, bucket=Bucket, uses_r_object=Use, |
| 58 | + be_state=BE}}. |
| 59 | + |
| 60 | +run(get, KeyGen, _ValueGen, |
| 61 | + #state{backend=Backend, bucket=Bucket, uses_r_object=RObjP, |
| 62 | + be_state=BE} = State) -> |
| 63 | + Key = KeyGen(), |
| 64 | + if RObjP -> |
| 65 | + {_ok_err, _, NewBE} = Backend:get_object(Bucket, Key, false, BE), |
| 66 | + {ok, State#state{be_state = NewBE}}; |
| 67 | + true -> |
| 68 | + {_ok_err, _, NewBE} = Backend:get(Bucket, Key, BE), |
| 69 | + {ok, State#state{be_state = NewBE}} |
| 70 | + end; |
| 71 | +run(put, KeyGen, ValueGen, |
| 72 | + #state{backend=Backend, bucket=Bucket, be_state=BE} = State) -> |
| 73 | + Key = KeyGen(), |
| 74 | + Val = ValueGen(), |
| 75 | + {ok, NewBE} = Backend:put(Bucket, Key, [], Val, BE), |
| 76 | + {ok, State#state{be_state = NewBE}}; |
| 77 | +run(do_something_else, KeyGen, ValueGen, State) -> |
| 78 | + _Key = KeyGen(), |
| 79 | + ValueGen(), |
| 80 | + {ok, State}; |
| 81 | +run(an_error, KeyGen, _ValueGen, State) -> |
| 82 | + _Key = KeyGen(), |
| 83 | + {error, went_wrong, State}; |
| 84 | +run(another_error, KeyGen, _ValueGen, State) -> |
| 85 | + _Key = KeyGen(), |
| 86 | + {error, {bad, things, happened}, State}. |
| 87 | + |
0 commit comments