Search in sources :

Example 26 with TemporaryStorageException

use of com.thinkaurelius.titan.diskstorage.TemporaryStorageException 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)

Example 27 with TemporaryStorageException

use of com.thinkaurelius.titan.diskstorage.TemporaryStorageException in project titan by thinkaurelius.

the class CassandraThriftStoreManager method getCompressionOptions.

@Override
public Map<String, String> getCompressionOptions(String cf) throws StorageException {
    CTConnection conn = null;
    Map<String, String> result = null;
    try {
        conn = pool.borrowObject(keySpaceName);
        Cassandra.Client client = conn.getClient();
        KsDef ksDef = client.describe_keyspace(keySpaceName);
        for (CfDef cfDef : ksDef.getCf_defs()) {
            if (null != cfDef && cfDef.getName().equals(cf)) {
                result = cfDef.getCompression_options();
                break;
            }
        }
        return result;
    } catch (InvalidRequestException e) {
        log.debug("Keyspace {} does not exist", keySpaceName);
        return null;
    } catch (Exception e) {
        throw new TemporaryStorageException(e);
    } finally {
        pool.returnObjectUnsafe(keySpaceName, conn);
    }
}
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) 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 28 with TemporaryStorageException

use of com.thinkaurelius.titan.diskstorage.TemporaryStorageException in project titan by thinkaurelius.

the class CTConnectionFactory method validateSchemaIsSettled.

/* This method was adapted from cassandra 0.7.5 cli/CliClient.java */
public static void validateSchemaIsSettled(Cassandra.Client thriftClient, String currentVersionId) throws InterruptedException, StorageException {
    log.debug("Waiting for Cassandra schema propagation...");
    Map<String, List<String>> versions = null;
    final TimeUUIDType ti = TimeUUIDType.instance;
    final long start = System.currentTimeMillis();
    long lastTry = 0;
    final long limit = start + SCHEMA_WAIT_MAX;
    final long minSleep = SCHEMA_WAIT_INCREMENT;
    boolean inAgreement = false;
    outer: while (limit - System.currentTimeMillis() >= 0 && !inAgreement) {
        // Block for a little while if we're looping too fast
        final long now = System.currentTimeMillis();
        long sinceLast = now - lastTry;
        long willSleep = minSleep - sinceLast;
        if (0 < willSleep) {
            log.debug("Schema not yet propagated; " + "rechecking in {} ms", willSleep);
            Thread.sleep(willSleep);
        }
        // Issue thrift query
        try {
            lastTry = System.currentTimeMillis();
            // getting schema version for nodes of the ring
            versions = thriftClient.describe_schema_versions();
        } catch (Exception e) {
            throw new PermanentStorageException("Failed to fetch Cassandra Thrift schema versions: " + ((e instanceof InvalidRequestException) ? ((InvalidRequestException) e).getWhy() : e.getMessage()));
        }
        int nodeCount = 0;
        // Check schema version
        UUID benchmark = UUID.fromString(currentVersionId);
        ByteBuffer benchmarkBB = ti.decompose(benchmark);
        for (String version : versions.keySet()) {
            if (version.equals(StorageProxy.UNREACHABLE)) {
                nodeCount += versions.get(version).size();
                continue;
            }
            UUID uuid = UUID.fromString(version);
            ByteBuffer uuidBB = ti.decompose(uuid);
            if (-1 < ti.compare(uuidBB, benchmarkBB)) {
                log.debug("Version {} equals or comes after required version {}", uuid, benchmark);
                nodeCount += versions.get(version).size();
                continue;
            }
            continue outer;
        }
        log.debug("Found {} unreachable or out-of-date Cassandra nodes", nodeCount);
        inAgreement = true;
    }
    if (null == versions) {
        throw new TemporaryStorageException("Couldn't contact Cassandra nodes before timeout");
    }
    if (versions.containsKey(StorageProxy.UNREACHABLE))
        log.warn("Warning: unreachable nodes: {}", Joiner.on(", ").join(versions.get(StorageProxy.UNREACHABLE)));
    if (!inAgreement) {
        throw new TemporaryStorageException("The schema has not settled in " + SCHEMA_WAIT_MAX + " ms. Wanted version " + currentVersionId + "; Versions are " + FBUtilities.toString(versions));
    } else {
        log.debug("Cassandra schema version {} propagated in about {} ms; Versions are {}", new Object[] { currentVersionId, System.currentTimeMillis() - start, FBUtilities.toString(versions) });
    }
}
Also used : TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) TimeUUIDType(org.apache.cassandra.db.marshal.TimeUUIDType) ByteBuffer(java.nio.ByteBuffer) TTransportException(org.apache.thrift.transport.TTransportException) StorageException(com.thinkaurelius.titan.diskstorage.StorageException) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException)

Example 29 with TemporaryStorageException

use of com.thinkaurelius.titan.diskstorage.TemporaryStorageException in project titan by thinkaurelius.

the class AstyanaxOrderedKeyColumnValueStore method containsKey.

@Override
public boolean containsKey(StaticBuffer key, StoreTransaction txh) throws StorageException {
    try {
        // See getSlice() below for a warning suppression justification
        @SuppressWarnings("rawtypes") RowQuery rq = (RowQuery) keyspace.prepareQuery(columnFamily).withRetryPolicy(retryPolicy.duplicate()).setConsistencyLevel(getTx(txh).getReadConsistencyLevel().getAstyanaxConsistency()).getKey(key.asByteBuffer());
        @SuppressWarnings("unchecked") OperationResult<ColumnList<ByteBuffer>> r = rq.withColumnRange(EMPTY, EMPTY, false, 1).execute();
        return 0 < r.getResult().size();
    } catch (ConnectionException e) {
        throw new TemporaryStorageException(e);
    }
}
Also used : TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) RowQuery(com.netflix.astyanax.query.RowQuery) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException)

Example 30 with TemporaryStorageException

use of com.thinkaurelius.titan.diskstorage.TemporaryStorageException in project titan by thinkaurelius.

the class AstyanaxOrderedKeyColumnValueStore method getNamesSlice.

public Map<ByteBuffer, List<Entry>> getNamesSlice(List<StaticBuffer> keys, SliceQuery query, StoreTransaction txh) throws StorageException {
    ByteBuffer[] requestKeys = new ByteBuffer[keys.size()];
    {
        for (int i = 0; i < keys.size(); i++) {
            requestKeys[i] = keys.get(i).asByteBuffer();
        }
    }
    /*
         * RowQuery<K,C> should be parameterized as
         * RowQuery<ByteBuffer,ByteBuffer>. However, this causes the following
         * compilation error when attempting to call withColumnRange on a
         * RowQuery<ByteBuffer,ByteBuffer> instance:
         *
         * java.lang.Error: Unresolved compilation problem: The method
         * withColumnRange(ByteBuffer, ByteBuffer, boolean, int) is ambiguous
         * for the type RowQuery<ByteBuffer,ByteBuffer>
         *
         * The compiler substitutes ByteBuffer=C for both startColumn and
         * endColumn, compares it to its identical twin with that type
         * hard-coded, and dies.
         *
         */
    RowSliceQuery rq = keyspace.prepareQuery(columnFamily).setConsistencyLevel(getTx(txh).getReadConsistencyLevel().getAstyanaxConsistency()).withRetryPolicy(retryPolicy.duplicate()).getKeySlice(requestKeys);
    // Thank you, Astyanax, for making builder pattern useful :(
    int limit = ((query.hasLimit()) ? query.getLimit() : Integer.MAX_VALUE - 1);
    rq.withColumnRange(query.getSliceStart().asByteBuffer(), query.getSliceEnd().asByteBuffer(), false, limit + 1);
    OperationResult<Rows<ByteBuffer, ByteBuffer>> r;
    try {
        r = (OperationResult<Rows<ByteBuffer, ByteBuffer>>) rq.execute();
    } catch (ConnectionException e) {
        throw new TemporaryStorageException(e);
    }
    return convertResult(r.getResult(), query.getSliceEnd().asByteBuffer(), limit);
}
Also used : RowSliceQuery(com.netflix.astyanax.query.RowSliceQuery) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) ByteBuffer(java.nio.ByteBuffer) StaticByteBuffer(com.thinkaurelius.titan.diskstorage.util.StaticByteBuffer) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException)

Aggregations

TemporaryStorageException (com.thinkaurelius.titan.diskstorage.TemporaryStorageException)37 StorageException (com.thinkaurelius.titan.diskstorage.StorageException)11 PermanentStorageException (com.thinkaurelius.titan.diskstorage.PermanentStorageException)10 IOException (java.io.IOException)10 StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)9 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)6 Test (org.junit.Test)6 CTConnection (com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnection)5 InvalidRequestException (org.apache.cassandra.thrift.InvalidRequestException)5 NotFoundException (org.apache.cassandra.thrift.NotFoundException)5 SchemaDisagreementException (org.apache.cassandra.thrift.SchemaDisagreementException)5 TException (org.apache.thrift.TException)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 ConsistentKeyLockStatus (com.thinkaurelius.titan.diskstorage.locking.consistentkey.ConsistentKeyLockStatus)4 ByteBuffer (java.nio.ByteBuffer)4 Cassandra (org.apache.cassandra.thrift.Cassandra)4 CfDef (org.apache.cassandra.thrift.CfDef)4 KsDef (org.apache.cassandra.thrift.KsDef)4 TitanException (com.thinkaurelius.titan.core.TitanException)3 Entry (com.thinkaurelius.titan.diskstorage.keycolumnvalue.Entry)3