From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Kirill Yukhin Subject: [PATCH 1/4] Pass necessary fields to tuple_format contructor Date: Tue, 22 Jan 2019 17:07:17 +0300 Message-Id: <8c3d49689175993d54b50c01e11b37511befdc5e.1548165435.git.kyukhin@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: vdavydov.dev@gmail.com Cc: tarantool-patches@freelists.org, Kirill Yukhin List-ID: There were three extra fields of tuple_format which were setup after it was created. Fix that by extending tuple_format contstructor w/ three new arguments: engine, is_temporary, exact_field_count. --- src/box/blackhole.c | 6 +++--- src/box/memtx_space.c | 8 +++----- src/box/tuple.c | 8 ++++---- src/box/tuple_format.c | 13 ++++++++----- src/box/tuple_format.h | 11 ++++++++--- src/box/vinyl.c | 12 +++++++----- src/box/vy_lsm.c | 9 +++++---- test/unit/vy_iterators_helper.c | 12 ++++++------ test/unit/vy_mem.c | 4 ++-- test/unit/vy_point_lookup.c | 4 ++-- 10 files changed, 48 insertions(+), 39 deletions(-) diff --git a/src/box/blackhole.c b/src/box/blackhole.c index 0412ffe..64e24cd 100644 --- a/src/box/blackhole.c +++ b/src/box/blackhole.c @@ -155,13 +155,13 @@ blackhole_engine_create_space(struct engine *engine, struct space_def *def, /* Allocate tuples on runtime arena, but check space format. */ struct tuple_format *format; - format = tuple_format_new(&tuple_format_runtime->vtab, NULL, 0, - def->fields, def->field_count, def->dict); + format = tuple_format_new(&tuple_format_runtime->vtab, NULL, NULL, 0, + def->fields, def->field_count, def->dict, + false, def->exact_field_count); if (format == NULL) { free(space); return NULL; } - format->exact_field_count = def->exact_field_count; tuple_format_ref(format); if (space_create(space, engine, &blackhole_space_vtab, diff --git a/src/box/memtx_space.c b/src/box/memtx_space.c index eb790a6..49d09af 100644 --- a/src/box/memtx_space.c +++ b/src/box/memtx_space.c @@ -990,15 +990,13 @@ memtx_space_new(struct memtx_engine *memtx, keys[key_count++] = index_def->key_def; struct tuple_format *format = - tuple_format_new(&memtx_tuple_format_vtab, keys, key_count, - def->fields, def->field_count, def->dict); + tuple_format_new(&memtx_tuple_format_vtab, memtx, keys, key_count, + def->fields, def->field_count, def->dict, + def->opts.is_temporary, def->exact_field_count); if (format == NULL) { free(memtx_space); return NULL; } - format->engine = memtx; - format->is_temporary = def->opts.is_temporary; - format->exact_field_count = def->exact_field_count; tuple_format_ref(format); if (space_create((struct space *)memtx_space, (struct engine *)memtx, diff --git a/src/box/tuple.c b/src/box/tuple.c index 2343f0e..5295800 100644 --- a/src/box/tuple.c +++ b/src/box/tuple.c @@ -207,8 +207,8 @@ tuple_init(field_name_hash_f hash) /* * Create a format for runtime tuples */ - tuple_format_runtime = tuple_format_new(&tuple_format_runtime_vtab, - NULL, 0, NULL, 0, NULL); + tuple_format_runtime = tuple_format_new(&tuple_format_runtime_vtab, NULL, + NULL, 0, NULL, 0, NULL, false, 0); if (tuple_format_runtime == NULL) return -1; @@ -379,8 +379,8 @@ box_tuple_format_t * box_tuple_format_new(struct key_def **keys, uint16_t key_count) { box_tuple_format_t *format = - tuple_format_new(&tuple_format_runtime_vtab, - keys, key_count, NULL, 0, NULL); + tuple_format_new(&tuple_format_runtime_vtab, NULL, + keys, key_count, NULL, 0, NULL, false, 0); if (format != NULL) tuple_format_ref(format); return format; diff --git a/src/box/tuple_format.c b/src/box/tuple_format.c index e11b4e6..6edc0fb 100644 --- a/src/box/tuple_format.c +++ b/src/box/tuple_format.c @@ -398,17 +398,20 @@ tuple_format_delete(struct tuple_format *format) } struct tuple_format * -tuple_format_new(struct tuple_format_vtab *vtab, struct key_def * const *keys, - uint16_t key_count, const struct field_def *space_fields, - uint32_t space_field_count, struct tuple_dictionary *dict) +tuple_format_new(struct tuple_format_vtab *vtab, void *engine, + struct key_def * const *keys, uint16_t key_count, + const struct field_def *space_fields, + uint32_t space_field_count, struct tuple_dictionary *dict, + bool is_temporary, uint32_t exact_field_count) { struct tuple_format *format = tuple_format_alloc(keys, key_count, space_field_count, dict); if (format == NULL) return NULL; format->vtab = *vtab; - format->engine = NULL; - format->is_temporary = false; + format->engine = engine; + format->is_temporary = is_temporary; + format->exact_field_count = exact_field_count; if (tuple_format_register(format) < 0) { tuple_format_destroy(format); free(format); diff --git a/src/box/tuple_format.h b/src/box/tuple_format.h index 30b93b6..9778fda 100644 --- a/src/box/tuple_format.h +++ b/src/box/tuple_format.h @@ -258,18 +258,23 @@ tuple_format_unref(struct tuple_format *format) /** * Allocate, construct and register a new in-memory tuple format. * @param vtab Virtual function table for specific engines. + * @param engine Pointer to storage engine. * @param keys Array of key_defs of a space. * @param key_count The number of keys in @a keys array. * @param space_fields Array of fields, defined in a space format. * @param space_field_count Length of @a space_fields. + * @param is_temporary Set if format is temporary. + * @param exact_field_count Exact field count for format. * * @retval not NULL Tuple format. * @retval NULL Memory error. */ struct tuple_format * -tuple_format_new(struct tuple_format_vtab *vtab, struct key_def * const *keys, - uint16_t key_count, const struct field_def *space_fields, - uint32_t space_field_count, struct tuple_dictionary *dict); +tuple_format_new(struct tuple_format_vtab *vtab, void *engine, + struct key_def * const *keys, uint16_t key_count, + const struct field_def *space_fields, + uint32_t space_field_count, struct tuple_dictionary *dict, + bool is_temporary, uint32_t exact_field_count); /** * Check, if @a format1 can store any tuples of @a format2. For diff --git a/src/box/vinyl.c b/src/box/vinyl.c index d6117f4..abae076 100644 --- a/src/box/vinyl.c +++ b/src/box/vinyl.c @@ -619,13 +619,14 @@ vinyl_engine_create_space(struct engine *engine, struct space_def *def, keys[key_count++] = index_def->key_def; struct tuple_format *format = - tuple_format_new(&vy_tuple_format_vtab, keys, key_count, - def->fields, def->field_count, def->dict); + tuple_format_new(&vy_tuple_format_vtab, NULL, keys, + key_count, + def->fields, def->field_count, def->dict, + false, def->exact_field_count); if (format == NULL) { free(space); return NULL; } - format->exact_field_count = def->exact_field_count; tuple_format_ref(format); if (space_create(space, engine, &vinyl_space_vtab, @@ -3043,8 +3044,9 @@ vy_send_lsm(struct vy_join_ctx *ctx, struct vy_lsm_recovery_info *lsm_info) lsm_info->key_part_count); if (ctx->key_def == NULL) goto out; - ctx->format = tuple_format_new(&vy_tuple_format_vtab, &ctx->key_def, - 1, NULL, 0, NULL); + ctx->format = tuple_format_new(&vy_tuple_format_vtab, NULL, + &ctx->key_def, 1, NULL, 0, NULL, false, + 0); if (ctx->format == NULL) goto out_free_key_def; tuple_format_ref(ctx->format); diff --git a/src/box/vy_lsm.c b/src/box/vy_lsm.c index 5eb3fd7..983a655 100644 --- a/src/box/vy_lsm.c +++ b/src/box/vy_lsm.c @@ -60,8 +60,8 @@ vy_lsm_env_create(struct vy_lsm_env *env, const char *path, vy_upsert_thresh_cb upsert_thresh_cb, void *upsert_thresh_arg) { - env->key_format = tuple_format_new(&vy_tuple_format_vtab, - NULL, 0, NULL, 0, NULL); + env->key_format = tuple_format_new(&vy_tuple_format_vtab, NULL, + NULL, 0, NULL, 0, NULL, false, 0); if (env->key_format == NULL) return -1; tuple_format_ref(env->key_format); @@ -153,8 +153,9 @@ vy_lsm_new(struct vy_lsm_env *lsm_env, struct vy_cache_env *cache_env, */ lsm->disk_format = format; } else { - lsm->disk_format = tuple_format_new(&vy_tuple_format_vtab, - &cmp_def, 1, NULL, 0, NULL); + lsm->disk_format = tuple_format_new(&vy_tuple_format_vtab, NULL, + &cmp_def, 1, NULL, 0, NULL, + false, 0); if (lsm->disk_format == NULL) goto fail_format; } diff --git a/test/unit/vy_iterators_helper.c b/test/unit/vy_iterators_helper.c index 7fad560..7031097 100644 --- a/test/unit/vy_iterators_helper.c +++ b/test/unit/vy_iterators_helper.c @@ -21,8 +21,8 @@ vy_iterator_C_test_init(size_t cache_size) tuple_init(NULL); vy_cache_env_create(&cache_env, cord_slab_cache()); vy_cache_env_set_quota(&cache_env, cache_size); - vy_key_format = tuple_format_new(&vy_tuple_format_vtab, NULL, 0, - NULL, 0, NULL); + vy_key_format = tuple_format_new(&vy_tuple_format_vtab, NULL, NULL, 0, + NULL, 0, NULL, false, 0); tuple_format_ref(vy_key_format); size_t mem_size = 64 * 1024 * 1024; @@ -201,8 +201,8 @@ create_test_mem(struct key_def *def) /* Create format */ struct key_def * const defs[] = { def }; struct tuple_format *format = - tuple_format_new(&vy_tuple_format_vtab, defs, def->part_count, - NULL, 0, NULL); + tuple_format_new(&vy_tuple_format_vtab, NULL, defs, + def->part_count, NULL, 0, NULL, false, 0); fail_if(format == NULL); /* Create mem */ @@ -219,8 +219,8 @@ create_test_cache(uint32_t *fields, uint32_t *types, *def = box_key_def_new(fields, types, key_cnt); assert(*def != NULL); vy_cache_create(cache, &cache_env, *def, true); - *format = tuple_format_new(&vy_tuple_format_vtab, def, 1, NULL, 0, - NULL); + *format = tuple_format_new(&vy_tuple_format_vtab, NULL, def, 1, NULL, 0, + NULL, false, 0); tuple_format_ref(*format); } diff --git a/test/unit/vy_mem.c b/test/unit/vy_mem.c index ebf3fbc..911f082 100644 --- a/test/unit/vy_mem.c +++ b/test/unit/vy_mem.c @@ -77,8 +77,8 @@ test_iterator_restore_after_insertion() /* Create format */ struct tuple_format *format = tuple_format_new(&vy_tuple_format_vtab, - &key_def, 1, NULL, 0, - NULL); + NULL, &key_def, 1, NULL, + 0, NULL, false, 0); assert(format != NULL); tuple_format_ref(format); diff --git a/test/unit/vy_point_lookup.c b/test/unit/vy_point_lookup.c index 65dafcb..634fffa 100644 --- a/test/unit/vy_point_lookup.c +++ b/test/unit/vy_point_lookup.c @@ -84,8 +84,8 @@ test_basic() vy_cache_create(&cache, &cache_env, key_def, true); struct tuple_format *format = tuple_format_new(&vy_tuple_format_vtab, - &key_def, 1, NULL, 0, - NULL); + NULL, &key_def, 1, NULL, + 0, NULL, false, 0); isnt(format, NULL, "tuple_format_new is not NULL"); tuple_format_ref(format); -- 2.19.1