Search in sources :

Example 1 with NotFoundException

use of org.apache.cassandra.thrift.NotFoundException in project atlasdb by palantir.

the class SchemaMutationLock method queryExistingLockColumn.

private Optional<Column> queryExistingLockColumn(CassandraClient client) throws TException {
    TableReference lockTableRef = lockTable.get();
    Column existingColumn = null;
    ConsistencyLevel localQuorum = ConsistencyLevel.LOCAL_QUORUM;
    try {
        ColumnOrSuperColumn result = queryRunner.run(client, lockTableRef, () -> client.get(lockTableRef, getGlobalDdlLockRowName(), getGlobalDdlLockColumnName(), localQuorum));
        existingColumn = result.getColumn();
    } catch (UnavailableException e) {
        throw new InsufficientConsistencyException("Checking the schema lock requires " + localQuorum + " Cassandra nodes to be up and available.", e);
    } catch (NotFoundException e) {
        log.debug("No existing schema lock found in table [{}]", SafeArg.of("tableName", lockTableRef));
    }
    return Optional.ofNullable(existingColumn);
}
Also used : ConsistencyLevel(org.apache.cassandra.thrift.ConsistencyLevel) ColumnOrSuperColumn(org.apache.cassandra.thrift.ColumnOrSuperColumn) InsufficientConsistencyException(com.palantir.atlasdb.keyvalue.api.InsufficientConsistencyException) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) Column(org.apache.cassandra.thrift.Column) ColumnOrSuperColumn(org.apache.cassandra.thrift.ColumnOrSuperColumn) UnavailableException(org.apache.cassandra.thrift.UnavailableException) NotFoundException(org.apache.cassandra.thrift.NotFoundException)

Example 2 with NotFoundException

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

the class BriskDBUtil method validateAndGetColumn.

/**
 * Validates that the result is not empty and get the value for the <code>columnName</code> column.
 * @param rows the raw result from StorageProxy.read(....)
 * @param columnName column name
 * @return the Column that was requested if it exists.
 * @throws NotFoundException if the result doesn't exist (including if the value holds a tumbstone)
 */
public static IColumn validateAndGetColumn(List<Row> rows, ByteBuffer columnName) throws NotFoundException {
    if (rows.isEmpty())
        throw new NotFoundException();
    if (rows.size() > 1)
        throw new RuntimeException("Block id returned more than one row");
    Row row = rows.get(0);
    if (row.cf == null)
        throw new NotFoundException();
    IColumn col = row.cf.getColumn(columnName);
    if (col == null || !col.isLive())
        throw new NotFoundException();
    return col;
}
Also used : IColumn(org.apache.cassandra.db.IColumn) NotFoundException(org.apache.cassandra.thrift.NotFoundException) Row(org.apache.cassandra.db.Row)

Example 3 with NotFoundException

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

the class MetaStorePersisterTest method testEntityDeletion.

@Test
public void testEntityDeletion() throws Exception {
    setupClient();
    Database database = new Database();
    database.setName("dbname");
    database.setDescription("description");
    database.setLocationUri("uri");
    database.setParameters(new HashMap<String, String>());
    metaStorePersister.save(database.metaDataMap, database, database.getName());
    Table table = new Table();
    table.setDbName("dbname");
    table.setTableName("table_one");
    metaStorePersister.save(table.metaDataMap, table, table.getDbName());
    Database foundDb = new Database();
    foundDb.setName("dbname");
    metaStorePersister.load(foundDb, "dbname");
    assertEquals(database, foundDb);
    Table foundTable = new Table();
    foundTable.setDbName(table.getDbName());
    foundTable.setTableName(table.getTableName());
    metaStorePersister.load(foundTable, "dbname");
    assertEquals(table, foundTable);
    metaStorePersister.remove(foundTable, "dbname");
    metaStorePersister.remove(foundDb, "dbname");
    try {
        metaStorePersister.load(foundTable, "dbname");
        fail();
        metaStorePersister.load(foundDb, "dbname");
        fail();
    } catch (NotFoundException e) {
    // win! \o/
    }
}
Also used : Table(org.apache.hadoop.hive.metastore.api.Table) Database(org.apache.hadoop.hive.metastore.api.Database) NotFoundException(org.apache.cassandra.thrift.NotFoundException)

Example 4 with NotFoundException

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

the class CassandraThriftStoreManager method clearStorage.

