Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH] test: concurrent tuple update segfault on bitset index iteration
@ 2020-08-19 17:23 Ilya Kosarev
  2020-08-25 15:23 ` Aleksandr Lyapunov
  0 siblings, 1 reply; 2+ messages in thread
From: Ilya Kosarev @ 2020-08-19 17:23 UTC (permalink / raw)
  To: alyapunov; +Cc: tarantool-patches

Concurrent tuple update could segfault on BITSET_ALL_NOT_SET iterator
usage. Fixed in 850054b2dbca257076c3f7c22e00564ac55b70d5.

Closes #1088
---
Branch: https://github.com/tarantool/tarantool/tree/i.kosarev/gh-1088-concurrent-tuple-update-segfault-with-bitset-index
Issue: https://github.com/tarantool/tarantool/issues/1088

 test/box/bitset.result   | 86 ++++++++++++++++++++++++++++++++++++++++
 test/box/bitset.test.lua | 42 ++++++++++++++++++++
 2 files changed, 128 insertions(+)

diff --git a/test/box/bitset.result b/test/box/bitset.result
index bf44773ef3..5da068385c 100644
--- a/test/box/bitset.result
+++ b/test/box/bitset.result
@@ -2020,3 +2020,89 @@ s:drop()
 box.schema.func.drop('s')
 ---
 ...
+-- gh-1088 concurrent tuple update segfaults on BITSET_ALL_NOT_SET iteration
+test_run = require('test_run').new()
+---
+...
+fiber = require('fiber')
+---
+...
+s = box.schema.space.create('gh-1088')
+---
+...
+_ = s:create_index('primary', {type = 'hash', parts = {1, 'num'}})
+---
+...
+_ = s:create_index('bitset', {unique = false, type = 'BITSET', parts = {2, 'num'}})
+---
+...
+for i = 1, 100 do s:insert{i, 0, i - 1} end
+---
+...
+counter = 0
+---
+...
+test_run:cmd("setopt delimiter ';'")
+---
+- true
+...
+function update()
+    for _, t in s.index.bitset:pairs(1, {iterator = box.index.BITS_ALL_NOT_SET}) do
+        counter = counter + 1
+        s:update(t[1], {{'+', 3, 11}})
+        fiber.sleep(0)
+    end
+    fiber.self():cancel()
+end;
+---
+...
+test_run:cmd("setopt delimiter ''");
+---
+- true
+...
+fibers = {}
+---
+...
+for _ = 1, 100 do table.insert(fibers, fiber.create(update)) end
+---
+...
+updating = true
+---
+...
+test_run:cmd("setopt delimiter ';'")
+---
+- true
+...
+while updating do
+    updating = false
+    for _, f in pairs(fibers) do
+        if f:status() ~= 'dead' then updating = true end
+    end
+    fiber.sleep(0.001)
+end;
+---
+...
+test_run:cmd("setopt delimiter ''");
+---
+- true
+...
+s:get(1)
+---
+- [1, 0, 1100]
+...
+s:get(2)
+---
+- [2, 0, 1101]
+...
+s:get(3)
+---
+- [3, 0, 1102]
+...
+s:get(4)
+---
+- [4, 0, 1103]
+...
+counter -- total updates counter
+---
+- 10000
+...
diff --git a/test/box/bitset.test.lua b/test/box/bitset.test.lua
index d644d34e0b..dd432edeb0 100644
--- a/test/box/bitset.test.lua
+++ b/test/box/bitset.test.lua
@@ -162,3 +162,45 @@ _ = s:create_index('pk')
 _ = s:create_index('idx', {type = 'bitset', func = box.func.s.id, parts = {{1, 'unsigned'}}})
 s:drop()
 box.schema.func.drop('s')
+
+-- gh-1088 concurrent tuple update segfaults on BITSET_ALL_NOT_SET iteration
+test_run = require('test_run').new()
+fiber = require('fiber')
+
+s = box.schema.space.create('gh-1088')
+_ = s:create_index('primary', {type = 'hash', parts = {1, 'num'}})
+_ = s:create_index('bitset', {unique = false, type = 'BITSET', parts = {2, 'num'}})
+for i = 1, 100 do s:insert{i, 0, i - 1} end
+
+counter = 0
+test_run:cmd("setopt delimiter ';'")
+function update()
+    for _, t in s.index.bitset:pairs(1, {iterator = box.index.BITS_ALL_NOT_SET}) do
+        counter = counter + 1
+        s:update(t[1], {{'+', 3, 11}})
+        fiber.sleep(0)
+    end
+    fiber.self():cancel()
+end;
+test_run:cmd("setopt delimiter ''");
+
+fibers = {}
+for _ = 1, 100 do table.insert(fibers, fiber.create(update)) end
+
+updating = true
+test_run:cmd("setopt delimiter ';'")
+while updating do
+    updating = false
+    for _, f in pairs(fibers) do
+        if f:status() ~= 'dead' then updating = true end
+    end
+    fiber.sleep(0.001)
+end;
+test_run:cmd("setopt delimiter ''");
+
+s:get(1)
+s:get(2)
+s:get(3)
+s:get(4)
+
+counter -- total updates counter
-- 
2.17.1

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-08-25 15:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-19 17:23 [Tarantool-patches] [PATCH] test: concurrent tuple update segfault on bitset index iteration Ilya Kosarev
2020-08-25 15:23 ` Aleksandr Lyapunov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox