forked from thepaul/cassandra-dtest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeletion_test.py
79 lines (56 loc) · 2.66 KB
/
deletion_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
from dtest import Tester
import time
from jmxutils import make_mbean, JolokiaAgent, remove_perf_disable_shared_mem
class TestDeletion(Tester):
def gc_test(self):
""" Test that tombstone are fully purge after gc_grace """
cluster = self.cluster
cluster.populate(1).start()
[node1] = cluster.nodelist()
time.sleep(.5)
session = self.patient_cql_connection(node1)
self.create_ks(session, 'ks', 1)
self.create_cf(session, 'cf', gc_grace=0, key_type='int', columns={'c1': 'int'})
session.execute('insert into cf (key, c1) values (1,1)')
session.execute('insert into cf (key, c1) values (2,1)')
node1.flush()
result = session.execute('select * from cf;')
assert len(result) == 2 and len(result[0]) == 2 and len(result[1]) == 2, result
session.execute('delete from cf where key=1')
result = session.execute('select * from cf;')
if cluster.version() < '1.2': # > 1.2 doesn't show tombstones
assert len(result) == 2 and len(result[0]) == 1 and len(result[1]) == 1, result
node1.flush()
time.sleep(.5)
node1.compact()
time.sleep(.5)
result = session.execute('select * from cf;')
assert len(result) == 1 and len(result[0]) == 2, result
def tombstone_size_test(self):
self.cluster.populate(1)
node1 = self.cluster.nodelist()[0]
remove_perf_disable_shared_mem(node1)
self.cluster.start(wait_for_binary_proto=True)
[node1] = self.cluster.nodelist()
session = self.patient_cql_connection(node1)
self.create_ks(session, 'ks', 1)
session.execute('CREATE TABLE test (i int PRIMARY KEY)')
stmt = session.prepare('DELETE FROM test where i = ?')
for i in range(100):
session.execute(stmt, [i])
self.assertEqual(memtable_count(node1, 'ks', 'test'), 100)
self.assertGreater(memtable_size(node1, 'ks', 'test'), 0)
def memtable_size(node, keyspace, table):
version = node.get_cassandra_version()
name = 'MemtableOnHeapSize' if version >= '2.1' else 'MemtableDataSize'
return table_metric(node, keyspace, table, name)
def memtable_count(node, keyspace, table):
return table_metric(node, keyspace, table, 'MemtableColumnsCount')
def table_metric(node, keyspace, table, name):
version = node.get_cassandra_version()
typeName = "ColumnFamily" if version <= '2.2.X' else 'Table'
with JolokiaAgent(node) as jmx:
mbean = make_mbean('metrics', type=typeName,
name=name, keyspace=keyspace, scope=table)
value = jmx.read_attribute(mbean, 'Value')
return value