maedhroz commented on a change in pull request #1221:
URL: https://github.com/apache/cassandra/pull/1221#discussion_r728228653
##########
File path: test/unit/org/apache/cassandra/schema/SchemaKeyspaceTest.java
##########
@@ -63,15 +84,112 @@ public static void defineSchema() throws
ConfigurationException
SchemaLoader.standardCFMD(KEYSPACE1,
CF_STANDARD1));
}
- /** See CASSANDRA-16856. Make sure schema pulls are synchronized to
prevent concurrent schema pull/writes
- *
- * @throws Exception
- */
+ /** See CASSANDRA-16856/16996. Make sure schema pulls are synchronized to
prevent concurrent schema pull/writes */
@Test
public void testSchemaPullSynchoricity() throws Exception
{
- Method method =
SchemaKeyspace.class.getDeclaredMethod("convertSchemaToMutations");
+ for (String methodName : Arrays.asList("schemaKeyspaceAsMutations",
+ "truncateSchemaKeyspace",
+ "saveSystemKeyspace",
+ "updateVersion"))
+ {
+ Method method = Schema.class.getDeclaredMethod(methodName);
+ assertTrue(Modifier.isSynchronized(method.getModifiers()));
+ }
+
+ Method method = Schema.class.getDeclaredMethod("merge",
Collection.class);
assertTrue(Modifier.isSynchronized(method.getModifiers()));
+ method = Schema.class.getDeclaredMethod("transform",
SchemaTransformation.class, boolean.class, long.class);
+ assertTrue(Modifier.isSynchronized(method.getModifiers()));
+ }
+
+ /** See CASSANDRA-16856/16996. Make sure schema pulls are synchronized to
prevent concurrent schema pull/writes */
+ @Test
+ @BMRule(name = "Delay system ks schema",
+ targetClass = "SchemaKeyspace",
+ targetMethod = "applyChanges",
+ action =
"org.apache.cassandra.schema.SchemaKeyspaceTest.threadBlock.countDown();"
+ +
"org.apache.cassandra.schema.SchemaKeyspaceTest.threadBlock.await();",
+ targetLocation = "AT EXIT")
+ public void testNoVisiblePartialSchemaUpdates() throws Exception
+ {
+ String keyspace = "sandbox";
+ AtomicBoolean foundCollision = new AtomicBoolean(false);
+ ExecutorService pool = Executors.newFixedThreadPool(2);
+ CountDownLatch pendingStarts = new CountDownLatch(2);
+ CountDownLatch blockedThreadFinished = new CountDownLatch(1);
+
+ threadBlock = new CountDownLatch(2);
+ pool.execute(() -> {
+ pendingStarts.countDown();
+ createTable(keyspace, "CREATE TABLE test (a text primary key, b
int, c int)");
+ });
+ // Wait until table is created and that thread blocks
+ Util.spinAssertEquals(1L, () -> pendingStarts.getCount(), 5);
+ Util.spinAssertEquals(1L, () -> threadBlock.getCount(), 5);
+
+ pool.execute(() -> {
+ pendingStarts.countDown();
+ foundCollision.set(Schema.instance.schemaKeyspaceAsMutations()
+ .stream()
+ .filter(m ->
m.getPartitionUpdates().toString().contains(keyspace))
+ .collect(Collectors.counting())
+ > 0);
+ blockedThreadFinished.countDown();
+ });
+
+ pendingStarts.await(10, TimeUnit.SECONDS);
+ Util.spinAssertEquals(1L, () -> threadBlock.getCount(), 5);
+ assertFalse(blockedThreadFinished.await(5, TimeUnit.SECONDS));
+ assertEquals(false, foundCollision.get());
+
+ // Do not execute the tasks. Just kill it.
+ pool.shutdownNow();
+ }
+
+ @Test
+ @BMRule(name = "delay partition updates to schema tables",
+ targetClass = "CassandraTableWriteHandler",
+ targetMethod = "write",
+ action = "Thread.sleep(100);",
Review comment:
Minor note...if we're concerned about making sure thread overlap is
99.9% guaranteed (which is fine for a fuzz test), we could easily raise this
10x to 1000.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]