Search in sources :

Example 1 with ThriftKeyspaceDefinitionImpl

use of com.netflix.astyanax.thrift.ddl.ThriftKeyspaceDefinitionImpl in project coprhd-controller by CoprHD.

the class DbClientContext method alterKeyspaceWithThrift.

/**
 * Update the keyspace definition using low-level thrift API
 * This is to bypass the precheck logic in Astyanax that throws SchemaDisagreementException when there are
 * unreachable nodes in the cluster. Refer to https://github.com/Netflix/astyanax/issues/443 for details.
 *
 * @param kd existing keyspace definition, could be null
 * @param update new keyspace definition
 * @return new schema version after the update
 */
private String alterKeyspaceWithThrift(KeyspaceDefinition kd, KeyspaceDefinition update) throws ConnectionException {
    final KeyspaceTracerFactory ks = EmptyKeyspaceTracerFactory.getInstance();
    ConnectionPool<Cassandra.Client> pool = (ConnectionPool<Cassandra.Client>) clusterContext.getConnectionPool();
    final KsDef def = ((ThriftKeyspaceDefinitionImpl) update).getThriftKeyspaceDefinition();
    if (kd != null) {
        return pool.executeWithFailover(new AbstractOperationImpl<String>(ks.newTracer(CassandraOperationType.UPDATE_KEYSPACE)) {

            @Override
            public String internalExecute(Cassandra.Client client, ConnectionContext context) throws Exception {
                return client.system_update_keyspace(def);
            }
        }, clusterContext.getAstyanaxConfiguration().getRetryPolicy().duplicate()).getResult();
    } else {
        return pool.executeWithFailover(new AbstractOperationImpl<String>(ks.newTracer(CassandraOperationType.ADD_KEYSPACE)) {

            @Override
            public String internalExecute(Cassandra.Client client, ConnectionContext context) throws Exception {
                return client.system_add_keyspace(def);
            }
        }, clusterContext.getAstyanaxConfiguration().getRetryPolicy().duplicate()).getResult();
    }
}
Also used : ConnectionPool(com.netflix.astyanax.connectionpool.ConnectionPool) AbstractOperationImpl(com.netflix.astyanax.thrift.AbstractOperationImpl) Cassandra(org.apache.cassandra.thrift.Cassandra) EmptyKeyspaceTracerFactory(com.netflix.astyanax.shallows.EmptyKeyspaceTracerFactory) KeyspaceTracerFactory(com.netflix.astyanax.KeyspaceTracerFactory) KsDef(org.apache.cassandra.thrift.KsDef) ConnectionContext(com.netflix.astyanax.connectionpool.ConnectionContext) SSLConnectionContext(com.netflix.astyanax.connectionpool.SSLConnectionContext) ThriftKeyspaceDefinitionImpl(com.netflix.astyanax.thrift.ddl.ThriftKeyspaceDefinitionImpl)

Aggregations

KeyspaceTracerFactory (com.netflix.astyanax.KeyspaceTracerFactory)1 ConnectionContext (com.netflix.astyanax.connectionpool.ConnectionContext)1 ConnectionPool (com.netflix.astyanax.connectionpool.ConnectionPool)1 SSLConnectionContext (com.netflix.astyanax.connectionpool.SSLConnectionContext)1 EmptyKeyspaceTracerFactory (com.netflix.astyanax.shallows.EmptyKeyspaceTracerFactory)1 AbstractOperationImpl (com.netflix.astyanax.thrift.AbstractOperationImpl)1 ThriftKeyspaceDefinitionImpl (com.netflix.astyanax.thrift.ddl.ThriftKeyspaceDefinitionImpl)1 Cassandra (org.apache.cassandra.thrift.Cassandra)1 KsDef (org.apache.cassandra.thrift.KsDef)1