forked from thepaul/cassandra-dtest
/
upgrade_supercolumns_test.py
216 lines (175 loc) · 7.75 KB
/
upgrade_supercolumns_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
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
from dtest import Tester, debug
from ccmlib.cluster import Cluster
from ccmlib.common import get_version_from_build
from pytools import since
import random, os, time, re
# Tests upgrade between 1.2->2.0 for super columns (since that's where
# we removed then internally)
class TestSCUpgrade(Tester):
def __init__(self, *args, **kwargs):
self.ignore_log_patterns = [
# This one occurs if we do a non-rolling upgrade, the node
# it's trying to send the migration to hasn't started yet,
# and when it does, it gets replayed and everything is fine.
r'Can\'t send migration request: node.*is down',
]
Tester.__init__(self, *args, **kwargs)
@since('2.0')
def upgrade_with_index_creation_test(self):
cluster = self.cluster
# Forcing cluster version on purpose
cluster.set_install_dir(version="1.2.16")
cluster.populate(2).start()
[node1, node2] = cluster.nodelist()
cli = node1.cli()
cli.do("create keyspace test with placement_strategy = 'SimpleStrategy' and strategy_options = {replication_factor : 2} and durable_writes = true")
cli.do("use test")
cli.do("create column family sc_test with column_type = 'Super' and comparator = 'UTF8Type' and subcomparator = 'UTF8Type' and default_validation_class = 'UTF8Type' and key_validation_class = 'UTF8Type'")
for i in range(0, 2):
for j in range(0, 2):
cli.do("set sc_test['k0']['sc%d']['c%d'] = 'v'" % (i, j))
assert not cli.has_errors(), cli.errors()
cli.close()
CASSANDRA_DIR = os.environ.get('CASSANDRA_DIR')
if get_version_from_build(CASSANDRA_DIR) >= '2.1':
#Upgrade nodes to 2.0.
#See CASSANDRA-7008
self.upgrade_to_version("git:cassandra-2.0")
time.sleep(.5)
# Upgrade node 1
node1.flush()
time.sleep(.5)
node1.stop(wait_other_notice=True)
self.set_node_to_current_version(node1)
node1.start(wait_other_notice=True)
time.sleep(.5)
cli = node1.cli()
cli.do("use test")
cli.do("consistencylevel as quorum")
# Check we can still get data properly
cli.do("get sc_test['k0']")
assert_scs(cli, ['sc0', 'sc1'])
assert_columns(cli, ['c0', 'c1'])
cli.do("get sc_test['k0']['sc1']")
assert_columns(cli, ['c0', 'c1'])
cli.do("get sc_test['k0']['sc1']['c1']")
assert_columns(cli, ['c1'])
#CASSANDRA-7188
@since('2.0')
def upgrade_with_counters_test(self):
cluster = self.cluster
# Forcing cluster version on purpose
cluster.set_install_dir(version="1.2.19")
cluster.populate(3).start()
node1, node2, node3 = cluster.nodelist()
cli = node1.cli()
cli.do("create keyspace test with placement_strategy = 'SimpleStrategy' and strategy_options = {replication_factor : 2} and durable_writes = true")
cli.do("use test")
cli.do("create column family sc_test with column_type = 'Super' and default_validation_class = 'CounterColumnType' AND key_validation_class=UTF8Type AND comparator=UTF8Type")
for i in xrange(2):
for j in xrange(2):
for k in xrange(20):
cli.do("incr sc_test['Counter1']['sc%d']['c%d'] by 1" % (i, j))
assert not cli.has_errors(), cli.errors()
cli.close()
##If we are on 2.1 or any higher version,
##upgrade to 2.0.latest.
##Otherwise, we must be on a 2.0.x, so we
##should be upgrading to that version.
##This will let us test upgrading
##from 1.2.19 to each of the 2.0 minor releases.
CASSANDRA_DIR = os.environ.get('CASSANDRA_DIR')
if get_version_from_build(CASSANDRA_DIR) >= '2.1':
#Upgrade nodes to 2.0.
#See CASSANDRA-7008
self.upgrade_to_version("git:cassandra-2.0", [node1])
time.sleep(.5)
else:
node1.drain()
node1.watch_log_for("DRAINED")
node1.stop(wait_other_notice=False)
self.set_node_to_current_version(node1)
node1.start(wait_other_notice=True)
cli = node1.cli()
cli.do("use test")
for i in xrange(2):
for j in xrange(2):
for k in xrange(50):
cli.do("incr sc_test['Counter1']['sc%d']['c%d'] by 1" % (i, j))
cli2 = node2.cli()
cli2.do("use test")
for i in xrange(2):
for j in xrange(2):
for k in xrange(50):
cli2.do("incr sc_test['Counter1']['sc%d']['c%d'] by 1" % (i, j))
cli3 = node3.cli()
cli3.do("use test")
for i in xrange(2):
for j in xrange(2):
for k in xrange(50):
cli3.do("incr sc_test['Counter1']['sc%d']['c%d'] by 1" % (i, j))
if get_version_from_build(CASSANDRA_DIR) >= '2.1':
#Upgrade nodes to 2.0.
#See CASSANDRA-7008
self.upgrade_to_version("git:cassandra-2.0", [node2, node3])
time.sleep(.5)
else:
node2.drain()
node3.drain()
node2.watch_log_for("DRAINED")
node3.watch_log_for("DRAINED")
node2.stop(wait_other_notice=False)
node3.stop(wait_other_notice=False)
self.set_node_to_current_version(node2)
self.set_node_to_current_version(node3)
node2.start(wait_other_notice=True)
node3.start(wait_other_notice=True)
cli = node1.cli()
cli.do("use test")
cli.do("consistencylevel as quorum")
# Check we can still get data properly
cli.do("get sc_test['Counter1']")
assert_scs(cli, ['sc0', 'sc1'])
assert_counter_columns(cli, ['c0', 'c1'])
cli.do("get sc_test['Counter1']['sc1']")
assert_counter_columns(cli, ['c0', 'c1'])
cli.do("get sc_test['Counter1']['sc1']['c1']")
assert_counter_columns(cli, ['c1'])
assert not cli.has_errors(), cli.errors()
cli.close()
def upgrade_to_version(self, tag, nodes=None):
debug('Upgrading to ' + tag)
if nodes is None:
nodes = self.cluster.nodelist()
for node in nodes:
debug('Shutting down node: ' + node.name)
node.drain()
node.watch_log_for("DRAINED")
node.stop(wait_other_notice=False)
# Update Cassandra Directory
for node in nodes:
node.set_install_dir(version=tag)
debug("Set new cassandra dir for %s: %s" % (node.name, node.get_install_dir()))
self.cluster.set_install_dir(version=tag)
# Restart nodes on new version
for node in nodes:
debug('Starting %s on new version (%s)' % (node.name, tag))
# Setup log4j / logback again (necessary moving from 2.0 -> 2.1):
node.set_log_level("INFO")
node.start(wait_other_notice=True)
node.nodetool('upgradesstables -a')
def assert_scs(cli, names):
assert not cli.has_errors(), cli.errors()
output = cli.last_output()
for name in names:
assert re.search('super_column=%s' % name, output) is not None, 'Cannot find super column %s in %s' % (name, output)
def assert_columns(cli, names):
assert not cli.has_errors(), cli.errors()
output = cli.last_output()
for name in names:
assert re.search('name=%s' % name, output) is not None, 'Cannot find column %s in %s' % (name, output)
def assert_counter_columns(cli, names):
assert not cli.has_errors(), cli.errors()
output = cli.last_output()
for name in names:
assert re.search('counter=%s' % name, output) is not None, 'Cannot find column %s in %s' % (name, output)