Skip to content

Instantly share code, notes, and snippets.

@R-omk
Created April 15, 2019 07:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save R-omk/2ed809c0f890fef98882596e82d9f8ba to your computer and use it in GitHub Desktop.
Save R-omk/2ed809c0f890fef98882596e82d9f8ba to your computer and use it in GitHub Desktop.
tarantool Segmentation fault transaction
--
box.cfg {
memtx_max_tuple_size = 1048576 + 200;
force_recovery = true;
}
local fiber = require('fiber')
local function dd(...)
local x = debug.getinfo(2)
local dbg = string.format('[%s:%d][%s]', x.source, x.currentline, x.name)
local formatter_yaml = require('yaml').new()
formatter_yaml.cfg {
encode_invalid_numbers = true;
encode_load_metatables = true;
encode_use_tostring = true;
encode_invalid_as_nil = true;
}
require('log').info('\n ++VAR DUMP++ %s %s \n %s', dbg,
require('json').encode({ debug.traceback() }),
formatter_yaml.encode({ ... }))
end
dd('start !!!!')
local engine = 'vinyl';
box.internal.sql_create_function('WAITFOR', 'INT', function(n)
require('fiber').sleep(n)
return n
end)
box.execute('pragma sql_default_engine=\'' .. engine .. '\'')
box.execute("CREATE TABLE INTVIEW (key VARCHAR(100) PRIMARY KEY, data INTEGER);")
box.execute("CREATE TABLE STRINGVIEW (key VARCHAR(100) PRIMARY KEY, data VARCHAR(100));")
box.execute("CREATE TABLE HISTORY (id INTEGER PRIMARY KEY AUTOINCREMENT, data VARCHAR(100));")
local intvalue = 10;
local strvalue = intvalue .. ''
box.execute("INSERT INTO INTVIEW VALUES ('v1' , ?);", {intvalue})
box.execute("INSERT INTO STRINGVIEW VALUES ('v1' , ?);", {strvalue})
-- view
fiber.create(function()
for id = 1, 300 do
fiber.sleep(0.2)
local st, err = pcall(function(id)
box.execute('START TRANSACTION;')
box.execute("UPDATE INTVIEW SET data = ? WHERE key = 'v1';", {id})
box.execute("UPDATE STRINGVIEW SET data = ? WHERE key = 'v1';", {id..''})
box.commit()
end, id)
if not st then
dd('VIEW transaction', st, err)
end
end
end)
-- HISTORY
fiber.create(function()
for id = 1, 5 do
fiber.sleep(1)
local st, err = pcall(function(id)
box.execute('START TRANSACTION;')
-- box.execute("INSERT INTO HISTORY VALUES (NULL , ?);", {'start transaction' .. id})
box.execute('SELECT WAITFOR(1) AS S')
local intview = box.execute("SELECT data FROM INTVIEW WHERE key = 'v1'")
dd('intview', id, intview)
box.execute('SELECT WAITFOR(1) AS S')
local stringview = box.execute("SELECT data FROM STRINGVIEW WHERE key = 'v1'")
dd('stringview', id, stringview)
box.execute('SELECT WAITFOR(1) AS S')
local res = intview['rows'][1][1] .. ' is ' .. stringview['rows'][1][1]
box.execute("INSERT INTO HISTORY VALUES (NULL , ?);", { res})
box.commit()
end, id)
dd('HISTORY transaction', st, err)
end
end)
version: '2'
services:
tnt:
command: "tarantool /opt/tarantool/app.lua"
image: tarantool/tarantool:2
volumes:
- "./app.lua:/opt/tarantool/app.lua"
CLEAN:
docker-compose down -v
START:
docker-compose up
RUN: CLEAN START
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment