Search in sources :

Example 1 with SchemaDisagreementException

use of org.apache.cassandra.thrift.SchemaDisagreementException in project titan by thinkaurelius.

the class CassandraThriftStoreManager method ensureColumnFamilyExists.

private void ensureColumnFamilyExists(String ksName, String cfName, String comparator) throws StorageException {
    CTConnection conn = null;
    try {
        KsDef keyspaceDef = ensureKeyspaceExists(ksName);
        conn = pool.borrowObject(ksName);
        Cassandra.Client client = conn.getClient();
        log.debug("Looking up metadata on keyspace {}...", ksName);
        boolean foundColumnFamily = false;
        for (CfDef cfDef : keyspaceDef.getCf_defs()) {
            String curCfName = cfDef.getName();
            if (curCfName.equals(cfName))
                foundColumnFamily = true;
        }
        if (!foundColumnFamily) {
            createColumnFamily(client, ksName, cfName, comparator);
        } else {
            log.debug("Keyspace {} and ColumnFamily {} were found.", ksName, cfName);
        }
    } catch (SchemaDisagreementException e) {
        throw new TemporaryStorageException(e);
    } catch (Exception e) {
        throw new PermanentStorageException(e);
    } finally {
        pool.returnObjectUnsafe(ksName, conn);
    }
}
Also used : CTConnection(com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnection) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) Cassandra(org.apache.cassandra.thrift.Cassandra) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) KsDef(org.apache.cassandra.thrift.KsDef) SchemaDisagreementException(org.apache.cassandra.thrift.SchemaDisagreementException) CfDef(org.apache.cassandra.thrift.CfDef) NotFoundException(org.apache.cassandra.thrift.NotFoundException) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) TException(org.apache.thrift.TException) StorageException(com.thinkaurelius.titan.diskstorage.StorageException) SchemaDisagreementException(org.apache.cassandra.thrift.SchemaDisagreementException)

Example 2 with SchemaDisagreementException

use of org.apache.cassandra.thrift.SchemaDisagreementException in project titan by thinkaurelius.

the class CassandraThriftStoreManager method ensureKeyspaceExists.

private KsDef ensureKeyspaceExists(String keyspaceName) throws NotFoundException, InvalidRequestException, TException, SchemaDisagreementException, StorageException {
    CTConnection connection = null;
    try {
        connection = pool.borrowObject(SYSTEM_KS);
        Cassandra.Client client = connection.getClient();
        try {
            // Side effect: throws Exception if keyspaceName doesn't exist
            // Don't remove
            client.set_keyspace(keyspaceName);
            client.set_keyspace(SYSTEM_KS);
            log.debug("Found existing keyspace {}", keyspaceName);
        } catch (InvalidRequestException e) {
            // Keyspace didn't exist; create it
            log.debug("Creating keyspace {}...", keyspaceName);
            KsDef ksdef = new KsDef().setName(keyspaceName).setCf_defs(// cannot be null but can be empty
            new LinkedList<CfDef>()).setStrategy_class("org.apache.cassandra.locator.SimpleStrategy").setStrategy_options(ImmutableMap.of("replication_factor", String.valueOf(replicationFactor)));
            client.set_keyspace(SYSTEM_KS);
            try {
                client.system_add_keyspace(ksdef);
                log.debug("Created keyspace {}", keyspaceName);
            } catch (InvalidRequestException ire) {
                log.error("system_add_keyspace failed for keyspace=" + keyspaceName, ire);
                throw ire;
            }
        }
        return client.describe_keyspace(keyspaceName);
    } catch (Exception e) {
        throw new TemporaryStorageException(e);
    } finally {
        pool.returnObjectUnsafe(SYSTEM_KS, connection);
    }
}
Also used : CTConnection(com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnection) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) Cassandra(org.apache.cassandra.thrift.Cassandra) InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException) KsDef(org.apache.cassandra.thrift.KsDef) LinkedList(java.util.LinkedList) NotFoundException(org.apache.cassandra.thrift.NotFoundException) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) TException(org.apache.thrift.TException) StorageException(com.thinkaurelius.titan.diskstorage.StorageException) SchemaDisagreementException(org.apache.cassandra.thrift.SchemaDisagreementException)

Example 3 with SchemaDisagreementException

use of org.apache.cassandra.thrift.SchemaDisagreementException in project titan by thinkaurelius.

the class CassandraThriftStoreManager method createColumnFamily.

private void createColumnFamily(Cassandra.Client client, String ksName, String cfName, String comparator) throws StorageException {
    CfDef createColumnFamily = new CfDef();
    createColumnFamily.setName(cfName);
    createColumnFamily.setKeyspace(ksName);
    createColumnFamily.setComparator_type(comparator);
    ImmutableMap.Builder<String, String> compressionOptions = new ImmutableMap.Builder<String, String>();
    if (compressionEnabled) {
        compressionOptions.put("sstable_compression", compressionClass).put("chunk_length_kb", Integer.toString(compressionChunkSizeKB));
    }
    createColumnFamily.setCompression_options(compressionOptions.build());
    // Hard-coded caching settings
    if (cfName.startsWith(Backend.EDGESTORE_NAME)) {
        createColumnFamily.setCaching("keys_only");
    } else if (cfName.startsWith(Backend.VERTEXINDEX_STORE_NAME)) {
        createColumnFamily.setCaching("rows_only");
    }
    log.debug("Adding column family {} to keyspace {}...", cfName, ksName);
    try {
        client.system_add_column_family(createColumnFamily);
    } catch (SchemaDisagreementException e) {
        throw new TemporaryStorageException("Error in setting up column family", e);
    } catch (Exception e) {
        throw new PermanentStorageException(e);
    }
    log.debug("Added column family {} to keyspace {}.", cfName, ksName);
}
Also used : TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) SchemaDisagreementException(org.apache.cassandra.thrift.SchemaDisagreementException) CfDef(org.apache.cassandra.thrift.CfDef) ImmutableMap(com.google.common.collect.ImmutableMap) NotFoundException(org.apache.cassandra.thrift.NotFoundException) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) TException(org.apache.thrift.TException) StorageException(com.thinkaurelius.titan.diskstorage.StorageException) SchemaDisagreementException(org.apache.cassandra.thrift.SchemaDisagreementException)

Aggregations

PermanentStorageException (com.thinkaurelius.titan.diskstorage.PermanentStorageException)3 StorageException (com.thinkaurelius.titan.diskstorage.StorageException)3 TemporaryStorageException (com.thinkaurelius.titan.diskstorage.TemporaryStorageException)3 InvalidRequestException (org.apache.cassandra.thrift.InvalidRequestException)3 NotFoundException (org.apache.cassandra.thrift.NotFoundException)3 SchemaDisagreementException (org.apache.cassandra.thrift.SchemaDisagreementException)3 TException (org.apache.thrift.TException)3 CTConnection (com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnection)2 Cassandra (org.apache.cassandra.thrift.Cassandra)2 CfDef (org.apache.cassandra.thrift.CfDef)2 KsDef (org.apache.cassandra.thrift.KsDef)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 LinkedList (java.util.LinkedList)1