/**
 * Connect to Cassandra via Thrift on the specified host and port and attempt to truncate the named keyspace.
 * <p/>
 * This is a utility method intended mainly for testing. It is
 * equivalent to issuing 'truncate <cf>' for each of the column families in keyspace using
 * the cassandra-cli tool.
 * <p/>
 * Using truncate is better for a number of reasons, most significantly because it doesn't
 * involve any schema modifications which can take time to propagate across the cluster such
 * leaves nodes in the inconsistent state and could result in read/write failures.
 * Any schema modifications are discouraged until there is no traffic to Keyspace or ColumnFamilies.
 *
 * @throws StorageException if any checked Thrift or UnknownHostException is thrown in the body of this method
 */
public void clearStorage() throws StorageException {
    openStores.clear();
    // "log prefix"
    final String lp = "ClearStorage: ";
    /*
         * log4j is capable of automatically writing the name of a method that
         * generated a log message, but the docs warn that "generating caller
         * location information is extremely slow and should be avoided unless
         * execution speed is not an issue."
         */
    CTConnection conn = null;
    try {
        conn = pool.borrowObject(SYSTEM_KS);
        Cassandra.Client client = conn.getClient();
        KsDef ksDef;
        try {
            client.set_keyspace(keySpaceName);
            ksDef = client.describe_keyspace(keySpaceName);
        } catch (NotFoundException e) {
            log.debug(lp + "Keyspace {} does not exist, not attempting to truncate.", keySpaceName);
            return;
        } catch (InvalidRequestException e) {
            log.debug(lp + "InvalidRequestException when attempting to describe keyspace {}, not attempting to truncate.", keySpaceName);
            return;
        }
        if (null == ksDef) {
            log.debug(lp + "Received null KsDef for keyspace {}; not truncating its CFs", keySpaceName);
            return;
        }
        List<CfDef> cfDefs = ksDef.getCf_defs();
        if (null == cfDefs) {
            log.debug(lp + "Received empty CfDef list for keyspace {}; not truncating CFs", keySpaceName);
            return;
        }
        for (CfDef cfDef : ksDef.getCf_defs()) {
            client.truncate(cfDef.name);
            log.info(lp + "Truncated CF {} in keyspace {}", cfDef.name, keySpaceName);
        }
    /*
             * Clearing the CTConnectionPool is unnecessary. This method
             * removes no keyspaces. All open Cassandra connections will
             * remain valid.
             */
    } catch (Exception e) {
        throw new TemporaryStorageException(e);
    } finally {
        if (conn != null && conn.getClient() != null) {
            try {
                conn.getClient().set_keyspace(SYSTEM_KS);
            } catch (InvalidRequestException e) {
                log.warn("Failed to reset keyspace", e);
            } catch (TException e) {
                log.warn("Failed to reset keyspace", e);
            }
        }
        pool.returnObjectUnsafe(SYSTEM_KS, conn);
    }
}
Also used : CTConnection(com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnection) TException(org.apache.thrift.TException) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) Cassandra(org.apache.cassandra.thrift.Cassandra) NotFoundException(org.apache.cassandra.thrift.NotFoundException) 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 5 with NotFoundException

use of org.apache.cassandra.thrift.NotFoundException in project atlasdb by palantir.

the class CassandraClientPoolImpl method sanityCheckRingConsistency.

