use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.
the class BerkeleyJEKeyValueStore method getSlice.
@Override
public RecordIterator<KeyValueEntry> getSlice(KVQuery query, StoreTransaction txh) throws BackendException {
log.trace("beginning db={}, op=getSlice, tx={}", name, txh);
final Transaction tx = getTransaction(txh);
final StaticBuffer keyStart = query.getStart();
final StaticBuffer keyEnd = query.getEnd();
final KeySelector selector = query.getKeySelector();
final List<KeyValueEntry> result = new ArrayList<>();
final DatabaseEntry foundKey = keyStart.as(ENTRY_FACTORY);
final DatabaseEntry foundData = new DatabaseEntry();
try (final Cursor cursor = db.openCursor(tx, null)) {
OperationStatus status = cursor.getSearchKeyRange(foundKey, foundData, getLockMode(txh));
// Iterate until given condition is satisfied or end of records
while (status == OperationStatus.SUCCESS) {
StaticBuffer key = getBuffer(foundKey);
if (key.compareTo(keyEnd) >= 0)
break;
if (selector.include(key)) {
result.add(new KeyValueEntry(key, getBuffer(foundData)));
}
if (selector.reachedLimit())
break;
status = cursor.getNext(foundKey, foundData, getLockMode(txh));
}
} catch (Exception e) {
throw new PermanentBackendException(e);
}
log.trace("db={}, op=getSlice, tx={}, resultcount={}", name, txh, result.size());
return new RecordIterator<KeyValueEntry>() {
private final Iterator<KeyValueEntry> entries = result.iterator();
@Override
public boolean hasNext() {
return entries.hasNext();
}
@Override
public KeyValueEntry next() {
return entries.next();
}
@Override
public void close() {
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
}
use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.
the class AstyanaxStoreManager method getRetryPolicy.
private static RetryPolicy getRetryPolicy(String serializedRetryPolicy) throws BackendException {
String[] tokens = serializedRetryPolicy.split(",");
String policyClassName = tokens[0];
int argCount = tokens.length - 1;
Integer[] args = new Integer[argCount];
for (int i = 1; i < tokens.length; i++) {
args[i - 1] = Integer.valueOf(tokens[i]);
}
try {
RetryPolicy rp = instantiate(policyClassName, args, serializedRetryPolicy);
log.debug("Instantiated RetryPolicy object {} from config string \"{}\"", rp, serializedRetryPolicy);
return rp;
} catch (Exception e) {
throw new PermanentBackendException("Failed to instantiate Astyanax Retry Policy class", e);
}
}
use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.
the class CassandraThriftStoreManager method ensureColumnFamilyExists.
private void ensureColumnFamilyExists(String ksName, String cfName) throws BackendException {
CTConnection conn = null;
try {
KsDef keyspaceDef = ensureKeyspaceExists(ksName);
conn = pool.borrowObject(ksName);
Cassandra.Client client = conn.getClient();
log.debug("Looking up metadata on keyspace {}...", ksName);
boolean foundColumnFamily = false;
for (CfDef cfDef : keyspaceDef.getCf_defs()) {
String curCfName = cfDef.getName();
if (curCfName.equals(cfName))
foundColumnFamily = true;
}
if (!foundColumnFamily) {
createColumnFamily(client, ksName, cfName, "org.apache.cassandra.db.marshal.BytesType");
} else {
log.debug("Keyspace {} and ColumnFamily {} were found.", ksName, cfName);
}
} catch (SchemaDisagreementException e) {
throw new TemporaryBackendException(e);
} catch (Exception e) {
throw new PermanentBackendException(e);
} finally {
pool.returnObjectUnsafe(ksName, conn);
}
}
use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.
the class CassandraThriftStoreManager method getCompressionOptions.
@Override
public Map<String, String> getCompressionOptions(String cf) throws BackendException {
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 TemporaryBackendException(e);
} finally {
pool.returnObjectUnsafe(keySpaceName, conn);
}
}
use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.
the class CassandraThriftStoreManager method getLocalKeyPartition.
@Override
public List<KeyRange> getLocalKeyPartition() throws BackendException {
CTConnection conn = null;
IPartitioner partitioner = getCassandraPartitioner();
if (!(partitioner instanceof AbstractByteOrderedPartitioner))
throw new UnsupportedOperationException("getLocalKeyPartition() only supported by byte ordered partitioner.");
Token.TokenFactory tokenFactory = partitioner.getTokenFactory();
try {
// Resist the temptation to describe SYSTEM_KS. It has no ring.
// Instead, we'll create our own keyspace (or check that it exists), then describe it.
ensureKeyspaceExists(keySpaceName);
conn = pool.borrowObject(keySpaceName);
final List<TokenRange> ranges = conn.getClient().describe_ring(keySpaceName);
final List<KeyRange> keyRanges = new ArrayList<>(ranges.size());
for (TokenRange range : ranges) {
if (!NetworkUtil.hasLocalAddress(range.endpoints))
continue;
keyRanges.add(CassandraHelper.transformRange(tokenFactory.fromString(range.start_token), tokenFactory.fromString(range.end_token)));
}
return keyRanges;
} catch (Exception e) {
throw CassandraThriftKeyColumnValueStore.convertException(e);
} finally {
pool.returnObjectUnsafe(keySpaceName, conn);
}
}
Aggregations