Skip to content

Commit 429f86f

Browse files
Don't change password on restart (#1550)
Eliminate unnecessary transactions after the restart before the replication sync. This reduces the chance the hardware restart leads to WAL corruption.
1 parent 8ff3b0a commit 429f86f

File tree

4 files changed

+121
-19
lines changed

4 files changed

+121
-19
lines changed

CHANGELOG.rst

+12
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,21 @@ and this project adheres to
1212
[Unreleased]
1313
-------------------------------------------------------------------------------
1414

15+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16+
Added
17+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18+
1519
- 'Make all instances writeable' configuration field can be hidden via
1620
frontend-core's ``set_variable`` feature or at runtime.
1721

22+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23+
Fixed
24+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25+
26+
- Eliminate unnecessary transactions after the restart before the replication
27+
sync. This reduces the chance the hardware restart leads to WAL corruption
28+
([#1546](https://github.com/tarantool/cartridge/issues/1546)).
29+
1830
-------------------------------------------------------------------------------
1931
[2.7.1] - 2021-08-18
2032
-------------------------------------------------------------------------------

cartridge/confapplier.lua

+17-11
Original file line numberDiff line numberDiff line change
@@ -491,23 +491,29 @@ local function boot_instance(clusterwide_config)
491491
end
492492

493493
do
494-
log.info('Setting password for user %q ...', username)
495-
-- To be sure netbox is operable, password should always be
496-
-- equal to the cluster_cookie.
497-
-- Function `passwd` is safe to be called on multiple replicas,
498-
-- it never cause replication conflict
499-
500494
local read_only = box.cfg.read_only
501-
box.cfg({read_only = false})
502495

503496
if vars.upgrade_schema then
497+
log.info('Upgrading schema ...')
498+
box.cfg({read_only = false})
504499
cartridge_schema_upgrade(clusterwide_config)
505500
end
506501

507-
BoxError:pcall(
508-
box.schema.user.passwd,
509-
username, password
510-
)
502+
-- To be sure netbox is operable, password should always be
503+
-- equal to the cluster_cookie.
504+
-- Function `passwd` is safe to be called on multiple replicas,
505+
-- it never cause replication conflict
506+
-- But don't commit anything if it's already ok.
507+
local user = box.space[box.schema.USER_ID].index.name:get(username)
508+
-- https://github.com/tarantool/tarantool/blob/2.7.3/src/box/lua/schema.lua#L2719-L2724
509+
if user == nil or user.auth['chap-sha1'] ~= box.schema.user.password(password) then
510+
log.info('Setting password for user %q ...', username)
511+
box.cfg({read_only = false})
512+
BoxError:pcall(
513+
box.schema.user.passwd,
514+
username, password
515+
)
516+
end
511517

512518
box.cfg({read_only = read_only})
513519
end
+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
local t = require('luatest')
2+
local h = require('test.helper')
3+
local g = t.group()
4+
5+
local fio = require('fio')
6+
7+
g.before_each(function()
8+
g.cluster = h.Cluster:new({
9+
datadir = fio.tempdir(),
10+
server_command = h.entrypoint('srv_basic'),
11+
cookie = h.random_cookie(),
12+
replicasets = {
13+
{
14+
roles = {},
15+
servers = {
16+
{ alias = 'master' },
17+
{ alias = 'replica' },
18+
},
19+
},
20+
},
21+
})
22+
g.cluster:start()
23+
g.master = g.cluster:server('master')
24+
g.replica = g.cluster:server('replica')
25+
end)
26+
27+
g.after_all(function()
28+
g.cluster:stop()
29+
fio.rmtree(g.cluster.datadir)
30+
end)
31+
32+
function g.test_master_restart_with_missing_xlog()
33+
g.master.net_box:eval([[
34+
-- create space
35+
box.schema.create_space('test')
36+
box.space.test:create_index('primary')
37+
box.space.test:insert{1}
38+
39+
box.snapshot()
40+
41+
-- that transaction now stored in memory and xlog
42+
box.begin()
43+
box.space.test:insert{2}
44+
box.space.test:insert{3}
45+
box.commit()
46+
]])
47+
48+
-- check that data replicated
49+
t.helpers.retrying({}, function()
50+
local content = g.replica.net_box:eval([[
51+
return box.space.test:select()
52+
]])
53+
t.assert_equals(content, {{1}, {2}, {3}})
54+
end)
55+
56+
-- stop master and remove xlogs
57+
g.master:stop()
58+
for _, name in ipairs(fio.glob(g.master.workdir .. '/*.xlog')) do
59+
t.assert(fio.unlink(name))
60+
end
61+
g.master:start()
62+
63+
-- check that data still on replica
64+
local content = g.replica.net_box:eval([[
65+
return box.space.test:select()
66+
]])
67+
t.assert_equals(content, {{1}, {2}, {3}})
68+
69+
t.helpers.retrying({}, function()
70+
local info_replication = g.master.net_box:eval([[
71+
return box.info.replication
72+
]])
73+
t.assert_covers(info_replication[2].downstream, { status = 'follow' })
74+
t.assert_covers(info_replication[2].upstream, { status = 'follow' })
75+
76+
-- check that data restored on master
77+
local content = g.master.net_box:eval([[
78+
return box.space.test:select()
79+
]])
80+
t.assert_equals(content, {{1}, {2}, {3}})
81+
end)
82+
end

test/integration/zones_test.lua

+10-8
Original file line numberDiff line numberDiff line change
@@ -263,14 +263,16 @@ h.after_all(function()
263263
end)
264264

265265
function h.test_zones_distances()
266-
t.assert_items_equals(
267-
h.A1:graphql({query = '{servers {uuid zone}}'}).data.servers,
268-
{
269-
{uuid = h.A1.instance_uuid, zone = 'z1'},
270-
{uuid = h.A2.instance_uuid, zone = 'z2'},
271-
{uuid = h.A3.instance_uuid, zone = box.NULL},
272-
}
273-
)
266+
helpers.retrying({}, function()
267+
t.assert_items_equals(
268+
h.A1:graphql({query = '{servers {uuid zone}}'}).data.servers,
269+
{
270+
{uuid = h.A1.instance_uuid, zone = 'z1'},
271+
{uuid = h.A2.instance_uuid, zone = 'z2'},
272+
{uuid = h.A3.instance_uuid, zone = box.NULL},
273+
}
274+
)
275+
end)
274276

275277
local distances = h.cluster.main_server:call(
276278
'package.loaded.cartridge.config_get_readonly', {'zone_distances'}

0 commit comments

Comments
 (0)