You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by aw...@apache.org on 2017/11/15 21:46:39 UTC
[11/50] cassandra git commit: Added test to verify indexes are not
rebuilt at startup if not actually needed.
Added test to verify indexes are not rebuilt at startup if not actually needed.
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/b724df80
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/b724df80
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/b724df80
Branch: refs/heads/master
Commit: b724df80d3bbb55b6b41845633e3a9034116f3be
Parents: 894bc92
Author: Sergio Bossa <se...@gmail.com>
Authored: Mon Jul 24 14:08:32 2017 +0100
Committer: Sergio Bossa <se...@gmail.com>
Committed: Tue Jul 25 18:47:50 2017 +0100
----------------------------------------------------------------------
secondary_indexes_test.py | 69 ++++++++++++------------------------------
tools/data.py | 18 ++++++++++-
2 files changed, 37 insertions(+), 50 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/b724df80/secondary_indexes_test.py
----------------------------------------------------------------------
diff --git a/secondary_indexes_test.py b/secondary_indexes_test.py
index 1edd30e..11cd3af 100644
--- a/secondary_indexes_test.py
+++ b/secondary_indexes_test.py
@@ -14,11 +14,10 @@ from cassandra.query import BatchStatement, SimpleStatement
from dtest import (DISABLE_VNODES, OFFHEAP_MEMTABLES, DtestTimeoutError,
Tester, debug, CASSANDRA_VERSION_FROM_BUILD, create_ks, create_cf)
from tools.assertions import assert_bootstrap_state, assert_invalid, assert_none, assert_one, assert_row_count
-from tools.data import index_is_built, rows_to_list
+from tools.data import block_until_index_is_built, index_is_built, rows_to_list
from tools.decorators import since
from tools.misc import new_node
-
class TestSecondaryIndexes(Tester):
@staticmethod
@@ -306,28 +305,14 @@ class TestSecondaryIndexes(Tester):
lookup_value = session.execute('select "C0" from standard1 limit 1')[0].C0
session.execute('CREATE INDEX ix_c0 ON standard1("C0");')
- start = time.time()
- while time.time() < start + 30:
- debug("waiting for index to build")
- time.sleep(1)
- if index_is_built(node1, session, 'keyspace1', 'standard1', 'ix_c0'):
- break
- else:
- raise DtestTimeoutError()
+ block_until_index_is_built(node1, session, 'keyspace1', 'standard1', 'ix_c0')
stmt = session.prepare('select * from standard1 where "C0" = ?')
self.assertEqual(1, len(list(session.execute(stmt, [lookup_value]))))
before_files = self._index_sstables_files(node1, 'keyspace1', 'standard1', 'ix_c0')
node1.nodetool("rebuild_index keyspace1 standard1 ix_c0")
- start = time.time()
- while time.time() < start + 30:
- debug("waiting for index to rebuild")
- time.sleep(1)
- if index_is_built(node1, session, 'keyspace1', 'standard1', 'ix_c0'):
- break
- else:
- raise DtestTimeoutError()
+ block_until_index_is_built(node1, session, 'keyspace1', 'standard1', 'ix_c0')
after_files = self._index_sstables_files(node1, 'keyspace1', 'standard1', 'ix_c0')
self.assertNotEqual(before_files, after_files)
@@ -447,39 +432,39 @@ class TestSecondaryIndexes(Tester):
'Cannot execute this query as it might involve data filtering')
@since('4.0')
- def test_index_is_not_always_rebuilt_at_start(self):
+ def test_index_is_not_rebuilt_at_restart(self):
"""
- @jira_ticket CASSANDRA-10130
+ @jira_ticket CASSANDRA-13725
- Tests the management of index status during manual index rebuilding failures.
+ Tests the index is not rebuilt at restart if already built.
"""
cluster = self.cluster
- cluster.populate(1, install_byteman=True).start(wait_for_binary_proto=True)
+ cluster.populate(1).start(wait_for_binary_proto=True)
node = cluster.nodelist()[0]
session = self.patient_cql_connection(node)
create_ks(session, 'k', 1)
session.execute("CREATE TABLE k.t (k int PRIMARY KEY, v int)")
- session.execute("CREATE INDEX idx ON k.t(v)")
session.execute("INSERT INTO k.t(k, v) VALUES (0, 1)")
- session.execute("INSERT INTO k.t(k, v) VALUES (2, 3)")
- # Verify that the index is marked as built and it can answer queries
+ debug("Create the index")
+ session.execute("CREATE INDEX idx ON k.t(v)")
+ block_until_index_is_built(node, session, 'k', 't', 'idx')
+ before_files = self._index_sstables_files(node, 'k', 't', 'idx')
+
+ debug("Verify the index is marked as built and it can be queried")
assert_one(session, """SELECT * FROM system."IndexInfo" WHERE table_name='k'""", ['k', 'idx'])
assert_one(session, "SELECT * FROM k.t WHERE v = 1", [0, 1])
- # Restart the node to trigger any eventual undesired index rebuild
- before_files = self._index_sstables_files(node, 'k', 't', 'idx')
- node.nodetool('drain')
+ debug("Restart the node and verify the index build is not submitted")
node.stop()
- cluster.start()
- session = self.patient_cql_connection(node)
- session.execute("USE k")
+ node.start(wait_for_binary_proto=True)
after_files = self._index_sstables_files(node, 'k', 't', 'idx')
+ self.assertEqual(before_files, after_files)
- # Verify that, the index is not rebuilt, marked as built, and it can answer queries
- self.assertNotEqual(before_files, after_files)
+ debug("Verify the index is still marked as built and it can be queried")
+ session = self.patient_cql_connection(node)
assert_one(session, """SELECT * FROM system."IndexInfo" WHERE table_name='k'""", ['k', 'idx'])
assert_one(session, "SELECT * FROM k.t WHERE v = 1", [0, 1])
@@ -610,14 +595,7 @@ class TestSecondaryIndexes(Tester):
session.execute("CREATE INDEX composites_index on ks.regular_table (b)")
for node in cluster.nodelist():
- start = time.time()
- while time.time() < start + 10:
- debug("waiting for index to build")
- time.sleep(1)
- if index_is_built(node, session, 'ks', 'regular_table', 'composites_index'):
- break
- else:
- raise DtestTimeoutError()
+ block_until_index_is_built(node, session, 'ks', 'regular_table', 'composites_index')
insert_args = [(i, i % 2) for i in xrange(100)]
execute_concurrent_with_args(session,
@@ -1067,14 +1045,7 @@ class TestSecondaryIndexesOnCollections(Tester):
stmt = "CREATE INDEX user_uuids_values on map_index_search.users (uuids);"
session.execute(stmt)
- start = time.time()
- while time.time() < start + 30:
- debug("waiting for index to build")
- time.sleep(1)
- if index_is_built(node1, session, 'map_index_search', 'users', 'user_uuids_values'):
- break
- else:
- raise DtestTimeoutError()
+ block_until_index_is_built(node1, session, 'map_index_search', 'users', 'user_uuids_values')
# shuffle the log in-place, and double-check a slice of records by querying the secondary index
random.shuffle(log)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/b724df80/tools/data.py
----------------------------------------------------------------------
diff --git a/tools/data.py b/tools/data.py
index e1a3cfc..597a10c 100644
--- a/tools/data.py
+++ b/tools/data.py
@@ -6,7 +6,8 @@ from cassandra.query import SimpleStatement
from nose.tools import assert_equal, assert_true
import assertions
-from dtest import create_cf
+from dtest import debug, create_cf, DtestTimeoutError
+from tools.funcutils import get_rate_limited_function
def create_c1c2_table(tester, session, read_repair=None):
@@ -149,3 +150,18 @@ def index_is_built(node, session, keyspace, table_name, idx_name):
full_idx_name = idx_name if node.get_cassandra_version() > '3.0' else '{}.{}'.format(table_name, idx_name)
index_query = """SELECT * FROM system."IndexInfo" WHERE table_name = '{}' AND index_name = '{}'""".format(keyspace, full_idx_name)
return len(list(session.execute(index_query))) == 1
+
+def block_until_index_is_built(node, session, keyspace, table_name, idx_name):
+ """
+ Waits up to 30 seconds for a secondary index to be built, and raises
+ DtestTimeoutError if it is not.
+ """
+ start = time.time()
+ rate_limited_debug = get_rate_limited_function(debug, 5)
+ while time.time() < start + 30:
+ rate_limited_debug("waiting for index to build")
+ time.sleep(1)
+ if index_is_built(node, session, keyspace, table_name, idx_name):
+ break
+ else:
+ raise DtestTimeoutError()
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org