From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladimir Davydov Subject: [PATCH 01/12] vinyl: use vy_lsm_env::empty_key where appropriate Date: Thu, 21 Feb 2019 13:26:01 +0300 Message-Id: <559411db1be54b5dcfcc40ee882275235c20dcd0.1550744027.git.vdavydov.dev@gmail.com> In-Reply-To: References: In-Reply-To: References: To: kostja@tarantool.org Cc: tarantool-patches@freelists.org List-ID: No need to allocate an empty key during DDL - we already have one preallocated in vy_lsm_env. --- src/box/vinyl.c | 34 ++++++++++------------------------ src/box/vy_tx.c | 10 +++------- src/box/vy_tx.h | 4 +--- 3 files changed, 14 insertions(+), 34 deletions(-) diff --git a/src/box/vinyl.c b/src/box/vinyl.c index 947ca355..23c5b9c3 100644 --- a/src/box/vinyl.c +++ b/src/box/vinyl.c @@ -1038,17 +1038,15 @@ vinyl_space_prepare_alter(struct space *old_space, struct space *new_space) * before the trigger was installed so that DDL doesn't miss * their working set. */ -static int +static void vy_abort_writers_for_ddl(struct vy_env *env, struct vy_lsm *lsm) { - if (tx_manager_abort_writers(env->xm, lsm) != 0) - return -1; + tx_manager_abort_writers(env->xm, lsm); /* * Wait for prepared transactions to complete * (we can't abort them as they reached WAL). */ wal_sync(); - return 0; } /** Argument passed to vy_check_format_on_replace(). */ @@ -1109,10 +1107,6 @@ vinyl_space_check_format(struct space *space, struct tuple_format *format) */ struct vy_lsm *pk = vy_lsm(space->index[0]); - struct tuple *key = vy_stmt_new_select(pk->env->key_format, NULL, 0); - if (key == NULL) - return -1; - struct trigger on_replace; struct vy_check_format_ctx ctx; ctx.format = format; @@ -1121,13 +1115,12 @@ vinyl_space_check_format(struct space *space, struct tuple_format *format) trigger_create(&on_replace, vy_check_format_on_replace, &ctx, NULL); trigger_add(&space->on_replace, &on_replace); - int rc = vy_abort_writers_for_ddl(env, pk); - if (rc != 0) - goto out; + vy_abort_writers_for_ddl(env, pk); struct vy_read_iterator itr; - vy_read_iterator_open(&itr, pk, NULL, ITER_ALL, key, + vy_read_iterator_open(&itr, pk, NULL, ITER_ALL, pk->env->empty_key, &env->xm->p_committed_read_view); + int rc; int loops = 0; struct tuple *tuple; while ((rc = vy_read_iterator_next(&itr, &tuple)) == 0) { @@ -1151,10 +1144,9 @@ vinyl_space_check_format(struct space *space, struct tuple_format *format) break; } vy_read_iterator_close(&itr); -out: + diag_destroy(&ctx.diag); trigger_clear(&on_replace); - tuple_unref(key); return rc; } @@ -4183,10 +4175,6 @@ vinyl_space_build_index(struct space *src_space, struct index *new_index, * may yield, we install an on_replace trigger to forward * DML requests issued during the build. */ - struct tuple *key = vy_stmt_new_select(pk->env->key_format, NULL, 0); - if (key == NULL) - return -1; - struct trigger on_replace; struct vy_build_ctx ctx; ctx.lsm = new_lsm; @@ -4198,13 +4186,12 @@ vinyl_space_build_index(struct space *src_space, struct index *new_index, trigger_create(&on_replace, vy_build_on_replace, &ctx, NULL); trigger_add(&src_space->on_replace, &on_replace); - int rc = vy_abort_writers_for_ddl(env, pk); - if (rc != 0) - goto out; + vy_abort_writers_for_ddl(env, pk); struct vy_read_iterator itr; - vy_read_iterator_open(&itr, pk, NULL, ITER_ALL, key, + vy_read_iterator_open(&itr, pk, NULL, ITER_ALL, pk->env->empty_key, &env->xm->p_committed_read_view); + int rc; int loops = 0; struct tuple *tuple; int64_t build_lsn = env->xm->lsn; @@ -4260,10 +4247,9 @@ vinyl_space_build_index(struct space *src_space, struct index *new_index, diag_move(&ctx.diag, diag_get()); rc = -1; } -out: + diag_destroy(&ctx.diag); trigger_clear(&on_replace); - tuple_unref(key); return rc; } diff --git a/src/box/vy_tx.c b/src/box/vy_tx.c index 53bc1d86..b1fcfabb 100644 --- a/src/box/vy_tx.c +++ b/src/box/vy_tx.c @@ -1056,21 +1056,17 @@ vy_tx_set_with_colmask(struct vy_tx *tx, struct vy_lsm *lsm, return 0; } -int +void tx_manager_abort_writers(struct tx_manager *xm, struct vy_lsm *lsm) { - struct tuple *key = vy_stmt_new_select(lsm->env->key_format, NULL, 0); - if (key == NULL) - return -1; struct vy_tx *tx; rlist_foreach_entry(tx, &xm->writers, in_writers) { assert(!vy_tx_is_ro(tx)); if (tx->state == VINYL_TX_READY && - write_set_search_key(&tx->write_set, lsm, key) != NULL) + write_set_search_key(&tx->write_set, lsm, + lsm->env->empty_key) != NULL) tx->state = VINYL_TX_ABORT; } - tuple_unref(key); - return 0; } void diff --git a/src/box/vy_tx.h b/src/box/vy_tx.h index 87066091..9524936f 100644 --- a/src/box/vy_tx.h +++ b/src/box/vy_tx.h @@ -277,10 +277,8 @@ tx_manager_mem_used(struct tx_manager *xm); /** * Abort all rw transactions that affect the given LSM tree * and haven't reached WAL yet. - * - * Returns 0 on success, -1 on memory allocation error. */ -int +void tx_manager_abort_writers(struct tx_manager *xm, struct vy_lsm *lsm); /** Initialize a tx object. */ -- 2.11.0