File: consistent.test.lua

package info (click to toggle)
tarantool 1.7.2.385.g952d79e-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 21,556 kB
  • ctags: 28,405
  • sloc: ansic: 180,313; cpp: 26,044; sh: 15,513; python: 4,893; makefile: 1,412
file content (175 lines) | stat: -rw-r--r-- 4,107 bytes parent folder | download
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
--# create server replica with rpl_master=default, script='replication/replica.lua'
--# start server replica
--# set connection default
box.schema.user.grant('guest', 'replication')
-- Wait until the grant reaches the replica
--# set connection replica
while box.space['_priv']:len() < 1 do box.fiber.sleep(0.01) end
--# setopt delimiter ';'
--# set connection default, replica
do
    begin_lsn = -1
    function _set_pri_lsn(_lsn)
        begin_lsn = _lsn
    end
    function _print_lsn()
        return (box.info.lsn - begin_lsn + 1)
    end
    function _insert(_begin, _end, msg)
        local a = {}
        for i = _begin, _end do
            table.insert(a, box.space[0]:insert{i, msg..' - '..i})
        end
        return unpack(a)
    end
    function _select(_begin, _end)
        local a = {}
        while box.info.lsn < begin_lsn + _end + 2 do
            box.fiber.sleep(0.001)
        end
        for i = _begin, _end do
            table.insert(a, box.space[0]:get{i})
        end
        return unpack(a)
    end
end;
--# setopt delimiter ''
--# set connection default
--# set variable replica_port to 'replica.listen'

-- set begin lsn on master and replica.
begin_lsn = box.info.lsn
a = box.net.box.new('127.0.0.1', replica_port)
a:call('_set_pri_lsn', box.info.lsn)
a:close()

s = box.schema.space.create('tweedledum', {id = 0});
index = s:create_index('primary', {type = 'hash'})
_insert(1, 10, 'master')
_select(1, 10)
--# set connection replica
_select(1, 10)

--# set connection default
-- Master LSN:
_print_lsn()

--# set connection replica
-- Replica LSN:
_print_lsn()

-----------------------------
--  Master LSN > Replica LSN
-----------------------------
--------------------
-- Replica to Master
--------------------
old_replication_source = box.cfg.replication_source
box.cfg{replication_source=""}
--# set connection default
_insert(11, 20, 'master')
_select(11, 20)
--# set connection replica
_insert (11, 15, 'replica')
_select (11, 15)

--# set connection default
-- Master LSN:
_print_lsn()
--# set connection replica
-- Replica LSN:
_print_lsn()

-------------------
-- rollback Replica
-------------------
box.cfg{replication_source=old_replication_source}
_select(11, 20)
--# set connection default
-- Master LSN:
_print_lsn()
--# set connection replica
-- Replica LSN:
_print_lsn()

------------------------------
--  Master LSN == Replica LSN
------------------------------
--------------------
-- Replica to Master
--------------------
box.cfg{replication_source=""}
--# set connection default
_insert(21, 30, 'master')
_select(21, 30)
--# set connection replica
_insert(21, 30, 'replica')
_select(21, 30)

--# set connection default
-- Master LSN:
_print_lsn()
--# set connection replica
-- Replica LSN:
_print_lsn()

-------------------
-- rollback Replica
-------------------
box.cfg{replication_source=old_replication_source}
_select(21, 30)

--# set connection default
-- Master LSN:
_print_lsn()
--# set connection replica
-- Replica LSN:
_print_lsn()

-----------------------------
--  Master LSN < Replica LSN
-----------------------------
--------------------
-- Replica to Master
--------------------
box.cfg{replication_source=""}
--# set connection default
_insert(31, 40, 'master')
_select(31, 40)
--# set connection replica
_insert(31, 50, 'replica')
_select(31, 50)

--# set connection default
-- Master LSN:
_print_lsn()
--# set connection replica
-- Replica LSN:
_print_lsn()

-------------------
-- rollback Replica
-------------------
box.cfg{replication_source=old_replication_source}
_select(31, 50)
--# set connection default
_insert(41, 60, 'master')
--# set connection replica
_select(41, 60)

--# set connection default
-- Master LSN:
_print_lsn()
--# set connection replica
-- Replica LSN:
_print_lsn()

-- Test that a replica replies with master connection URL on update request
--# push filter '127.0.0.1:.*' to '127.0.0.1:<port>'
box.space[0]:insert{0, 'replica is RO'}
--# clear filter
--# stop server replica
--# cleanup server replica
--# set connection default
box.space[0]:drop()
box.schema.user.revoke('guest', 'replication')