From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladimir Davydov Subject: [PATCH 6/8] vinyl: zap vy_stmt_column_mask and mem_format_with_colmask Date: Sun, 14 Oct 2018 21:16:50 +0300 Message-Id: <5cee1c5def7419e661c4579689ed6c33bbb7517f.1539539421.git.vdavydov.dev@gmail.com> In-Reply-To: References: In-Reply-To: References: To: kostja@tarantool.org Cc: tarantool-patches@freelists.org List-ID: Finally, these atrocities are not used anywhere and can be removed. --- src/box/vinyl.c | 41 ++++++++++---------------------------- src/box/vy_lsm.c | 25 +++++------------------ src/box/vy_lsm.h | 8 -------- src/box/vy_mem.c | 14 ++++--------- src/box/vy_mem.h | 17 +++++++--------- src/box/vy_stmt.c | 12 ----------- src/box/vy_stmt.h | 44 ----------------------------------------- test/unit/vy_iterators_helper.c | 8 +------- test/unit/vy_point_lookup.c | 11 ++++------- 9 files changed, 31 insertions(+), 149 deletions(-) diff --git a/src/box/vinyl.c b/src/box/vinyl.c index 4e6c5d56..c1e70cb2 100644 --- a/src/box/vinyl.c +++ b/src/box/vinyl.c @@ -1138,8 +1138,6 @@ vinyl_space_swap_index(struct space *old_space, struct space *new_space, SWAP(old_lsm, new_lsm); SWAP(old_lsm->check_is_unique, new_lsm->check_is_unique); SWAP(old_lsm->mem_format, new_lsm->mem_format); - SWAP(old_lsm->mem_format_with_colmask, - new_lsm->mem_format_with_colmask); SWAP(old_lsm->disk_format, new_lsm->disk_format); SWAP(old_lsm->opts, new_lsm->opts); key_def_swap(old_lsm->key_def, new_lsm->key_def); @@ -1737,12 +1735,10 @@ vy_perform_update(struct vy_env *env, struct vy_tx *tx, struct txn_stmt *stmt, if (space->index_count == 1) return 0; - struct tuple *delete; - delete = vy_stmt_new_surrogate_delete(pk->mem_format_with_colmask, - stmt->old_tuple); + struct tuple *delete = vy_stmt_new_surrogate_delete(pk->mem_format, + stmt->old_tuple); if (delete == NULL) return -1; - vy_stmt_set_column_mask(delete, column_mask); for (uint32_t i = 1; i < space->index_count; ++i) { struct vy_lsm *lsm = vy_lsm(space->index[i]); @@ -1821,19 +1817,10 @@ vy_update(struct vy_env *env, struct vy_tx *tx, struct txn_stmt *stmt, */ if (tuple_validate_raw(pk->mem_format, new_tuple)) return -1; - - if (space->index_count == 1) { - stmt->new_tuple = vy_stmt_new_replace(pk->mem_format, new_tuple, - new_tuple_end); - if (stmt->new_tuple == NULL) - return -1; - } else { - stmt->new_tuple = vy_stmt_new_replace(pk->mem_format_with_colmask, - new_tuple, new_tuple_end); - if (stmt->new_tuple == NULL) - return -1; - vy_stmt_set_column_mask(stmt->new_tuple, column_mask); - } + stmt->new_tuple = vy_stmt_new_replace(pk->mem_format, new_tuple, + new_tuple_end); + if (stmt->new_tuple == NULL) + return -1; if (vy_check_update(space, pk, stmt->old_tuple, stmt->new_tuple, column_mask) != 0) return -1; @@ -2070,18 +2057,10 @@ vy_upsert(struct vy_env *env, struct vy_tx *tx, struct txn_stmt *stmt, if (tuple_validate_raw(pk->mem_format, new_tuple)) return -1; new_tuple_end = new_tuple + new_size; - if (space->index_count == 1) { - stmt->new_tuple = vy_stmt_new_replace(pk->mem_format, new_tuple, - new_tuple_end); - if (stmt->new_tuple == NULL) - return -1; - } else { - stmt->new_tuple = vy_stmt_new_replace(pk->mem_format_with_colmask, - new_tuple, new_tuple_end); - if (stmt->new_tuple == NULL) - return -1; - vy_stmt_set_column_mask(stmt->new_tuple, column_mask); - } + stmt->new_tuple = vy_stmt_new_replace(pk->mem_format, new_tuple, + new_tuple_end); + if (stmt->new_tuple == NULL) + return -1; if (vy_check_update(space, pk, stmt->old_tuple, stmt->new_tuple, column_mask) != 0) { diag_log(); diff --git a/src/box/vy_lsm.c b/src/box/vy_lsm.c index de5ad314..80341267 100644 --- a/src/box/vy_lsm.c +++ b/src/box/vy_lsm.c @@ -161,16 +161,6 @@ vy_lsm_new(struct vy_lsm_env *lsm_env, struct vy_cache_env *cache_env, } tuple_format_ref(lsm->disk_format); - if (index_def->iid == 0) { - lsm->mem_format_with_colmask = - vy_tuple_format_new_with_colmask(format); - if (lsm->mem_format_with_colmask == NULL) - goto fail_mem_format_with_colmask; - } else { - lsm->mem_format_with_colmask = pk->mem_format_with_colmask; - } - tuple_format_ref(lsm->mem_format_with_colmask); - if (vy_lsm_stat_create(&lsm->stat) != 0) goto fail_stat; @@ -178,8 +168,8 @@ vy_lsm_new(struct vy_lsm_env *lsm_env, struct vy_cache_env *cache_env, if (lsm->run_hist == NULL) goto fail_run_hist; - lsm->mem = vy_mem_new(mem_env, *lsm->env->p_generation, - cmp_def, format, lsm->mem_format_with_colmask, + lsm->mem = vy_mem_new(mem_env, cmp_def, format, + *lsm->env->p_generation, space_cache_version); if (lsm->mem == NULL) goto fail_mem; @@ -215,8 +205,6 @@ fail_mem: fail_run_hist: vy_lsm_stat_destroy(&lsm->stat); fail_stat: - tuple_format_unref(lsm->mem_format_with_colmask); -fail_mem_format_with_colmask: tuple_format_unref(lsm->disk_format); fail_format: key_def_delete(cmp_def); @@ -270,7 +258,6 @@ vy_lsm_delete(struct vy_lsm *lsm) vy_range_tree_iter(lsm->tree, NULL, vy_range_tree_free_cb, NULL); vy_range_heap_destroy(&lsm->range_heap); tuple_format_unref(lsm->disk_format); - tuple_format_unref(lsm->mem_format_with_colmask); key_def_delete(lsm->cmp_def); key_def_delete(lsm->key_def); histogram_delete(lsm->run_hist); @@ -807,9 +794,8 @@ vy_lsm_rotate_mem(struct vy_lsm *lsm) struct vy_mem *mem; assert(lsm->mem != NULL); - mem = vy_mem_new(lsm->mem->env, *lsm->env->p_generation, - lsm->cmp_def, lsm->mem_format, - lsm->mem_format_with_colmask, space_cache_version); + mem = vy_mem_new(lsm->mem->env, lsm->cmp_def, lsm->mem_format, + *lsm->env->p_generation, space_cache_version); if (mem == NULL) return -1; @@ -857,8 +843,7 @@ vy_lsm_set(struct vy_lsm *lsm, struct vy_mem *mem, lsm->stat.memory.count.bytes += tuple_size(stmt); /* Abort transaction if format was changed by DDL */ - if (format_id != tuple_format_id(mem->format_with_colmask) && - format_id != tuple_format_id(mem->format)) { + if (format_id != tuple_format_id(mem->format)) { diag_set(ClientError, ER_TRANSACTION_CONFLICT); return -1; } diff --git a/src/box/vy_lsm.h b/src/box/vy_lsm.h index 2e026ced..d8d9f9d0 100644 --- a/src/box/vy_lsm.h +++ b/src/box/vy_lsm.h @@ -193,14 +193,6 @@ struct vy_lsm { /** Tuple format of the space this LSM tree belongs to. */ struct tuple_format *mem_format; /** - * Format for tuples of type REPLACE or DELETE which - * are a result of an UPDATE operation. Such tuples - * contain a column mask which preserves the list - * of actually changed columns. Used when creating - * tuples for vy_mem, and used only by primary key. - */ - struct tuple_format *mem_format_with_colmask; - /** * If this LSM tree is for a secondary index, the following * variable points to the LSM tree of the primary index of * the same space, otherwise it is set to NULL. Referenced diff --git a/src/box/vy_mem.c b/src/box/vy_mem.c index ccd079f0..f8b89d4e 100644 --- a/src/box/vy_mem.c +++ b/src/box/vy_mem.c @@ -96,9 +96,8 @@ vy_mem_tree_extent_free(void *ctx, void *p) } struct vy_mem * -vy_mem_new(struct vy_mem_env *env, int64_t generation, - struct key_def *cmp_def, struct tuple_format *format, - struct tuple_format *format_with_colmask, +vy_mem_new(struct vy_mem_env *env, struct key_def *cmp_def, + struct tuple_format *format, int64_t generation, uint32_t space_cache_version) { struct vy_mem *index = calloc(1, sizeof(*index)); @@ -114,8 +113,6 @@ vy_mem_new(struct vy_mem_env *env, int64_t generation, index->space_cache_version = space_cache_version; index->format = format; tuple_format_ref(format); - index->format_with_colmask = format_with_colmask; - tuple_format_ref(format_with_colmask); vy_mem_tree_create(&index->tree, cmp_def, vy_mem_tree_extent_alloc, vy_mem_tree_extent_free, index); @@ -129,7 +126,6 @@ vy_mem_delete(struct vy_mem *index) { index->env->tree_extent_size -= index->tree_extent_size; tuple_format_unref(index->format); - tuple_format_unref(index->format_with_colmask); fiber_cond_destroy(&index->pin_cond); TRASH(index); free(index); @@ -160,8 +156,7 @@ vy_mem_insert_upsert(struct vy_mem *mem, const struct tuple *stmt) { assert(vy_stmt_type(stmt) == IPROTO_UPSERT); /* Check if the statement can be inserted in the vy_mem. */ - assert(stmt->format_id == tuple_format_id(mem->format_with_colmask) || - stmt->format_id == tuple_format_id(mem->format)); + assert(stmt->format_id == tuple_format_id(mem->format)); /* The statement must be from a lsregion. */ assert(!vy_stmt_is_refable(stmt)); size_t size = tuple_size(stmt); @@ -220,8 +215,7 @@ vy_mem_insert(struct vy_mem *mem, const struct tuple *stmt) { assert(vy_stmt_type(stmt) != IPROTO_UPSERT); /* Check if the statement can be inserted in the vy_mem. */ - assert(stmt->format_id == tuple_format_id(mem->format_with_colmask) || - stmt->format_id == tuple_format_id(mem->format)); + assert(stmt->format_id == tuple_format_id(mem->format)); /* The statement must be from a lsregion. */ assert(!vy_stmt_is_refable(stmt)); size_t size = tuple_size(stmt); diff --git a/src/box/vy_mem.h b/src/box/vy_mem.h index d6afeed1..b41c3c0b 100644 --- a/src/box/vy_mem.h +++ b/src/box/vy_mem.h @@ -194,12 +194,12 @@ struct vy_mem { */ int64_t generation; /** - * Format of vy_mem REPLACE and DELETE tuples without - * column mask. + * Format of statements stored in this in-memory index. + * Note, the statements don't reference the format by + * themselves, instead it is referenced once by vy_mem. + * This allows us to drop vy_mem in O(1). */ struct tuple_format *format; - /** Format of vy_mem tuples with column mask. */ - struct tuple_format *format_with_colmask; /** * Number of active writers to this index. * @@ -254,19 +254,16 @@ vy_mem_wait_pinned(struct vy_mem *mem) * Instantiate a new in-memory level. * * @param env Vinyl memory environment. - * @param generation Generation of statements stored in the tree. * @param key_def key definition. * @param format Format for REPLACE and DELETE tuples. - * @param format_with_colmask Format for tuples, which have - * column mask. + * @param generation Generation of statements stored in the tree. * @param space_cache_version Data dictionary cache version * @retval new vy_mem instance on success. * @retval NULL on error, check diag. */ struct vy_mem * -vy_mem_new(struct vy_mem_env *env, int64_t generation, - struct key_def *cmp_def, struct tuple_format *format, - struct tuple_format *format_with_colmask, +vy_mem_new(struct vy_mem_env *env, struct key_def *cmp_def, + struct tuple_format *format, int64_t generation, uint32_t space_cache_version); /** diff --git a/src/box/vy_stmt.c b/src/box/vy_stmt.c index bb9e1edb..7082952b 100644 --- a/src/box/vy_stmt.c +++ b/src/box/vy_stmt.c @@ -748,15 +748,3 @@ vy_stmt_str(const struct tuple *stmt) return ""; return buf; } - -struct tuple_format * -vy_tuple_format_new_with_colmask(struct tuple_format *mem_format) -{ - struct tuple_format *format = tuple_format_dup(mem_format); - if (format == NULL) - return NULL; - /* + size of column mask. */ - assert(format->extra_size == 0); - format->extra_size = sizeof(uint64_t); - return format; -} diff --git a/src/box/vy_stmt.h b/src/box/vy_stmt.h index 4a67b3c7..c3381402 100644 --- a/src/box/vy_stmt.h +++ b/src/box/vy_stmt.h @@ -219,39 +219,6 @@ vy_stmt_set_n_upserts(struct tuple *stmt, uint8_t n) *((uint8_t *)stmt - 1) = n; } -/** Get the column mask of the specified tuple. */ -static inline uint64_t -vy_stmt_column_mask(const struct tuple *tuple) -{ - enum iproto_type type = vy_stmt_type(tuple); - assert(type == IPROTO_INSERT || type == IPROTO_REPLACE || - type == IPROTO_DELETE); - (void) type; - if (tuple_format(tuple)->extra_size == sizeof(uint64_t)) { - /* Tuple has column mask */ - const char *extra = tuple_extra(tuple); - return load_u64(extra); - } - return UINT64_MAX; /* return default value */ -} - -/** - * Set the column mask in the tuple. - * @param tuple Tuple to set column mask. - * @param column_mask Bitmask of the updated columns. - */ -static inline void -vy_stmt_set_column_mask(struct tuple *tuple, uint64_t column_mask) -{ - enum iproto_type type = vy_stmt_type(tuple); - assert(type == IPROTO_INSERT || type == IPROTO_REPLACE || - type == IPROTO_DELETE); - assert(tuple_format(tuple)->extra_size == sizeof(uint64_t)); - (void) type; - char *extra = (char *) tuple_extra(tuple); - store_u64(extra, column_mask); -} - /** * Free the tuple of a vinyl space. * @pre tuple->refs == 0 @@ -710,17 +677,6 @@ const char * vy_stmt_str(const struct tuple *stmt); /** - * Create a tuple format with column mask of an update operation. - * @sa vy_index.column_mask, vy_can_skip_update(). - * @param mem_format A base tuple format. - * - * @retval not NULL Success. - * @retval NULL Memory or format register error. - */ -struct tuple_format * -vy_tuple_format_new_with_colmask(struct tuple_format *mem_format); - -/** * Check if a key of @a tuple contains NULL. * @param tuple Tuple to check. * @param def Key def to check by. diff --git a/test/unit/vy_iterators_helper.c b/test/unit/vy_iterators_helper.c index 58eaa220..dcd76e4c 100644 --- a/test/unit/vy_iterators_helper.c +++ b/test/unit/vy_iterators_helper.c @@ -205,14 +205,8 @@ create_test_mem(struct key_def *def) 0, NULL, 0, NULL); fail_if(format == NULL); - /* Create format with column mask */ - struct tuple_format *format_with_colmask = - vy_tuple_format_new_with_colmask(format); - assert(format_with_colmask != NULL); - /* Create mem */ - struct vy_mem *mem = vy_mem_new(&mem_env, 1, def, format, - format_with_colmask, 0); + struct vy_mem *mem = vy_mem_new(&mem_env, def, format, 1, 0); fail_if(mem == NULL); return mem; } diff --git a/test/unit/vy_point_lookup.c b/test/unit/vy_point_lookup.c index 642cb4ce..8cf0fb72 100644 --- a/test/unit/vy_point_lookup.c +++ b/test/unit/vy_point_lookup.c @@ -179,9 +179,8 @@ test_basic() /* create second run */ struct vy_mem *run_mem = - vy_mem_new(pk->mem->env, *pk->env->p_generation, - pk->cmp_def, pk->mem_format, - pk->mem_format_with_colmask, 0); + vy_mem_new(pk->mem->env, pk->cmp_def, pk->mem_format, + *pk->env->p_generation, 0); for (size_t i = 0; i < num_of_keys; i++) { if (!in_run2[i]) @@ -211,10 +210,8 @@ test_basic() vy_run_unref(run); /* create first run */ - run_mem = - vy_mem_new(pk->mem->env, *pk->env->p_generation, - pk->cmp_def, pk->mem_format, - pk->mem_format_with_colmask, 0); + run_mem = vy_mem_new(pk->mem->env, pk->cmp_def, pk->mem_format, + *pk->env->p_generation, 0); for (size_t i = 0; i < num_of_keys; i++) { if (!in_run1[i]) -- 2.11.0