Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@freelists.org
Cc: kostja@tarantool.org
Subject: [tarantool-patches] [PATCH 3/4] swim: fix inability to set generation only
Date: Fri, 28 Jun 2019 01:25:45 +0200	[thread overview]
Message-ID: <c8bc033dc6f0e291548418b22567d69f84e21801.1561677891.git.v.shpilevoy@tarantool.org> (raw)
In-Reply-To: <cover.1561677891.git.v.shpilevoy@tarantool.org>

swim.new() is declared as allowed to be called before swim:cfg().
But in fact swim.new({generation = ...}) didn't work because
after generation extraction the empty config {} was passed to
swim:cfg() and led to an error.

The patch allows to call swim.new() with generation only, as well
as without parameters at all.

Follow up #4280
---
 src/lua/swim.lua        | 5 +++++
 test/swim/swim.result   | 6 ++++++
 test/swim/swim.test.lua | 4 ++++
 3 files changed, 15 insertions(+)

diff --git a/src/lua/swim.lua b/src/lua/swim.lua
index 686c376cc..69d077c37 100644
--- a/src/lua/swim.lua
+++ b/src/lua/swim.lua
@@ -980,6 +980,11 @@ local function swim_new(cfg)
         -- Nullify in order to do not raise errors in the
         -- following swim:cfg() about unknown parameters.
         cfg.generation = nil
+        -- When only 'generation' is specified, empty config will
+        -- raise an error at swim:cfg(). It should not.
+        if next(cfg) == nil then
+            cfg = nil
+        end
     end
     local ptr = internal.swim_new(generation)
     if ptr == nil then
diff --git a/test/swim/swim.result b/test/swim/swim.result
index 318b4bed9..26f74f9f4 100644
--- a/test/swim/swim.result
+++ b/test/swim/swim.result
@@ -1574,6 +1574,12 @@ s1:delete()
 s2:delete()
 ---
 ...
+-- It is allowed to create a SWIM with a generation value, but do
+-- not configure it.
+swim.new({generation = 0})
+---
+- []
+...
 --
 -- Check that Lua triggers don't keep a reference of SWIM instance
 -- preventing its GC.
diff --git a/test/swim/swim.test.lua b/test/swim/swim.test.lua
index 16b77b602..496beced5 100644
--- a/test/swim/swim.test.lua
+++ b/test/swim/swim.test.lua
@@ -535,6 +535,10 @@ s1:cfg({generation = 5})
 s1:delete()
 s2:delete()
 
+-- It is allowed to create a SWIM with a generation value, but do
+-- not configure it.
+swim.new({generation = 0})
+
 --
 -- Check that Lua triggers don't keep a reference of SWIM instance
 -- preventing its GC.
-- 
2.20.1 (Apple Git-117)

  parent reply	other threads:[~2019-06-27 23:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-27 23:25 [tarantool-patches] [PATCH 0/4] SWIM amendments Vladislav Shpilevoy
2019-06-27 23:25 ` [tarantool-patches] [PATCH 1/4] swim: fix a leak when a trigger is installed Vladislav Shpilevoy
2019-06-27 23:25 ` [tarantool-patches] [PATCH 2/4] swim: fix a dangerous yield in ffi.gc Vladislav Shpilevoy
2019-06-27 23:25 ` Vladislav Shpilevoy [this message]
2019-06-27 23:25 ` [tarantool-patches] [PATCH 4/4] swim: default generation is timestamp Vladislav Shpilevoy
2019-06-28 11:25 ` [tarantool-patches] Re: [PATCH 0/4] SWIM amendments Konstantin Osipov
2019-06-28 21:02   ` 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=c8bc033dc6f0e291548418b22567d69f84e21801.1561677891.git.v.shpilevoy@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH 3/4] swim: fix inability to set generation only' \
    /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