[
https://issues.apache.org/jira/browse/CASSANDRA-11288?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15175417#comment-15175417
]
Oliver Lockwood commented on CASSANDRA-11288:
---------------------------------------------
See below for the Java class and Gradle build script. I will test this shortly
against Cassandra 2.1, stand by.
{code:title=SchemaChanger.java|borderStyle=solid}
package com.oliverlockwood.cassandra;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.ConsistencyLevel;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.SimpleStatement;
import com.google.common.collect.Lists;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class SchemaChanger {
private static final Logger LOGGER =
LoggerFactory.getLogger(SchemaChanger.class);
private static final List<String> CQL_COMMANDS = Lists.newArrayList(
"DROP KEYSPACE IF EXISTS testkeyspace;",
"CREATE KEYSPACE testkeyspace WITH replication = {'class':
'NetworkTopologyStrategy', '50': 1};",
"USE testkeyspace;",
"CREATE TABLE IF NOT EXISTS table_1 (field_1 text primary key, field_2
text, field_3 list<text>, field_4 text);",
"CREATE TABLE IF NOT EXISTS table_2 (field_1 int, field_2 blob, field_3
timestamp, field_4 timestamp, field_5 timestamp, field_6 timestamp, PRIMARY
KEY(field_1));",
"CREATE TABLE IF NOT EXISTS table_3 (field_1 int primary key, field_2
text);",
"CREATE TABLE IF NOT EXISTS table_4 (field_1 timestamp, field_2 text,
field_3 text, PRIMARY KEY (field_1));",
"CREATE TABLE IF NOT EXISTS table_5 (field_1 text PRIMARY KEY , field_2
text);",
"CREATE TABLE IF NOT EXISTS table_6 (field_1 text primary key, field_2
timestamp, field_3 text);",
"ALTER TABLE table_1 WITH compaction = { 'class' :
'LeveledCompactionStrategy' };",
"ALTER TABLE table_2 WITH compaction = { 'class' :
'LeveledCompactionStrategy' };",
"ALTER TABLE table_3 WITH compaction = { 'class' :
'LeveledCompactionStrategy' };",
"ALTER TABLE table_4 WITH compaction = { 'class' :
'LeveledCompactionStrategy' };",
"ALTER TABLE table_5 WITH compaction = { 'class' :
'LeveledCompactionStrategy' };",
"ALTER TABLE table_6 WITH compaction = { 'class' :
'LeveledCompactionStrategy' };",
"DROP TABLE table_4;",
"CREATE TABLE table_4(field_1 timestamp, field_2 text, field_3 text,
field_4 text, PRIMARY KEY (field_1,field_2));",
"ALTER TABLE table_4 WITH compaction = { 'class' :
'LeveledCompactionStrategy' };",
"CREATE TABLE table_7 (field_1 text primary key, field_2 text, field_3
text, field_4 text, field_5 text, field_6 list<text>, field_7 text);",
"ALTER TABLE table_7 WITH compaction = { 'class' :
'LeveledCompactionStrategy' };",
"CREATE TABLE table_8 (field_1 text primary key, field_2 text, field_3
text, field_4 text, field_5 text, field_6 text, field_7 text, field_8 boolean,
field_9 text, field_10 list<text>);",
"ALTER TABLE table_8 WITH compaction = { 'class' :
'LeveledCompactionStrategy' };",
"DROP TABLE table_1;",
"CREATE TABLE table_1 (field_1 text primary key, field_2 text) WITH
compaction = { 'class' : 'LeveledCompactionStrategy' };",
"DROP TABLE table_7;",
"CREATE TABLE table_7 (field_1 text primary key, field_2 text) WITH
compaction = { 'class' : 'LeveledCompactionStrategy' };",
"DROP TABLE table_8;",
"CREATE TABLE table_8 (field_1 text primary key, field_2 text) WITH
compaction = { 'class' : 'LeveledCompactionStrategy' };"
);
public static void main(String[] args) {
Map<String, String[]> envToHostsMap = new HashMap<>();
envToHostsMap.put("d1", new String[] {"hostname.here.com"});
envToHostsMap.put("u1", new String[] {"hostname.here.com"});
String[] hosts = envToHostsMap.get(args[0]);
try (Cluster cluster = createCluster(hosts, 9042);
Session session = cluster.connect()) {
CQL_COMMANDS.stream()
.map(stringStatement -> new
SimpleStatement(stringStatement).setConsistencyLevel(ConsistencyLevel.ALL))
.forEach(statement -> {
LOGGER.debug("Executing cql statement {}", statement);
session.execute(statement);
});
}
}
private static Cluster createCluster(String[] hosts, int port) {
return Cluster.builder()
.addContactPoints(hosts)
.withPort(port)
.build();
}
}
{code}
{code:title=build.gradle|borderStyle=solid}
buildscript {
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.2'
classpath 'io.spring.gradle:dependency-management-plugin:0.5.3.RELEASE'
}
}
import
com.github.jengelman.gradle.plugins.shadow.transformers.ServiceFileTransformer
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'com.github.johnrengelman.shadow'
mainClassName = 'com.oliverlockwood.cassandra.SchemaChanger'
shadowJar {
baseName = project.name
classifier = ''
exclude 'META-INF/*.DSA'
exclude 'META-INF/*.RSA'
exclude 'META-INF/*.SF'
transform(ServiceFileTransformer)
}
configurations.all {
// check for updates every build
resolutionStrategy.cacheChangingModulesFor 0, 'minutes'
}
repositories {
mavenLocal()
}
dependencies {
compile 'com.datastax.cassandra:cassandra-driver-core:2.1.8'
compile 'org.slf4j:slf4j-log4j12:1.7.12'
compile 'org.slf4j:slf4j-api:1.7.12'
}
{code}
> Schema agreement appears to be false positive following a DROP TABLE command
> ----------------------------------------------------------------------------
>
> Key: CASSANDRA-11288
> URL: https://issues.apache.org/jira/browse/CASSANDRA-11288
> Project: Cassandra
> Issue Type: Bug
> Environment: Cassandra 2.0.14.439 (DSE 4.6.7)
> 2 nodes OR 4 nodes
> Connecting with Datastax Java driver 2.1.8 OR 2.0.12 OR 2.1.4 OR 2.1.9 OR
> 3.0.0
> Reporter: Oliver Lockwood
>
> As part of a schema migration operation, our application is calling the
> following operations on the Java driver consecutively:
> {noformat}
> session.execute("DROP TABLE table_name");
> session.execute("CREATE TABLE table_name (...)");
> {noformat}
> The second of these sometimes fails with a {{DriverException}} whose message
> is "Table keyspace.table_name already exists".
> In the schema migration operation, there's 4 of these drop/create pairings
> and, although it's random which exact one fails, we've never managed to get
> further than the third operation in approximately 10 attempts - so there's a
> reasonably high proportion of failure.
> I don't believe this is a driver issue because the driver is checking for
> schema agreement (as per
> https://github.com/datastax/java-driver/blob/2.1/driver-core/src/main/java/com/datastax/driver/core/ControlConnection.java#L701)
> and we are seeing a log message to that effect.
> {noformat}
> c.d.d.c.ControlConnection - [] [] [] [] [] [] [] [] Checking for schema
> agreement: versions are [02bce936-fddd-3bef-bb54-124d31bede57]
> {noformat}
> This log message appears in between our own logs which say "Executing
> statement DROP TABLE..." and "Executing statement CREATE TABLE...", so we can
> be reasonably sure this log message refers to the DROP operation being viewed
> as "in agreement".
> Could this be a bug in the Cassandra server erroneously reporting that the
> schemas are in agreement across the 2 nodes when, in fact, they are not?
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)