Skip to content
Snippets Groups Projects
Commit 586cdecf authored by Konstantin Osipov's avatar Konstantin Osipov
Browse files

Rename space->n to space_id(). Remove key_def->cmp_order, which was unused.

Remove key_def->max_fieldno as well.
Rename space_n() to space_id(), space_by_n to space_by_id().
parent a67af3df
No related branches found
No related tags found
No related merge requests found
...@@ -387,7 +387,7 @@ snapshot_space(struct space *sp, void *udata) ...@@ -387,7 +387,7 @@ snapshot_space(struct space *sp, void *udata)
pk->initIterator(it, ITER_ALL, NULL, 0); pk->initIterator(it, ITER_ALL, NULL, 0);
while ((tuple = it->next(it))) while ((tuple = it->next(it)))
snapshot_write_tuple(ud->l, ud->batch, space_n(sp), tuple); snapshot_write_tuple(ud->l, ud->batch, space_id(sp), tuple);
} }
void void
......
...@@ -56,7 +56,7 @@ lbox_pushspace(struct lua_State *L, struct space *space) ...@@ -56,7 +56,7 @@ lbox_pushspace(struct lua_State *L, struct space *space)
/* space.n */ /* space.n */
lua_pushstring(L, "n"); lua_pushstring(L, "n");
lua_pushnumber(L, space->no); lua_pushnumber(L, space_id(space));
lua_settable(L, -3); lua_settable(L, -3);
/* all exists spaces are enabled */ /* all exists spaces are enabled */
...@@ -133,7 +133,7 @@ lbox_pushspace(struct lua_State *L, struct space *space) ...@@ -133,7 +133,7 @@ lbox_pushspace(struct lua_State *L, struct space *space)
static void static void
lbox_add_space(struct space *space, struct lua_State *L) lbox_add_space(struct space *space, struct lua_State *L)
{ {
lua_pushnumber(L, space->no); lua_pushnumber(L, space_id(space));
lbox_pushspace(L, space); lbox_pushspace(L, space);
lua_settable(L, -3); lua_settable(L, -3);
} }
......
...@@ -41,7 +41,6 @@ key_def_create(struct key_def *def, uint32_t id, ...@@ -41,7 +41,6 @@ key_def_create(struct key_def *def, uint32_t id,
struct tarantool_cfg_space_index *cfg_index) struct tarantool_cfg_space_index *cfg_index)
{ {
def->id = id; def->id = id;
def->max_fieldno = 0;
def->part_count = 0; def->part_count = 0;
def->type = STR2ENUM(index_type, cfg_index->type); def->type = STR2ENUM(index_type, cfg_index->type);
...@@ -57,7 +56,6 @@ key_def_create(struct key_def *def, uint32_t id, ...@@ -57,7 +56,6 @@ key_def_create(struct key_def *def, uint32_t id,
break; break;
} }
def->max_fieldno = MAX(def->max_fieldno, cfg_key->fieldno);
def->part_count++; def->part_count++;
} }
...@@ -65,13 +63,6 @@ key_def_create(struct key_def *def, uint32_t id, ...@@ -65,13 +63,6 @@ key_def_create(struct key_def *def, uint32_t id,
def->parts = (struct key_part *) malloc(sizeof(struct key_part) * def->parts = (struct key_part *) malloc(sizeof(struct key_part) *
def->part_count); def->part_count);
uint32_t cmp_order_size = (def->max_fieldno + 1) * sizeof(uint32_t);
/* init compare order array */
def->cmp_order = (uint32_t *) malloc(cmp_order_size);
for (uint32_t fieldno = 0; fieldno <= def->max_fieldno; fieldno++)
def->cmp_order[fieldno] = UINT32_MAX;
/* fill fields and compare order */ /* fill fields and compare order */
for (uint32_t k = 0; cfg_index->key_field[k] != NULL; ++k) { for (uint32_t k = 0; cfg_index->key_field[k] != NULL; ++k) {
auto cfg_key = cfg_index->key_field[k]; auto cfg_key = cfg_index->key_field[k];
...@@ -84,9 +75,6 @@ key_def_create(struct key_def *def, uint32_t id, ...@@ -84,9 +75,6 @@ key_def_create(struct key_def *def, uint32_t id,
/* fill keys */ /* fill keys */
def->parts[k].fieldno = cfg_key->fieldno; def->parts[k].fieldno = cfg_key->fieldno;
def->parts[k].type = STR2ENUM(field_type, cfg_key->type); def->parts[k].type = STR2ENUM(field_type, cfg_key->type);
/* fill compare order */
if (def->cmp_order[cfg_key->fieldno] == UINT32_MAX)
def->cmp_order[cfg_key->fieldno] = k;
} }
def->is_unique = cfg_index->unique; def->is_unique = cfg_index->unique;
} }
...@@ -96,6 +84,5 @@ void ...@@ -96,6 +84,5 @@ void
key_def_destroy(struct key_def *key_def) key_def_destroy(struct key_def *key_def)
{ {
free(key_def->parts); free(key_def->parts);
free(key_def->cmp_order);
} }
...@@ -62,28 +62,16 @@ struct key_part { ...@@ -62,28 +62,16 @@ struct key_part {
/* Descriptor of a multipart key. */ /* Descriptor of a multipart key. */
struct key_def { struct key_def {
/** Ordinal index number in the index array. */
uint32_t id; uint32_t id;
/* Description of parts of a multipart index. */ /** The size of the 'parts' array. */
struct key_part *parts;
/*
* An array holding field positions in 'parts' array.
* Imagine there is index[1] = { key_field[0].fieldno=5,
* key_field[1].fieldno=3 }.
* 'parts' array for such index contains data from
* key_field[0] and key_field[1] respectively.
* max_fieldno is 5, and cmp_order array holds offsets of
* field 3 and 5 in 'parts' array: -1, -1, -1, 0, -1, 1.
*/
uint32_t *cmp_order;
/* The size of the 'parts' array. */
uint32_t part_count; uint32_t part_count;
/* /** Description of parts of a multipart index. */
* Max fieldno in 'parts' array. Defines the size of struct key_part *parts;
* cmp_order array (which is max_fieldno + 1). /** Index type. */
*/
uint32_t max_fieldno;
bool is_unique;
enum index_type type; enum index_type type;
/** Is this key unique. */
bool is_unique;
}; };
struct tarantool_cfg_space_index; struct tarantool_cfg_space_index;
......
...@@ -57,12 +57,12 @@ static bool primary_indexes_enabled = false; ...@@ -57,12 +57,12 @@ static bool primary_indexes_enabled = false;
static void static void
space_create(struct space *space, uint32_t space_no, space_create(struct space *space, uint32_t id,
struct key_def *key_defs, uint32_t key_count, struct key_def *key_defs, uint32_t key_count,
uint32_t arity) uint32_t arity)
{ {
memset(space, 0, sizeof(struct space)); memset(space, 0, sizeof(struct space));
space->no = space_no; space->id = id;
space->arity = arity; space->arity = arity;
space->key_count = key_count; space->key_count = key_count;
space->format = tuple_format_new(key_defs, key_count); space->format = tuple_format_new(key_defs, key_count);
...@@ -88,18 +88,18 @@ space_destroy(struct space *space) ...@@ -88,18 +88,18 @@ space_destroy(struct space *space)
} }
struct space * struct space *
space_new(uint32_t space_no, struct key_def *key_defs, space_new(uint32_t id, struct key_def *key_defs,
uint32_t key_count, uint32_t arity) uint32_t key_count, uint32_t arity)
{ {
struct space *space = space_by_n(space_no); struct space *space = space_by_id(id);
if (space) if (space)
tnt_raise(LoggedError, ER_SPACE_EXISTS, space_no); tnt_raise(LoggedError, ER_SPACE_EXISTS, id);
space = (struct space *) malloc(sizeof(struct space)); space = (struct space *) malloc(sizeof(struct space));
space_create(space, space_no, key_defs, key_count, arity); space_create(space, id, key_defs, key_count, arity);
const struct mh_i32ptr_node_t node = { space->no, space }; const struct mh_i32ptr_node_t node = { space_id(space), space };
mh_i32ptr_put(spaces, &node, NULL, NULL); mh_i32ptr_put(spaces, &node, NULL, NULL);
return space; return space;
...@@ -108,7 +108,7 @@ space_new(uint32_t space_no, struct key_def *key_defs, ...@@ -108,7 +108,7 @@ space_new(uint32_t space_no, struct key_def *key_defs,
static void static void
space_delete(struct space *space) space_delete(struct space *space)
{ {
const struct mh_i32ptr_node_t node = { space->no, NULL }; const struct mh_i32ptr_node_t node = { space_id(space), NULL };
mh_int_t k = mh_i32ptr_get(spaces, &node, NULL); mh_int_t k = mh_i32ptr_get(spaces, &node, NULL);
assert(k != mh_end(spaces)); assert(k != mh_end(spaces));
mh_i32ptr_del(spaces, k, NULL); mh_i32ptr_del(spaces, k, NULL);
...@@ -118,9 +118,9 @@ space_delete(struct space *space) ...@@ -118,9 +118,9 @@ space_delete(struct space *space)
/* return space by its number */ /* return space by its number */
struct space * struct space *
space_by_n(uint32_t n) space_by_id(uint32_t id)
{ {
const struct mh_i32ptr_node_t node = { n, NULL }; const struct mh_i32ptr_node_t node = { id, NULL };
mh_int_t space = mh_i32ptr_get(spaces, &node, NULL); mh_int_t space = mh_i32ptr_get(spaces, &node, NULL);
if (space == mh_end(spaces)) if (space == mh_end(spaces))
return NULL; return NULL;
...@@ -311,7 +311,8 @@ build_secondary_indexes(void) ...@@ -311,7 +311,8 @@ build_secondary_indexes(void)
if (space->key_count <= 1) if (space->key_count <= 1)
continue; /* no secondary keys */ continue; /* no secondary keys */
say_info("Building secondary keys in space %d...", space->no); say_info("Building secondary keys in space %d...",
space_id(space));
Index *pk = space->index[0]; Index *pk = space->index[0];
for (uint32_t j = 1; j < space->key_count; j++) { for (uint32_t j = 1; j < space->key_count; j++) {
...@@ -319,7 +320,7 @@ build_secondary_indexes(void) ...@@ -319,7 +320,7 @@ build_secondary_indexes(void)
index->build(pk); index->build(pk);
} }
say_info("Space %d: done", space->no); say_info("Space %d: done", space_id(space));
} }
/* enable secondary indexes now */ /* enable secondary indexes now */
......
...@@ -53,8 +53,8 @@ struct space { ...@@ -53,8 +53,8 @@ struct space {
*/ */
uint32_t key_count; uint32_t key_count;
/** Space number. */ /** Space numeric id. */
uint32_t no; uint32_t id;
/** Default tuple format used by this space */ /** Default tuple format used by this space */
struct tuple_format *format; struct tuple_format *format;
...@@ -62,7 +62,7 @@ struct space { ...@@ -62,7 +62,7 @@ struct space {
/** Get space ordinal number. */ /** Get space ordinal number. */
static inline uint32_t space_n(struct space *sp) { return sp->no; } static inline uint32_t space_id(struct space *space) { return space->id; }
/** /**
* @brief A single method to handle REPLACE, DELETE and UPDATE. * @brief A single method to handle REPLACE, DELETE and UPDATE.
...@@ -183,20 +183,20 @@ space_foreach(void (*func)(struct space *sp, void *udata), void *udata); ...@@ -183,20 +183,20 @@ space_foreach(void (*func)(struct space *sp, void *udata), void *udata);
* *
* @return NULL if space not found, otherwise space object. * @return NULL if space not found, otherwise space object.
*/ */
struct space *space_by_n(uint32_t space_no); struct space *space_by_id(uint32_t id);
static inline struct space * static inline struct space *
space_find(uint32_t space_no) space_find(uint32_t id)
{ {
struct space *s = space_by_n(space_no); struct space *space = space_by_id(id);
if (s) if (space)
return s; return space;
tnt_raise(ClientError, ER_NO_SUCH_SPACE, space_no); tnt_raise(ClientError, ER_NO_SUCH_SPACE, id);
} }
struct space * struct space *
space_new(uint32_t space_no, struct key_def *key_defs, space_new(uint32_t id, struct key_def *key_defs,
uint32_t key_count, uint32_t arity); uint32_t key_count, uint32_t arity);
...@@ -210,13 +210,13 @@ void end_build_primary_indexes(void); ...@@ -210,13 +210,13 @@ void end_build_primary_indexes(void);
void build_secondary_indexes(void); void build_secondary_indexes(void);
static inline Index * static inline Index *
index_find(struct space *sp, uint32_t index_no) index_find(struct space *space, uint32_t index_id)
{ {
Index *idx = space_index(sp, index_no); Index *index = space_index(space, index_id);
if (idx == NULL) if (index == NULL)
tnt_raise(LoggedError, ER_NO_SUCH_INDEX, index_no, tnt_raise(LoggedError, ER_NO_SUCH_INDEX, index_id,
space_n(sp)); space_id(space));
return idx; return index;
} }
#endif /* TARANTOOL_BOX_SPACE_H_INCLUDED */ #endif /* TARANTOOL_BOX_SPACE_H_INCLUDED */
...@@ -76,8 +76,12 @@ tuple_format_alloc_and_register(struct key_def *key_def, ...@@ -76,8 +76,12 @@ tuple_format_alloc_and_register(struct key_def *key_def,
uint32_t field_count; uint32_t field_count;
/* find max max field no */ /* find max max field no */
for (; key_def < end; key_def++) for (; key_def < end; key_def++) {
max_fieldno= MAX(max_fieldno, key_def->max_fieldno); struct key_part *part = key_def->parts;
struct key_part *pend = part + key_def->part_count;
for (; part < pend; part++)
max_fieldno= MAX(max_fieldno, part->fieldno);
}
if (formats_size == formats_capacity) { if (formats_size == formats_capacity) {
uint32_t new_capacity = formats_capacity ? uint32_t new_capacity = formats_capacity ?
......
...@@ -487,7 +487,7 @@ memcached_init(const char *bind_ipaddr, int memcached_port) ...@@ -487,7 +487,7 @@ memcached_init(const char *bind_ipaddr, int memcached_port)
stat_base = stat_register(memcached_stat_strs, memcached_stat_MAX); stat_base = stat_register(memcached_stat_strs, memcached_stat_MAX);
struct space *sp = space_by_n(cfg.memcached_space); struct space *sp = space_by_id(cfg.memcached_space);
memcached_index = space_index(sp, 0); memcached_index = space_index(sp, 0);
/* run memcached server */ /* run memcached server */
...@@ -512,14 +512,10 @@ memcached_space_init() ...@@ -512,14 +512,10 @@ memcached_space_init()
key_def.type = HASH; key_def.type = HASH;
key_def.parts = (struct key_part *) malloc(sizeof(struct key_part)); key_def.parts = (struct key_part *) malloc(sizeof(struct key_part));
key_def.cmp_order = (uint32_t *) malloc(sizeof(uint32_t));
key_def.parts[0].fieldno = 0; key_def.parts[0].fieldno = 0;
key_def.parts[0].type = STRING; key_def.parts[0].type = STRING;
key_def.max_fieldno = 1;
key_def.cmp_order[0] = 0;
(void) space_new(cfg.memcached_space, &key_def, 1, 4); (void) space_new(cfg.memcached_space, &key_def, 1, 4);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment