From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 5BF742187E for ; Mon, 4 Jun 2018 18:17:34 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sGHtQ8ZGNvXp for ; Mon, 4 Jun 2018 18:17:34 -0400 (EDT) Received: from smtp1.mail.ru (smtp1.mail.ru [94.100.179.111]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id A5847250CF for ; Mon, 4 Jun 2018 18:17:33 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH 1/1] netbox: introduce iterable future objects From: Vladislav Shpilevoy References: Message-ID: <5ff69264-a09d-21a5-6f6f-59f8cb31376c@tarantool.org> Date: Tue, 5 Jun 2018 01:17:27 +0300 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: kostja@tarantool.org Hi. I have removed ability to continue iteration after a timeout error. I have decided it can be added later if anybody needs. On 24/05/2018 23:50, Vladislav Shpilevoy wrote: > Netbox has two major ways to execute a request: sync and async. > During execution of any a server can send multiplie responses via > IPROTO_CHUNK. And the execution ways differ in how to handle the > chunks (called messages or pushes). > > For a sync request a one can specify on_push callback and its > on_push_ctx argument called on each message. > > When a request is async a user has a future object only, and can > not specify any callbacks. To get the pushed messages a one must > iterate over future object like this: > for i, message in future:pairs(one_iteration_timeout) do > ... > end > Or ignore messages just calling future:wait_result(). Anyway > messages are not deleted, so a one can iterate over future object > again and again. > > Follow up #2677 > --- Below the diff of removal: ================================================ diff --git a/src/box/lua/net_box.lua b/src/box/lua/net_box.lua index 5d896f7e3..851f245b1 100644 --- a/src/box/lua/net_box.lua +++ b/src/box/lua/net_box.lua @@ -281,12 +281,6 @@ local function create_transport(host, port, user, password, callback, -- @retval box.NULL, error An error occured. When this -- function is called in 'for k, v in future:pairs()', -- `k` becomes box.NULL, and `v` becomes error object. - -- If a one want to stop the cycle, he can do break. - -- With no break the cycle will be continued until - -- the request is finished. The iteration continuation - -- is useful for example when time is out during a - -- next message waiting, but a one does not consider - -- this error be critical. -- On error the key becomes exactly box.NULL instead -- of nil, because nil is treated by Lua as iteration -- end marker. Nil does not participate in iteration, @@ -294,13 +288,7 @@ local function create_transport(host, port, user, password, callback, -- local function request_iterator_next(iterator, i) if i == box.NULL then - -- If a user continues iteration after an error - - -- restore position. - if not iterator.next_i then - return nil, nil - end - i = iterator.next_i - iterator.next_i = nil + return nil, nil else i = i + 1 end @@ -334,7 +322,6 @@ local function create_transport(host, port, user, password, callback, goto retry end until timeout <= 0 - iterator.next_i = i return box.NULL, box.error.new(E_TIMEOUT) end -- diff --git a/test/box/push.result b/test/box/push.result index 0816c6754..340a6c04f 100644 --- a/test/box/push.result +++ b/test/box/push.result @@ -390,68 +390,7 @@ keys - 5 - 6 ... --- Test timeouts inside `for`. Even if a timeout is got, a user --- can continue iteration making as many attempts to get a message --- as he wants. -future = c:call('do_pushes', {}, {is_async = true}) ---- -... -messages = {} ---- -... -keys = {} ---- -... -err_count = 0 ---- -... -test_run:cmd("setopt delimiter ';'") ---- -- true -... -for i, message in future:pairs(0.01) do - if i == nil then - err_count = err_count + 1 - assert(message.code == box.error.TIMEOUT) - if err_count % 2 == 0 then - cond:signal() - end - else - table.insert(messages, message) - table.insert(keys, i) - end -end; ---- -... -test_run:cmd("setopt delimiter ''"); ---- -- true -... --- Messages and keys are got in the correct order and with no --- duplicates regardless of big timeout count. -messages ---- -- - 101 - - 102 - - 103 - - 104 - - 105 - - [true] -... -keys ---- -- - 1 - - 2 - - 3 - - 4 - - 5 - - 6 -... -err_count ---- -- 10 -... --- Test non-timeout error. +-- Test error. s = box.schema.create_space('test') --- ... diff --git a/test/box/push.test.lua b/test/box/push.test.lua index 10bc201df..480c58ca3 100644 --- a/test/box/push.test.lua +++ b/test/box/push.test.lua @@ -191,34 +191,7 @@ for i, message in future:pairs() do table.insert(messages, message) table.insert messages keys --- Test timeouts inside `for`. Even if a timeout is got, a user --- can continue iteration making as many attempts to get a message --- as he wants. -future = c:call('do_pushes', {}, {is_async = true}) -messages = {} -keys = {} -err_count = 0 -test_run:cmd("setopt delimiter ';'") -for i, message in future:pairs(0.01) do - if i == nil then - err_count = err_count + 1 - assert(message.code == box.error.TIMEOUT) - if err_count % 2 == 0 then - cond:signal() - end - else - table.insert(messages, message) - table.insert(keys, i) - end -end; -test_run:cmd("setopt delimiter ''"); --- Messages and keys are got in the correct order and with no --- duplicates regardless of big timeout count. -messages -keys -err_count - --- Test non-timeout error. +-- Test error. s = box.schema.create_space('test') pk = s:create_index('pk') s:replace{1}