Search in sources :

Example 1 with KsDef

use of org.apache.cassandra.thrift.KsDef in project brisk by riptano.

the class CassandraHiveMetaStoreTest method testAutoCreateFromKeyspace.

@Test
public void testAutoCreateFromKeyspace() throws Exception {
    CassandraHiveMetaStore metaStore = new CassandraHiveMetaStore();
    Configuration conf = buildConfiguration();
    CassandraClientHolder clientHolder = new CassandraClientHolder(conf);
    KsDef ksDef = setupOtherKeyspace(conf, "AutoCreatedFromKeyspace", false);
    clientHolder.getClient().system_add_keyspace(ksDef);
    conf.setBoolean("cassandra.autoCreateHiveSchema", true);
    metaStore.setConf(conf);
    Database foundDb = metaStore.getDatabase("AutoCreatedFromKeyspace");
    assertNotNull(foundDb);
    CfDef cf = new CfDef("AutoCreatedFromKeyspace", "OtherCf2");
    cf.setKey_validation_class("UTF8Type");
    cf.setComparator_type("UTF8Type");
    clientHolder.getClient().set_keyspace("HiveMetaStore");
    clientHolder.getClient().system_add_column_family(cf);
    metaStore.getAllTables("AutoCreatedFromKeyspace");
    assertNotNull(metaStore.getTable("AutoCreatedFromKeyspace", "OtherCf2"));
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) KsDef(org.apache.cassandra.thrift.KsDef) CfDef(org.apache.cassandra.thrift.CfDef) Test(org.junit.Test)

Example 2 with KsDef

use of org.apache.cassandra.thrift.KsDef in project brisk by riptano.

the class SchemaManagerServiceTest method testCreateOnConfigWithMetaData.

@Test
public void testCreateOnConfigWithMetaData() throws Exception {
    KsDef ksDef = setupOtherKeyspace(configuration, "ConfigCreatedKeyspaceMetaData", true);
    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, "ConfigCreatedKeyspaceMetaData")) {
            fail("keyspace not created by configuration");
        }
    }
    Table table = cassandraHiveMetaStore.getTable("ConfigCreatedKeyspaceMetaData", "OtherCf1");
    assertNotNull(table);
    StorageDescriptor sd = table.getSd();
    assertEquals(5, sd.getColsSize());
    for (Iterator<FieldSchema> iterator = sd.getColsIterator(); iterator.hasNext(); ) {
        FieldSchema fs = iterator.next();
        if (StringUtils.equals(fs.getName(), "col_name_utf8"))
            assertEquals("string", fs.getType());
        if (StringUtils.equals(fs.getName(), "col_name_bytes"))
            assertEquals("string", fs.getType());
        if (StringUtils.equals(fs.getName(), "col_name_timeuuid"))
            assertEquals("string", fs.getType());
        if (StringUtils.equals(fs.getName(), "col_name_long"))
            assertEquals("int", fs.getType());
        if (StringUtils.equals(fs.getName(), "col_name_int"))
            assertEquals("bigint", fs.getType());
    }
}
Also used : Table(org.apache.hadoop.hive.metastore.api.Table) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) KsDef(org.apache.cassandra.thrift.KsDef) Test(org.junit.Test)

Example 3 with KsDef

use of org.apache.cassandra.thrift.KsDef 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)

Example 4 with KsDef

use of org.apache.cassandra.thrift.KsDef in project brisk by riptano.

the class SchemaManagerService method findUnmappedKeyspaces.

/**
 * Returns a List of Keyspace definitions that are not yet created as 'databases'
 * in the Hive meta store. The list of keyspaces required for brisk operation are ignored.
 * @return
 */
public List<KsDef> findUnmappedKeyspaces() {
    List<KsDef> defs;
    try {
        defs = cassandraClientHolder.getClient().describe_keyspaces();
        for (Iterator<KsDef> iterator = defs.iterator(); iterator.hasNext(); ) {
            KsDef ksDef = iterator.next();
            String name = ksDef.name;
            log.debug("Found ksDef name: {}", name);
            if (StringUtils.indexOfAny(name, SYSTEM_KEYSPACES) > -1 || isKeyspaceMapped(name)) {
                log.debug("REMOVING ksDef name from unmapped List: {}", name);
                iterator.remove();
            }
        }
    } catch (Exception ex) {
        throw new CassandraHiveMetaStoreException("Could not retrieve unmapped keyspaces", ex);
    }
    return defs;
}
Also used : KsDef(org.apache.cassandra.thrift.KsDef) CharacterCodingException(java.nio.charset.CharacterCodingException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) NotFoundException(org.apache.cassandra.thrift.NotFoundException) InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException) ConfigurationException(org.apache.cassandra.config.ConfigurationException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException)

