Search in sources :

Example 6 with NotFoundException

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

the class TrackerManager method getCurrentJobtrackerLocation.

/**
 * Retrieves the current job tracker IP.
 *
 * @return the current job tracker IP
 * @throws TrackerManagerException
 */
public static InetAddress getCurrentJobtrackerLocation() throws TrackerManagerException {
    ReadCommand rc = new SliceByNamesReadCommand(BriskSchema.KEYSPACE_NAME, currentJobtrackerKey, cp, Arrays.asList(columnName));
    String result;
    try {
        List<Row> rows = StorageProxy.read(Arrays.asList(rc), ConsistencyLevel.QUORUM);
        IColumn col = validateAndGetColumn(rows, columnName);
        // ByteBuffer util duplicates for us the value.
        result = ByteBufferUtil.string(col.value());
        return InetAddress.getByName(result);
    } catch (NotFoundException e) {
        return null;
    } catch (Exception e) {
        throw new TrackerManagerException(e);
    }
}
Also used : IColumn(org.apache.cassandra.db.IColumn) SliceByNamesReadCommand(org.apache.cassandra.db.SliceByNamesReadCommand) ReadCommand(org.apache.cassandra.db.ReadCommand) SliceByNamesReadCommand(org.apache.cassandra.db.SliceByNamesReadCommand) NotFoundException(org.apache.cassandra.thrift.NotFoundException) Row(org.apache.cassandra.db.Row) NotFoundException(org.apache.cassandra.thrift.NotFoundException)

Example 7 with NotFoundException

use of org.apache.cassandra.thrift.NotFoundException 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 8 with NotFoundException

use of org.apache.cassandra.thrift.NotFoundException in project scale7-pelops by s7.

the class Operand method tryOperation.

protected <ReturnType> ReturnType tryOperation(IOperation<ReturnType> operation, OperandPolicy operandPolicy) throws PelopsException {
    Set<String> avoidNodes = null;
    Exception lastException = null;
    int retries = 0;
    do {
        // Get a connection to a Cassandra node
        IPooledConnection conn = null;
        try {
            conn = thrift.getConnectionExcept(avoidNodes);
        } catch (Exception e) {
            // the pool is responsible for blocking and waiting for a connection, so don't retry
            throw operandPolicy.getExceptionTranslator().translate(e);
        }
        try {
            // Return result!
            return operation.execute(conn);
        } catch (Exception e) {
            // Should we try again?
            if (e instanceof TimedOutException || e instanceof TTransportException || e instanceof UnavailableException) {
                logger.warn("Operation failed as result of network exception. Connection to node {} is being marked as corrupt " + "(and will probably be be destroyed). Cause of failure is {}", conn.getNode().getAddress(), e);
                // This connection is "broken" by network timeout or other problem.
                conn.corrupted();
                // to avoid create the set for every request create the set here
                if (avoidNodes == null)
                    avoidNodes = new HashSet<String>(10);
                avoidNodes.add(conn.getNode().getAddress());
                retries++;
                lastException = e;
            } else if (e instanceof NotFoundException) {
                // Re-throw application-level exceptions immediately.
                throw operandPolicy.getExceptionTranslator().translate(e);
            } else {
                // This connection is "broken" by network timeout or other problem.
                conn.corrupted();
                // Re-throw application-level exceptions immediately.
                throw operandPolicy.getExceptionTranslator().translate(e);
            }
        } finally {
            conn.release();
        }
    } while (retries < operandPolicy.getMaxOpRetries());
    throw operandPolicy.getExceptionTranslator().translate(lastException);
}
Also used : TimedOutException(org.apache.cassandra.thrift.TimedOutException) UnavailableException(org.apache.cassandra.thrift.UnavailableException) TTransportException(org.apache.thrift.transport.TTransportException) NotFoundException(org.apache.cassandra.thrift.NotFoundException) TimedOutException(org.apache.cassandra.thrift.TimedOutException) PelopsException(org.scale7.cassandra.pelops.exceptions.PelopsException) UnavailableException(org.apache.cassandra.thrift.UnavailableException) TTransportException(org.apache.thrift.transport.TTransportException) NotFoundException(org.apache.cassandra.thrift.NotFoundException) IPooledConnection(org.scale7.cassandra.pelops.pool.IThriftPool.IPooledConnection)

Aggregations

NotFoundException (org.apache.cassandra.thrift.NotFoundException)8 TableReference (com.palantir.atlasdb.keyvalue.api.TableReference)2 PermanentStorageException (com.thinkaurelius.titan.diskstorage.PermanentStorageException)2 StorageException (com.thinkaurelius.titan.diskstorage.StorageException)2 TemporaryStorageException (com.thinkaurelius.titan.diskstorage.TemporaryStorageException)2 CTConnection (com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnection)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 HashMultimap (com.google.common.collect.HashMultimap)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables (com.google.common.collect.Iterables)1 Maps (com.google.common.collect.Maps)1 Multimap (com.google.common.collect.Multimap)1 RangeMap (com.google.common.collect.RangeMap)1 Sets (com.google.common.collect.Sets)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 AsyncInitializer (com.palantir.async.initializer.AsyncInitializer)1 AtlasDbConstants (com.palantir.atlasdb.AtlasDbConstants)1 CassandraKeyValueServiceConfig (com.palantir.atlasdb.cassandra.CassandraKeyValueServiceConfig)1 CassandraKeyValueServiceRuntimeConfig (com.palantir.atlasdb.cassandra.CassandraKeyValueServiceRuntimeConfig)1