DROP COMPACT STORAGE should invalidate prepared statements still using CompactTableMetadata

patch by Caleb Rackliffe; reviewed by Alex Petrov, Mick Semb Wever for CASSANDRA-16361
This commit is contained in:
Caleb Rackliffe 2020-12-17 16:27:36 -06:00 committed by Mick Semb Wever
parent 3cfc8502b8
commit d9859d231f
No known key found for this signature in database
GPG Key ID: E91335D77E3E87CB
4 changed files with 63 additions and 1 deletions

View File

@ -1,4 +1,5 @@
4.0-beta4
* DROP COMPACT STORAGE should invalidate prepared statements still using CompactTableMetadata (CASSANDRA-16361)
* Update default num_tokens to 16 and allocate_tokens_for_local_replication_factor to 3 (CASSANDRA-13701)
* Remove use of String.intern() (CASSANDRA-15810)
* Fix the missing bb position in ByteBufferAccessor.getUnsignedShort (CASSANDRA-16249)

View File

@ -162,6 +162,12 @@ public class QueryProcessor implements QueryHandler
SystemKeyspace.resetPreparedStatements();
}
@VisibleForTesting
public static ConcurrentMap<String, Prepared> getInternalStatements()
{
return internalStatements;
}
@VisibleForTesting
public static QueryState internalQueryState()
{

View File

@ -558,7 +558,8 @@ public class TableMetadata implements SchemaElement
|| !regularAndStaticColumns.equals(updated.regularAndStaticColumns)
|| !indexes.equals(updated.indexes)
|| params.defaultTimeToLive != updated.params.defaultTimeToLive
|| params.gcGraceSeconds != updated.params.gcGraceSeconds;
|| params.gcGraceSeconds != updated.params.gcGraceSeconds
|| ( !Flag.isCQLTable(flags) && Flag.isCQLTable(updated.flags) );
}
/**

View File

@ -18,9 +18,19 @@
package org.apache.cassandra.cql3.validation.operations;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.Test;
import org.apache.cassandra.cql3.CQLTester;
import org.apache.cassandra.cql3.QueryHandler;
import org.apache.cassandra.cql3.QueryProcessor;
import org.apache.cassandra.schema.Schema;
import org.apache.cassandra.schema.SchemaChangeListener;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class CompactTableTest extends CQLTester
{
@ -46,6 +56,50 @@ public class CompactTableTest extends CQLTester
row(1, 1, 1));
}
@Test
public void dropCompactStorageShouldInvalidatePreparedStatements() throws Throwable
{
createTable("CREATE TABLE %s (pk int, ck int, v int, PRIMARY KEY (pk, ck)) WITH COMPACT STORAGE;");
execute("INSERT INTO %s (pk, ck, v) VALUES (1, 1, 1)");
String templateSelect = "SELECT * FROM %s WHERE pk = 1";
assertRows(execute(templateSelect), row(1, 1, 1));
// Verify that the prepared statement has been added to the cache after our first query.
String formattedQuery = formatQuery(templateSelect);
ConcurrentMap<String, QueryHandler.Prepared> original = QueryProcessor.getInternalStatements();
assertTrue(original.containsKey(formattedQuery));
// Verify that schema change listeners are told statements are affected with DROP COMPACT STORAGE.
SchemaChangeListener listener = new SchemaChangeListener()
{
public void onAlterTable(String keyspace, String table, boolean affectsStatements)
{
assertTrue(affectsStatements);
}
};
Schema.instance.registerListener(listener);
try
{
alterTable("ALTER TABLE %s DROP COMPACT STORAGE");
ConcurrentMap<String, QueryHandler.Prepared> postDrop = QueryProcessor.getInternalStatements();
// Verify that the prepared statement has been removed the cache after DROP COMPACT STORAGE.
assertFalse(postDrop.containsKey(formattedQuery));
// Verify that the prepared statement has been added back to the cache after our second query.
assertRows(execute(templateSelect), row(1, 1, 1));
ConcurrentMap<String, QueryHandler.Prepared> postQuery = QueryProcessor.getInternalStatements();
assertTrue(postQuery.containsKey(formattedQuery));
}
finally
{
// Clean up the listener so this doesn't fail other tests.
Schema.instance.unregisterListener(listener);
}
}
@Test
public void compactStorageSemanticsTest() throws Throwable
{