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
|
env = require('test_run')
test_run = env.new()
engine = test_run:get_cfg('engine')
index = test_run:get_cfg('index')
box.schema.user.grant('guest', 'replication')
space = box.schema.space.create('test', { id = 99999, engine = engine })
_ = space:create_index('primary', { type = index})
_ = space:create_index('secondary', { type = index, unique = false, parts = {2, 'unsigned'}})
space2 = box.schema.space.create('test2', { id = 99998, engine = engine})
_ = space2:create_index('primary', { parts = {1, 'unsigned', 2, 'string'}})
space3 = box.schema.space.create('test3', { id = 99997, engine = engine})
_ = space3:create_index('primary', { parts = {{1, 'string', collation = 'unicode_ci'}}})
box.snapshot()
-- replica join
test_run:cmd("create server replica with rpl_master=default, script='replication/replica.lua'")
test_run:cmd("start server replica")
test_run:wait_lsn('replica', 'default')
test_run:cmd('switch replica')
box.space.test:select()
box.space.test.index.secondary:select()
box.space.test2:select()
box.space.test3:select()
test_run:cmd('switch default')
test_run:cmd("stop server replica")
_ = test_run:cmd("cleanup server replica")
-- new data
for k = 1, 8 do box.space.test:insert{k, 17 - k} end
for k = 16, 9, -1 do box.space.test:insert{k, 17 - k} end
_ = box.space.test2:insert{1, 'test1', 1}
_ = box.space.test2:upsert({1, 'test1', 10}, {{'=', 3, 10}})
_ = box.space.test2:upsert({2, 'test2', 20}, {{'=', 3, 20}})
_ = box.space.test2:insert{3, 'test3', 30}
_ = box.space.test3:insert{'Ёж'}
_ = box.space.test3:insert{'ель'}
_ = box.space.test3:insert{'Юла'}
_ = box.space.test3:insert{'Эль'}
_ = box.space.test3:insert{'ёлка'}
_ = box.space.test3:insert{'йогурт'}
-- replica join
test_run:cmd("deploy server replica")
test_run:cmd("start server replica")
test_run:wait_lsn('replica', 'default')
test_run:cmd('switch replica')
box.space.test:select()
box.space.test.index.secondary:select()
box.space.test2:select()
box.space.test3:select()
test_run:cmd('switch default')
test_run:cmd("stop server replica")
_ = test_run:cmd("cleanup server replica")
-- add snapshot
box.snapshot()
-- replica join
test_run:cmd("deploy server replica")
test_run:cmd("start server replica")
test_run:wait_lsn('replica', 'default')
test_run:cmd('switch replica')
box.space.test:select()
box.space.test.index.secondary:select()
box.space.test2:select()
box.space.test3:select()
test_run:cmd('switch default')
test_run:cmd("stop server replica")
_ = test_run:cmd("cleanup server replica")
-- new data
for k = 8, 1, -1 do box.space.test:update(k, {{'-', 2, 8}}) end
for k = 9, 16 do box.space.test:delete(k) end
box.space.test.index.primary:alter{parts = {1, 'integer'}}
for k = -8, -1 do box.space.test:insert{k, 9 + k} end
_ = box.space.test2:upsert({1, 'test1', 11}, {{'+', 3, 1}})
_ = box.space.test2:update({2, 'test2'}, {{'+', 3, 2}})
_ = box.space.test2:delete{3, 'test3'}
_ = box.space.test3:upsert({'ёж', 123}, {{'!', 2, 123}})
_ = box.space.test3:update('ЭЛЬ', {{'!', 2, 456}})
_ = box.space.test3:delete('ёлка')
box.snapshot()
-- replica join
test_run:cmd("deploy server replica")
test_run:cmd("start server replica")
test_run:wait_lsn('replica', 'default')
test_run:cmd('switch replica')
box.space.test:select()
box.space.test.index.secondary:select()
box.space.test2:select()
box.space.test3:select()
test_run:cmd('switch default')
test_run:cmd("stop server replica")
_ = test_run:cmd("cleanup server replica")
-- recreate space
space:drop()
space = box.schema.space.create('test', { id = 12345, engine = engine })
_ = space:create_index('primary', { type = index})
_ = space:insert{12345}
-- truncate space
space3:truncate()
-- replica join
test_run:cmd("deploy server replica")
test_run:cmd("start server replica")
test_run:wait_lsn('replica', 'default')
test_run:cmd('switch replica')
box.space.test.id
box.space.test:select()
box.space.test2:select()
box.space.test3:select()
test_run:cmd('switch default')
test_run:cmd("stop server replica")
_ = test_run:cmd("cleanup server replica")
space:drop()
space2:drop()
space3:drop()
box.snapshot()
space = box.schema.space.create('test', { id = 99998, engine = engine })
index = space:create_index('primary', { type = test_run:get_cfg('index')})
for i = 0, 9 do space:insert({i, 'test' .. tostring(i)}) end
test_run:cmd("deploy server replica")
test_run:cmd("start server replica")
test_run:wait_lsn('replica', 'default')
test_run:cmd('restart server replica')
test_run:cmd('switch replica')
box.space.test:select()
test_run:cmd('switch default')
test_run:cmd("stop server replica")
_ = test_run:cmd("cleanup server replica")
space:drop()
box.snapshot()
box.schema.user.revoke('guest', 'replication')
|