use of org.apache.cassandra.thrift.KsDef in project brisk by riptano.
the class SchemaManagerServiceTest method testSkipCreateOnConfig.
@Test
public void testSkipCreateOnConfig() throws Exception {
KsDef ksDef = setupOtherKeyspace(configuration, "SkipCreatedKeyspace", false);
cassandraClientHolder.getClient().system_add_keyspace(ksDef);
schemaManagerService.createKeyspaceSchemasIfNeeded();
List<KsDef> keyspaces = schemaManagerService.findUnmappedKeyspaces();
boolean skipped = false;
for (KsDef ks : keyspaces) {
if (StringUtils.equals(ks.name, "SkipCreatedKeyspace")) {
skipped = true;
}
}
assertTrue(skipped);
}
use of org.apache.cassandra.thrift.KsDef in project brisk by riptano.
the class SchemaManagerServiceTest method testCreateOnConfig.
@Test
public void testCreateOnConfig() throws Exception {
KsDef ksDef = setupOtherKeyspace(configuration, "ConfigCreatedKeyspace", false);
cassandraClientHolder.getClient().system_add_keyspace(ksDef);
configuration.setBoolean("cassandra.autoCreateHiveSchema", true);
schemaManagerService.createKeyspaceSchemasIfNeeded();
List<KsDef> keyspaces = schemaManagerService.findUnmappedKeyspaces();
for (KsDef ks : keyspaces) {
if (StringUtils.equals(ks.name, "ConfigCreatedKeyspace")) {
fail("keyspace not created by configuration");
}
}
}
use of org.apache.cassandra.thrift.KsDef in project brisk by riptano.
the class SchemaManagerServiceTest method testDiscoverUnmappedKeyspaces.
@Test
public void testDiscoverUnmappedKeyspaces() throws Exception {
cassandraClientHolder.getClient().system_add_keyspace(setupOtherKeyspace(configuration, "OtherKeyspace", false));
// init the meta store for usage
List<KsDef> keyspaces = schemaManagerService.findUnmappedKeyspaces();
boolean foundCreated = false;
// don't impose a keyspace maintenance burden. Looking for specifics is good enough
for (KsDef ksDef : keyspaces) {
if (StringUtils.equals(ksDef.name, "OtherKeyspace")) {
foundCreated = true;
break;
}
}
assertTrue(foundCreated);
}
use of org.apache.cassandra.thrift.KsDef in project coprhd-controller by CoprHD.
the class SchemaUtil method addColumnFamily.
/**
* Adds CF to keyspace
*
* @param def
* @return
*/
@SuppressWarnings("unchecked")
public String addColumnFamily(final ThriftColumnFamilyDefinitionImpl def) {
AstyanaxContext<Cluster> context = clientContext.getClusterContext();
final KeyspaceTracerFactory ks = EmptyKeyspaceTracerFactory.getInstance();
ConnectionPool<Cassandra.Client> pool = (ConnectionPool<Cassandra.Client>) context.getConnectionPool();
final String cfname = def.getName();
_log.info("Adding CF: {}", cfname);
try {
return pool.executeWithFailover(new AbstractOperationImpl<String>(ks.newTracer(CassandraOperationType.ADD_COLUMN_FAMILY)) {
@Override
public String internalExecute(Cassandra.Client client, ConnectionContext context) throws Exception {
client.set_keyspace(_keyspaceName);
// This method can be retried several times, so server may already have received the 'creating CF' request
// and created the CF, we check the existence of the CF first before issuing another 'creating CF' request
// which will cause the 'CF already exists' exception
KsDef kd = client.describe_keyspace(_keyspaceName);
List<CfDef> cfs = kd.getCf_defs();
for (CfDef cf : cfs) {
if (cf.getName().equals(cfname)) {
_log.info("The CF {} has already been created", cfname);
return null;
}
}
_log.info("To create CF {}", cfname);
return client.system_add_column_family(def.getThriftColumnFamilyDefinition());
}
}, context.getAstyanaxConfiguration().getRetryPolicy().duplicate()).getResult();
} catch (final OperationException e) {
throw DatabaseException.retryables.operationFailed(e);
} catch (final ConnectionException e) {
throw DatabaseException.retryables.connectionFailed(e);
}
}
use of org.apache.cassandra.thrift.KsDef in project atlasdb by palantir.
the class CassandraKeyValueServiceImpl method lowerConsistencyWhenSafe.
private void lowerConsistencyWhenSafe() {
Set<String> dcs;
Map<String, String> strategyOptions;
try {
dcs = clientPool.runWithRetry(client -> CassandraVerifier.sanityCheckDatacenters(client, config));
KsDef ksDef = clientPool.runWithRetry(client -> client.describe_keyspace(config.getKeyspaceOrThrow()));
strategyOptions = Maps.newHashMap(ksDef.getStrategy_options());
if (dcs.size() == 1) {
String dc = dcs.iterator().next();
if (strategyOptions.get(dc) != null) {
int currentRf = Integer.parseInt(strategyOptions.get(dc));
if (currentRf == config.replicationFactor()) {
if (currentRf == 2 && config.clusterMeetsNormalConsistencyGuarantees()) {
log.info("Setting Read Consistency to ONE, as cluster has only one datacenter at RF2.");
readConsistency = ConsistencyLevel.ONE;
}
}
}
}
} catch (TException e) {
return;
}
}
Aggregations