forked from scylladb/scylla-cluster-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlongevity_test.py
280 lines (232 loc) · 12.9 KB
/
longevity_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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#!/usr/bin/env python
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See LICENSE for more details.
#
# Copyright (c) 2016 ScyllaDB
import os
import re
import time
import yaml
from avocado import main
from sdcm.tester import ClusterTester
class LongevityTest(ClusterTester):
"""
Test a Scylla cluster stability over a time period.
:avocado: enable
"""
def _run_all_stress_cmds(self, stress_queue, params):
stress_cmds = params['stress_cmd']
if not isinstance(stress_cmds, list):
stress_cmds = [stress_cmds]
# In some cases we want the same stress_cmd to run several times (can be used with round_robin or not).
stress_multiplier = self.params.get('stress_multiplier', default=1)
if stress_multiplier > 1:
stress_cmds *= stress_multiplier
for stress_cmd in stress_cmds:
params.update({'stress_cmd': stress_cmd})
self._parse_stress_cmd(stress_cmd, params)
# Run all stress commands
self.log.debug('stress cmd: {}'.format(stress_cmd))
stress_queue.append(self.run_stress_thread(**params))
time.sleep(2)
# Remove "user profile" param for the next command
if 'profile' in params:
del params['profile']
if 'keyspace_name' in params:
del params['keyspace_name']
return stress_queue
def _parse_stress_cmd(self, stress_cmd, params):
# Due to an issue with scylla & cassandra-stress - we need to create the counter table manually
if 'counter_' in stress_cmd:
self._create_counter_table()
# When using cassandra-stress with "user profile" the profile yaml should be provided
if 'profile' in stress_cmd:
cs_profile = re.search('profile=(.*)yaml', stress_cmd).group(1) + 'yaml'
cs_profile = os.path.join(os.path.dirname(__file__), 'data_dir', os.path.basename(cs_profile))
with open(cs_profile, 'r') as yaml_stream:
profile = yaml.safe_load(yaml_stream)
keyspace_name = profile['keyspace']
params.update({'profile': cs_profile, 'keyspace_name': keyspace_name})
if 'compression' in stress_cmd:
if 'keyspace_name' not in params:
keyspace_name = "keyspace_{}".format(re.search('compression=(.*)Compressor', stress_cmd).group(1))
params.update({'keyspace_name': keyspace_name})
return params
default_params = {'timeout': 650000}
@staticmethod
def _get_keyspace_name(ks_number, keyspace_pref='keyspace'):
return '{}{}'.format(keyspace_pref, ks_number)
def test_custom_time(self):
"""
Run cassandra-stress with params defined in data_dir/scylla.yaml
"""
self.db_cluster.add_nemesis(nemesis=self.get_nemesis_class(),
tester_obj=self)
stress_queue = list()
write_queue = list()
verify_queue = list()
# prepare write workload
prepare_write_cmd = self.params.get('prepare_write_cmd', default=None)
keyspace_num = self.params.get('keyspace_num', default=1)
pre_create_schema = self.params.get('pre_create_schema', default=False)
if prepare_write_cmd:
# In some cases (like many keyspaces), we want to create the schema (all keyspaces & tables) before the load
# starts - due to the heavy load, the schema propogation can take long time and c-s fails.
if pre_create_schema:
self._pre_create_schema(keyspace_num)
# When the load is too heavy for one lader when using MULTI-KEYSPACES, the load is spreaded evenly across
# the loaders (round_robin).
if keyspace_num > 1 and self.params.get('round_robin', default='false').lower() == 'true':
self.log.debug("Using round_robin for multiple Keyspaces...")
for i in xrange(1, keyspace_num + 1):
keyspace_name = self._get_keyspace_name(i)
self._run_all_stress_cmds(write_queue, params={'stress_cmd': prepare_write_cmd,
'keyspace_name': keyspace_name,
'round_robin': True})
# Not using round_robin and all keyspaces will run on all loaders
else:
self._run_all_stress_cmds(write_queue, params={'stress_cmd': prepare_write_cmd,
'keyspace_num': keyspace_num})
# In some cases we don't want the nemesis to run during the "prepare" stage in order to be 100% sure that
# all keys were written succesfully
if self.params.get('nemesis_during_prepare', default='true').lower() == 'true':
# Wait for some data (according to the param in the yal) to be populated, for multi keyspace need to
# pay attention to the fact it checks only on keyspace1
self.db_cluster.wait_total_space_used_per_node(keyspace=None)
self.db_cluster.start_nemesis(interval=self.params.get('nemesis_interval'))
# Wait on the queue till all threads come back.
# todo: we need to improve this part for some cases that threads are being killed and we don't catch it.
for stress in write_queue:
self.verify_stress_thread(queue=stress)
# Run nodetool flush on all nodes to make sure nothing left in memory
self._flush_all_nodes()
# In case we would like to verify all keys were written successfully before we start other stress / nemesis
prepare_verify_cmd = self.params.get('prepare_verify_cmd', default=None)
if prepare_verify_cmd:
self._run_all_stress_cmds(verify_queue, params={'stress_cmd': prepare_verify_cmd,
'keyspace_num': keyspace_num})
for stress in verify_queue:
self.verify_stress_thread(queue=stress)
stress_cmd = self.params.get('stress_cmd', default=None)
if stress_cmd:
# Stress: Same as in prepare_write - allow the load to be spread across all loaders when using multi ks
if keyspace_num > 1 and self.params.get('round_robin', default='false').lower() == 'true':
self.log.debug("Using round_robin for multiple Keyspaces...")
for i in xrange(1, keyspace_num + 1):
keyspace_name = self._get_keyspace_name(i)
params = {'keyspace_name': keyspace_name, 'round_robin': True, 'stress_cmd': stress_cmd}
self._run_all_stress_cmds(stress_queue, params)
# The old method when we run all stress_cmds for all keyspace on the same loader
else:
params = {'keyspace_num': keyspace_num, 'stress_cmd': stress_cmd}
self._run_all_stress_cmds(stress_queue, params)
# Check if we shall wait for total_used_space or if nemesis wasn't started
if not prepare_write_cmd or self.params.get('nemesis_during_prepare', default='true').lower() == 'false':
self.db_cluster.wait_total_space_used_per_node(keyspace=None)
self.db_cluster.start_nemesis(interval=self.params.get('nemesis_interval'))
stress_read_cmd = self.params.get('stress_read_cmd', default=None)
if stress_read_cmd:
params = {'keyspace_num': keyspace_num, 'stress_cmd': stress_read_cmd}
self._run_all_stress_cmds(stress_queue, params)
for stress in stress_queue:
self.verify_stress_thread(queue=stress)
def test_batch_custom_time(self):
"""
The test runs like test_custom_time but desgined for running multiple stress commands in batches.
It take the keyspace_num and calculates the number of batches to run based on batch_size.
For every batch, it runs the stress and verify them and only then moves to the next batch.
Test assumes:
- pre_create_schema (The test pre-creating the schema for all batches)
- round_robin
- No nemesis during prepare
:param keyspace_num: Number of keyspaces to be batched (in future it can be enahnced with number of tables).
:param batch_size: Number of stress commands to run together in a batch.
"""
self.db_cluster.add_nemesis(nemesis=self.get_nemesis_class(), tester_obj=self)
total_stress = self.params.get('keyspace_num') # In future it may be 1 keyspace but multiple tables in it.
batch_size = self.params.get('batch_size', default=1)
prepare_write_cmd = self.params.get('prepare_write_cmd', default=None)
if prepare_write_cmd:
self._run_stress_in_batches(total_stress=total_stress, batch_size=batch_size,
stress_cmd=prepare_write_cmd)
self.db_cluster.start_nemesis(interval=self.params.get('nemesis_interval'))
stress_cmd = self.params.get('stress_cmd', default=None)
self._run_stress_in_batches(total_stress=batch_size, batch_size=batch_size,
stress_cmd=stress_cmd)
def _run_stress_in_batches(self, total_stress, batch_size, stress_cmd):
stress_queue = list()
self._pre_create_schema(keyspace_num=total_stress)
num_of_batches = int(total_stress / batch_size)
for batch in xrange(0, num_of_batches):
for i in xrange(1 + batch * batch_size, (batch + 1) * batch_size + 1):
keyspace_name = self._get_keyspace_name(i)
self._run_all_stress_cmds(stress_queue, params={'stress_cmd': stress_cmd,
'keyspace_name': keyspace_name, 'round_robin': True})
for stress in stress_queue:
self.verify_stress_thread(queue=stress)
def _create_counter_table(self):
"""
workaround for the issue https://github.com/scylladb/scylla-tools-java/issues/32
remove when resolved
"""
node = self.db_cluster.nodes[0]
session = self.cql_connection_patient(node)
session.execute("""
CREATE KEYSPACE IF NOT EXISTS keyspace1
WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '3'} AND durable_writes = true;
""")
session.execute("""
CREATE TABLE IF NOT EXISTS keyspace1.counter1 (
key blob PRIMARY KEY,
"C0" counter,
"C1" counter,
"C2" counter,
"C3" counter,
"C4" counter
) WITH COMPACT STORAGE
AND bloom_filter_fp_chance = 0.01
AND caching = '{"keys":"ALL","rows_per_partition":"ALL"}'
AND comment = ''
AND compaction = {'class': 'SizeTieredCompactionStrategy'}
AND compression = {}
AND dclocal_read_repair_chance = 0.1
AND default_time_to_live = 0
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND read_repair_chance = 0.0
AND speculative_retry = '99.0PERCENTILE';
""")
def _pre_create_schema(self, keyspace_num=1, in_memory=False):
"""
For cases we are testing many keyspaces and tables, It's a possibility that we will do it better and faster than
cassandra-stress.
"""
node = self.db_cluster.nodes[0]
session = self.cql_connection_patient(node)
self.log.debug('Pre Creating Schema for c-s with {} keyspaces'.format(keyspace_num))
for i in xrange(1, keyspace_num+1):
keyspace_name = 'keyspace{}'.format(i)
self.create_ks(session, keyspace_name, rf=3)
self.log.debug('{} Created'.format(keyspace_name))
self.create_cf(session, 'standard1', key_type='blob', read_repair=0.0, compact_storage=True,
columns={'"C0"': 'blob', '"C1"': 'blob', '"C2"': 'blob', '"C3"': 'blob', '"C4"': 'blob'},
in_memory=in_memory)
def _flush_all_nodes(self):
"""
This function will connect all db nodes in the cluster and run "nodetool flush" command.
:return:
"""
for node in self.db_cluster.nodes:
node.remoter.run('sudo nodetool flush')
if __name__ == '__main__':
main()