use of com.netflix.astyanax.connectionpool.exceptions.ConnectionException in project titan by thinkaurelius.
the class AstyanaxKeyColumnValueStore method getKeys.
@Override
public KeyIterator getKeys(KeyRangeQuery query, StoreTransaction txh) throws BackendException {
// this query could only be done when byte-ordering partitioner is used
// because Cassandra operates on tokens internally which means that even contiguous
// range of keys (e.g. time slice) with random partitioner could produce disjoint set of tokens
// returning ambiguous results to the user.
Partitioner partitioner = storeManager.getPartitioner();
if (partitioner != Partitioner.BYTEORDER)
throw new PermanentBackendException("getKeys(KeyRangeQuery could only be used with byte-ordering partitioner.");
ByteBuffer start = query.getKeyStart().asByteBuffer(), end = query.getKeyEnd().asByteBuffer();
RowSliceQuery rowSlice = keyspace.prepareQuery(columnFamily).setConsistencyLevel(getTx(txh).getReadConsistencyLevel().getAstyanax()).withRetryPolicy(retryPolicy.duplicate()).getKeyRange(start, end, null, null, Integer.MAX_VALUE);
// Astyanax is bad at builder pattern :(
rowSlice.withColumnRange(query.getSliceStart().asByteBuffer(), query.getSliceEnd().asByteBuffer(), false, query.getLimit());
// Omit final the query's keyend from the result, if present in result
final Rows<ByteBuffer, ByteBuffer> r;
try {
r = ((OperationResult<Rows<ByteBuffer, ByteBuffer>>) rowSlice.execute()).getResult();
} catch (ConnectionException e) {
throw new TemporaryBackendException(e);
}
Iterator<Row<ByteBuffer, ByteBuffer>> i = Iterators.filter(r.iterator(), new KeySkipPredicate(query.getKeyEnd().asByteBuffer()));
return new RowIterator(i, query);
}
use of com.netflix.astyanax.connectionpool.exceptions.ConnectionException in project titan by thinkaurelius.
the class AstyanaxStoreManager method getCompressionOptions.
@Override
public Map<String, String> getCompressionOptions(String cf) throws BackendException {
try {
Keyspace k = keyspaceContext.getClient();
KeyspaceDefinition kdef = k.describeKeyspace();
if (null == kdef) {
throw new PermanentBackendException("Keyspace " + k.getKeyspaceName() + " is undefined");
}
ColumnFamilyDefinition cfdef = kdef.getColumnFamily(cf);
if (null == cfdef) {
throw new PermanentBackendException("Column family " + cf + " is undefined");
}
return cfdef.getCompressionOptions();
} catch (ConnectionException e) {
throw new PermanentBackendException(e);
}
}
use of com.netflix.astyanax.connectionpool.exceptions.ConnectionException in project titan by thinkaurelius.
the class AstyanaxStoreManager method ensureKeyspaceExists.
private void ensureKeyspaceExists(Cluster cl) throws BackendException {
KeyspaceDefinition ksDef;
try {
ksDef = cl.describeKeyspace(keySpaceName);
if (null != ksDef && ksDef.getName().equals(keySpaceName)) {
log.debug("Found keyspace {}", keySpaceName);
return;
}
} catch (ConnectionException e) {
log.debug("Failed to describe keyspace {}", keySpaceName);
}
log.debug("Creating keyspace {}...", keySpaceName);
try {
ksDef = cl.makeKeyspaceDefinition().setName(keySpaceName).setStrategyClass(storageConfig.get(REPLICATION_STRATEGY)).setStrategyOptions(strategyOptions);
cl.addKeyspace(ksDef);
log.debug("Created keyspace {}", keySpaceName);
} catch (ConnectionException e) {
log.debug("Failed to create keyspace {}", keySpaceName);
throw new TemporaryBackendException(e);
}
}
use of com.netflix.astyanax.connectionpool.exceptions.ConnectionException in project titan by thinkaurelius.
the class AstyanaxKeyColumnValueStore method getKeys.
@Override
public KeyIterator getKeys(@Nullable SliceQuery sliceQuery, StoreTransaction txh) throws BackendException {
if (storeManager.getPartitioner() != Partitioner.RANDOM)
throw new PermanentBackendException("This operation is only allowed when random partitioner (md5 or murmur3) is used.");
AllRowsQuery allRowsQuery = keyspace.prepareQuery(columnFamily).getAllRows();
if (sliceQuery != null) {
allRowsQuery.withColumnRange(sliceQuery.getSliceStart().asByteBuffer(), sliceQuery.getSliceEnd().asByteBuffer(), false, sliceQuery.getLimit());
}
Rows<ByteBuffer, ByteBuffer> result;
try {
/* Note: we need to fetch columns for each row as well to remove "range ghosts" */
OperationResult op = // pre-fetch that many rows at a time
allRowsQuery.setRowLimit(storeManager.getPageSize()).setConcurrencyLevel(// one execution thread for fetching portion of rows
1).setExceptionCallback(new ExceptionCallback() {
private int retries = 0;
@Override
public boolean onException(ConnectionException e) {
try {
// make 3 re-tries
return retries > 2;
} finally {
retries++;
}
}
}).execute();
result = ((OperationResult<Rows<ByteBuffer, ByteBuffer>>) op).getResult();
} catch (ConnectionException e) {
throw new PermanentBackendException(e);
}
return new RowIterator(result.iterator(), sliceQuery);
}
use of com.netflix.astyanax.connectionpool.exceptions.ConnectionException in project zuul by Netflix.
the class HystrixCassandraPut method run.
@Override
protected Void run() throws Exception {
try {
MutationBatch m = keyspace.prepareMutationBatch().setConsistencyLevel(ConsistencyLevel.CL_QUORUM);
// Setting columns in a standard column
ColumnListMutation<String> cm = m.withRow(columnFamily, rowKey);
for (String key : attributes.keySet()) {
Object o = attributes.get(key);
if (o != null) {
// unfortunately the 'putColumn' method does not nicely figure out what type the Object is so we need to do it manually
if (o instanceof String) {
cm.putColumn(key, (String) o, ttlSeconds);
} else if (o instanceof Boolean) {
cm.putColumn(key, (Boolean) o, ttlSeconds);
} else if (o instanceof Integer) {
cm.putColumn(key, (Integer) o, ttlSeconds);
} else if (o instanceof Long) {
cm.putColumn(key, (Long) o, ttlSeconds);
} else if (o instanceof Double) {
cm.putColumn(key, (Double) o, ttlSeconds);
} else if (o instanceof Date) {
cm.putColumn(key, (Date) o, ttlSeconds);
} else if (o instanceof byte[]) {
cm.putColumn(key, (byte[]) o, ttlSeconds);
} else if (o instanceof ByteBuffer) {
cm.putColumn(key, (ByteBuffer) o, ttlSeconds);
} else {
throw new IllegalArgumentException("Unsupported object instance type: " + o.getClass().getSimpleName());
}
}
}
m.execute();
return null;
} catch (ConnectionException e) {
throw e;
}
}
Aggregations