[tarantool-patches] [PATCH v2 2/5] vinyl: rename vy_index::id to index_id

  • From: Vladimir Davydov <vdavydov.dev@xxxxxxxxx>
  • To: kostja@xxxxxxxxxxxxx
  • Date: Tue, 20 Mar 2018 14:29:02 +0300

Throughout Vinyl we use the term 'id' for calling members representing
unique object identifiers: vy_slice::id, vy_run::id, vy_range::id.
There's one exception though: vy_index::id is the ordinal number of the
index in a space. This is confusing. Besides, I'm planning to assign a
unique id to each vinyl index so that I could look them up in vylog.
I'd like to call the new member 'id' for consistency. So let's rename
vy_index::id to index_id.
---
 src/box/vinyl.c             | 38 ++++++++++++++++++++------------------
 src/box/vy_index.c          | 18 +++++++++---------
 src/box/vy_index.h          |  4 ++--
 src/box/vy_point_lookup.c   |  2 +-
 src/box/vy_read_iterator.c  |  5 +++--
 src/box/vy_scheduler.c      | 19 ++++++++++---------
 src/box/vy_tx.c             |  4 ++--
 test/unit/vy_point_lookup.c |  6 +++---
 8 files changed, 50 insertions(+), 46 deletions(-)

diff --git a/src/box/vinyl.c b/src/box/vinyl.c
index d3659b0b..af3621df 100644
--- a/src/box/vinyl.c
+++ b/src/box/vinyl.c
@@ -830,7 +830,7 @@ vinyl_index_commit_create(struct index *base, int64_t lsn)
         * recovery.
         */
        vy_log_tx_begin();
-       vy_log_create_index(index->commit_lsn, index->id,
+       vy_log_create_index(index->commit_lsn, index->index_id,
                            index->space_id, index->key_def);
        vy_log_insert_range(index->commit_lsn, range->id, NULL, NULL);
        vy_log_tx_try_commit();
@@ -1305,7 +1305,7 @@ vinyl_index_bsize(struct index *base)
        struct vy_index *index = vy_index(base);
        ssize_t bsize = vy_index_mem_tree_size(index) +
                index->page_index_size + index->bloom_size;
-       if (index->id > 0)
+       if (index->index_id > 0)
                bsize += index->stat.disk.count.bytes;
        return bsize;
 }
@@ -1425,7 +1425,8 @@ vy_check_is_unique(struct vy_env *env, struct vy_tx *tx, 
struct space *space,
        if (found) {
                tuple_unref(found);
                diag_set(ClientError, ER_TUPLE_FOUND,
-                        index_name_by_id(space, index->id), space_name(space));
+                        index_name_by_id(space, index->index_id),
+                        space_name(space));
                return -1;
        }
        return 0;
