From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 11.2 \(3445.5.20\)) Subject: Re: [tarantool-patches] [PATCH 0/5] session: introduce box.session.push From: "v.shpilevoy@tarantool.org" In-Reply-To: Date: Mon, 19 Mar 2018 16:41:12 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: References: To: tarantool-patches@freelists.org Cc: vdavydov.dev@gmail.com List-ID: Sorry, forgot a description. Box.session.push() allows to send a message to a client with no finishing a main request. It means, that a client can split a big response in several pushes, or send notifications from a long polling request. Tarantool now supports two push types: via text protocol and via binary protocol. Text pushes are needed mainly for printing, logging and all other stdout output, written on a host side from a client console connection. Text protocol push message contains "push:" prefix followed by a YAML formatted text, where as a final response always has '---' prefix. To catch pushed messages client uses console.connect() on_push option, which takes a function with a single argument - message. IProto message is encoded just like a regular response, but instead of IPROTO_DATA it has IPROTO_PUSH with a single element - pushed MessagePack encoded data. Text push is trivial - it is just blocking write into a socket with a prefix. Binary push is more complex. =20 TX thread to notify IProto thread about new data in obuf sends a message 'push_msg'. IProto thread, got this message, notifies libev about new data, and then sends 'push_msg' back with updated write position. TX thread, received the message back, updates its version of a write position. If IProto do not send a write position, then TX would write to the same obuf again and again, because it can not know that IProto already flushed another obuf. To avoid multiple 'push_msg' in fly between IProto and TX, the only one 'push_msg' per connection is used. To deliver pushes, appeared when 'push_msg' was in fly, TX thread sets a flag every time when sees, that 'push_msg' is sent, and there is a new push. When 'push_msg' returns, it checks this flag, and if it is set, then the IProto is notified again. > 19 =D0=BC=D0=B0=D1=80=D1=82=D0=B0 2018 =D0=B3., =D0=B2 16:34, = Vladislav Shpilevoy =D0=BD=D0=B0=D0=BF=D0=B8=D1= =81=D0=B0=D0=BB(=D0=B0): >=20 > Branch: = http://github.com/tarantool/tarantool/tree/gh-2677-box-session-push > Issue: https://github.com/tarantool/tarantool/issues/2677 >=20 > Vladislav Shpilevoy (5): > session: forbid creation from Lua binary and applier sessions > lua: port console yaml formatting to C > Remove empty function declaration > session: introduce session_owner > session: introduce box.session.push >=20 > src/box/applier.cc | 4 +- > src/box/authentication.cc | 4 +- > src/box/authentication.h | 3 +- > src/box/box.cc | 4 +- > src/box/box.h | 2 +- > src/box/iproto.cc | 321 = +++++++++++++++++++++++---- > src/box/iproto_constants.c | 3 +- > src/box/iproto_constants.h | 8 + > src/box/lua/call.c | 1 + > src/box/lua/console.c | 42 ++++ > src/box/lua/console.h | 8 + > src/box/lua/console.lua | 40 +--- > src/box/lua/net_box.c | 37 ++++ > src/box/lua/net_box.lua | 97 ++++++-- > src/box/lua/session.c | 252 ++++++++++++++++++++- > src/box/port.c | 7 + > src/box/port.h | 15 ++ > src/box/session.cc | 86 +++++++- > src/box/session.h | 106 +++++++-- > src/box/vinyl.c | 3 +- > src/box/xrow.c | 40 +++- > src/box/xrow.h | 26 ++- > src/fio.c | 12 + > src/fio.h | 16 ++ > src/lua/socket.h | 2 - > test/app-tap/console.test.lua | 9 +- > test/box-tap/session.test.lua | 12 +- > test/box/net.box.result | 2 +- > test/box/net.box.test.lua | 2 +- > test/box/push.result | 364 = +++++++++++++++++++++++++++++++ > test/box/push.test.lua | 163 ++++++++++++++ > test/replication/before_replace.result | 14 ++ > test/replication/before_replace.test.lua | 11 + > third_party/lua-yaml/lyaml.cc | 9 +- > third_party/lua-yaml/lyaml.h | 3 + > 35 files changed, 1576 insertions(+), 152 deletions(-) > create mode 100644 test/box/push.result > create mode 100644 test/box/push.test.lua >=20 > --=20 > 2.14.3 (Apple Git-98) >=20 >=20