[tarantool-patches] Re: [PATCH 1/1] netbox: introduce iterable future objects

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Tue Jun 5 01:17:27 MSK 2018


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}





More information about the Tarantool-patches mailing list