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