jacek-lewandowski commented on code in PR #2713:
URL: https://github.com/apache/cassandra/pull/2713#discussion_r1354248710
##########
test/unit/org/apache/cassandra/cql3/statements/DescribeStatementTest.java:
##########
@@ -377,6 +393,54 @@ public void testDescribe() throws Throwable
}
}
+ private static volatile CountDownLatch describeStatementLatch;
+ public static void awaitDescribeStatementLatch()
+ {
+ if (Arrays.stream(Thread.currentThread().getStackTrace()).anyMatch(ste
-> ste.getClassName().equals(DescribeStatement.class.getName())))
+ {
+ describeStatementLatch.decrement();
+ describeStatementLatch.awaitThrowUncheckedOnInterrupt();
+ }
+ }
+
+ @Test
+ @BMRule(name = "await describe statement latch",
+ targetClass = "Schema",
+ targetMethod = "distributedAndLocalKeyspaces",
+ targetLocation = "AT ENTRY",
+ action =
"org.apache.cassandra.cql3.statements.DescribeStatementTest.awaitDescribeStatementLatch()")
+ public void testNotReturningPartiallyAppliedSchema() throws Throwable
+ {
+ Duration timeout =
Duration.ofMillis(DatabaseDescriptor.getReadRpcTimeout(TimeUnit.MILLISECONDS));
+
+ describeStatementLatch = CountDownLatch.newCountDownLatch(2);
+ ForkJoinTask<ResultSet> describeFuture =
ForkJoinPool.commonPool().submit(() -> {
+ try
+ {
+ return executeNetWithPaging(ProtocolVersion.CURRENT, "DESCRIBE
KEYSPACES", 1);
+ }
+ catch (Throwable e)
+ {
+ throw new RuntimeException(e);
+ }
+ });
+ // wait for the describe statement to be in progress
+ Awaitility.await().atMost(timeout).until(() ->
describeStatementLatch.count() == 1);
+
+ // at this point, the describe statement got the schema version and is
about to get the keyspaces
+ // we will now create a keyspace, release the lock, and let the
describe statement continue
+ String ks = createKeyspace("CREATE KEYSPACE %s WITH REPLICATION =
{'class' : 'SimpleStrategy', 'replication_factor' : 1};");
+ describeStatementLatch.decrement();
+
+ // the paginated describe statement should complete successfully and
should include the new keyspace even though
+ // the keyspace was created after the describe statement started; this
proves that when the describe statement
+ // finds itself in a situation where the schema being changed, it will
wait for completion before actually
+ // starting execution; otherwise we would get an exception
Review Comment:
It is a bug if we can return schema and schema version where version does
not correspond to the schema, which will result in paging failure; You are
right that the bug exists in 4.0 as well; 3.11 and prior do not have
server-side `DescribeStatement`. I'll create a separate ticket to fix that
starting from 4.0 (https://issues.apache.org/jira/browse/CASSANDRA-18921)
--
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]