diff --git a/src/box/CMakeLists.txt b/src/box/CMakeLists.txt index a4246b11d20633050219dba763e1535fa4ce15e1..bb02aaa38b9e6d57a441fb4f5e689cd77f9b8345 100644 --- a/src/box/CMakeLists.txt +++ b/src/box/CMakeLists.txt @@ -26,4 +26,7 @@ add_custom_target(generate_lua_sources} set_property(DIRECTORY PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${lua_sources}) tarantool_module("box" tuple.m index.m hash_index.m tree_index.m space.m - port.m request.m txn.m box.m ${lua_sources} box_lua.m box_lua_space.m) + port.m request.m txn.m box.m ${lua_sources} box_lua.m box_lua_space.m + bitset_index.m) + +target_link_libraries(tarantool_box bitset) diff --git a/src/box/bitset_index.h b/src/box/bitset_index.h new file mode 100644 index 0000000000000000000000000000000000000000..fbaf074409b3253a72dc96a24f02078591f2f5f8 --- /dev/null +++ b/src/box/bitset_index.h @@ -0,0 +1,50 @@ +#ifndef TARANTOOL_BOX_INDEX_BITSET_H_INCLUDED +#define TARANTOOL_BOX_INDEX_BITSET_H_INCLUDED + +/* + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/** + * @brief Objective C wrapper for bitset_index + * @see bitset/index.h + */ + +#include "index.h" +#include <lib/bitset/index.h> + +struct bitset_index; +struct bitset_expr; + +@interface BitsetIndex: Index { + @private + struct bitset_index index; +} +@end + +#endif /* TARANTOOL_BOX_INDEX_BITSET_H_INCLUDED */ diff --git a/src/box/bitset_index.m b/src/box/bitset_index.m new file mode 100644 index 0000000000000000000000000000000000000000..5d0eba8815fe4354cbb8ba20a20dfb0d1c67f861 --- /dev/null +++ b/src/box/bitset_index.m @@ -0,0 +1,301 @@ +/* + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "bitset_index.h" + +#include <string.h> + +#include "salloc.h" +#include "tuple.h" +#include "space.h" +#include "exception.h" +#include "pickle.h" +#include <lib/bitset/index.h> + +static struct index_traits bitset_index_traits = { + .allows_partial_key = false, +}; + +static inline size_t +tuple_to_value(struct tuple *tuple) +{ + size_t value = salloc_ptr_to_index(tuple); + assert(salloc_ptr_from_index(value) == tuple); + return value; +} + +static inline struct tuple * +value_to_tuple(size_t value) +{ + return salloc_ptr_from_index(value); +} + +struct iterator_wrapper { + struct iterator base; /* Must be the first member. */ + struct bitset_iterator bitset_it; +}; + +static struct iterator_wrapper * +iterator_wrapper(struct iterator *it) +{ + return (struct iterator_wrapper *) it; +} + +void +iterator_wrapper_free(struct iterator *iterator) +{ + assert(iterator->free == iterator_wrapper_free); + struct iterator_wrapper *it = iterator_wrapper(iterator); + + bitset_iterator_destroy(&it->bitset_it); + free(it); +} + +struct tuple * +iterator_wrapper_next(struct iterator *iterator) +{ + assert(iterator->free == iterator_wrapper_free); + struct iterator_wrapper *it = iterator_wrapper(iterator); + + size_t value = bitset_iterator_next(&it->bitset_it); + if (value == SIZE_MAX) + return NULL; + + return value_to_tuple(value); +} + +@implementation BitsetIndex; + ++ (struct index_traits *) traits +{ + return &bitset_index_traits; +} + +- (id) init: (struct key_def *) key_def_arg :(struct space *) space_arg +{ + assert (!key_def_arg->is_unique); + + self = [super init: key_def_arg :space_arg]; + assert (self != NULL); + + if (bitset_index_create(&self->index, realloc) != 0) + panic_syserror("bitset_index_create"); + + return self; +} + +- (void) free +{ + bitset_index_destroy(&self->index); + [super free]; +} + +- (void) beginBuild +{ + tnt_raise(ClientError, :ER_UNSUPPORTED, "BitsetIndex", "beginBuild()"); +} + +- (void) buildNext: (struct tuple *)tuple +{ + (void) tuple; + tnt_raise(ClientError, :ER_UNSUPPORTED, "BitsetIndex", "buildNext()"); +} + +- (void) endBuild +{ + tnt_raise(ClientError, :ER_UNSUPPORTED, "BitsetIndex", "endBuild()"); +} + +- (void) build: (Index *) pk +{ + assert (!key_def->is_unique); + + struct iterator *it = pk->position; + struct tuple *tuple; + [pk initIterator: it :ITER_ALL :NULL :0]; + + while ((tuple = it->next(it))) + [self replace: NULL :tuple :DUP_INSERT]; +} + +- (size_t) size +{ + return bitset_index_size(&self->index); +} + +- (struct tuple *) min +{ + tnt_raise(ClientError, :ER_UNSUPPORTED, "BitsetIndex", "min()"); + return NULL; +} + +- (struct tuple *) max +{ + tnt_raise(ClientError, :ER_UNSUPPORTED, "BitsetIndex", "max()"); + return NULL; +} + +- (struct iterator *) allocIterator +{ + struct iterator_wrapper *it = malloc(sizeof(struct iterator_wrapper)); + if (!it) + return NULL; + + memset(it, 0, sizeof(struct iterator_wrapper)); + it->base.next = iterator_wrapper_next; + it->base.free = iterator_wrapper_free; + + bitset_iterator_create(&it->bitset_it, realloc); + + return (struct iterator *) it; +} + +- (struct tuple *) findByKey: (void *) key :(int) part_count +{ + (void) key; + (void) part_count; + tnt_raise(ClientError, :ER_UNSUPPORTED, "BitsetIndex", "findByKey()"); + return NULL; +} + +- (struct tuple *) findByTuple: (struct tuple *) tuple +{ + (void) tuple; + tnt_raise(ClientError, :ER_UNSUPPORTED, "BitsetIndex", "findByTuple()"); + return NULL; +} + +- (struct tuple *) replace: (struct tuple *) old_tuple + : (struct tuple *) new_tuple + : (u32) flags +{ + assert(!key_def->is_unique); + assert(old_tuple != NULL || new_tuple != NULL); + (void) flags; + + struct tuple *ret = NULL; + + if (old_tuple != NULL) { + size_t value = tuple_to_value(old_tuple); +#if defined(DEBUG) + say_debug("BitsetIndex: remove value = %zu (%p)", + value, old_tuple); +#endif /* defined(DEBUG) */ + if (bitset_index_contains_value(&self->index, value)) { + ret = old_tuple; + + assert (old_tuple != new_tuple); + bitset_index_remove_value(&self->index, value); + } + } + + if (new_tuple != NULL) { + const void *field = tuple_field(new_tuple, + key_def->parts[0].fieldno); + assert (field != NULL); + size_t bitset_key_size = (size_t) load_varint32(&field); + const void *bitset_key = field; + + size_t value = tuple_to_value(new_tuple); +#if defined(DEBUG) + say_debug("BitsetIndex: insert value = %zu (%p)", + value, new_tuple); +#endif /* defined(DEBUG) */ + if (bitset_index_insert(&self->index, bitset_key, + bitset_key_size, value) < 0) { + tnt_raise(ClientError, :ER_MEMORY_ISSUE, 0, + "BitsetIndex", "insert"); + } + } + + return ret; +} + +- (void) initIterator: (struct iterator *) iterator:(enum iterator_type) type + :(const void *) key :(int) part_count +{ + assert(iterator->free == iterator_wrapper_free); + struct iterator_wrapper *it = iterator_wrapper(iterator); + + const void *bitset_key = NULL; + size_t bitset_key_size = 0; + + if (type != ITER_ALL) { + check_key_parts(key_def, part_count, + bitset_index_traits.allows_partial_key); + const void *key2 = key; + bitset_key_size = (size_t) load_varint32(&key2); + bitset_key = key2; + } + + struct bitset_expr expr; + bitset_expr_create(&expr, realloc); + @try { + int rc = 0; + switch (type) { + case ITER_ALL: + rc = bitset_index_expr_all(&expr); + break; + case ITER_EQ: + rc = bitset_index_expr_equals(&expr, bitset_key, + bitset_key_size); + break; + case ITER_BITS_ALL_SET: + rc = bitset_index_expr_all_set(&expr, bitset_key, + bitset_key_size); + break; + case ITER_BITS_ALL_NOT_SET: + rc = bitset_index_expr_all_not_set(&expr, bitset_key, + bitset_key_size); + break; + case ITER_BITS_ANY_SET: + rc = bitset_index_expr_any_set(&expr, bitset_key, + bitset_key_size); + break; + default: + tnt_raise(ClientError, :ER_UNSUPPORTED, + "BitsetIndex", "requested iterator type"); + } + + if (rc != 0) { + tnt_raise(ClientError, :ER_MEMORY_ISSUE, + 0, "BitsetIndex", "iterator expression"); + } + + if (bitset_index_init_iterator(&self->index, &it->bitset_it, + &expr) != 0) { + tnt_raise(ClientError, :ER_MEMORY_ISSUE, + 0, "BitsetIndex", "iterator state"); + } + } @finally { + bitset_expr_destroy(&expr); + } +} + +@end diff --git a/src/box/index.h b/src/box/index.h index 7d394fb1b22783bfa91b0269b7f0e56e889d06e4..9c989731e53e75617876526e05d89b3e6fa8b03c 100644 --- a/src/box/index.h +++ b/src/box/index.h @@ -43,9 +43,10 @@ struct space; enum field_data_type { UNKNOWN = -1, NUM = 0, NUM64, STRING, field_data_type_MAX }; extern const char *field_data_type_strs[]; -#define INDEX_TYPE(_) \ - _(HASH, 0) /* HASH Index */ \ - _(TREE, 1) /* TREE Index */ \ +#define INDEX_TYPE(_) \ + _(HASH, 0) /* HASH Index */ \ + _(TREE, 1) /* TREE Index */ \ + _(BITSET, 2) /* BITSET Index */ \ ENUM(index_type, INDEX_TYPE); extern const char *index_type_strs[]; @@ -79,6 +80,9 @@ extern const char *index_type_strs[]; _(ITER_LE, 4) /* key <= x */ \ _(ITER_GE, 5) /* key >= x */ \ _(ITER_GT, 6) /* key > x */ \ + _(ITER_BITS_ALL_SET, 7) /* all bits from x are set in key */ \ + _(ITER_BITS_ANY_SET, 8) /* at least one x's bit is set */ \ + _(ITER_BITS_ALL_NOT_SET, 9) /* all bits are not set */ \ ENUM(iterator_type, ITERATOR_TYPE); extern const char *iterator_type_strs[]; diff --git a/src/box/index.m b/src/box/index.m index c105cb4a30c7d5a0d7b6c79679f61fd7f16e6458..b36865a9f2279a158afa314d938ca0920e8fbc25 100644 --- a/src/box/index.m +++ b/src/box/index.m @@ -29,6 +29,7 @@ #include "index.h" #include "hash_index.h" #include "tree_index.h" +#include "bitset_index.h" #include "tuple.h" #include "say.h" #include "exception.h" @@ -108,6 +109,8 @@ replace_check_dup(struct tuple *old_tuple, return [HashIndex alloc: key_def :space]; case TREE: return [TreeIndex alloc: key_def :space]; + case BITSET: + return [BitsetIndex alloc]; default: assert(false); } diff --git a/src/box/space.m b/src/box/space.m index 179ba6510de0f7cccecb62fd85411485d1444b4b..22b3a8981285ddd3371d25914d6fd626f6dc5232 100644 --- a/src/box/space.m +++ b/src/box/space.m @@ -572,6 +572,21 @@ check_spaces(struct tarantool_cfg *conf) case TREE: /* extra check for tree index not needed */ break; + case BITSET: + /* check bitset index */ + /* bitset index must has single-field key */ + if (key_part_count != 1) { + out_warning(0, "(space = %zu index = %zu) " + "bitset index must has a single-field key", i, j); + return -1; + } + /* bitset index must not be unique */ + if (index->unique) { + out_warning(0, "(space = %zu index = %zu) " + "bitset index must be non-unique", i, j); + return -1; + } + break; default: assert(false); } diff --git a/test/big/bitset.lua b/test/big/bitset.lua new file mode 100644 index 0000000000000000000000000000000000000000..b4331b248d5e48b5d40c18e17bfb86e330b1e02a --- /dev/null +++ b/test/big/bitset.lua @@ -0,0 +1,39 @@ +local SPACE_NO = 24 +local INDEX_NO = 1 + +function fill(...) + local nums = table.generate(arithmetic(...)); + table.shuffle(nums); + for _k, v in ipairs(nums) do + box.insert(SPACE_NO, v, v); + end +end + +function delete(...) + local nums = table.generate(arithmetic(...)); + table.shuffle(nums); + for _k, v in ipairs(nums) do + box.delete(SPACE_NO, v); + end +end + +function clear() + box.space[SPACE_NO]:truncate() +end + +function dump(...) + iterate(SPACE_NO, INDEX_NO, 1, 2, ...); +end + +function test_insert_delete(n) + local t = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, + 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127} + + table.shuffle(t); + + clear(); + fill(1, n); + + for _, v in ipairs(t) do delete(v, n / v) end + dump(box.index.BITS_ALL) +end diff --git a/test/big/bitset.result b/test/big/bitset.result new file mode 100644 index 0000000000000000000000000000000000000000..e0bf2c192b3253a4ccf3ef604777c443ab1fd476 --- /dev/null +++ b/test/big/bitset.result @@ -0,0 +1,1526 @@ +lua dofile('utils.lua') +--- +... +lua dofile('bitset.lua') +--- +... + +#-----------------------------------------------------------------------------# +# BitsetIndex: insert/delete +#-----------------------------------------------------------------------------# + +lua test_insert_delete(128) +--- +sorted output +$ 1$ +... + +#-----------------------------------------------------------------------------# +# BitsetIndex: ALL +#-----------------------------------------------------------------------------# + +lua clear() +--- +... +lua fill(1, 128) +--- +... +lua dump(box.index.BITS_ALL) +--- +sorted output +$ 1$ +$ 2$ +$ 3$ +$ 4$ +$ 5$ +$ 6$ +$ 7$ +$ 8$ +$ 9$ +$ 10$ +$ 11$ +$ 12$ +$ 13$ +$ 14$ +$ 15$ +$ 16$ +$ 17$ +$ 18$ +$ 19$ +$ 20$ +$ 21$ +$ 22$ +$ 23$ +$ 24$ +$ 25$ +$ 26$ +$ 27$ +$ 28$ +$ 29$ +$ 30$ +$ 31$ +$ 32$ +$ 33$ +$ 34$ +$ 35$ +$ 36$ +$ 37$ +$ 38$ +$ 39$ +$ 40$ +$ 41$ +$ 42$ +$ 43$ +$ 44$ +$ 45$ +$ 46$ +$ 47$ +$ 48$ +$ 49$ +$ 50$ +$ 51$ +$ 52$ +$ 53$ +$ 54$ +$ 55$ +$ 56$ +$ 57$ +$ 58$ +$ 59$ +$ 60$ +$ 61$ +$ 62$ +$ 63$ +$ 64$ +$ 65$ +$ 66$ +$ 67$ +$ 68$ +$ 69$ +$ 70$ +$ 71$ +$ 72$ +$ 73$ +$ 74$ +$ 75$ +$ 76$ +$ 77$ +$ 78$ +$ 79$ +$ 80$ +$ 81$ +$ 82$ +$ 83$ +$ 84$ +$ 85$ +$ 86$ +$ 87$ +$ 88$ +$ 89$ +$ 90$ +$ 91$ +$ 92$ +$ 93$ +$ 94$ +$ 95$ +$ 96$ +$ 97$ +$ 98$ +$ 99$ +$ 100$ +$ 101$ +$ 102$ +$ 103$ +$ 104$ +$ 105$ +$ 106$ +$ 107$ +$ 108$ +$ 109$ +$ 110$ +$ 111$ +$ 112$ +$ 113$ +$ 114$ +$ 115$ +$ 116$ +$ 117$ +$ 118$ +$ 119$ +$ 120$ +$ 121$ +$ 122$ +$ 123$ +$ 124$ +$ 125$ +$ 126$ +$ 127$ +$ 128$ +... + +#-----------------------------------------------------------------------------# +# BitsetIndex: BITS_ALL_SET (single bit) +#-----------------------------------------------------------------------------# + +lua dump(box.index.BITS_ALL_SET, 0) +--- +sorted output +... +lua dump(box.index.BITS_ALL_SET, 1) +--- +sorted output +$ 1$ +$ 3$ +$ 5$ +$ 7$ +$ 9$ +$ 11$ +$ 13$ +$ 15$ +$ 17$ +$ 19$ +$ 21$ +$ 23$ +$ 25$ +$ 27$ +$ 29$ +$ 31$ +$ 33$ +$ 35$ +$ 37$ +$ 39$ +$ 41$ +$ 43$ +$ 45$ +$ 47$ +$ 49$ +$ 51$ +$ 53$ +$ 55$ +$ 57$ +$ 59$ +$ 61$ +$ 63$ +$ 65$ +$ 67$ +$ 69$ +$ 71$ +$ 73$ +$ 75$ +$ 77$ +$ 79$ +$ 81$ +$ 83$ +$ 85$ +$ 87$ +$ 89$ +$ 91$ +$ 93$ +$ 95$ +$ 97$ +$ 99$ +$ 101$ +$ 103$ +$ 105$ +$ 107$ +$ 109$ +$ 111$ +$ 113$ +$ 115$ +$ 117$ +$ 119$ +$ 121$ +$ 123$ +$ 125$ +$ 127$ +... +lua dump(box.index.BITS_ALL_SET, 2) +--- +sorted output +$ 2$ +$ 3$ +$ 6$ +$ 7$ +$ 10$ +$ 11$ +$ 14$ +$ 15$ +$ 18$ +$ 19$ +$ 22$ +$ 23$ +$ 26$ +$ 27$ +$ 30$ +$ 31$ +$ 34$ +$ 35$ +$ 38$ +$ 39$ +$ 42$ +$ 43$ +$ 46$ +$ 47$ +$ 50$ +$ 51$ +$ 54$ +$ 55$ +$ 58$ +$ 59$ +$ 62$ +$ 63$ +$ 66$ +$ 67$ +$ 70$ +$ 71$ +$ 74$ +$ 75$ +$ 78$ +$ 79$ +$ 82$ +$ 83$ +$ 86$ +$ 87$ +$ 90$ +$ 91$ +$ 94$ +$ 95$ +$ 98$ +$ 99$ +$ 102$ +$ 103$ +$ 106$ +$ 107$ +$ 110$ +$ 111$ +$ 114$ +$ 115$ +$ 118$ +$ 119$ +$ 122$ +$ 123$ +$ 126$ +$ 127$ +... +lua dump(box.index.BITS_ALL_SET, 8) +--- +sorted output +$ 8$ +$ 9$ +$ 10$ +$ 11$ +$ 12$ +$ 13$ +$ 14$ +$ 15$ +$ 24$ +$ 25$ +$ 26$ +$ 27$ +$ 28$ +$ 29$ +$ 30$ +$ 31$ +$ 40$ +$ 41$ +$ 42$ +$ 43$ +$ 44$ +$ 45$ +$ 46$ +$ 47$ +$ 56$ +$ 57$ +$ 58$ +$ 59$ +$ 60$ +$ 61$ +$ 62$ +$ 63$ +$ 72$ +$ 73$ +$ 74$ +$ 75$ +$ 76$ +$ 77$ +$ 78$ +$ 79$ +$ 88$ +$ 89$ +$ 90$ +$ 91$ +$ 92$ +$ 93$ +$ 94$ +$ 95$ +$ 104$ +$ 105$ +$ 106$ +$ 107$ +$ 108$ +$ 109$ +$ 110$ +$ 111$ +$ 120$ +$ 121$ +$ 122$ +$ 123$ +$ 124$ +$ 125$ +$ 126$ +$ 127$ +... +lua dump(box.index.BITS_ALL_SET, 1073741824) +--- +sorted output +... +lua dump(box.index.BITS_ALL_SET, 2147483648) +--- +sorted output +... +lua dump(box.index.BITS_ALL_SET, 4294967296) +--- +sorted output +... + +#-----------------------------------------------------------------------------# +# BitsetIndex: BITS_ALL_SET (multiple bit) +#-----------------------------------------------------------------------------# + +lua dump(box.index.BITS_ALL_SET, 3) +--- +sorted output +$ 3$ +$ 7$ +$ 11$ +$ 15$ +$ 19$ +$ 23$ +$ 27$ +$ 31$ +$ 35$ +$ 39$ +$ 43$ +$ 47$ +$ 51$ +$ 55$ +$ 59$ +$ 63$ +$ 67$ +$ 71$ +$ 75$ +$ 79$ +$ 83$ +$ 87$ +$ 91$ +$ 95$ +$ 99$ +$ 103$ +$ 107$ +$ 111$ +$ 115$ +$ 119$ +$ 123$ +$ 127$ +... +lua dump(box.index.BITS_ALL_SET, 7) +--- +sorted output +$ 7$ +$ 15$ +$ 23$ +$ 31$ +$ 39$ +$ 47$ +$ 55$ +$ 63$ +$ 71$ +$ 79$ +$ 87$ +$ 95$ +$ 103$ +$ 111$ +$ 119$ +$ 127$ +... +lua dump(box.index.BITS_ALL_SET, 31) +--- +sorted output +$ 31$ +$ 63$ +$ 95$ +$ 127$ +... +lua dump(box.index.BITS_ALL_SET, 5) +--- +sorted output +$ 5$ +$ 7$ +$ 13$ +$ 15$ +$ 21$ +$ 23$ +$ 29$ +$ 31$ +$ 37$ +$ 39$ +$ 45$ +$ 47$ +$ 53$ +$ 55$ +$ 61$ +$ 63$ +$ 69$ +$ 71$ +$ 77$ +$ 79$ +$ 85$ +$ 87$ +$ 93$ +$ 95$ +$ 101$ +$ 103$ +$ 109$ +$ 111$ +$ 117$ +$ 119$ +$ 125$ +$ 127$ +... +lua dump(box.index.BITS_ALL_SET, 10) +--- +sorted output +$ 10$ +$ 11$ +$ 14$ +$ 15$ +$ 26$ +$ 27$ +$ 30$ +$ 31$ +$ 42$ +$ 43$ +$ 46$ +$ 47$ +$ 58$ +$ 59$ +$ 62$ +$ 63$ +$ 74$ +$ 75$ +$ 78$ +$ 79$ +$ 90$ +$ 91$ +$ 94$ +$ 95$ +$ 106$ +$ 107$ +$ 110$ +$ 111$ +$ 122$ +$ 123$ +$ 126$ +$ 127$ +... +lua dump(box.index.BITS_ALL_SET, 27) +--- +sorted output +$ 27$ +$ 31$ +$ 59$ +$ 63$ +$ 91$ +$ 95$ +$ 123$ +$ 127$ +... +lua dump(box.index.BITS_ALL_SET, 341) +--- +sorted output +... +lua dump(box.index.BITS_ALL_SET, 2147483649) +--- +sorted output +... +lua dump(box.index.BITS_ALL_SET, 4294967295) +--- +sorted output +... + +#-----------------------------------------------------------------------------# +# BitsetIndex: BITS_ALL_NOT_SET (single bit) +#-----------------------------------------------------------------------------# + +lua dump(box.index.BITS_ALL_NOT_SET, 0) +--- +sorted output +$ 1$ +$ 2$ +$ 3$ +$ 4$ +$ 5$ +$ 6$ +$ 7$ +$ 8$ +$ 9$ +$ 10$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 +$ 31$ +$ 32$ +$ 33$ +$ 34$ +$ 35$ +$ 36$ +$ 37$ +$ 38$ +$ 39$ +$ 40$ +$ 41$ +$ 42$ +$ 43$ +$ 44$ +$ 45$ +$ 46$ +$ 47$ +$ 48$ +$ 49$ +$ 50$ +$ 51$ +$ 52$ +$ 53$ +$ 54$ +$ 55$ +$ 56$ +$ 57$ +$ 58$ +$ 59$ +$ 60$ +$ 61$ +$ 62$ +$ 63$ +$ 64$ +$ 65$ +$ 66$ +$ 67$ +$ 68$ +$ 69$ +$ 70$ +$ 71$ +$ 72$ +$ 73$ +$ 74$ +$ 75$ +$ 76$ +$ 77$ +$ 78$ +$ 79$ +$ 80$ +$ 81$ +$ 82$ +$ 83$ +$ 84$ +$ 85$ +$ 86$ +$ 87$ +$ 88$ +$ 89$ +$ 90$ +$ 91$ +$ 92$ +$ 93$ +$ 94$ +$ 95$ +$ 96$ +$ 97$ +$ 98$ +$ 99$ +$ 100$ +$ 101$ +$ 102$ +$ 103$ +$ 104$ +$ 105$ +$ 106$ +$ 107$ +$ 108$ +$ 109$ +$ 110$ +$ 111$ +$ 112$ +$ 113$ +$ 114$ +$ 115$ +$ 116$ +$ 117$ +$ 118$ +$ 119$ +$ 120$ +$ 121$ +$ 122$ +$ 123$ +$ 124$ +$ 125$ +$ 126$ +$ 127$ +$ 128$ +... + +#-----------------------------------------------------------------------------# +# BitsetIndex: BITS_ALL_NOT_SET (multiple bit) +#-----------------------------------------------------------------------------# + +lua dump(box.index.BITS_ALL_NOT_SET, 3) +--- +sorted output +$ 4$ +$ 8$ +$ 12$ +$ 16$ +$ 20$ +$ 24$ +$ 28$ +$ 32$ +$ 36$ +$ 40$ +$ 44$ +$ 48$ +$ 52$ +$ 56$ +$ 60$ +$ 64$ +$ 68$ +$ 72$ +$ 76$ +$ 80$ +$ 84$ +$ 88$ +$ 92$ +$ 96$ +$ 100$ +$ 104$ +$ 108$ +$ 112$ +$ 116$ +$ 120$ +$ 124$ +$ 128$ +... +lua dump(box.index.BITS_ALL_NOT_SET, 7) +--- +sorted output +$ 8$ +$ 16$ +$ 24$ +$ 32$ +$ 40$ +$ 48$ +$ 56$ +$ 64$ +$ 72$ +$ 80$ +$ 88$ +$ 96$ +$ 104$ +$ 112$ +$ 120$ +$ 128$ +... +lua dump(box.index.BITS_ALL_NOT_SET, 10) +--- +sorted output +$ 1$ +$ 4$ +$ 5$ +$ 16$ +$ 17$ +$ 20$ +$ 21$ +$ 32$ +$ 33$ +$ 36$ +$ 37$ +$ 48$ +$ 49$ +$ 52$ +$ 53$ +$ 64$ +$ 65$ +$ 68$ +$ 69$ +$ 80$ +$ 81$ +$ 84$ +$ 85$ +$ 96$ +$ 97$ +$ 100$ +$ 101$ +$ 112$ +$ 113$ +$ 116$ +$ 117$ +$ 128$ +... +lua dump(box.index.BITS_ALL_NOT_SET, 27) +--- +sorted output +$ 4$ +$ 32$ +$ 36$ +$ 64$ +$ 68$ +$ 96$ +$ 100$ +$ 128$ +... +lua dump(box.index.BITS_ALL_NOT_SET, 85) +--- +sorted output +$ 2$ +$ 8$ +$ 10$ +$ 32$ +$ 34$ +$ 40$ +$ 42$ +$ 128$ +... +lua dump(box.index.BITS_ALL_NOT_SET, 4294967295) +--- +sorted output +... + +#-----------------------------------------------------------------------------# +# BitsetIndex: BITS_ANY_SET (single bit) +#-----------------------------------------------------------------------------# + +lua dump(box.index.BITS_ANY_SET, 0) +--- +sorted output +... +lua dump(box.index.BITS_ANY_SET, 16) +--- +sorted output +$ 16$ +$ 17$ +$ 18$ +$ 19$ +$ 20$ +$ 21$ +$ 22$ +$ 23$ +$ 24$ +$ 25$ +$ 26$ +$ 27$ +$ 28$ +$ 29$ +$ 30$ +$ 31$ +$ 48$ +$ 49$ +$ 50$ +$ 51$ +$ 52$ +$ 53$ +$ 54$ +$ 55$ +$ 56$ +$ 57$ +$ 58$ +$ 59$ +$ 60$ +$ 61$ +$ 62$ +$ 63$ +$ 80$ +$ 81$ +$ 82$ +$ 83$ +$ 84$ +$ 85$ +$ 86$ +$ 87$ +$ 88$ +$ 89$ +$ 90$ +$ 91$ +$ 92$ +$ 93$ +$ 94$ +$ 95$ +$ 112$ +$ 113$ +$ 114$ +$ 115$ +$ 116$ +$ 117$ +$ 118$ +$ 119$ +$ 120$ +$ 121$ +$ 122$ +$ 123$ +$ 124$ +$ 125$ +$ 126$ +$ 127$ +... +lua dump(box.index.BITS_ANY_SET, 128) +--- +sorted output +$ 128$ +... +lua dump(box.index.BITS_ANY_SET, 4294967296) +--- +sorted output +... + +#-----------------------------------------------------------------------------# +# BitsetIndex: BITS_ANY_SET (multiple bit) +#-----------------------------------------------------------------------------# + +lua dump(box.index.BITS_ANY_SET, 7) +--- +sorted output +$ 1$ +$ 2$ +$ 3$ +$ 4$ +$ 5$ +$ 6$ +$ 7$ +$ 9$ +$ 10$ +$ 11$ +$ 12$ +$ 13$ +$ 14$ +$ 15$ +$ 17$ +$ 18$ +$ 19$ +$ 20$ +$ 21$ +$ 22$ +$ 23$ +$ 25$ +$ 26$ +$ 27$ +$ 28$ +$ 29$ +$ 30$ +$ 31$ +$ 33$ +$ 34$ +$ 35$ +$ 36$ +$ 37$ +$ 38$ +$ 39$ +$ 41$ +$ 42$ +$ 43$ +$ 44$ +$ 45$ +$ 46$ +$ 47$ +$ 49$ +$ 50$ +$ 51$ +$ 52$ +$ 53$ +$ 54$ +$ 55$ +$ 57$ +$ 58$ +$ 59$ +$ 60$ +$ 61$ +$ 62$ +$ 63$ +$ 65$ +$ 66$ +$ 67$ +$ 68$ +$ 69$ +$ 70$ +$ 71$ +$ 73$ +$ 74$ +$ 75$ +$ 76$ +$ 77$ +$ 78$ +$ 79$ +$ 81$ +$ 82$ +$ 83$ +$ 84$ +$ 85$ +$ 86$ +$ 87$ +$ 89$ +$ 90$ +$ 91$ +$ 92$ +$ 93$ +$ 94$ +$ 95$ +$ 97$ +$ 98$ +$ 99$ +$ 100$ +$ 101$ +$ 102$ +$ 103$ +$ 105$ +$ 106$ +$ 107$ +$ 108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 15$ +$ 16$ +$ 17$ +$ 18$ +$ 19$ +$ 20$ +$ 21$ +$ 22$ +$ 23$ +$ 24$ +$ 25$ +$ 26$ +$ 27$ +$ 28$ +$ 29$ +$ 30$ +$ 31$ +$ 32$ +$ 33$ +$ 34$ +$ 35$ +$ 36$ +$ 37$ +$ 38$ +$ 39$ +$ 40$ +$ 41$ +$ 42$ +$ 43$ +$ 44$ +$ 45$ +$ 46$ +$ 47$ +$ 48$ +$ 49$ +$ 50$ +$ 51$ +$ 52$ +$ 53$ +$ 54$ +$ 55$ +$ 56$ +$ 57$ +$ 58$ +$ 59$ +$ 60$ +$ 61$ +$ 62$ +$ 63$ +$ 64$ +$ 65$ +$ 66$ +$ 67$ +$ 68$ +$ 69$ +$ 70$ +$ 71$ +$ 72$ +$ 73$ +$ 74$ +$ 75$ +$ 76$ +$ 77$ +$ 78$ +$ 79$ +$ 80$ +$ 81$ +$ 82$ +$ 83$ +$ 84$ +$ 85$ +$ 86$ +$ 87$ +$ 88$ +$ 89$ +$ 90$ +$ 91$ +$ 92$ +$ 93$ +$ 94$ +$ 95$ +$ 96$ +$ 97$ +$ 98$ +$ 99$ +$ 100$ +$ 101$ +$ 102$ +$ 103$ +$ 104$ +$ 105$ +$ 106$ +$ 107$ +$ 108$ +$ 109$ +$ 110$ +$ 111$ +$ 112$ +$ 113$ +$ 114$ +$ 115$ +$ 116$ +$ 117$ +$ 118$ +$ 119$ +$ 120$ +$ 121$ +$ 122$ +$ 123$ +$ 124$ +$ 125$ +$ 126$ +$ 127$ +... diff --git a/test/big/bitset.test b/test/big/bitset.test new file mode 100644 index 0000000000000000000000000000000000000000..fca6bc10c3920829d67eb68fc71b81ec432f874a --- /dev/null +++ b/test/big/bitset.test @@ -0,0 +1,108 @@ +# encoding: tarantool +# + +import os +import shutil + +for file in ("utils.lua", "bitset.lua"): + src_path = os.path.join("big/", file) + dst_path = os.path.join(vardir, file) + shutil.copy(src_path, dst_path) + exec admin "lua dofile('%s')" % (file) + os.unlink(dst_path); + +print """ +#-----------------------------------------------------------------------------# +# BitsetIndex: insert/delete +#-----------------------------------------------------------------------------# +"""; + +exec admin "lua test_insert_delete(128)" + +print """ +#-----------------------------------------------------------------------------# +# BitsetIndex: ALL +#-----------------------------------------------------------------------------# +"""; + +exec admin "lua clear()" +exec admin "lua fill(1, 128)" +exec admin "lua dump(box.index.BITS_ALL)" + +print """ +#-----------------------------------------------------------------------------# +# BitsetIndex: BITS_ALL_SET (single bit) +#-----------------------------------------------------------------------------# +"""; + +exec admin "lua dump(box.index.BITS_ALL_SET, 0)" + +exec admin "lua dump(box.index.BITS_ALL_SET, 1)" +exec admin "lua dump(box.index.BITS_ALL_SET, 2)" +exec admin "lua dump(box.index.BITS_ALL_SET, 8)" +exec admin "lua dump(box.index.BITS_ALL_SET, 1073741824)" +exec admin "lua dump(box.index.BITS_ALL_SET, 2147483648)" +exec admin "lua dump(box.index.BITS_ALL_SET, 4294967296)" + +print """ +#-----------------------------------------------------------------------------# +# BitsetIndex: BITS_ALL_SET (multiple bit) +#-----------------------------------------------------------------------------# +"""; + +exec admin "lua dump(box.index.BITS_ALL_SET, 3)" +exec admin "lua dump(box.index.BITS_ALL_SET, 7)" +exec admin "lua dump(box.index.BITS_ALL_SET, 31)" +exec admin "lua dump(box.index.BITS_ALL_SET, 5)" +exec admin "lua dump(box.index.BITS_ALL_SET, 10)" +exec admin "lua dump(box.index.BITS_ALL_SET, 27)" +exec admin "lua dump(box.index.BITS_ALL_SET, 341)" +exec admin "lua dump(box.index.BITS_ALL_SET, 2147483649)" +exec admin "lua dump(box.index.BITS_ALL_SET, 4294967295)" + +print """ +#-----------------------------------------------------------------------------# +# BitsetIndex: BITS_ALL_NOT_SET (single bit) +#-----------------------------------------------------------------------------# +"""; + +exec admin "lua dump(box.index.BITS_ALL_NOT_SET, 0)" + +exec admin "lua dump(box.index.BITS_ALL_NOT_SET, 2)" +exec admin "lua dump(box.index.BITS_ALL_NOT_SET, 8)" +exec admin "lua dump(box.index.BITS_ALL_NOT_SET, 4294967296)" + +print """ +#-----------------------------------------------------------------------------# +# BitsetIndex: BITS_ALL_NOT_SET (multiple bit) +#-----------------------------------------------------------------------------# +"""; + +exec admin "lua dump(box.index.BITS_ALL_NOT_SET, 3)" +exec admin "lua dump(box.index.BITS_ALL_NOT_SET, 7)" +exec admin "lua dump(box.index.BITS_ALL_NOT_SET, 10)" +exec admin "lua dump(box.index.BITS_ALL_NOT_SET, 27)" +exec admin "lua dump(box.index.BITS_ALL_NOT_SET, 85)" +exec admin "lua dump(box.index.BITS_ALL_NOT_SET, 4294967295)" + +print """ +#-----------------------------------------------------------------------------# +# BitsetIndex: BITS_ANY_SET (single bit) +#-----------------------------------------------------------------------------# +"""; + +exec admin "lua dump(box.index.BITS_ANY_SET, 0)" + +exec admin "lua dump(box.index.BITS_ANY_SET, 16)" +exec admin "lua dump(box.index.BITS_ANY_SET, 128)" +exec admin "lua dump(box.index.BITS_ANY_SET, 4294967296)" + +print """ +#-----------------------------------------------------------------------------# +# BitsetIndex: BITS_ANY_SET (multiple bit) +#-----------------------------------------------------------------------------# +"""; + +exec admin "lua dump(box.index.BITS_ANY_SET, 7)" +exec admin "lua dump(box.index.BITS_ANY_SET, 84)" +exec admin "lua dump(box.index.BITS_ANY_SET, 113)" diff --git a/test/big/iterator.lua b/test/big/iterator.lua deleted file mode 100644 index f9557af5e3d8bea67a22e527fba8e3f830a5994c..0000000000000000000000000000000000000000 --- a/test/big/iterator.lua +++ /dev/null @@ -1,27 +0,0 @@ -function iterate(space_no, index_no, f1, f2, ...) - local sorted = (box.space[space_no].index[index_no].type == "TREE"); - local pkeys = {}; - local tkeys = {}; - local values = {}; - for v in box.space[space_no].index[index_no]:iterator(...) do - local pk = v:slice(0, 1); - local tk = '$'; - for f = f1, f2-1, 1 do tk = (tk..(v[f])..'$'); end; - table.insert(values, tk); - if pkeys[pk] ~= nil then - print('Duplicate tuple (primary key): ', pk); - end - if box.space[space_no].index[index_no].unique and tkeys[tk] ~= nil then - print('Duplicate tuple (test key): ', tk); - end; - tkeys[pk] = true; - tkeys[tk] = true; - end; - - if not sorted then - table.sort(values); - print('sorted output'); - end; - - for i,v in ipairs(values) do print(v) end; -end; diff --git a/test/big/iterator.result b/test/big/iterator.result index adb61724241eda93ceb1fcf7eb2dcc45e7740091..460a83a06ee5191bb9a24ba63aae38aca04bbc3f 100644 --- a/test/big/iterator.result +++ b/test/big/iterator.result @@ -1,4 +1,4 @@ -lua dofile('iterator.lua') +lua dofile('utils.lua') --- ... lua box.insert(20, 'pid_001', 'sid_001', 'tid_998', 'a') @@ -764,7 +764,7 @@ lua iterate(20, 3, 2, 4, box.index.LT, 'tid_000') ... lua iterate(20, 3, 2, 4, box.index.LT, 'tid_996', 'to', 'many', 'keys') --- -error: 'iterator.lua:6: Key part count 4 is greater than index part count 2' +error: 'utils.lua:27: Key part count 4 is greater than index part count 2' ... #-----------------------------------------------------------------------------# diff --git a/test/big/iterator.test b/test/big/iterator.test index 2182f7c2b2a03ac0e6436db35ed609cf29ed9c49..53fd5531bce1051cd2e18a455fad100f1f20f723 100644 --- a/test/big/iterator.test +++ b/test/big/iterator.test @@ -3,10 +3,10 @@ import os import shutil -iterator_lua_path = os.path.join(vardir, "iterator.lua") -shutil.copy("big/iterator.lua", iterator_lua_path) +iterator_lua_path = os.path.join(vardir, "utils.lua") +shutil.copy("big/utils.lua", iterator_lua_path) -exec admin "lua dofile('iterator.lua')" +exec admin "lua dofile('utils.lua')" shutil.rmtree(iterator_lua_path, True) exec admin "lua box.insert(20, 'pid_001', 'sid_001', 'tid_998', 'a')" diff --git a/test/big/tarantool.cfg b/test/big/tarantool.cfg index 0d26c1670ffbb5a505a1777ba0fee83cdf68e872..1c129d0b3a7d4341c01472adfc8bd102449790b1 100644 --- a/test/big/tarantool.cfg +++ b/test/big/tarantool.cfg @@ -337,3 +337,16 @@ space[23].index[0].key_field[0].fieldno = 2 space[23].index[0].key_field[0].type = "NUM" space[23].index[0].key_field[1].fieldno = 1 space[23].index[0].key_field[1].type = "NUM" + +# bitset::replace test +space[24].enabled = true +space[24].index[0].type = "HASH" +space[24].index[0].unique = true +space[24].index[0].key_field[0].fieldno = 0 +space[24].index[0].key_field[0].type = "NUM" + +space[24].index[1].type = "BITSET" +space[24].index[1].unique = false +space[24].index[1].key_field[0].fieldno = 1 +space[24].index[1].key_field[0].type = "NUM" + diff --git a/test/big/utils.lua b/test/big/utils.lua new file mode 100644 index 0000000000000000000000000000000000000000..2e32faa1dc6b7489081b8ac4bd5516b64390de18 --- /dev/null +++ b/test/big/utils.lua @@ -0,0 +1,82 @@ +function space_field_types(space_no) + local types = {}; + for _, index in pairs(box.space[space_no].index) do + for _,key_def in pairs(index.key_field) do + types[key_def.fieldno] = key_def.type; + end + end + return types; +end + +function iterate(space_no, index_no, f1, f2, ...) + local sorted = (box.space[space_no].index[index_no].type == "TREE"); + local pkeys = {}; + local tkeys = {}; + local values = {}; + local types = space_field_types(space_no); + function get_field(tuple, field_no) + local f = tuple[field_no] + if (types[field_no] == 'NUM') then + return string.format('%8d', box.unpack('i', f)); + elseif (types[field_no] == 'NUM64') then + return string.format('%8ld', box.unpack('l', f)); + else + return f + end + end + for v in box.space[space_no].index[index_no]:iterator(...) do + local pk = get_field(v, 0); + local tk = '$'; + for f = f1, f2-1, 1 do tk = (tk..(get_field(v, f))..'$'); end; + table.insert(values, tk); + if pkeys[pk] ~= nil then + print('Duplicate tuple (primary key): ', pk); + end + if box.space[space_no].index[index_no].unique and tkeys[tk] ~= nil then + print('Duplicate tuple (test key): ', tk); + end; + tkeys[pk] = true; + tkeys[tk] = true; + end; + + if not sorted then + table.sort(values); + print('sorted output'); + end; + + for i,v in ipairs(values) do print(v) end; +end + +function arithmetic(d, count) + if not d then d = 1 end + local a = 0; + local i = 0; + + return function() + if count and (i >= count) then + return nil; + end + + i = i + 1; + a = a + d; + return a; + end +end + +function table.shuffle(t) + local n = #t + while n >= 2 do + local k = math.random(n) + t[k], t[n] = t[n], t[k] + n = n - 1 + end +end + +function table.generate(iter) + local t = {}; + for k in iter do + table.insert(t, k); + end + + return t; +end