[tarantool-patches] [PATCH 3/4] swim: fix inability to set generation only

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Fri Jun 28 02:25:45 MSK 2019


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)





More information about the Tarantool-patches mailing list