@@ -1448,7 +1449,7 @@ vy_insert_primary(struct vy_env *env, struct vy_tx *tx, 
struct space *space,
 {
        assert(vy_stmt_type(stmt) == IPROTO_INSERT);
        assert(tx != NULL && tx->state == VINYL_TX_READY);
-       assert(pk->id == 0);
+       assert(pk->index_id == 0);
        /*
         * A primary index is always unique and the new tuple must not
         * conflict with existing tuples.
@@ -1477,7 +1478,7 @@ vy_insert_secondary(struct vy_env *env, struct vy_tx *tx, 
struct space *space,
        assert(vy_stmt_type(stmt) == IPROTO_INSERT ||
               vy_stmt_type(stmt) == IPROTO_REPLACE);
        assert(tx != NULL && tx->state == VINYL_TX_READY);
-       assert(index->id > 0);
+       assert(index->index_id > 0);
        /*
         * If the index is unique then the new tuple must not
         * conflict with existing tuples. If the index is not
@@ -1529,7 +1530,7 @@ vy_replace_one(struct vy_env *env, struct vy_tx *tx, 
struct space *space,
        (void)env;
        assert(tx != NULL && tx->state == VINYL_TX_READY);
        struct vy_index *pk = vy_index(space->index[0]);
-       assert(pk->id == 0);
+       assert(pk->index_id == 0);
        if (tuple_validate_raw(pk->mem_format, request->tuple))
                return -1;
        struct tuple *new_tuple =
@@ -1589,7 +1590,7 @@ vy_replace_impl(struct vy_env *env, struct vy_tx *tx, 
struct space *space,
                return -1;
        /* Primary key is dumped last. */
        assert(!vy_is_committed_one(env, space, pk));
-       assert(pk->id == 0);
+       assert(pk->index_id == 0);
        if (tuple_validate_raw(pk->mem_format, request->tuple))
                return -1;
        new_stmt = vy_stmt_new_replace(pk->mem_format, request->tuple,
@@ -1729,7 +1730,7 @@ vy_index_full_by_key(struct vy_index *index, struct vy_tx 
*tx,
        tuple_unref(key);
        if (rc != 0)
                return -1;
-       if (index->id == 0 || found == NULL) {
+       if (index->index_id == 0 || found == NULL) {
                *result = found;
                return 0;
        }
@@ -1835,7 +1836,7 @@ vy_delete(struct vy_env *env, struct vy_tx *tx, struct 
txn_stmt *stmt,
                assert(stmt->old_tuple != NULL);
                return vy_delete_impl(env, tx, space, stmt->old_tuple);
        } else { /* Primary is the single index in the space. */
-               assert(index->id == 0);
+               assert(index->index_id == 0);
                struct tuple *delete =
                        vy_stmt_new_surrogate_delete_from_key(request->key,
                                                              pk->key_def,
@@ -1874,7 +1875,8 @@ vy_check_update(struct space *space, const struct 
vy_index *pk,
        if (!key_update_can_be_skipped(pk->key_def->column_mask, column_mask) &&
            vy_tuple_compare(old_tuple, new_tuple, pk->key_def) != 0) {
                diag_set(ClientError, ER_CANT_UPDATE_PRIMARY_KEY,
-                        index_name_by_id(space, pk->id), space_name(space));
+                        index_name_by_id(space, pk->index_id),
+                        space_name(space));
                return -1;
        }
        return 0;
@@ -1918,7 +1920,7 @@ vy_update(struct vy_env *env, struct vy_tx *tx, struct 
txn_stmt *stmt,
        /* Apply update operations. */
        struct vy_index *pk = vy_index(space->index[0]);
        assert(pk != NULL);
-       assert(pk->id == 0);
+       assert(pk->index_id == 0);
        /* Primary key is dumped last. */
        assert(!vy_is_committed_one(env, space, pk));
        uint64_t column_mask = 0;
@@ -2007,7 +2009,7 @@ vy_insert_first_upsert(struct vy_env *env, struct vy_tx 
*tx,
        assert(space->index_count > 0);
        assert(vy_stmt_type(stmt) == IPROTO_INSERT);
        struct vy_index *pk = vy_index(space->index[0]);
-       assert(pk->id == 0);
+       assert(pk->index_id == 0);
        if (vy_tx_set(tx, pk, stmt) != 0)
                return -1;
        struct vy_index *index;
@@ -2292,7 +2294,7 @@ vy_insert(struct vy_env *env, struct vy_tx *tx, struct 
txn_stmt *stmt,
        if (pk == NULL)
                /* The space hasn't the primary index. */
                return -1;
-       assert(pk->id == 0);
+       assert(pk->index_id == 0);
        /* Primary key is dumped last. */
        assert(!vy_is_committed_one(env, space, pk));
        if (tuple_validate_raw(pk->mem_format, request->tuple))
@@ -3571,7 +3573,7 @@ vy_squash_process(struct vy_squash *squash)
        struct key_def *def = index->cmp_def;
 
        /* Upserts enabled only in the primary index. */
-       assert(index->id == 0);
+       assert(index->index_id == 0);
 
        /*
         * Use the committed read view to avoid squashing
@@ -3666,7 +3668,7 @@ vy_squash_process(struct vy_squash *squash)
                        tuple_unref(result);
                        return 0;
                }
-               assert(index->id == 0);
+               assert(index->index_id == 0);
                struct tuple *applied =
                        vy_apply_upsert(mem_stmt, result, def, mem->format,
                                        mem->upsert_format, true);
@@ -3860,7 +3862,7 @@ vinyl_iterator_primary_next(struct iterator *base, struct 
tuple **ret)
 {
        assert(base->next = vinyl_iterator_primary_next);
        struct vinyl_iterator *it = (struct vinyl_iterator *)base;
-       assert(it->index->id == 0);
+       assert(it->index->index_id == 0);
        struct tuple *tuple;
 
        if (it->tx == NULL) {
@@ -3894,7 +3896,7 @@ vinyl_iterator_secondary_next(struct iterator *base, 
struct tuple **ret)
 {
        assert(base->next = vinyl_iterator_secondary_next);
        struct vinyl_iterator *it = (struct vinyl_iterator *)base;
-       assert(it->index->id > 0);
+       assert(it->index->index_id > 0);
        struct tuple *tuple;
 
        if (it->tx == NULL) {
@@ -3977,7 +3979,7 @@ vinyl_index_create_iterator(struct index *base, enum 
iterator_type type,
        }
 
        iterator_create(&it->base, base);
-       if (index->id == 0)
+       if (index->index_id == 0)
                it->base.next = vinyl_iterator_primary_next;
        else
                it->base.next = vinyl_iterator_secondary_next;
diff --git a/src/box/vy_index.c b/src/box/vy_index.c
index 9c199ddd..e4f567e2 100644
--- a/src/box/vy_index.c
+++ b/src/box/vy_index.c
@@ -62,7 +62,7 @@ vy_index_validate_formats(const struct vy_index *index)
        assert(index->upsert_format != NULL);
        uint32_t index_field_count = index->mem_format->index_field_count;
        (void) index_field_count;
-       if (index->id == 0) {
+       if (index->index_id == 0) {
                assert(index->disk_format == index->mem_format);
                assert(index->disk_format->index_field_count ==
                       index_field_count);
@@ -115,7 +115,7 @@ vy_index_name(struct vy_index *index)
 {
        char *buf = tt_static_buf();
        snprintf(buf, TT_STATIC_BUF_LEN, "%u/%u",
-                (unsigned)index->space_id, (unsigned)index->id);
+                (unsigned)index->space_id, (unsigned)index->index_id);
        return buf;
 }
 
@@ -236,7 +236,7 @@ vy_index_new(struct vy_index_env *index_env, struct 
vy_cache_env *cache_env,
        index->in_dump.pos = UINT32_MAX;
        index->in_compact.pos = UINT32_MAX;
        index->space_id = index_def->space_id;
-       index->id = index_def->iid;
+       index->index_id = index_def->iid;
        index->opts = index_def->opts;
        index->check_is_unique = index->opts.is_unique;
        vy_index_read_set_new(&index->read_set);
@@ -355,7 +355,7 @@ vy_index_create(struct vy_index *index)
        int rc;
        char path[PATH_MAX];
        vy_index_snprint_path(path, sizeof(path), index->env->path,
-                             index->space_id, index->id);
+                             index->space_id, index->index_id);
        char *path_sep = path;
        while (*path_sep == '/') {
                /* Don't create root */
@@ -404,10 +404,10 @@ vy_index_recover_run(struct vy_index *index,
 
        run->dump_lsn = run_info->dump_lsn;
        if (vy_run_recover(run, index->env->path,
-                          index->space_id, index->id) != 0 &&
+                          index->space_id, index->index_id) != 0 &&
            (!force_recovery ||
             vy_run_rebuild_index(run, index->env->path,
-                                 index->space_id, index->id,
+                                 index->space_id, index->index_id,
                                  index->cmp_def, index->key_def,
                                  index->mem_format, index->upsert_format,
                                  &index->opts) != 0)) {
@@ -553,7 +553,7 @@ vy_index_recover(struct vy_index *index, struct vy_recovery 
*recovery,
         */
        struct vy_index_recovery_info *index_info;
        index_info = vy_recovery_lookup_index(recovery,
-                                             index->space_id, index->id);
+                       index->space_id, index->index_id);
        if (is_checkpoint_recovery) {
                if (index_info == NULL) {
                        /*
@@ -565,7 +565,7 @@ vy_index_recover(struct vy_index *index, struct vy_recovery 
*recovery,
                        diag_set(ClientError, ER_INVALID_VYLOG_FILE,
                                 tt_sprintf("Index %u/%u not found",
                                            (unsigned)index->space_id,
-                                           (unsigned)index->id));
+                                           (unsigned)index->index_id));
                        return -1;
                }
                if (lsn > index_info->index_lsn) {
@@ -850,7 +850,7 @@ vy_index_commit_upsert(struct vy_index *index, struct 
vy_mem *mem,
         * UPSERT is enabled only for the spaces with the single
         * index.
         */
-       assert(index->id == 0);
+       assert(index->index_id == 0);
 
        const struct tuple *older;
        int64_t lsn = vy_stmt_lsn(stmt);
diff --git a/src/box/vy_index.h b/src/box/vy_index.h
index 4368f6a5..7a5a8aa8 100644
--- a/src/box/vy_index.h
+++ b/src/box/vy_index.h
@@ -148,8 +148,8 @@ struct vy_index {
         * until all pending operations have completed.
         */
        int refs;
-       /** Index ID visible to the user. */
-       uint32_t id;
+       /** Ordinal index number in the index array. */
+       uint32_t index_id;
        /** ID of the space this index belongs to. */
        uint32_t space_id;
        /** Index options. */
diff --git a/src/box/vy_point_lookup.c b/src/box/vy_point_lookup.c
index ab0bc6b8..d92cb94f 100644
--- a/src/box/vy_point_lookup.c
+++ b/src/box/vy_point_lookup.c
@@ -267,7 +267,7 @@ vy_point_lookup_scan_slice(struct vy_index *index, struct 
vy_slice *slice,
        vy_run_iterator_open(&run_itr, &index->stat.disk.iterator, slice,
                             ITER_EQ, key, rv, index->cmp_def, index->key_def,
                             index->disk_format, index->upsert_format,
-                            index->id == 0);
+                            index->index_id == 0);
        struct tuple *stmt;
        rc = vy_run_iterator_next_key(&run_itr, &stmt);
        while (rc == 0 && stmt != NULL) {
diff --git a/src/box/vy_read_iterator.c b/src/box/vy_read_iterator.c
index a265f587..3b5e34fc 100644
--- a/src/box/vy_read_iterator.c
+++ b/src/box/vy_read_iterator.c
@@ -649,7 +649,7 @@ vy_read_iterator_squash_upsert(struct vy_read_iterator *itr,
        struct tuple *t = itr->curr_stmt;
 
        /* Upserts enabled only in the primary index. */
-       assert(vy_stmt_type(t) != IPROTO_UPSERT || index->id == 0);
+       assert(vy_stmt_type(t) != IPROTO_UPSERT || index->index_id == 0);
        tuple_ref(t);
        while (vy_stmt_type(t) == IPROTO_UPSERT) {
                struct tuple *next;
@@ -755,7 +755,8 @@ vy_read_iterator_add_disk(struct vy_read_iterator *itr)
                                     iterator_type, itr->key,
                                     itr->read_view, index->cmp_def,
                                     index->key_def, index->disk_format,
-                                    index->upsert_format, index->id == 0);
+                                    index->upsert_format,
+                                    index->index_id == 0);
        }
 }
 
diff --git a/src/box/vy_scheduler.c b/src/box/vy_scheduler.c
index 382cf071..05234532 100644
--- a/src/box/vy_scheduler.c
+++ b/src/box/vy_scheduler.c
@@ -207,7 +207,7 @@ vy_dump_heap_less(struct heap_node *a, struct heap_node *b)
         * ahead of secondary indexes of the same space, i.e. it must
         * be dumped last.
         */
-       return i1->id > i2->id;
+       return i1->index_id > i2->index_id;
 }
 
 #define HEAP_NAME vy_dump_heap
@@ -637,7 +637,7 @@ vy_task_write_run(struct vy_scheduler *scheduler, struct 
vy_task *task)
 
        struct vy_run_writer writer;
        if (vy_run_writer_create(&writer, task->new_run, index->env->path,
-                                index->space_id, index->id,
+                                index->space_id, index->index_id,
                                 index->cmp_def, index->key_def,
                                 task->page_size, task->bloom_fpr,
                                 task->max_output_count) != 0)
@@ -839,7 +839,7 @@ delete_mems:
        index->is_dumping = false;
        vy_scheduler_update_index(scheduler, index);
 
-       if (index->id != 0)
+       if (index->index_id != 0)
                vy_scheduler_unpin_index(scheduler, index->pk);
 
        assert(scheduler->dump_task_count > 0);
@@ -893,7 +893,7 @@ vy_task_dump_abort(struct vy_scheduler *scheduler, struct 
vy_task *task,
        index->is_dumping = false;
        vy_scheduler_update_index(scheduler, index);
 
-       if (index->id != 0)
+       if (index->index_id != 0)
                vy_scheduler_unpin_index(scheduler, index->pk);
 
        assert(scheduler->dump_task_count > 0);
@@ -935,7 +935,7 @@ vy_task_dump_new(struct vy_scheduler *scheduler, struct 
vy_index *index,
        assert(scheduler->dump_generation < scheduler->generation);
 
        struct errinj *inj = errinj(ERRINJ_VY_INDEX_DUMP, ERRINJ_INT);
-       if (inj != NULL && inj->iparam == (int)index->id) {
+       if (inj != NULL && inj->iparam == (int)index->index_id) {
                diag_set(ClientError, ER_INJECTION, "vinyl index dump");
                goto err;
        }
@@ -990,7 +990,7 @@ vy_task_dump_new(struct vy_scheduler *scheduler, struct 
vy_index *index,
        struct vy_stmt_stream *wi;
        bool is_last_level = (index->run_count == 0);
        wi = vy_write_iterator_new(index->cmp_def, index->disk_format,
-                                  index->upsert_format, index->id == 0,
+                                  index->upsert_format, index->index_id == 0,
                                   is_last_level, scheduler->read_views);
        if (wi == NULL)
                goto err_wi;
@@ -1010,7 +1010,7 @@ vy_task_dump_new(struct vy_scheduler *scheduler, struct 
vy_index *index,
        index->is_dumping = true;
        vy_scheduler_update_index(scheduler, index);
 
-       if (index->id != 0) {
+       if (index->index_id != 0) {
                /*
                 * The primary index must be dumped after all
                 * secondary indexes of the same space - see
@@ -1124,7 +1124,8 @@ vy_task_compact_complete(struct vy_scheduler *scheduler, 
struct vy_task *task)
                vy_log_tx_begin();
                rlist_foreach_entry(run, &unused_runs, in_unused) {
                        if (vy_run_remove_files(index->env->path,
-                                               index->space_id, index->id,
+                                               index->space_id,
+                                               index->index_id,
                                                run->id) == 0) {
                                vy_log_forget_run(run->id);
                        }
@@ -1265,7 +1266,7 @@ vy_task_compact_new(struct vy_scheduler *scheduler, 
struct vy_index *index,
        struct vy_stmt_stream *wi;
        bool is_last_level = (range->compact_priority == range->slice_count);
        wi = vy_write_iterator_new(index->cmp_def, index->disk_format,
-                                  index->upsert_format, index->id == 0,
+                                  index->upsert_format, index->index_id == 0,
                                   is_last_level, scheduler->read_views);
        if (wi == NULL)
                goto err_wi;
diff --git a/src/box/vy_tx.c b/src/box/vy_tx.c
index 01130020..1b583240 100644
--- a/src/box/vy_tx.c
+++ b/src/box/vy_tx.c
@@ -525,7 +525,7 @@ vy_tx_prepare(struct vy_tx *tx)
        MAYBE_UNUSED uint32_t current_space_id = 0;
        stailq_foreach_entry(v, &tx->log, next_in_log) {
                struct vy_index *index = v->index;
-               if (index->id == 0) {
+               if (index->index_id == 0) {
                        /* The beginning of the new txn_stmt is met. */
                        current_space_id = index->space_id;
                        repsert = NULL;
@@ -816,7 +816,7 @@ vy_tx_set(struct vy_tx *tx, struct vy_index *index, struct 
tuple *stmt)
        struct txv *old = write_set_search_key(&tx->write_set, index, stmt);
        /* Found a match of the previous action of this transaction */
        if (old != NULL && vy_stmt_type(stmt) == IPROTO_UPSERT) {
-               assert(index->id == 0);
+               assert(index->index_id == 0);
                uint8_t old_type = vy_stmt_type(old->stmt);
                assert(old_type == IPROTO_UPSERT ||
                       old_type == IPROTO_INSERT ||
diff --git a/test/unit/vy_point_lookup.c b/test/unit/vy_point_lookup.c
index 52f4427e..c324160f 100644
--- a/test/unit/vy_point_lookup.c
+++ b/test/unit/vy_point_lookup.c
@@ -19,7 +19,7 @@ write_run(struct vy_run *run, const char *dir_name,
 {
        struct vy_run_writer writer;
        if (vy_run_writer_create(&writer, run, dir_name,
-                                index->space_id, index->id,
+                                index->space_id, index->index_id,
                                 index->cmp_def, index->key_def,
                                 4096, 0.1, 100500) != 0)
                goto fail;
@@ -193,7 +193,7 @@ test_basic()
        }
        struct vy_stmt_stream *write_stream
                = vy_write_iterator_new(pk->cmp_def, pk->disk_format,
-                                       pk->upsert_format, pk->id == 0,
+                                       pk->upsert_format, true,
                                        true, &read_views);
        vy_write_iterator_new_mem(write_stream, run_mem);
        struct vy_run *run = vy_run_new(&run_env, 1);
@@ -228,7 +228,7 @@ test_basic()
        }
        write_stream
                = vy_write_iterator_new(pk->cmp_def, pk->disk_format,
-                                       pk->upsert_format, pk->id == 0,
+                                       pk->upsert_format, true,
                                        true, &read_views);
        vy_write_iterator_new_mem(write_stream, run_mem);
        run = vy_run_new(&run_env, 2);
-- 
2.11.0


Other related posts:

  • » [tarantool-patches] [PATCH v2 2/5] vinyl: rename vy_index::id to index_id - Vladimir Davydov