Skip to content

(Obsolete) 3.0 config #3773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/book/admin/start_stop_instance.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ With a single ``tt`` call, you can:
* connect to a specific instance of an application
* stop a specific instance of an application or all its instances

.. _admin-start_stop_instance-multi-instance-layout:

Application layout
~~~~~~~~~~~~~~~~~~

Expand Down
72 changes: 72 additions & 0 deletions doc/code_snippets/test/config/config_test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
local fio = require('fio')
local server = require('luatest.server')
local t = require('luatest')
local treegen = require('test.treegen')
local justrun = require('test.justrun')
local g = t.group()

g.before_all(function()
treegen.init(g)
end)

g.after_all(function()
treegen.clean(g)
end)

g.before_each(function(cg)
cg.server = server:new {
box_cfg = {},
workdir = fio.cwd() .. '/tmp'
}
cg.server:start()
cg.server:exec(function()
box.schema.space.create('bands')
box.space.bands:format({
{ name = 'id', type = 'unsigned' },
{ name = 'band_name', type = 'string' },
{ name = 'year', type = 'unsigned' }
})
box.space.bands:create_index('primary', { parts = { 'id' } })
end)
end)

g.after_each(function(cg)
cg.server:stop()
cg.server:drop()
end)

g.test_config_option = function()
local dir = treegen.prepare_directory(g, {}, {})
local file_config = [[
log:
level: 7

memtx:
min_tuple_size: 32
memory: 100000000

groups:
group-001:
replicasets:
replicaset-001:
instances:
instance-001: {}
]]
treegen.write_script(dir, 'config.yaml', file_config)

local script = [[
print(box.cfg.memtx_min_tuple_size)
print(box.cfg.memtx_memory)
print(box.cfg.log_level)
os.exit(0)
]]
treegen.write_script(dir, 'main.lua', script)

local env = {TT_LOG_LEVEL = 0}
local opts = {nojson = true, stderr = false}
local args = {'--name', 'instance-001', '--config', 'config.yaml',
'main.lua'}
local res = justrun.tarantool(dir, env, args, opts)
t.assert_equals(res.exit_code, 0)
t.assert_equals(res.stdout, table.concat({32, 100000000, 0}, "\n"))
end
5 changes: 5 additions & 0 deletions doc/code_snippets/test/config/etcd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
config:
etcd:
prefix: /example
endpoints:
- http://localhost:2379
3 changes: 3 additions & 0 deletions doc/code_snippets/test/config/instances.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
app.instance-001:
app.instance-002:
app.instance-003:
9 changes: 9 additions & 0 deletions doc/code_snippets/test/config/iproto_global_scope.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
iproto:
listen: "3301"

groups:
group-001:
replicasets:
replicaset-001:
instances:
instance-001: {}
8 changes: 8 additions & 0 deletions doc/code_snippets/test/config/iproto_group_scope.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
groups:
group-001:
iproto:
listen: "3301"
replicasets:
replicaset-001:
instances:
instance-001: {}
8 changes: 8 additions & 0 deletions doc/code_snippets/test/config/iproto_instance_scope.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
groups:
group-001:
replicasets:
replicaset-001:
instances:
instance-001:
iproto:
listen: "3301"
8 changes: 8 additions & 0 deletions doc/code_snippets/test/config/iproto_replicaset_scope.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
groups:
group-001:
replicasets:
replicaset-001:
iproto:
listen: "3301"
instances:
instance-001: {}
3 changes: 3 additions & 0 deletions doc/code_snippets/test/config/myapp.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
local log = require('log').new("myapp")
local config = require('config')
log.info("%s from app, %s!", config:get('app.cfg.greeting'), box.info.name)
30 changes: 30 additions & 0 deletions doc/code_snippets/test/config/replicaset_automatic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
credentials:
users:
replicator:
password: 'topsecret'
roles: [replication]
client:
password: 'secret'
roles: [super]

iproto:
advertise:
peer: replicator@

replication:
failover: election

groups:
group-001:
replicasets:
replicaset-001:
instances:
instance-001:
iproto:
listen: 127.0.0.1:3301
instance-002:
iproto:
listen: 127.0.0.1:3302
instance-003:
iproto:
listen: 127.0.0.1:3303
31 changes: 31 additions & 0 deletions doc/code_snippets/test/config/replicaset_manual.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
credentials:
users:
replicator:
password: 'topsecret'
roles: [replication]
client:
password: 'secret'
roles: [super]

iproto:
advertise:
peer: replicator@

replication:
failover: manual

