Tarantool development patches archive
 help / color / mirror / Atom feed
From: Leonid Vasiliev <lvasiliev@tarantool.org>
To: v.shpilevoy@tarantool.org
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH V4 3/6] session: add offset to SQL session settings array
Date: Thu, 16 Apr 2020 20:38:42 +0300	[thread overview]
Message-ID: <fd9e807458cccf7e3869ea1f9cff375e4fe489db.1587058424.git.lvasiliev@tarantool.org> (raw)
In-Reply-To: <cover.1587058424.git.lvasiliev@tarantool.org>
In-Reply-To: <cover.1587058424.git.lvasiliev@tarantool.org>

From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>

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

  parent reply	other threads:[~2020-04-16 17:38 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-16 17:38 [Tarantool-patches] [PATCH V4 0/6] Extending error functionality Leonid Vasiliev
2020-04-16 17:38 ` [Tarantool-patches] [PATCH V4 1/6] error: add custom error type Leonid Vasiliev
2020-04-17  0:49   ` Vladislav Shpilevoy
2020-04-18 17:14     ` lvasiliev
2020-04-16 17:38 ` [Tarantool-patches] [PATCH V4 2/6] error: send custom type in IProto Leonid Vasiliev
2020-04-17  0:51   ` Vladislav Shpilevoy
2020-04-16 17:38 ` Leonid Vasiliev [this message]
2020-04-16 17:38 ` [Tarantool-patches] [PATCH V4 4/6] error: add session setting for error type marshaling Leonid Vasiliev
2020-04-16 19:48   ` Konstantin Osipov
2020-04-17  0:51     ` Vladislav Shpilevoy
2020-04-17  7:35       ` Konstantin Osipov
2020-04-16 17:38 ` [Tarantool-patches] [PATCH V4 5/6] error: update constructors of some errors Leonid Vasiliev
2020-04-16 17:38 ` [Tarantool-patches] [PATCH V4 6/6] error: add error MsgPack encoding Leonid Vasiliev
2020-04-17  0:58   ` Vladislav Shpilevoy
2020-04-18 17:46     ` lvasiliev
2020-04-17  0:51 ` [Tarantool-patches] [PATCH V4 0/6] Extending error functionality Vladislav Shpilevoy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fd9e807458cccf7e3869ea1f9cff375e4fe489db.1587058424.git.lvasiliev@tarantool.org \
    --to=lvasiliev@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH V4 3/6] session: add offset to SQL session settings array' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox