Skip to content

Commit b8722e4

Browse files
committed
Factor index_spec type out into riak_kv_backend
It's bad practice to copy and paste the same type spec to a bunch of different modules, especially in a case like this where it's part of a defined behavior.
1 parent 16dd167 commit b8722e4

7 files changed

+38
-38
lines changed

src/riak_kv_backend.erl

+6-4
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@
3131
any() |
3232
no_return()).
3333

34+
-type index_spec() :: {add, Index, SecondaryKey} | {remove, Index, SecondaryKey}.
35+
3436
-export_type([fold_buckets_fun/0,
3537
fold_keys_fun/0,
36-
fold_objects_fun/0]).
38+
fold_objects_fun/0,
39+
index_spec/0]).
3740

3841
%% These are just here to make the callback specs more succinct and readable
3942
-type state() :: term().
@@ -54,12 +57,11 @@
5457
{ok, Value :: term(), state()} |
5558
{ok, not_found, state()} |
5659
{error, term(), state()}.
57-
%% TODO pull all the copy-pasted index_spec() type specs into this mod and use in the callback spec
58-
-callback put(riak_object:bucket(), riak_object:key(), IndexSpecs :: term(), Value :: binary(),
60+
-callback put(riak_object:bucket(), riak_object:key(), [index_spec()], Value :: binary(),
5961
state()) ->
6062
{ok, state()} |
6163
{error, term(), state()}.
62-
-callback delete(riak_object:bucket(), riak_object:key(), IndexSpecs :: term(), state()) ->
64+
-callback delete(riak_object:bucket(), riak_object:key(), [index_spec()], state()) ->
6365
{ok, state()} |
6466
{error, term(), state()}.
6567

src/riak_kv_bitcask_backend.erl

+6-6
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,10 @@ get(Bucket, Key, #state{ref=Ref, key_vsn=KVers}=State) ->
222222
%% NOTE: The bitcask backend does not currently support
223223
%% secondary indexing and the_IndexSpecs parameter
224224
%% is ignored.
225-
-type index_spec() :: {add, Index, SecondaryKey} | {remove, Index, SecondaryKey}.
226-
-spec put(riak_object:bucket(), riak_object:key(), [index_spec()], binary(), state()) ->
227-
{ok, state()} |
228-
{error, term(), state()}.
225+
-spec put(riak_object:bucket(), riak_object:key(), [riak_kv_backend:index_spec()],
226+
binary(), state()) ->
227+
{ok, state()} |
228+
{error, term(), state()}.
229229
put(Bucket, PrimaryKey, _IndexSpecs, Val,
230230
#state{ref=Ref, key_vsn=KeyVsn}=State) ->
231231
BitcaskKey = make_bk(KeyVsn, Bucket, PrimaryKey),
@@ -240,8 +240,8 @@ put(Bucket, PrimaryKey, _IndexSpecs, Val,
240240
%% NOTE: The bitcask backend does not currently support
241241
%% secondary indexing and the_IndexSpecs parameter
242242
%% is ignored.
243-
-spec delete(riak_object:bucket(), riak_object:key(), [index_spec()], state()) ->
244-
{ok, state()}.
243+
-spec delete(riak_object:bucket(), riak_object:key(), [riak_kv_backend:index_spec()], state()) ->
244+
{ok, state()}.
245245
delete(Bucket, Key, _IndexSpecs,
246246
#state{ref=Ref, key_vsn=KeyVsn}=State) ->
247247
BitcaskKey = make_bk(KeyVsn, Bucket, Key),

src/riak_kv_eleveldb_backend.erl

+7-7
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,10 @@ get(Bucket, Key, #state{read_opts=ReadOpts,
171171
end.
172172

173173
%% @doc Insert an object into the eleveldb backend.
174-
-type index_spec() :: {add, Index, SecondaryKey} | {remove, Index, SecondaryKey}.
175-
-spec put(riak_object:bucket(), riak_object:key(), [index_spec()], binary(), state()) ->
176-
{ok, state()} |
177-
{error, term(), state()}.
174+
-spec put(riak_object:bucket(), riak_object:key(), [riak_kv_backend:index_spec()],
175+
binary(), state()) ->
176+
{ok, state()} |
177+
{error, term(), state()}.
178178
put(Bucket, PrimaryKey, IndexSpecs, Val, #state{ref=Ref,
179179
write_opts=WriteOpts,
180180
legacy_indexes=WriteLegacy,
@@ -307,9 +307,9 @@ fixed_index_status(#state{fixed_indexes=Fixed}) ->
307307
Fixed.
308308

309309
%% @doc Delete an object from the eleveldb backend
310-
-spec delete(riak_object:bucket(), riak_object:key(), [index_spec()], state()) ->
311-
{ok, state()} |
312-
{error, term(), state()}.
310+
-spec delete(riak_object:bucket(), riak_object:key(), [riak_kv_backend:index_spec()], state()) ->
311+
{ok, state()} |
312+
{error, term(), state()}.
313313
delete(Bucket, PrimaryKey, IndexSpecs, #state{ref=Ref,
314314
write_opts=WriteOpts,
315315
fixed_indexes=FixedIndexes}=State) ->

src/riak_kv_memory_backend.erl

+3-4
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,8 @@ get(Bucket, Key, State=#state{data_ref=DataRef,
203203
end.
204204

205205
%% @doc Insert an object into the memory backend.
206-
-type index_spec() :: {add, Index, SecondaryKey} | {remove, Index, SecondaryKey}.
207-
-spec put(riak_object:bucket(), riak_object:key(), [index_spec()], binary(), state()) ->
208-
{ok, state()}.
206+
-spec put(riak_object:bucket(), riak_object:key(), [riak_kv_backend:index_spec()],
207+
binary(), state()) -> {ok, state()}.
209208
put(Bucket, PrimaryKey, IndexSpecs, Val, State=#state{data_ref=DataRef,
210209
index_ref=IndexRef,
211210
max_memory=MaxMemory,
@@ -253,7 +252,7 @@ put(Bucket, PrimaryKey, IndexSpecs, Val, State=#state{data_ref=DataRef,
253252
put_obj_size=Size}}.
254253

255254
%% @doc Delete an object from the memory backend
256-
-spec delete(riak_object:bucket(), riak_object:key(), [index_spec()], state()) ->
255+
-spec delete(riak_object:bucket(), riak_object:key(), [riak_kv_backend:index_spec()], state()) ->
257256
{ok, state()}.
258257
delete(Bucket, Key, IndexSpecs, State=#state{data_ref=DataRef,
259258
index_ref=IndexRef,

src/riak_kv_multi_backend.erl

+5-5
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,10 @@ get(Bucket, Key, State) ->
228228

229229
%% @doc Insert an object with secondary index
230230
%% information into the kv backend
231-
-type index_spec() :: {add, Index, SecondaryKey} | {remove, Index, SecondaryKey}.
232-
-spec put(riak_object:bucket(), riak_object:key(), [index_spec()], binary(), state()) ->
233-
{ok, state()} |
234-
{error, term(), state()}.
231+
-spec put(riak_object:bucket(), riak_object:key(), [riak_kv_backend:index_spec()],
232+
binary(), state()) ->
233+
{ok, state()} |
234+
{error, term(), state()}.
235235
put(Bucket, PrimaryKey, IndexSpecs, Value, State) ->
236236
{Name, Module, SubState} = get_backend(Bucket, State),
237237
case Module:put(Bucket, PrimaryKey, IndexSpecs, Value, SubState) of
@@ -244,7 +244,7 @@ put(Bucket, PrimaryKey, IndexSpecs, Value, State) ->
244244
end.
245245

246246
%% @doc Delete an object from the backend
247-
-spec delete(riak_object:bucket(), riak_object:key(), [index_spec()], state()) ->
247+
-spec delete(riak_object:bucket(), riak_object:key(), [riak_kv_backend:index_spec()], state()) ->
248248
{ok, state()} |
249249
{error, term(), state()}.
250250
delete(Bucket, Key, IndexSpecs, State) ->

src/riak_kv_multi_prefix_backend.erl

+7-7
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,10 @@ get(Bucket, Key, State) ->
273273

274274
%% @doc Insert an object with secondary index
275275
%% information into the kv backend
276-
-type index_spec() :: {add, Index, SecondaryKey} | {remove, Index, SecondaryKey}.
277-
-spec put(riak_object:bucket(), riak_object:key(), [index_spec()], binary(), state()) ->
278-
{ok, state()} |
279-
{error, term(), state()}.
276+
-spec put(riak_object:bucket(), riak_object:key(), [riak_kv_backend:index_spec()],
277+
binary(), state()) ->
278+
{ok, state()} |
279+
{error, term(), state()}.
280280
put(Bucket, PrimaryKey, IndexSpecs, Value, State) ->
281281
{Name, Module, SubState} = get_backend(Bucket, State),
282282
case Module:put(Bucket, PrimaryKey, IndexSpecs, Value, SubState) of
@@ -289,9 +289,9 @@ put(Bucket, PrimaryKey, IndexSpecs, Value, State) ->
289289
end.
290290

291291
%% @doc Delete an object from the backend
292-
-spec delete(riak_object:bucket(), riak_object:key(), [index_spec()], state()) ->
293-
{ok, state()} |
294-
{error, term(), state()}.
292+
-spec delete(riak_object:bucket(), riak_object:key(), [riak_kv_backend:index_spec()], state()) ->
293+
{ok, state()} |
294+
{error, term(), state()}.
295295
delete(Bucket, Key, IndexSpecs, State) ->
296296
{Name, Module, SubState} = get_backend(Bucket, State),
297297
case Module:delete(Bucket, Key, IndexSpecs, SubState) of

src/riak_kv_yessir_backend.erl

+4-5
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,8 @@ make_get_return_val(RObj, false = _WantsBinary, #state{op_get = Gets} = S) ->
266266
{ok, RObj, S#state{op_get = Gets + 1}}.
267267

268268
%% @doc Store an object, yes, sir!
269-
-type index_spec() :: {add, Index, SecondaryKey} | {remove, Index, SecondaryKey}.
270-
-spec put(riak_object:bucket(), riak_object:key(), [index_spec()], binary(), state()) ->
271-
{ok, state()}.
269+
-spec put(riak_object:bucket(), riak_object:key(), [riak_kv_backend:index_spec()],
270+
binary(), state()) -> {ok, state()}.
272271
put(_Bucket, _PKey, _IndexSpecs, _Val, #state{op_put = Puts} = S) ->
273272
{ok, S#state{op_put = Puts + 1}}.
274273

@@ -286,8 +285,8 @@ put_object(Bucket, PKey, _IndexSpecs, RObj, #state{op_put = Puts} = S) ->
286285
{{ok, S#state{op_put = Puts + 1}}, EncodedVal}.
287286

288287
%% @doc Delete an object, yes, sir!
289-
-spec delete(riak_object:bucket(), riak_object:key(), [index_spec()], state()) ->
290-
{ok, state()}.
288+
-spec delete(riak_object:bucket(), riak_object:key(), [riak_kv_backend:index_spec()], state()) ->
289+
{ok, state()}.
291290
delete(_Bucket, _Key, _IndexSpecs, #state{op_delete = Deletes} = S) ->
292291
{ok, S#state{op_delete = Deletes + 1}}.
293292

0 commit comments

Comments
 (0)