1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
|
env = require('test_run')
test_run = env.new()
engine = test_run:get_cfg('engine')
fiber = require('fiber')
orig_synchro_quorum = box.cfg.replication_synchro_quorum
orig_synchro_timeout = box.cfg.replication_synchro_timeout
NUM_INSTANCES = 2
BROKEN_QUORUM = NUM_INSTANCES + 1
test_run:cmd("setopt delimiter ';'")
disable_sync_mode = function()
local s = box.space._space:get(box.space.sync.id)
local new_s = s:update({{'=', 6, {is_sync=false}}})
box.space._space:replace(new_s)
end;
test_run:cmd("setopt delimiter ''");
box.schema.user.grant('guest', 'replication')
-- Setup an async cluster with two instances.
test_run:cmd('create server replica with rpl_master=default,\
script="replication/replica.lua"')
test_run:cmd('start server replica with wait=True, wait_load=True')
-- Successful write.
-- Testcase setup.
test_run:switch('default')
box.cfg{replication_synchro_quorum=NUM_INSTANCES, replication_synchro_timeout=0.1}
_ = box.schema.space.create('sync', {is_sync=true, engine=engine})
_ = box.space.sync:create_index('pk')
-- Testcase body.
box.space.sync:insert{1} -- success
test_run:cmd('switch replica')
box.space.sync:select{} -- 1
-- Testcase cleanup.
test_run:switch('default')
box.space.sync:drop()
-- Unsuccessfull write.
-- Testcase setup.
test_run:switch('default')
box.cfg{replication_synchro_quorum=BROKEN_QUORUM, replication_synchro_timeout=0.1}
_ = box.schema.space.create('sync', {is_sync=true, engine=engine})
_ = box.space.sync:create_index('pk')
-- Testcase body.
box.space.sync:insert{1}
test_run:switch('replica')
box.space.sync:select{} -- none
-- Testcase cleanup.
test_run:switch('default')
box.space.sync:drop()
-- [RFC, quorum commit] attempt to write multiple transactions, expected the
-- same order as on client in case of achieved quorum.
-- Testcase setup.
test_run:switch('default')
box.cfg{replication_synchro_quorum=NUM_INSTANCES, replication_synchro_timeout=0.1}
_ = box.schema.space.create('sync', {is_sync=true, engine=engine})
_ = box.space.sync:create_index('pk')
-- Testcase body.
box.space.sync:insert{1}
box.space.sync:insert{2}
box.space.sync:insert{3}
box.space.sync:select{} -- 1, 2, 3
test_run:switch('replica')
box.space.sync:select{} -- 1, 2, 3
-- Testcase cleanup.
test_run:switch('default')
box.space.sync:drop()
-- Synchro timeout is not bigger than replication_synchro_timeout value.
-- Testcase setup.
test_run:switch('default')
box.cfg{replication_synchro_quorum=BROKEN_QUORUM, replication_synchro_timeout=orig_synchro_timeout}
_ = box.schema.space.create('sync', {is_sync=true, engine=engine})
_ = box.space.sync:create_index('pk')
-- Testcase body.
start = os.time()
box.space.sync:insert{1}
(os.time() - start) == box.cfg.replication_synchro_timeout -- true
-- Testcase cleanup.
test_run:switch('default')
box.space.sync:drop()
-- replication_synchro_quorum
test_run:switch('default')
INT_MIN = -2147483648
INT_MAX = 2147483648
box.cfg{replication_synchro_quorum=INT_MAX} -- error
box.cfg.replication_synchro_quorum -- old value
box.cfg{replication_synchro_quorum=INT_MIN} -- error
box.cfg.replication_synchro_quorum -- old value
-- replication_synchro_timeout
test_run:switch('default')
DOUBLE_MAX = 9007199254740992
box.cfg{replication_synchro_timeout=DOUBLE_MAX}
box.cfg.replication_synchro_timeout -- DOUBLE_MAX
box.cfg{replication_synchro_timeout=DOUBLE_MAX+1}
box.cfg.replication_synchro_timeout -- DOUBLE_MAX
box.cfg{replication_synchro_timeout=-1} -- error
box.cfg.replication_synchro_timeout -- old value
box.cfg{replication_synchro_timeout=0} -- error
box.cfg.replication_synchro_timeout -- old value
-- TX is in synchronous replication.
-- Testcase setup.
test_run:switch('default')
box.cfg{replication_synchro_quorum=NUM_INSTANCES, replication_synchro_timeout=0.1}
_ = box.schema.space.create('sync', {is_sync=true, engine=engine})
_ = box.space.sync:create_index('pk')
-- Testcase body.
box.begin() box.space.sync:insert({1}) box.commit()
box.begin() box.space.sync:insert({2}) box.commit()
-- Testcase cleanup.
box.space.sync:drop()
-- [RFC, summary] switch sync replicas into async ones, expected success and
-- data consistency on a leader and replicas.
-- Testcase setup.
test_run:switch('default')
box.cfg{replication_synchro_quorum=NUM_INSTANCES, replication_synchro_timeout=0.1}
_ = box.schema.space.create('sync', {is_sync=true, engine=engine})
_ = box.space.sync:create_index('pk')
-- Testcase body.
box.space.sync:insert{1}
box.space.sync:select{} -- 1
test_run:switch('replica')
box.space.sync:select{} -- 1
test_run:switch('default')
-- Disable synchronous mode.
disable_sync_mode()
-- Space is in async mode now.
box.cfg{replication_synchro_quorum=NUM_INSTANCES}
box.space.sync:insert{2} -- success
box.space.sync:insert{3} -- success
box.cfg{replication_synchro_quorum=BROKEN_QUORUM}
box.space.sync:insert{4} -- success
box.cfg{replication_synchro_quorum=NUM_INSTANCES}
box.space.sync:insert{5} -- success
box.space.sync:select{} -- 1, 2, 3, 4, 5
test_run:cmd('switch replica')
box.space.sync:select{} -- 1, 2, 3, 4, 5
-- Testcase cleanup.
test_run:switch('default')
box.space.sync:drop()
-- Warn user when setting `replication_synchro_quorum` to a value
-- greater than number of instances in a cluster, see gh-5122.
box.cfg{replication_synchro_quorum=BROKEN_QUORUM} -- warning
-- [RFC, summary] switch from leader to replica and vice versa, expected
-- success and data consistency on a leader and replicas (gh-5124).
-- Testcase setup.
test_run:switch('default')
box.cfg{replication_synchro_quorum=NUM_INSTANCES, replication_synchro_timeout=0.1}
_ = box.schema.space.create('sync', {is_sync=true, engine=engine})
_ = box.space.sync:create_index('pk')
-- Testcase body.
box.space.sync:insert{1}
box.space.sync:select{} -- 1
test_run:switch('replica')
box.space.sync:select{} -- 1
box.cfg{read_only=false} -- promote replica to master
test_run:switch('default')
box.cfg{read_only=true} -- demote master to replica
test_run:switch('replica')
box.space.sync:insert{2}
box.space.sync:select{} -- 1, 2
test_run:switch('default')
box.space.sync:select{} -- 1, 2
-- Revert cluster configuration.
test_run:switch('default')
box.cfg{read_only=false}
test_run:switch('replica')
box.cfg{read_only=true}
-- Testcase cleanup.
test_run:switch('default')
box.space.sync:drop()
-- Check behaviour with failed write to WAL on master (ERRINJ_WAL_IO).
-- Testcase setup.
test_run:switch('default')
box.cfg{replication_synchro_quorum=NUM_INSTANCES, replication_synchro_timeout=0.1}
_ = box.schema.space.create('sync', {is_sync=true, engine=engine})
_ = box.space.sync:create_index('pk')
-- Testcase body.
box.space.sync:insert{1}
box.space.sync:select{} -- 1
box.error.injection.set('ERRINJ_WAL_IO', true)
box.space.sync:insert{2}
box.error.injection.set('ERRINJ_WAL_IO', false)
box.space.sync:select{} -- 1
test_run:switch('replica')
box.space.sync:select{} -- 1
-- Testcase cleanup.
test_run:switch('default')
box.space.sync:drop()
-- [RFC, quorum commit] check behaviour with failure answer from a replica
-- (ERRINJ_WAL_SYNC) during write, expected disconnect from the replication
-- (gh-5123, set replication_synchro_quorum to 1).
-- Testcase setup.
test_run:switch('default')
box.cfg{replication_synchro_quorum=2, replication_synchro_timeout=0.1}
_ = box.schema.space.create('sync', {is_sync=true, engine=engine})
_ = box.space.sync:create_index('pk')
-- Testcase body.
box.space.sync:insert{1}
box.space.sync:select{} -- 1
test_run:switch('replica')
box.error.injection.set('ERRINJ_WAL_IO', true)
test_run:switch('default')
box.space.sync:insert{2}
test_run:switch('replica')
box.error.injection.set('ERRINJ_WAL_IO', false)
box.space.sync:select{} -- 1
-- Testcase cleanup.
test_run:switch('default')
box.space.sync:drop()
-- Teardown.
test_run:cmd('switch default')
test_run:cmd('stop server replica')
test_run:cmd('delete server replica')
test_run:cleanup_cluster()
box.schema.user.revoke('guest', 'replication')
box.cfg{ \
replication_synchro_quorum = orig_synchro_quorum, \
replication_synchro_timeout = orig_synchro_timeout, \
}
-- Setup an async cluster.
box.schema.user.grant('guest', 'replication')
test_run:cmd('create server replica with rpl_master=default,\
script="replication/replica.lua"')
test_run:cmd('start server replica with wait=True, wait_load=True')
-- [RFC, summary] switch async replica into sync one, expected
-- success and data consistency on a leader and replica.
-- Testcase setup.
_ = box.schema.space.create('sync', {engine=engine})
_ = box.space.sync:create_index('pk')
box.space.sync:insert{1} -- success
test_run:cmd('switch replica')
box.space.sync:select{} -- 1
test_run:switch('default')
-- Enable synchronous mode.
disable_sync_mode()
-- Space is in sync mode now.
box.cfg{replication_synchro_quorum=NUM_INSTANCES, replication_synchro_timeout=0.1}
box.space.sync:insert{2} -- success
box.cfg{replication_synchro_quorum=BROKEN_QUORUM, replication_synchro_timeout=0.1}
box.space.sync:insert{3} -- success
box.space.sync:select{} -- 1, 2, 3
test_run:cmd('switch replica')
box.space.sync:select{} -- 1, 2, 3
-- Testcase cleanup.
test_run:switch('default')
box.space.sync:drop()
-- Teardown.
test_run:cmd('switch default')
test_run:cmd('stop server replica')
test_run:cmd('delete server replica')
test_run:cleanup_cluster()
box.schema.user.revoke('guest', 'replication')
box.cfg{ \
replication_synchro_quorum = orig_synchro_quorum, \
replication_synchro_timeout = orig_synchro_timeout, \
}
|