// This method exists to verify a particularly nasty bug where cassandra doesn't have a
// consistent ring across all of it's nodes.  One node will think it owns more than the others
// think it does and they will not send writes to it, but it will respond to requests
// acting like it does.
private void sanityCheckRingConsistency() {
    Multimap<Set<TokenRange>, InetSocketAddress> tokenRangesToHost = HashMultimap.create();
    for (InetSocketAddress host : cassandra.getPools().keySet()) {
        CassandraClient client = null;
        try {
            client = CassandraClientFactory.getClientInternal(host, config);
            try {
                client.describe_keyspace(config.getKeyspaceOrThrow());
            } catch (NotFoundException e) {
                // don't care to check for ring consistency when we're not even fully initialized
                return;
            }
            tokenRangesToHost.put(ImmutableSet.copyOf(client.describe_ring(config.getKeyspaceOrThrow())), host);
        } catch (Exception e) {
            log.warn("Failed to get ring info from host: {}", SafeArg.of("host", CassandraLogHelper.host(host)), e);
        } finally {
            if (client != null) {
                client.getOutputProtocol().getTransport().close();
            }
        }
    }
    if (tokenRangesToHost.isEmpty()) {
        log.warn("Failed to get ring info for entire Cassandra cluster ({});" + " ring could not be checked for consistency.", UnsafeArg.of("keyspace", config.getKeyspaceOrThrow()));
        return;
    }
    if (tokenRangesToHost.keySet().size() == 1) {
        // all nodes agree on a consistent view of the cluster. Good.
        return;
    }
    RuntimeException ex = new IllegalStateException("Hosts have differing ring descriptions." + " This can lead to inconsistent reads and lost data. ");
    log.error("Cassandra does not appear to have a consistent ring across all of its nodes. This could cause us to" + " lose writes. The mapping of token ranges to hosts is:\n{}", UnsafeArg.of("tokenRangesToHost", CassandraLogHelper.tokenRangesToHost(tokenRangesToHost)), ex);
    // provide some easier to grok logging for the two most common cases
    if (tokenRangesToHost.size() > 2) {
        tokenRangesToHost.asMap().entrySet().stream().filter(entry -> entry.getValue().size() == 1).forEach(entry -> {
            // We've checked above that entry.getValue() has one element, so we never NPE here.
            String hostString = CassandraLogHelper.host(Iterables.getFirst(entry.getValue(), null));
            log.error("Host: {} disagrees with the other nodes about the ring state.", SafeArg.of("host", hostString));
        });
    }
    if (tokenRangesToHost.keySet().size() == 2) {
        ImmutableList<Set<TokenRange>> sets = ImmutableList.copyOf(tokenRangesToHost.keySet());
        Set<TokenRange> set1 = sets.get(0);
        Set<TokenRange> set2 = sets.get(1);
        log.error("Hosts are split. group1: {} group2: {}", SafeArg.of("hosts1", CassandraLogHelper.collectionOfHosts(tokenRangesToHost.get(set1))), SafeArg.of("hosts2", CassandraLogHelper.collectionOfHosts(tokenRangesToHost.get(set2))));
    }
    CassandraVerifier.logErrorOrThrow(ex.getMessage(), config.ignoreInconsistentRingChecks());
}
Also used : ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) Iterables(com.google.common.collect.Iterables) CassandraKeyValueServiceConfig(com.palantir.atlasdb.cassandra.CassandraKeyValueServiceConfig) ScheduledFuture(java.util.concurrent.ScheduledFuture) CassandraKeyValueServiceRuntimeConfig(com.palantir.atlasdb.cassandra.CassandraKeyValueServiceRuntimeConfig) LoggerFactory(org.slf4j.LoggerFactory) NotFoundException(org.apache.cassandra.thrift.NotFoundException) Multimap(com.google.common.collect.Multimap) Supplier(java.util.function.Supplier) AsyncInitializer(com.palantir.async.initializer.AsyncInitializer) FakeQosClient(com.palantir.atlasdb.qos.FakeQosClient) CassandraClientPoolMetrics(com.palantir.atlasdb.keyvalue.cassandra.pool.CassandraClientPoolMetrics) SafeArg(com.palantir.logsafe.SafeArg) HashMultimap(com.google.common.collect.HashMultimap) ImmutableList(com.google.common.collect.ImmutableList) PTExecutors(com.palantir.common.concurrent.PTExecutors) Map(java.util.Map) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) TokenRange(org.apache.cassandra.thrift.TokenRange) TableReference(com.palantir.atlasdb.keyvalue.api.TableReference) AtlasDbConstants(com.palantir.atlasdb.AtlasDbConstants) Logger(org.slf4j.Logger) ImmutableSet(com.google.common.collect.ImmutableSet) CassandraService(com.palantir.atlasdb.keyvalue.cassandra.pool.CassandraService) FunctionCheckedException(com.palantir.common.base.FunctionCheckedException) Cell(com.palantir.atlasdb.keyvalue.api.Cell) AutoDelegate(com.palantir.processors.AutoDelegate) Set(java.util.Set) QosClient(com.palantir.atlasdb.qos.QosClient) InetSocketAddress(java.net.InetSocketAddress) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) UnsafeArg(com.palantir.logsafe.UnsafeArg) Optional(java.util.Optional) RangeMap(com.google.common.collect.RangeMap) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) InetSocketAddress(java.net.InetSocketAddress) NotFoundException(org.apache.cassandra.thrift.NotFoundException) NotFoundException(org.apache.cassandra.thrift.NotFoundException) FunctionCheckedException(com.palantir.common.base.FunctionCheckedException) TokenRange(org.apache.cassandra.thrift.TokenRange)

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