use of com.datastax.driver.core.KeyspaceMetadata in project cassandra-driver-mapping by valchkou.
the class SchemaSync method drop.
public static synchronized void drop(String keyspace, Session session, Class<?> clazz) {
EntityTypeMetadata entityMetadata = EntityTypeParser.getEntityMetadata(clazz);
entityMetadata.markUnSynced(keyspace);
String table = entityMetadata.getTableName();
Cluster cluster = session.getCluster();
KeyspaceMetadata keyspaceMetadata = cluster.getMetadata().getKeyspace(keyspace);
TableMetadata tableMetadata = keyspaceMetadata.getTable(table);
if (tableMetadata != null) {
session.execute("USE " + keyspace);
// drop indexes
/*for (ColumnMetadata columnMetadata: tableMetadata.getColumns()) {
if (columnMetadata.getIndex() != null) {
session.execute(new DropIndex(keyspace, columnMetadata.getIndex().getName()));
}
}*/
// drop table
session.execute(new DropTable(keyspace, entityMetadata));
}
}
use of com.datastax.driver.core.KeyspaceMetadata in project zipkin by openzipkin.
the class Schema method getKeyspaceMetadata.
static KeyspaceMetadata getKeyspaceMetadata(Session session) {
String keyspace = session.getLoggedKeyspace();
Cluster cluster = session.getCluster();
KeyspaceMetadata keyspaceMetadata = cluster.getMetadata().getKeyspace(keyspace);
if (keyspaceMetadata == null) {
throw new IllegalStateException(String.format("Cannot read keyspace metadata for give keyspace: %s and cluster: %s", keyspace, cluster.getClusterName()));
}
return keyspaceMetadata;
}
use of com.datastax.driver.core.KeyspaceMetadata in project zipkin by openzipkin.
the class Schema method ensureExists.
static void ensureExists(String keyspace, Session session) {
KeyspaceMetadata keyspaceMetadata = session.getCluster().getMetadata().getKeyspace(keyspace);
if (keyspaceMetadata == null || keyspaceMetadata.getTable("traces") == null) {
LOG.info("Installing schema {}", SCHEMA);
applyCqlFile(keyspace, session, SCHEMA);
// refresh metadata since we've installed the schema
keyspaceMetadata = session.getCluster().getMetadata().getKeyspace(keyspace);
}
if (!hasUpgrade1_defaultTtl(keyspaceMetadata)) {
LOG.info("Upgrading schema {}", UPGRADE_1);
applyCqlFile(keyspace, session, UPGRADE_1);
}
}
use of com.datastax.driver.core.KeyspaceMetadata in project zipkin by openzipkin.
the class EnsureSchemaTest method installsTablesWhenMissing.
@Test
public void installsTablesWhenMissing() {
session.execute("CREATE KEYSPACE " + keyspace + " WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'};");
Schema.ensureExists(keyspace, session);
KeyspaceMetadata metadata = session.getCluster().getMetadata().getKeyspace(keyspace);
assertThat(metadata).isNotNull();
assertThat(Schema.hasUpgrade1_defaultTtl(metadata)).isTrue();
}
use of com.datastax.driver.core.KeyspaceMetadata in project zipkin by openzipkin.
the class Schema method readMetadata.
static Metadata readMetadata(Session session) {
KeyspaceMetadata keyspaceMetadata = getKeyspaceMetadata(session);
Map<String, String> replication = keyspaceMetadata.getReplication();
if ("SimpleStrategy".equals(replication.get("class")) && "1".equals(replication.get("replication_factor"))) {
LOG.warn("running with RF=1, this is not suitable for production. Optimal is 3+");
}
String compactionClass = keyspaceMetadata.getTable("traces").getOptions().getCompaction().get("class");
return new Metadata(compactionClass);
}
Aggregations