diff --git a/test/vinyl/dump_stress.result b/test/vinyl/dump_stress.result index b16e93b4ac6479aff0d83fb41392897c9127945d..5c1dd9a512c8d7dde262e71ec1ca0b35dd099b47 100644 --- a/test/vinyl/dump_stress.result +++ b/test/vinyl/dump_stress.result @@ -1,7 +1,7 @@ test_run = require('test_run').new() --- ... -test_run:cmd("create server test with script='vinyl/low_quota.lua'") +test_run:cmd("create server test with script='vinyl/low_quota_1.lua'") --- - true ... diff --git a/test/vinyl/dump_stress.test.lua b/test/vinyl/dump_stress.test.lua index 823d4c2bb8208d5a0765bbf6307e7b1bcb7aa105..e7f20d2d65131db3af5674b4ba05a9e1ad7426bf 100644 --- a/test/vinyl/dump_stress.test.lua +++ b/test/vinyl/dump_stress.test.lua @@ -1,6 +1,6 @@ test_run = require('test_run').new() -test_run:cmd("create server test with script='vinyl/low_quota.lua'") +test_run:cmd("create server test with script='vinyl/low_quota_1.lua'") test_run:cmd("start server test") test_run:cmd('switch test') diff --git a/test/vinyl/errinj.result b/test/vinyl/errinj.result index 1752bc220b4123eaac0d9651899f1cd740d9c227..242d583ad6322c31b3d68bc7946fea11709580d3 100644 --- a/test/vinyl/errinj.result +++ b/test/vinyl/errinj.result @@ -780,7 +780,7 @@ space:drop() -- -- Space drop in the middle of dump. -- -test_run:cmd("create server test with script='vinyl/low_quota.lua'") +test_run:cmd("create server test with script='vinyl/low_quota_1.lua'") --- - true ... diff --git a/test/vinyl/errinj.test.lua b/test/vinyl/errinj.test.lua index 3a599218f55c79a81ac1d2d149ace6edc04ad278..457fad6281bd0eaa13fd9cbcd446d9b4ba1ca6b1 100644 --- a/test/vinyl/errinj.test.lua +++ b/test/vinyl/errinj.test.lua @@ -314,7 +314,7 @@ space:drop() -- -- Space drop in the middle of dump. -- -test_run:cmd("create server test with script='vinyl/low_quota.lua'") +test_run:cmd("create server test with script='vinyl/low_quota_1.lua'") test_run:cmd("start server test") test_run:cmd('switch test') fiber = require 'fiber' diff --git a/test/vinyl/low_quota.lua b/test/vinyl/low_quota.lua index a0870d5f6475d3a2d0783fb0497caffc49cb7848..20269c8c26696c3aea4b210d0ae05fd3f99ed472 100644 --- a/test/vinyl/low_quota.lua +++ b/test/vinyl/low_quota.lua @@ -1,7 +1,9 @@ #!/usr/bin/env tarantool +local LIMIT = string.match(arg[0], "%d") + box.cfg{ - vinyl_memory = 1024 * 1024, + vinyl_memory = LIMIT * 1024 * 1024, } require('console').listen(os.getenv('ADMIN')) diff --git a/test/vinyl/low_quota_1.lua b/test/vinyl/low_quota_1.lua new file mode 120000 index 0000000000000000000000000000000000000000..b5b834c7c3373b279b3cf20cf2ef9e3662f113b6 --- /dev/null +++ b/test/vinyl/low_quota_1.lua @@ -0,0 +1 @@ +low_quota.lua \ No newline at end of file diff --git a/test/vinyl/low_quota_2.lua b/test/vinyl/low_quota_2.lua new file mode 120000 index 0000000000000000000000000000000000000000..b5b834c7c3373b279b3cf20cf2ef9e3662f113b6 --- /dev/null +++ b/test/vinyl/low_quota_2.lua @@ -0,0 +1 @@ +low_quota.lua \ No newline at end of file diff --git a/test/vinyl/quota_timeout.result b/test/vinyl/quota_timeout.result index ddd02215640db91db123150ab1638caf7af2a4bc..7a38e706b945dc481042ec32770008c8cd0013c3 100644 --- a/test/vinyl/quota_timeout.result +++ b/test/vinyl/quota_timeout.result @@ -1,7 +1,7 @@ test_run = require('test_run').new() --- ... -test_run:cmd("create server test with script='vinyl/low_quota.lua'") +test_run:cmd("create server test with script='vinyl/low_quota_1.lua'") --- - true ... diff --git a/test/vinyl/quota_timeout.test.lua b/test/vinyl/quota_timeout.test.lua index 5db1cd648a2a8cace1b558fbef963b8b6c94abdb..32bcf2cb49cfc994e3be5392bc8ccba50c74cac7 100644 --- a/test/vinyl/quota_timeout.test.lua +++ b/test/vinyl/quota_timeout.test.lua @@ -1,6 +1,6 @@ test_run = require('test_run').new() -test_run:cmd("create server test with script='vinyl/low_quota.lua'") +test_run:cmd("create server test with script='vinyl/low_quota_1.lua'") test_run:cmd("start server test") test_run:cmd('switch test') diff --git a/test/vinyl/recovery_quota.result b/test/vinyl/recovery_quota.result index eadb156d78b37f70c3f43c79101735d05015b1fe..ca8fd0a6e15164503184a1690ca922d64b6d7e42 100644 --- a/test/vinyl/recovery_quota.result +++ b/test/vinyl/recovery_quota.result @@ -1,12 +1,15 @@ test_run = require('test_run').new() --- ... +fio = require 'fio' +--- +... -- Upon start the test server creates a space and populates it with -- more tuples than can be stored in memory, which results in dumping -- some of them to disk. If on restart, during recovery from WAL, -- it replayed the dumped statements, it would exceed memory quota. -- Check that it does not. -test_run:cmd('create server test with script = "vinyl/low_quota.lua"') +test_run:cmd('create server test with script = "vinyl/low_quota_2.lua"') --- - true ... @@ -18,17 +21,20 @@ test_run:cmd('switch test') --- - true ... --- Create a vinyl space and trigger dump by exceeding memory quota (1 MB). +-- Create a vinyl space and trigger dump by exceeding memory quota. s = box.schema.space.create('test', {engine = 'vinyl'}) --- ... _ = s:create_index('pk', {run_count_per_level = 10}) --- ... -pad = string.rep('x', 1000) +pad_size = 1000 +--- +... +pad = string.rep('x', pad_size) --- ... -for i = 1, 2000 do s:insert{i, pad} end +for i = 1, 2 * box.cfg.vinyl_memory / pad_size do s:insert{i, pad} end --- ... -- Save the total number of committed and dumped statements. @@ -94,6 +100,28 @@ put_before - dump_before == put_after or {dump_before, dump_after, put_before, p --- - true ... +-- Disable dump and use all memory up to the limit. +box.error.injection.set('ERRINJ_VY_RUN_WRITE', false) +--- +- ok +... +box.cfg{vinyl_timeout=0.001} +--- +... +pad_size = 1000 +--- +... +pad = string.rep('x', pad_size) +--- +... +for i = 1, box.cfg.vinyl_memory / pad_size do box.space.test:replace{i, pad} end +--- +- error: Timed out waiting for Vinyl memory quota +... +box.info.vinyl().memory.used > 1024 * 1024 +--- +- true +... test_run:cmd('switch default') --- - true @@ -102,7 +130,42 @@ test_run:cmd('stop server test') --- - true ... +-- Check that tarantool can recover with a smaller memory limit. +_ = test_run:cmd(string.format('create server test2 with script = "vinyl/low_quota_1.lua", workdir = "%s"', fio.pathjoin(fio.cwd(), 'low_quota_2'))) +--- +... +_ = test_run:cmd('start server test2') +--- +... +_ = test_run:cmd('switch test2') +--- +... +fiber = require 'fiber' +--- +... +-- All memory above the limit must be dumped after recovery. +while box.space.test.index.pk:info().disk.dump.count == 0 do fiber.sleep(0.001) end +--- +... +stat = box.info.vinyl() +--- +... +stat.memory.used <= stat.memory.limit or {stat.memory.used, stat.memory.limit} +--- +- true +... +_ = test_run:cmd('switch default') +--- +... +test_run:cmd('stop server test2') +--- +- true +... test_run:cmd('cleanup server test') --- - true ... +test_run:cmd('cleanup server test2') +--- +- true +... diff --git a/test/vinyl/recovery_quota.test.lua b/test/vinyl/recovery_quota.test.lua index cf0c1eac022cf8032bc5dc51b69b0fc97667e06c..07483815f11de5c6c9fced8069a133dabb4e6fe5 100644 --- a/test/vinyl/recovery_quota.test.lua +++ b/test/vinyl/recovery_quota.test.lua @@ -1,4 +1,5 @@ test_run = require('test_run').new() +fio = require 'fio' -- Upon start the test server creates a space and populates it with -- more tuples than can be stored in memory, which results in dumping @@ -6,15 +7,16 @@ test_run = require('test_run').new() -- it replayed the dumped statements, it would exceed memory quota. -- Check that it does not. -test_run:cmd('create server test with script = "vinyl/low_quota.lua"') +test_run:cmd('create server test with script = "vinyl/low_quota_2.lua"') test_run:cmd('start server test') test_run:cmd('switch test') --- Create a vinyl space and trigger dump by exceeding memory quota (1 MB). +-- Create a vinyl space and trigger dump by exceeding memory quota. s = box.schema.space.create('test', {engine = 'vinyl'}) _ = s:create_index('pk', {run_count_per_level = 10}) -pad = string.rep('x', 1000) -for i = 1, 2000 do s:insert{i, pad} end +pad_size = 1000 +pad = string.rep('x', pad_size) +for i = 1, 2 * box.cfg.vinyl_memory / pad_size do s:insert{i, pad} end -- Save the total number of committed and dumped statements. var = box.schema.space.create('var') _ = var:create_index('pk', {parts = {1, 'string'}}) @@ -38,7 +40,28 @@ put_before = var:get('put')[2] put_after = stat.put.rows dump_after == 0 or dump_after put_before - dump_before == put_after or {dump_before, dump_after, put_before, put_after} +-- Disable dump and use all memory up to the limit. +box.error.injection.set('ERRINJ_VY_RUN_WRITE', false) +box.cfg{vinyl_timeout=0.001} +pad_size = 1000 +pad = string.rep('x', pad_size) +for i = 1, box.cfg.vinyl_memory / pad_size do box.space.test:replace{i, pad} end +box.info.vinyl().memory.used > 1024 * 1024 test_run:cmd('switch default') test_run:cmd('stop server test') + +-- Check that tarantool can recover with a smaller memory limit. +_ = test_run:cmd(string.format('create server test2 with script = "vinyl/low_quota_1.lua", workdir = "%s"', fio.pathjoin(fio.cwd(), 'low_quota_2'))) +_ = test_run:cmd('start server test2') +_ = test_run:cmd('switch test2') +fiber = require 'fiber' +-- All memory above the limit must be dumped after recovery. +while box.space.test.index.pk:info().disk.dump.count == 0 do fiber.sleep(0.001) end +stat = box.info.vinyl() +stat.memory.used <= stat.memory.limit or {stat.memory.used, stat.memory.limit} +_ = test_run:cmd('switch default') +test_run:cmd('stop server test2') + test_run:cmd('cleanup server test') +test_run:cmd('cleanup server test2') diff --git a/test/vinyl/suite.ini b/test/vinyl/suite.ini index 3466a57c4ff638c81dd2e09fa687512552195e8b..e6ba9e41c5bdef2720769d0782092eb07861c44a 100644 --- a/test/vinyl/suite.ini +++ b/test/vinyl/suite.ini @@ -2,7 +2,7 @@ core = tarantool description = vinyl integration tests script = vinyl.lua -release_disabled = errinj.test.lua errinj_gc.test.lua errinj_vylog.test.lua partial_dump.test.lua quota_timeout.test.lua +release_disabled = errinj.test.lua errinj_gc.test.lua errinj_vylog.test.lua partial_dump.test.lua quota_timeout.test.lua recovery_quota.test.lua config = suite.cfg lua_libs = suite.lua stress.lua large.lua txn_proxy.lua ../box/lua/utils.lua use_unix_sockets = True