groups:
group-001:
replicasets:
replicaset-001:
leader: instance-001
instances:
instance-001:
iproto:
listen: 127.0.0.1:3301
instance-002:
iproto:
listen: 127.0.0.1:3302
instance-003:
iproto:
listen: 127.0.0.1:3303
13 changes: 13 additions & 0 deletions doc/code_snippets/test/config/single_instance_app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
app:
file: 'myapp.lua'
cfg:
greeting: 'Hello'

groups:
group-001:
replicasets:
replicaset-001:
instances:
instance-001:
iproto:
listen: "3301"
10 changes: 10 additions & 0 deletions doc/code_snippets/test/config/single_instance_templating.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
groups:
group-001:
replicasets:
replicaset-001:
instances:
instance-001:
snapshot:
dir: ./var/{{ instance_name }}/snapshots
wal:
dir: ./var/{{ instance_name }}/wals
144 changes: 144 additions & 0 deletions doc/code_snippets/test/justrun.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
local fun = require('fun')
local log = require('log')
local json = require('json')
local fiber = require('fiber')
local popen = require('popen')

local justrun = {}

local function collect_stderr(ph)
local f = fiber.new(function()
local fiber_name = "child's stderr collector"
fiber.name(fiber_name, {truncate = true})

local chunks = {}

while true do
local chunk, err = ph:read({stderr = true})
if chunk == nil then
log.warn(('%s: got error, exiting: %s'):format(
fiber_name, tostring(err)))
break
end
if chunk == '' then
log.info(('%s: got EOF, exiting'):format(fiber_name))
break
end
table.insert(chunks, chunk)
end

-- Glue all chunks, strip trailing newline.
return table.concat(chunks):rstrip()
end)
f:set_joinable(true)
return f
end

local function cancel_stderr_fiber(stderr_fiber)
if stderr_fiber == nil then
return
end
stderr_fiber:cancel()
end

local function join_stderr_fiber(stderr_fiber)
if stderr_fiber == nil then
return
end
return select(2, assert(stderr_fiber:join()))
end

-- Run tarantool in given directory with given environment and
-- command line arguments and catch its output.
--
-- Expects JSON lines as the output and parses it into an array
-- (it can be disabled using `nojson` option).
--
-- Options:
--
-- - nojson (boolean, default: false)
--
-- Don't attempt to decode stdout as a stream of JSON lines,
-- return as is.
--
-- - stderr (boolean, default: false)
--
-- Collect stderr and place it into the `stderr` field of the
-- return value
function justrun.tarantool(dir, env, args, opts)
assert(type(dir) == 'string')
assert(type(env) == 'table')
assert(type(args) == 'table')
local opts = opts or {}
assert(type(opts) == 'table')

-- Prevent system/user inputrc configuration file from
-- influencing testing code.
env['INPUTRC'] = '/dev/null'

local tarantool_exe = arg[-1]
-- Use popen.shell() instead of popen.new() due to lack of
-- cwd option in popen (gh-5633).
local env_str = table.concat(fun.iter(env):map(function(k, v)
return ('%s=%q'):format(k, v)
end):totable(), ' ')
local command = ('cd %s && %s %s %s'):format(dir, env_str, tarantool_exe,
table.concat(args, ' '))
log.info(('Running a command: %s'):format(command))
local mode = opts.stderr and 'rR' or 'r'
local ph = popen.shell(command, mode)

local stderr_fiber
if opts.stderr then
stderr_fiber = collect_stderr(ph)
end

-- Read everything until EOF.
local chunks = {}
while true do
local chunk, err = ph:read()
if chunk == nil then
cancel_stderr_fiber(stderr_fiber)
ph:close()
error(err)
end
if chunk == '' then -- EOF
break
end
table.insert(chunks, chunk)
end

local exit_code = ph:wait().exit_code
local stderr = join_stderr_fiber(stderr_fiber)
ph:close()

-- If an error occurs, discard the output and return only the
-- exit code. However, return stderr.
if exit_code ~= 0 then
return {
exit_code = exit_code,
stderr = stderr,
}
end

-- Glue all chunks, strip trailing newline.
local res = table.concat(chunks):rstrip()
log.info(('Command output:\n%s'):format(res))

-- Decode JSON object per line into array of tables (if
-- `nojson` option is not passed).
local decoded
if opts.nojson then
decoded = res
else
decoded = fun.iter(res:split('\n')):map(json.decode):totable()
end

return {
exit_code = exit_code,
stdout = decoded,
stderr = stderr,
}
end

return justrun
Loading