[tarantool-patches] Re: [PATCH 1/3] netbox: allow to create a netbox connection from existing socket
v.shpilevoy at tarantool.org
v.shpilevoy at tarantool.org
Thu Mar 22 22:57:34 MSK 2018
All is fixed on branch. Here is the diff for fixes.
> diff --git a/src/box/lua/console.lua b/src/box/lua/console.lua
> index 2109c2fa0..02e7f1066 100644
> --- a/src/box/lua/console.lua
> +++ b/src/box/lua/console.lua
> @@ -32,7 +32,7 @@ local function format(status, ...)
> if status then
> local count = select('#', ...)
> if count == 0 then
> - return "---"..YAML_TERM
> + return "---\n...\n"
> end
> local res = {}
> for i=1,count,1 do
> @@ -424,7 +424,7 @@ local function connect(uri, opts)
> if greeting.protocol == 'Lua console' then
> remote = wrap_text_socket(connection, u)
> else
> - remote = net_box.wrap_socket(connection, greeting, u)
> + remote = net_box.wrap(connection, greeting, u)
> if not remote.host then
> remote.host = 'localhost'
> end
> diff --git a/src/box/lua/net_box.lua b/src/box/lua/net_box.lua
> index cf1a04237..57e2f1b17 100644
> --- a/src/box/lua/net_box.lua
> +++ b/src/box/lua/net_box.lua
> @@ -373,6 +373,8 @@ local function create_transport(host, port, user, password, callback,
> local tm_begin, tm = fiber.clock(), callback('fetch_connect_timeout')
> if existing_connection then
> connection = existing_connection
> + -- Nullify the connection - on reconnect it must not
> + -- be get again.
> existing_connection = nil
> assert(greeting)
> assert(greeting.protocol ~= 'Lua console')
> @@ -627,7 +629,7 @@ local console_mt = {
>
> local space_metatable, index_metatable
>
> -local function do_connect(host, port, opts, existing_connection, greeting)
> +local function connect_impl(host, port, opts, existing_connection, greeting)
> local user, password = opts.user, opts.password; opts.password = nil
> local last_reconnect_error
> local remote = {host = host, port = port, opts = opts, state = 'initial'}
> @@ -707,12 +709,12 @@ end
>
> local function connect(...)
> local host, port, opts = parse_connect_params(...)
> - return do_connect(host, port, opts)
> + return connect_impl(host, port, opts)
> end
>
> -local function wrap_socket(connection, greeting, url, opts)
> +local function wrap(connection, greeting, url, opts)
> if connection == nil or type(greeting) ~= 'table' then
> - error('Usage: netbox.wrap_socket(socket, greeting, [opts])')
> + error('Usage: netbox.wrap(socket, greeting, [opts])')
> end
> if greeting.protocol == 'Lua console' then
> error('Can not wrap console socket')
> @@ -721,7 +723,7 @@ local function wrap_socket(connection, greeting, url, opts)
> if not opts.user and not opts.password then
> opts.user, opts.password = url.login, url.password
> end
> - return do_connect(url.host, url.service, opts, connection, greeting)
> + return connect_impl(url.host, url.service, opts, connection, greeting)
> end
>
> local function check_remote_arg(remote, method)
> @@ -1151,7 +1153,7 @@ local this_module = {
> connect = connect,
> new = connect, -- Tarantool < 1.7.1 compatibility,
> decode_greeting = internal.decode_greeting,
> - wrap_socket = wrap_socket,
> + wrap = wrap,
> }
>
> function this_module.timeout(timeout, ...)
> diff --git a/test/box/net.box.result b/test/box/net.box.result
> index cb9410085..cbfa0c7a1 100644
> --- a/test/box/net.box.result
> +++ b/test/box/net.box.result
> @@ -2317,7 +2317,7 @@ greeting = s:read({chunk = 128})
> greeting = net.decode_greeting(greeting)
> ---
> ...
> -c = net.wrap_socket(s, greeting, uri)
> +c = net.wrap(s, greeting, uri, {reconnect_after = 0.01})
> ---
> ...
> c.state
> @@ -2362,6 +2362,23 @@ c.space.test:delete{1}
> ---
> - [1]
> ...
> +--
> +-- Break a connection to test reconnect_after.
> +--
> +_ = c._transport.perform_request(nil, nil, 'inject', nil, '\x80')
> +---
> +...
> +c.state
> +---
> +- error_reconnect
> +...
> +while not c:is_connected() do fiber.sleep(0.01) end
> +---
> +...
> +c:ping()
> +---
> +- true
> +...
> s:drop()
> ---
> ...
> diff --git a/test/box/net.box.test.lua b/test/box/net.box.test.lua
> index 487401514..e0cac1955 100644
> --- a/test/box/net.box.test.lua
> +++ b/test/box/net.box.test.lua
> @@ -950,7 +950,7 @@ uri = urilib.parse(tostring(box.cfg.listen))
> s = socket.tcp_connect(uri.host, uri.service)
> greeting = s:read({chunk = 128})
> greeting = net.decode_greeting(greeting)
> -c = net.wrap_socket(s, greeting, uri)
> +c = net.wrap(s, greeting, uri, {reconnect_after = 0.01})
> c.state
>
> a = 100
> @@ -964,6 +964,14 @@ c:reload_schema()
> c.space.test:replace{1}
> c.space.test:get{1}
> c.space.test:delete{1}
> +--
> +-- Break a connection to test reconnect_after.
> +--
> +_ = c._transport.perform_request(nil, nil, 'inject', nil, '\x80')
> +c.state
> +while not c:is_connected() do fiber.sleep(0.01) end
> +c:ping()
> +
> s:drop()
> c:close()
> c.state
>
>
More information about the Tarantool-patches
mailing list