forked from orioledb/orioledb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoast_index_test.py
170 lines (146 loc) · 4.34 KB
/
toast_index_test.py
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
#!/usr/bin/env python3
# coding: utf-8
from .base_test import BaseTest
from .base_test import ThreadQueryExecutor
from .base_test import generate_string as gen_str
from .base_test import wait_checkpointer_stopevent
class ToastIndexTest(BaseTest):
def init_table(self, stopEvents):
node = self.node
if stopEvents:
node.append_conf('postgresql.conf',
"orioledb.enable_stopevents = true\n")
node.start()
node.safe_psql('postgres',
"CREATE EXTENSION IF NOT EXISTS orioledb;\n"
"CREATE TABLE IF NOT EXISTS o_toast_index (\n"
" id integer PRIMARY KEY,\n"
" v1 text,\n"
" v2 text,\n"
" v3 text\n"
") USING orioledb;\n"
"CREATE INDEX o_toast_index_v1_idx ON o_toast_index(v1);\n"
"CREATE INDEX o_toast_index_v2_idx ON o_toast_index(v2);\n"
"CREATE INDEX o_toast_index_v3_idx ON o_toast_index(v3);\n")
for i in range(0, 10):
baseIndex = i * 3 + 1
node.safe_psql("INSERT INTO o_toast_index VALUES (%d, '%s', '%s', '%s')" %
(i + 1,
gen_str(2500, baseIndex),
gen_str(2500, baseIndex + 1),
gen_str(2500, baseIndex + 2)))
def do_update(self, con, j):
for i in range(0, 10):
baseIndex = j * 30 + i * 3 + 1
con.execute("UPDATE o_toast_index SET v1 = '%s', v2 = '%s', v3 = '%s' WHERE id = %d" %
(gen_str(2500, baseIndex),
gen_str(2500, baseIndex + 1),
gen_str(2500, baseIndex + 2),
i + 1))
def check_result(self, j):
node = self.node
con = node.connect()
baseRs = con.execute("SELECT * FROM o_toast_index;")
self.assertEqual(len(baseRs), 10)
for row in baseRs:
baseIndex = j * 30 + (row[0] - 1) * 3 + 1
self.assertEqual(row[1], gen_str(2500, baseIndex))
self.assertEqual(row[2], gen_str(2500, baseIndex + 1))
self.assertEqual(row[3], gen_str(2500, baseIndex + 2))
v1Rs = con.execute("SELECT id, v1 FROM o_toast_index ORDER BY v1;")
self.assertEqual(len(v1Rs), 10)
for row in v1Rs:
self.assertEqual(row[1], gen_str(2500, j * 30 + (row[0] - 1) * 3 + 1))
v2Rs = con.execute("SELECT id, v2 FROM o_toast_index ORDER BY v2;")
self.assertEqual(len(v2Rs), 10)
for row in v2Rs:
self.assertEqual(row[1], gen_str(2500, j * 30 + (row[0] - 1) * 3 + 2))
v3Rs = con.execute("SELECT id, v3 FROM o_toast_index ORDER BY v3;")
self.assertEqual(len(v3Rs), 10)
for row in v3Rs:
self.assertEqual(row[1], gen_str(2500, j * 30 + (row[0] - 1) * 3 + 3))
con.close()
def test_no_checkpoint(self):
self.init_table(False)
node = self.node
con = node.connect()
con.begin()
for j in range(1, 5):
self.do_update(con, j)
con.commit()
con.begin()
for j in range(5, 9):
self.do_update(con, j)
con.rollback()
con.close()
node.stop(['-m', 'immediate'])
node.start()
self.check_result(4)
node.stop()
def test_checkpoint_at_start(self):
self.init_table(False)
node = self.node
con = node.connect()
con.execute("CHECKPOINT;")
con.begin()
for j in range(1, 5):
self.do_update(con, j)
con.commit()
con.begin()
for j in range(5, 7):
self.do_update(con, j)
con.execute("CHECKPOINT;")
for j in range(7, 9):
self.do_update(con, j)
con.rollback()
con.close()
node.stop(['-m', 'immediate'])
node.start()
self.check_result(4)
node.stop()
def test_checkpoint_in_middle(self):
self.init_table(False)
node = self.node
con = node.connect()
con.begin()
for j in range(1, 5):
self.do_update(con, j)
con.commit()
con.begin()
for j in range(5, 7):
self.do_update(con, j)
con.execute("CHECKPOINT;")
for j in range(7, 9):
self.do_update(con, j)
con.rollback()
con.close()
node.stop(['-m', 'immediate'])
node.start()
self.check_result(4)
node.stop()
def test_checkpoint(self):
self.init_table(True)
node = self.node
con = node.connect()
chkpCon = node.connect()
con.begin()
for j in range(1, 4):
self.do_update(con, j)
con.execute("""
SELECT pg_stopevent_set('checkpoint_step',
'$.treeName == \"toast\" &&
$.action == \"walkUpwards\" &&
$.nextKey.value.attnum > 2');""")
t1 = ThreadQueryExecutor(chkpCon, "CHECKPOINT;")
t1.start()
wait_checkpointer_stopevent(node)
self.do_update(con, 4)
con.execute("SELECT pg_stopevent_reset('checkpoint_step')")
t1.join()
con.commit()
con.close()
chkpCon.close()
node.stop(['-m', 'immediate'])
node.start()
self.check_result(4)
node.stop()