Switch from binary_bucketlist

Allow for bucket listing of non-binary buckets (integer buckets, buckets with ascii strings)
This commit is contained in:
Martin Sumner 2018-09-01 10:39:23 +01:00
parent 41fb83abd1
commit 50967438d3
4 changed files with 19 additions and 18 deletions

View file

@ -503,7 +503,7 @@ book_head(Pid, Bucket, Key) ->
%% {bucket_stats, Bucket} -> return a key count and total object size within %% {bucket_stats, Bucket} -> return a key count and total object size within
%% a bucket %% a bucket
%% {riakbucket_stats, Bucket} -> as above, but for buckets with the Riak Tag %% {riakbucket_stats, Bucket} -> as above, but for buckets with the Riak Tag
%% {binary_bucketlist, Tag, {FoldKeysFun, Acc}} -> if we assume buckets and %% {bucket_list, Tag, {FoldKeysFun, Acc}} -> if we assume buckets and
%% keys are binaries, provides a fast bucket list function %% keys are binaries, provides a fast bucket list function
%% {index_query, %% {index_query,
%% Constraint, %% Constraint,
@ -1200,14 +1200,14 @@ get_runner(State,
leveled_runner:foldobjects_byindex(SnapFun, leveled_runner:foldobjects_byindex(SnapFun,
{Tag, Bucket, Field, FromTerm, ToTerm}, {Tag, Bucket, Field, FromTerm, ToTerm},
FoldObjectsFun); FoldObjectsFun);
get_runner(State, {binary_bucketlist, Tag, FoldAccT}) -> get_runner(State, {bucket_list, Tag, FoldAccT}) ->
{FoldBucketsFun, Acc} = FoldAccT, {FoldBucketsFun, Acc} = FoldAccT,
SnapFun = return_snapfun(State, ledger, no_lookup, false, false), SnapFun = return_snapfun(State, ledger, no_lookup, false, false),
leveled_runner:binary_bucketlist(SnapFun, Tag, FoldBucketsFun, Acc); leveled_runner:bucket_list(SnapFun, Tag, FoldBucketsFun, Acc);
get_runner(State, {first_bucket, Tag, FoldAccT}) -> get_runner(State, {first_bucket, Tag, FoldAccT}) ->
{FoldBucketsFun, Acc} = FoldAccT, {FoldBucketsFun, Acc} = FoldAccT,
SnapFun = return_snapfun(State, ledger, no_lookup, false, false), SnapFun = return_snapfun(State, ledger, no_lookup, false, false),
leveled_runner:binary_bucketlist(SnapFun, Tag, FoldBucketsFun, Acc, 1); leveled_runner:bucket_list(SnapFun, Tag, FoldBucketsFun, Acc, 1);
%% Set of specific runners, primarily used as exmaples for tests %% Set of specific runners, primarily used as exmaples for tests
get_runner(State, DeprecatedQuery) -> get_runner(State, DeprecatedQuery) ->
get_deprecatedrunner(State, DeprecatedQuery). get_deprecatedrunner(State, DeprecatedQuery).

View file

@ -23,8 +23,8 @@
-export([ -export([
bucket_sizestats/3, bucket_sizestats/3,
binary_bucketlist/4, bucket_list/4,
binary_bucketlist/5, bucket_list/5,
index_query/3, index_query/3,
bucketkey_query/4, bucketkey_query/4,
bucketkey_query/5, bucketkey_query/5,
@ -73,19 +73,20 @@ bucket_sizestats(SnapFun, Bucket, Tag) ->
end, end,
{async, Runner}. {async, Runner}.
-spec binary_bucketlist(fun(), leveled_codec:tag(), fun(), any()) -spec bucket_list(fun(), leveled_codec:tag(), fun(), any())
-> {async, fun()}. -> {async, fun()}.
%% @doc %% @doc
%% List buckets for tag, assuming bucket names are all binary type %% List buckets for tag, assuming bucket names are all either binary, ascii
binary_bucketlist(SnapFun, Tag, FoldBucketsFun, InitAcc) -> %% strings or integers
binary_bucketlist(SnapFun, Tag, FoldBucketsFun, InitAcc, -1). bucket_list(SnapFun, Tag, FoldBucketsFun, InitAcc) ->
bucket_list(SnapFun, Tag, FoldBucketsFun, InitAcc, -1).
-spec binary_bucketlist(fun(), leveled_codec:tag(), fun(), any(), integer()) -spec bucket_list(fun(), leveled_codec:tag(), fun(), any(), integer())
-> {async, fun()}. -> {async, fun()}.
%% @doc %% @doc
%% set Max Buckets to -1 to list all buckets, otherwise will only return %% set Max Buckets to -1 to list all buckets, otherwise will only return
%% MaxBuckets (use 1 to confirm that there exists any bucket for a given Tag) %% MaxBuckets (use 1 to confirm that there exists any bucket for a given Tag)
binary_bucketlist(SnapFun, Tag, FoldBucketsFun, InitAcc, MaxBuckets) -> bucket_list(SnapFun, Tag, FoldBucketsFun, InitAcc, MaxBuckets) ->
Runner = Runner =
fun() -> fun() ->
{ok, LedgerSnapshot, _JournalSnapshot} = SnapFun(), {ok, LedgerSnapshot, _JournalSnapshot} = SnapFun(),

View file

@ -778,7 +778,7 @@ is_empty_test(_Config) ->
ok = testutil:book_riakput(Bookie1, TestObject3, TestSpec3), ok = testutil:book_riakput(Bookie1, TestObject3, TestSpec3),
FoldBucketsFun = fun(B, Acc) -> sets:add_element(B, Acc) end, FoldBucketsFun = fun(B, Acc) -> sets:add_element(B, Acc) end,
BucketListQuery = {binary_bucketlist, BucketListQuery = {bucket_list,
?RIAK_TAG, ?RIAK_TAG,
{FoldBucketsFun, sets:new()}}, {FoldBucketsFun, sets:new()}},
{async, BL} = leveled_bookie:book_returnfolder(Bookie1, BucketListQuery), {async, BL} = leveled_bookie:book_returnfolder(Bookie1, BucketListQuery),

View file

@ -173,13 +173,13 @@ small_load_with2i(_Config) ->
true = Total2 == Total1, true = Total2 == Total1,
FoldBucketsFun = fun(B, Acc) -> sets:add_element(B, Acc) end, FoldBucketsFun = fun(B, Acc) -> sets:add_element(B, Acc) end,
% Should not find any buckets - as there is a non-binary bucket, and no % this should find Bucket and Bucket1 - as we can now find string-based
% binary ones % buckets using bucket_list - i.e. it isn't just binary buckets now
BucketListQuery = {binary_bucketlist, BucketListQuery = {bucket_list,
?RIAK_TAG, ?RIAK_TAG,
{FoldBucketsFun, sets:new()}}, {FoldBucketsFun, sets:new()}},
{async, BL} = leveled_bookie:book_returnfolder(Bookie2, BucketListQuery), {async, BL} = leveled_bookie:book_returnfolder(Bookie2, BucketListQuery),
true = sets:size(BL()) == 0, true = sets:size(BL()) == 2,
ok = leveled_bookie:book_close(Bookie2), ok = leveled_bookie:book_close(Bookie2),
testutil:reset_filestructure(). testutil:reset_filestructure().
@ -394,7 +394,7 @@ query_count(_Config) ->
testutil:check_forobject(Book4, TestObject), testutil:check_forobject(Book4, TestObject),
FoldBucketsFun = fun(B, Acc) -> sets:add_element(B, Acc) end, FoldBucketsFun = fun(B, Acc) -> sets:add_element(B, Acc) end,
BucketListQuery = {binary_bucketlist, BucketListQuery = {bucket_list,
?RIAK_TAG, ?RIAK_TAG,
{FoldBucketsFun, sets:new()}}, {FoldBucketsFun, sets:new()}},
{async, BLF1} = leveled_bookie:book_returnfolder(Book4, BucketListQuery), {async, BLF1} = leveled_bookie:book_returnfolder(Book4, BucketListQuery),