Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@freelists.org
Cc: vdavydov.dev@gmail.com
Subject: [PATCH 3/4] session: introduce 'dead' type
Date: Fri,  7 Dec 2018 18:46:34 +0300	[thread overview]
Message-ID: <e156739b41cec81767509fa781200a4d24baf03b.1544197465.git.v.shpilevoy@tarantool.org> (raw)
In-Reply-To: <cover.1544197465.git.v.shpilevoy@tarantool.org>
In-Reply-To: <cover.1544197465.git.v.shpilevoy@tarantool.org>

If an iproto connection is closed, there are no way
how to determine if this happened. Except setting an
on_disconnect trigger which sets a global flag or
something.

To deal with such orphan requests a new session type
is introduced that can be checked inside a request.

Needed for #3859
---
 src/box/session.cc |  2 ++
 src/box/session.h  | 14 ++++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/src/box/session.cc b/src/box/session.cc
index f868e9ecc..b8e20609b 100644
--- a/src/box/session.cc
+++ b/src/box/session.cc
@@ -42,6 +42,7 @@ const char *session_type_strs[] = {
 	"console",
 	"repl",
 	"applier",
+	"dead",
 	"unknown",
 };
 
@@ -57,6 +58,7 @@ struct session_vtab session_vtab_registry[] = {
 	/* CONSOLE */ generic_session_vtab,
 	/* REPL */ generic_session_vtab,
 	/* APPLIER */ generic_session_vtab,
+	/* DEAD */ generic_session_vtab,
 };
 
 static struct mh_i64ptr_t *session_registry;
diff --git a/src/box/session.h b/src/box/session.h
index 6ed97dc46..d998d06a0 100644
--- a/src/box/session.h
+++ b/src/box/session.h
@@ -56,6 +56,7 @@ enum session_type {
 	SESSION_TYPE_CONSOLE,
 	SESSION_TYPE_REPL,
 	SESSION_TYPE_APPLIER,
+	SESSION_TYPE_DEAD,
 	session_type_MAX,
 };
 
@@ -306,6 +307,19 @@ session_sync(struct session *session)
 	return session_vtab_registry[session->type].sync(session);
 }
 
+/**
+ * Make a session invalid. Its type is changed to 'dead' that
+ * automatically changes its vtab to a generic implementation,
+ * returning errors on everything. Mostly it is used to be able
+ * to determine if an iproto connection is closed inside a running
+ * request.
+ */
+static inline void
+session_kill(struct session *session)
+{
+	session->type = SESSION_TYPE_DEAD;
+}
+
 /**
  * In a common case, a session does not support push. This
  * function always returns -1 and sets ER_UNSUPPORTED error.
-- 
2.17.2 (Apple Git-113)

  parent reply	other threads:[~2018-12-07 15:46 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-07 15:46 [PATCH 0/4] Outdate disconnected session Vladislav Shpilevoy
2018-12-07 15:46 ` [PATCH 1/4] iproto: rename disconnect cmsg to destroy Vladislav Shpilevoy
2018-12-07 17:36   ` [tarantool-patches] " Konstantin Osipov
2018-12-11 12:54     ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-07 15:46 ` [PATCH 2/4] iproto: fire on_disconnect right after disconnect Vladislav Shpilevoy
2018-12-07 17:37   ` [tarantool-patches] " Konstantin Osipov
2018-12-11 12:55     ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-07 15:46 ` Vladislav Shpilevoy [this message]
2018-12-07 17:38   ` [tarantool-patches] [PATCH 3/4] session: introduce 'dead' type Konstantin Osipov
2018-12-07 20:40     ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-07 22:21       ` Konstantin Osipov
2018-12-07 22:42         ` Vladislav Shpilevoy
2018-12-07 15:46 ` [PATCH 4/4] session: kill a session of a closed connection Vladislav Shpilevoy
2018-12-07 17:35 ` [tarantool-patches] [PATCH 0/4] Outdate disconnected session Konstantin Osipov
2018-12-11 16:12   ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-07 17:41 ` [tarantool-patches] " Konstantin Osipov
2018-12-11 16:13   ` [tarantool-patches] " 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=e156739b41cec81767509fa781200a4d24baf03b.1544197465.git.v.shpilevoy@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=vdavydov.dev@gmail.com \
    --subject='Re: [PATCH 3/4] session: introduce '\''dead'\'' type' \
    /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