From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp14.mail.ru (smtp14.mail.ru [94.100.181.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id C2DAF4696C6 for ; Sat, 18 Apr 2020 18:29:46 +0300 (MSK) From: Leonid Vasiliev Date: Sat, 18 Apr 2020 18:29:38 +0300 Message-Id: In-Reply-To: References: In-Reply-To: References: Subject: [Tarantool-patches] [PATCH V5 3/6] session: add offset to SQL session settings array List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: v.shpilevoy@tarantool.org, alexander.turenko@tarantool.org Cc: tarantool-patches@dev.tarantool.org From: Vladislav Shpilevoy Session settings are stored in a monolithic array. Submodules can define a range of settings in there. For example, SQL. It occupies settings from 0 to 8. There is a second array of only SQL settings in build.c, of the same size, and it uses the same indexes. But if something will be added before SQL settings, so as they won't start from 0, it will break the equal indexes assumption. SQL should normalize all setting identifiers by SESSION_SETTING_SQL_BEGIN. --- src/box/sql/build.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/box/sql/build.c b/src/box/sql/build.c index aecba41..b1f9fed 100644 --- a/src/box/sql/build.c +++ b/src/box/sql/build.c @@ -3367,7 +3367,8 @@ sql_session_setting_get(int id, const char **mp_pair, const char **mp_pair_end) assert(id >= SESSION_SETTING_SQL_BEGIN && id < SESSION_SETTING_SQL_END); struct session *session = current_session(); uint32_t flags = session->sql_flags; - struct sql_option_metadata *opt = &sql_session_opts[id]; + struct sql_option_metadata *opt = + &sql_session_opts[id - SESSION_SETTING_SQL_BEGIN]; uint32_t mask = opt->mask; const char *name = session_setting_strs[id]; size_t name_len = strlen(name); @@ -3404,7 +3405,8 @@ static int sql_set_boolean_option(int id, bool value) { struct session *session = current_session(); - struct sql_option_metadata *option = &sql_session_opts[id]; + struct sql_option_metadata *option = + &sql_session_opts[id - SESSION_SETTING_SQL_BEGIN]; assert(option->field_type == FIELD_TYPE_BOOLEAN); #ifdef NDEBUG if ((session->sql_flags & SQL_SqlTrace) == 0) { @@ -3431,7 +3433,8 @@ sql_set_boolean_option(int id, bool value) static int sql_set_string_option(int id, const char *value) { - assert(sql_session_opts[id].field_type = FIELD_TYPE_STRING); + assert(sql_session_opts[id - SESSION_SETTING_SQL_BEGIN].field_type = + FIELD_TYPE_STRING); assert(id == SESSION_SETTING_SQL_DEFAULT_ENGINE); (void)id; enum sql_storage_engine engine = STR2ENUM(sql_storage_engine, value); @@ -3448,7 +3451,8 @@ sql_session_setting_set(int id, const char *mp_value) { assert(id >= SESSION_SETTING_SQL_BEGIN && id < SESSION_SETTING_SQL_END); enum mp_type mtype = mp_typeof(*mp_value); - enum field_type stype = sql_session_opts[id].field_type; + enum field_type stype = + sql_session_opts[id - SESSION_SETTING_SQL_BEGIN].field_type; uint32_t len; const char *tmp; switch(stype) { @@ -3473,10 +3477,10 @@ sql_session_setting_set(int id, const char *mp_value) void sql_session_settings_init() { - for (int id = SESSION_SETTING_SQL_BEGIN; id < SESSION_SETTING_SQL_END; - ++id) { + for (int i = 0, id = SESSION_SETTING_SQL_BEGIN; + id < SESSION_SETTING_SQL_END; ++id, ++i) { struct session_setting *setting = &session_settings[id]; - setting->field_type = sql_session_opts[id].field_type; + setting->field_type = sql_session_opts[i].field_type; setting->get = sql_session_setting_get; setting->set = sql_session_setting_set; } -- 2.7.4