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);
}
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;
}
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/
}
}
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);
}
}
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());
}
Aggregations