Example 5 with KsDef

use of org.apache.cassandra.thrift.KsDef in project brisk by riptano.

the class SchemaManagerService method createMetaStoreIfNeeded.

/**
 * Create the meta store keyspace if it does not already exist.
 * @return true if the keyspace did no exist and the creation was successful. False if the
 * keyspace already existed.
 * @throws {@link CassandraHiveMetaStoreException} wrapping the underlying exception if we
 * failed to create the keyspace.
 */
public boolean createMetaStoreIfNeeded() {
    if (configuration.getBoolean("cassandra.skipMetaStoreCreate", false))
        return false;
    try {
        cassandraClientHolder.applyKeyspace();
        return false;
    } catch (CassandraHiveMetaStoreException chmse) {
        log.debug("Attempting to create meta store keyspace: First set_keyspace call failed. Sleeping.");
    }
    // Sleep a random amount of time to stagger ks creations on many nodes
    try {
        Thread.sleep(5000);
    } catch (InterruptedException e1) {
    }
    // check again...
    try {
        cassandraClientHolder.applyKeyspace();
        return false;
    } catch (CassandraHiveMetaStoreException chmse) {
        log.debug("Attempting to create meta store keyspace after sleep.");
    }
    CfDef cf = new CfDef(cassandraClientHolder.getKeyspaceName(), cassandraClientHolder.getColumnFamily());
    cf.setKey_validation_class("UTF8Type");
    cf.setComparator_type("UTF8Type");
    KsDef ks = new KsDef(cassandraClientHolder.getKeyspaceName(), "org.apache.cassandra.locator.SimpleStrategy", Arrays.asList(cf));
    ks.setStrategy_options(KSMetaData.optsWithRF(configuration.getInt(CassandraClientHolder.CONF_PARAM_REPLICATION_FACTOR, 1)));
    try {
        cassandraClientHolder.getClient().system_add_keyspace(ks);
        return true;
    } catch (Exception e) {
        throw new CassandraHiveMetaStoreException("Could not create Hive MetaStore database: " + e.getMessage(), e);
    }
}
Also used : KsDef(org.apache.cassandra.thrift.KsDef) CfDef(org.apache.cassandra.thrift.CfDef) CharacterCodingException(java.nio.charset.CharacterCodingException) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) NotFoundException(org.apache.cassandra.thrift.NotFoundException) InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException) ConfigurationException(org.apache.cassandra.config.ConfigurationException) InvalidObjectException(org.apache.hadoop.hive.metastore.api.InvalidObjectException) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException)

Aggregations

KsDef (org.apache.cassandra.thrift.KsDef)25 CfDef (org.apache.cassandra.thrift.CfDef)11 Cassandra (org.apache.cassandra.thrift.Cassandra)7 InvalidRequestException (org.apache.cassandra.thrift.InvalidRequestException)7 NotFoundException (org.apache.cassandra.thrift.NotFoundException)7 Test (org.junit.Test)7 TException (org.apache.thrift.TException)6 PermanentStorageException (com.thinkaurelius.titan.diskstorage.PermanentStorageException)4 StorageException (com.thinkaurelius.titan.diskstorage.StorageException)4 TemporaryStorageException (com.thinkaurelius.titan.diskstorage.TemporaryStorageException)4 CTConnection (com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnection)4 SchemaDisagreementException (org.apache.cassandra.thrift.SchemaDisagreementException)4 CoordinatorClient (com.emc.storageos.coordinator.client.service.CoordinatorClient)2 DbClient (com.emc.storageos.db.client.DbClient)2 KeyspaceTracerFactory (com.netflix.astyanax.KeyspaceTracerFactory)2 ConnectionContext (com.netflix.astyanax.connectionpool.ConnectionContext)2 ConnectionPool (com.netflix.astyanax.connectionpool.ConnectionPool)2 CharacterCodingException (java.nio.charset.CharacterCodingException)2 HashMap (java.util.HashMap)2 Random (java.util.Random)2