File: transaction.test.lua

package info (click to toggle)
tarantool 2.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 85,364 kB
  • sloc: ansic: 513,760; cpp: 69,489; sh: 25,650; python: 19,190; perl: 14,973; makefile: 4,173; yacc: 1,329; sql: 1,074; pascal: 620; ruby: 190; awk: 18; lisp: 7
file content (91 lines) | stat: -rw-r--r-- 2,800 bytes parent folder | download | duplicates (3)
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
env = require('test_run')
test_run = env.new()
box.schema.user.grant('guest', 'replication')
engine = test_run:get_cfg('engine')

s = box.schema.space.create('test', {engine = engine})
_ = s:create_index('pk')
l = box.schema.space.create('l_space', {engine = engine, is_local = true})
_ = l:create_index('pk')

-- transaction w/o conflict
box.begin() s:insert({1, 'm'}) s:insert({2, 'm'}) box.commit()

test_run:cmd("create server replica with rpl_master=default, script='replication/replica.lua'")
test_run:cmd("start server replica")
test_run:cmd("switch replica")

-- insert a conflicting row
box.space.test:replace({4, 'r'})
v1 = box.info.vclock

test_run:cmd("switch default")
-- create a two-row transaction with conflicting second
box.begin() s:insert({3, 'm'}) s:insert({4, 'm'}) box.commit()
-- create a third transaction
box.begin() s:insert({5, 'm'}) s:insert({6, 'm'}) s:insert({7, 'm'}) box.commit()

test_run:cmd("switch replica")
-- nothing was applied
v1[1] == box.info.vclock[1]
box.space.test:select()
-- check replication status
box.info.replication[1].upstream.status
box.info.replication[1].upstream.message
-- set conflict to third transaction
_ = box.space.test:delete({4})
box.space.test:replace({6, 'r'})
-- restart replication
replication = box.cfg.replication
box.cfg{replication = {}}
box.cfg{replication = replication}
-- replication stopped of third transaction
-- flush wal
box.space.l_space:replace({1})
v1[1] + 2 == box.info.vclock[1]
box.space.test:select()
-- check replication status
box.info.replication[1].upstream.status
box.info.replication[1].upstream.message

-- check restart does not help
test_run:cmd("switch default")
test_run:cmd("restart server replica")
test_run:cmd("switch replica")

box.space.test:select()
-- set skip conflict rows and check that non-conflicting were applied
replication = box.cfg.replication
box.cfg{replication = {}, replication_skip_conflict = true}
box.cfg{replication = replication}

-- check last transaction applied without conflicting row
box.space.test:select()
box.info.replication[1].upstream.status

-- make some new conflicting rows with skip-conflicts
box.space.test:replace({8, 'r'})
box.space.test:replace({9, 'r'})

-- issue a conflicting tx
test_run:cmd("switch default")
box.begin() s:insert({8, 'm'}) s:insert({9, 'm'}) box.commit()

test_run:cmd("switch replica")
-- vclock should be increased but rows skipped
box.space.test:select()

-- check restart does not change something
test_run:cmd("switch default")
test_run:cmd("restart server replica")
test_run:cmd("switch replica")

box.space.test:select()
box.info.replication[1].upstream.status

test_run:cmd("switch default")
test_run:cmd("stop server replica")
test_run:cmd("cleanup server replica")

box.schema.user.revoke('guest', 'replication')
s:drop()