Tarantool development patches archive
 help / color / mirror / Atom feed
From: Ilya Kosarev <i.kosarev@tarantool.org>
To: kyukhin@tarantool.org
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH v2] test: concurrent tuple update segfault on bitset index iteration
Date: Mon, 31 Aug 2020 13:59:54 +0300	[thread overview]
Message-ID: <20200831105954.32408-1-i.kosarev@tarantool.org> (raw)

Concurrent tuple update could segfault on BITSET_ALL_NOT_SET iterator
usage. Fixed in 850054b2dbca257076c3f7c22e00564ac55b70d5. This patch
introduces corresponding test.

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

Changes in v2:
- put test in separate file

 ...gh-1088-concurrent-bitset-iteration.result | 94 +++++++++++++++++++
 ...-1088-concurrent-bitset-iteration.test.lua | 42 +++++++++
 2 files changed, 136 insertions(+)
 create mode 100644 test/engine/gh-1088-concurrent-bitset-iteration.result
 create mode 100644 test/engine/gh-1088-concurrent-bitset-iteration.test.lua

diff --git a/test/engine/gh-1088-concurrent-bitset-iteration.result b/test/engine/gh-1088-concurrent-bitset-iteration.result
new file mode 100644
index 0000000000..242c745628
--- /dev/null
+++ b/test/engine/gh-1088-concurrent-bitset-iteration.result
@@ -0,0 +1,94 @@
+-- test-run result file version 2
+-- 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/engine/gh-1088-concurrent-bitset-iteration.test.lua b/test/engine/gh-1088-concurrent-bitset-iteration.test.lua
new file mode 100644
index 0000000000..f57d1ecabe
--- /dev/null
+++ b/test/engine/gh-1088-concurrent-bitset-iteration.test.lua
@@ -0,0 +1,42 @@
+-- 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

             reply	other threads:[~2020-08-31 11:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-31 10:59 Ilya Kosarev [this message]
2020-08-31 11:36 ` Kirill Yukhin

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=20200831105954.32408-1-i.kosarev@tarantool.org \
    --to=i.kosarev@tarantool.org \
    --cc=kyukhin@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v2] test: concurrent tuple update segfault on bitset index iteration' \
    /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