forked from apache/cassandra-dtest
-
Notifications
You must be signed in to change notification settings - Fork 3
/
deletion_test.py
79 lines (56 loc) · 2.49 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
import time
import logging
from dtest import Tester, create_ks, create_cf
from tools.data import rows_to_list
from tools.jmxutils import (JolokiaAgent, make_mbean)
logger = logging.getLogger(__name__)
class TestDeletion(Tester):
def test_gc(self):
"""
Test that tombstone purging doesn't bring back deleted data by writing
2 rows to a table with gc_grace=0, deleting one of those rows, then
asserting that it isn't present in the results of SELECT *, before and
after a flush and compaction.
"""
cluster = self.cluster
cluster.populate(1).start()
[node1] = cluster.nodelist()
time.sleep(.5)
session = self.patient_cql_connection(node1)
create_ks(session, 'ks', 1)
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()
assert rows_to_list(session.execute('select * from cf;')) == [[1, 1], [2, 1]]
session.execute('delete from cf where key=1')
assert rows_to_list(session.execute('select * from cf;')) == [[2, 1]]
node1.flush()
time.sleep(.5)
node1.compact()
time.sleep(.5)
assert rows_to_list(session.execute('select * from cf;')) == [[2, 1]]
def test_tombstone_size(self):
self.cluster.populate(1)
self.cluster.start()
[node1] = self.cluster.nodelist()
session = self.patient_cql_connection(node1)
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])
assert memtable_count(node1, 'ks', 'test') == 100
assert memtable_size(node1, 'ks', 'test') > 0
def memtable_size(node, keyspace, table):
return table_metric(node, keyspace, table, 'MemtableOnHeapSize')
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 < '3.0' 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