mirror of https://github.com/apache/cassandra
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:
parent
3cfc8502b8
commit
d9859d231f
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue