From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Kirill Yukhin Subject: [PATCH v2 2/4] Set is_temporary flag for formats of ephemeral spaces Date: Thu, 24 Jan 2019 15:48:46 +0300 Message-Id: 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: Before the patch, when ephemeral space was created flag is_temporary was set after space was actually created. Which in turn lead to corresponding flag of tuple_format being set to `false`. So, having heavy load using ephemeral spaces (almost any SQL query) and snapshotting at the same time might lead to OOM, since tuples of ephemeral spaces were not marked as temporary and were not gc-ed. Patch sets the flag in space definition. --- src/box/space.c | 2 +- src/box/space_def.c | 14 ++++++++++++++ src/box/space_def.h | 9 +++++++++ src/box/sql.c | 6 +----- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/box/space.c b/src/box/space.c index 4d174f7..6245167 100644 --- a/src/box/space.c +++ b/src/box/space.c @@ -194,10 +194,10 @@ space_new(struct space_def *def, struct rlist *key_list) struct space * space_new_ephemeral(struct space_def *def, struct rlist *key_list) { + assert(def->opts.is_temporary); struct space *space = space_new(def, key_list); if (space == NULL) return NULL; - space->def->opts.is_temporary = true; space->vtab->init_ephemeral_space(space); return space; } diff --git a/src/box/space_def.c b/src/box/space_def.c index 3516bdd..d60c2d3 100644 --- a/src/box/space_def.c +++ b/src/box/space_def.c @@ -257,6 +257,20 @@ space_def_new(uint32_t id, uint32_t uid, uint32_t exact_field_count, return def; } +struct space_def* +space_def_new_ephemeral(uint32_t field_count) +{ + struct space_opts opts = space_opts_default; + opts.is_temporary = true; + struct space_def *space_def = space_def_new(0, 0, field_count, + "ephemeral", + strlen("ephemeral"), + "memtx", strlen("memtx"), + &opts, &field_def_default, + 0); + return space_def; +} + /** Free a default value's syntax trees of @a defs. */ void space_def_destroy_fields(struct field_def *fields, uint32_t field_count, diff --git a/src/box/space_def.h b/src/box/space_def.h index 8044f88..b6ab6b3 100644 --- a/src/box/space_def.h +++ b/src/box/space_def.h @@ -169,6 +169,15 @@ space_def_new(uint32_t id, uint32_t uid, uint32_t exact_field_count, const struct space_opts *opts, const struct field_def *fields, uint32_t field_count); +/** + * Create a new ephemeral space definition. + * @param field_count Number of fields in the space. + * + * @retval Space definition. + */ +struct space_def * +space_def_new_ephemeral(uint32_t field_count); + /** * Size of the space_def. * @param name_len Length of the space name. diff --git a/src/box/sql.c b/src/box/sql.c index 081a038..387da7b 100644 --- a/src/box/sql.c +++ b/src/box/sql.c @@ -408,11 +408,7 @@ sql_ephemeral_space_create(uint32_t field_count, struct sql_key_info *key_info) rlist_add_entry(&key_list, ephemer_index_def, link); struct space_def *ephemer_space_def = - space_def_new(0 /* space id */, 0 /* user id */, field_count, - "ephemeral", strlen("ephemeral"), - "memtx", strlen("memtx"), - &space_opts_default, &field_def_default, - 0 /* length of field_def */); + space_def_new_ephemeral(field_count); if (ephemer_space_def == NULL) { index_def_delete(ephemer_index_def); return NULL; -- 2.19.1