You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by ad...@apache.org on 2017/11/20 17:15:51 UTC
cassandra git commit: Fix flaky unit test
indexWithFailedInitializationIsNotQueryableAfterPartialRebuild
Repository: cassandra
Updated Branches:
refs/heads/trunk da410153e -> 5792b667e
Fix flaky unit test indexWithFailedInitializationIsNotQueryableAfterPartialRebuild
patch by Andres de la Peña; reviewed by Robert Stupp for CASSANDRA-13963
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/5792b667
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/5792b667
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/5792b667
Branch: refs/heads/trunk
Commit: 5792b667ecf461a40cc391bc1496287547179c91
Parents: da41015
Author: Andrés de la Peña <a....@gmail.com>
Authored: Wed Oct 18 12:25:26 2017 +0100
Committer: Andrés de la Peña <a....@gmail.com>
Committed: Mon Nov 20 17:07:45 2017 +0000
----------------------------------------------------------------------
CHANGES.txt | 1 +
.../cassandra/index/SecondaryIndexManager.java | 13 ++++++++
.../org/apache/cassandra/cql3/CQLTester.java | 33 ++++++++++++++++++++
.../index/SecondaryIndexManagerTest.java | 6 ++--
4 files changed, 51 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/5792b667/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index a690e17..03f5de8 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
4.0
+ * Fix flaky indexWithFailedInitializationIsNotQueryableAfterPartialRebuild (CASSANDRA-13963)
* Introduce leaf-only iterator (CASSANDRA-9988)
* Upgrade Guava to 23.3 and Airline to 0.8 (CASSANDRA-13997)
* Allow only one concurrent call to StatusLogger (CASSANDRA-12182)
http://git-wip-us.apache.org/repos/asf/cassandra/blob/5792b667/src/java/org/apache/cassandra/index/SecondaryIndexManager.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/index/SecondaryIndexManager.java b/src/java/org/apache/cassandra/index/SecondaryIndexManager.java
index 27a9b16..b60d811 100644
--- a/src/java/org/apache/cassandra/index/SecondaryIndexManager.java
+++ b/src/java/org/apache/cassandra/index/SecondaryIndexManager.java
@@ -276,6 +276,19 @@ public class SecondaryIndexManager implements IndexRegistry, INotificationConsum
return queryableIndexes.contains(index.getIndexMetadata().name);
}
+ /**
+ * Checks if the specified index has any running build task.
+ *
+ * @param indexName the index name
+ * @return {@code true} if the index is building, {@code false} otherwise
+ */
+ @VisibleForTesting
+ public synchronized boolean isIndexBuilding(String indexName)
+ {
+ AtomicInteger counter = inProgressBuilds.get(indexName);
+ return counter != null && counter.get() > 0;
+ }
+
public synchronized void removeIndex(String indexName)
{
Index index = unregisterIndex(indexName);
http://git-wip-us.apache.org/repos/asf/cassandra/blob/5792b667/test/unit/org/apache/cassandra/cql3/CQLTester.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/cql3/CQLTester.java b/test/unit/org/apache/cassandra/cql3/CQLTester.java
index 062a4bc..b038ce0 100644
--- a/test/unit/org/apache/cassandra/cql3/CQLTester.java
+++ b/test/unit/org/apache/cassandra/cql3/CQLTester.java
@@ -46,6 +46,7 @@ import com.datastax.driver.core.ResultSet;
import org.apache.cassandra.SchemaLoader;
import org.apache.cassandra.concurrent.ScheduledExecutors;
+import org.apache.cassandra.index.SecondaryIndexManager;
import org.apache.cassandra.schema.*;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.cql3.functions.FunctionName;
@@ -736,6 +737,38 @@ public abstract class CQLTester
return indexCreated;
}
+ /**
+ * Index creation is asynchronous, this method waits until the specified index hasn't any building task running.
+ * <p>
+ * This method differs from {@link #waitForIndex(String, String, String)} in that it doesn't require the index to be
+ * fully nor successfully built, so it can be used to wait for failing index builds.
+ *
+ * @param keyspace the index keyspace name
+ * @param indexName the index name
+ * @return {@code true} if the index build tasks have finished in 5 seconds, {@code false} otherwise
+ */
+ protected boolean waitForIndexBuilds(String keyspace, String indexName) throws InterruptedException
+ {
+ long start = System.currentTimeMillis();
+ SecondaryIndexManager indexManager = getCurrentColumnFamilyStore(keyspace).indexManager;
+
+ while (true)
+ {
+ if (!indexManager.isIndexBuilding(indexName))
+ {
+ return true;
+ }
+ else if (System.currentTimeMillis() - start > 5000)
+ {
+ return false;
+ }
+ else
+ {
+ Thread.sleep(10);
+ }
+ }
+ }
+
protected void createIndexMayThrow(String query) throws Throwable
{
String fullQuery = formatQuery(query);
http://git-wip-us.apache.org/repos/asf/cassandra/blob/5792b667/test/unit/org/apache/cassandra/index/SecondaryIndexManagerTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/index/SecondaryIndexManagerTest.java b/test/unit/org/apache/cassandra/index/SecondaryIndexManagerTest.java
index ac3e5b2..def96a4 100644
--- a/test/unit/org/apache/cassandra/index/SecondaryIndexManagerTest.java
+++ b/test/unit/org/apache/cassandra/index/SecondaryIndexManagerTest.java
@@ -440,7 +440,7 @@ public class SecondaryIndexManagerTest extends CQLTester
}
@Test
- public void indexWithfailedInitializationIsQueryableAfterFullRebuild() throws Throwable
+ public void indexWithFailedInitializationIsQueryableAfterFullRebuild() throws Throwable
{
createTable("CREATE TABLE %s (a int, b int, c int, PRIMARY KEY (a, b))");
@@ -458,11 +458,12 @@ public class SecondaryIndexManagerTest extends CQLTester
}
@Test
- public void indexWithfailedInitializationIsNotQueryableAfterPartialRebuild() throws Throwable
+ public void indexWithFailedInitializationIsNotQueryableAfterPartialRebuild() throws Throwable
{
TestingIndex.shouldFailCreate = true;
createTable("CREATE TABLE %s (a int, b int, c int, PRIMARY KEY (a, b))");
String indexName = createIndex(String.format("CREATE CUSTOM INDEX ON %%s(c) USING '%s'", TestingIndex.class.getName()));
+ assertTrue(waitForIndexBuilds(KEYSPACE, indexName));
TestingIndex.shouldFailCreate = false;
// the index shouldn't be queryable after the failed initialization
@@ -472,6 +473,7 @@ public class SecondaryIndexManagerTest extends CQLTester
// a successful partial build doesn't set the index as queryable
cfs.indexManager.handleNotification(new SSTableAddedNotification(cfs.getLiveSSTables(), null), this);
+ assertTrue(waitForIndexBuilds(KEYSPACE, indexName));
assertFalse(cfs.indexManager.isIndexQueryable(index));
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org