use of com.thinkaurelius.titan.diskstorage.PermanentBackendException in project titan by thinkaurelius.
the class BerkeleyJEStoreManager method beginTransaction.
@Override
public BerkeleyJETx beginTransaction(final BaseTransactionConfig txCfg) throws BackendException {
try {
Transaction tx = null;
Configuration effectiveCfg = new MergedConfiguration(txCfg.getCustomOptions(), getStorageConfig());
if (transactional) {
TransactionConfig txnConfig = new TransactionConfig();
ConfigOption.getEnumValue(effectiveCfg.get(ISOLATION_LEVEL), IsolationLevel.class).configure(txnConfig);
tx = environment.beginTransaction(null, txnConfig);
}
BerkeleyJETx btx = new BerkeleyJETx(tx, ConfigOption.getEnumValue(effectiveCfg.get(LOCK_MODE), LockMode.class), txCfg);
if (log.isTraceEnabled()) {
log.trace("Berkeley tx created", new TransactionBegin(btx.toString()));
}
return btx;
} catch (DatabaseException e) {
throw new PermanentBackendException("Could not start BerkeleyJE transaction", e);
}
}
use of com.thinkaurelius.titan.diskstorage.PermanentBackendException in project titan by thinkaurelius.
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);
Transaction tx = getTransaction(txh);
Cursor cursor = null;
final StaticBuffer keyStart = query.getStart();
final StaticBuffer keyEnd = query.getEnd();
final KeySelector selector = query.getKeySelector();
final List<KeyValueEntry> result = new ArrayList<KeyValueEntry>();
try {
DatabaseEntry foundKey = keyStart.as(ENTRY_FACTORY);
DatabaseEntry foundData = new DatabaseEntry();
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));
}
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();
}
};
} catch (Exception e) {
throw new PermanentBackendException(e);
} finally {
try {
if (cursor != null)
cursor.close();
} catch (Exception e) {
throw new PermanentBackendException(e);
}
}
}
use of com.thinkaurelius.titan.diskstorage.PermanentBackendException in project titan by thinkaurelius.
the class HBaseBinaryInputFormat method setConf.
@Override
public void setConf(final Configuration config) {
super.setConf(config);
//config.set(TableInputFormat.SCAN_COLUMN_FAMILY, Backend.EDGESTORE_NAME);
config.set(TableInputFormat.INPUT_TABLE, titanConf.get(HBaseStoreManager.HBASE_TABLE));
//config.set(HConstants.ZOOKEEPER_QUORUM, config.get(TITAN_HADOOP_GRAPH_INPUT_TITAN_STORAGE_HOSTNAME));
config.set(HConstants.ZOOKEEPER_QUORUM, titanConf.get(GraphDatabaseConfiguration.STORAGE_HOSTS)[0]);
// if (basicConf.get(TITAN_HADOOP_GRAPH_INPUT_TITAN_STORAGE_PORT, null) != null)
if (titanConf.has(GraphDatabaseConfiguration.STORAGE_PORT))
config.set(HConstants.ZOOKEEPER_CLIENT_PORT, String.valueOf(titanConf.get(GraphDatabaseConfiguration.STORAGE_PORT)));
config.set("autotype", "none");
log.debug("hbase.security.authentication={}", config.get("hbase.security.authentication"));
Scan scanner = new Scan();
String cfName = mrConf.get(TitanHadoopConfiguration.COLUMN_FAMILY_NAME);
// TODO the space-saving short name mapping leaks from HBaseStoreManager here
if (titanConf.get(HBaseStoreManager.SHORT_CF_NAMES)) {
try {
cfName = HBaseStoreManager.shortenCfName(cfName);
} catch (PermanentBackendException e) {
throw new RuntimeException(e);
}
}
scanner.addFamily(cfName.getBytes());
inputCFBytes = Bytes.toBytes(cfName);
//scanner.setFilter(getColumnFilter(titanSetup.inputSlice(this.vertexQuery))); // TODO
//TODO (minor): should we set other options in http://hbase.apache.org/apidocs/org/apache/hadoop/hbase/client/Scan.html for optimization?
Method converter;
try {
converter = TableMapReduceUtil.class.getDeclaredMethod("convertScanToString", Scan.class);
converter.setAccessible(true);
config.set(TableInputFormat.SCAN, (String) converter.invoke(null, scanner));
} catch (Exception e) {
throw new RuntimeException(e);
}
this.tableInputFormat.setConf(config);
}
use of com.thinkaurelius.titan.diskstorage.PermanentBackendException in project titan by thinkaurelius.
the class BackendOperation method executeDirect.
public static final <V> V executeDirect(Callable<V> exe, Duration totalWaitTime) throws BackendException {
Preconditions.checkArgument(!totalWaitTime.isZero(), "Need to specify a positive waitTime: %s", totalWaitTime);
long maxTime = System.currentTimeMillis() + totalWaitTime.toMillis();
Duration waitTime = pertubateTime(BASE_REATTEMPT_TIME);
BackendException lastException;
while (true) {
try {
return exe.call();
} catch (final Throwable e) {
//Find inner-most StorageException
Throwable ex = e;
BackendException storeEx = null;
do {
if (ex instanceof BackendException)
storeEx = (BackendException) ex;
} while ((ex = ex.getCause()) != null);
if (storeEx != null && storeEx instanceof TemporaryBackendException) {
lastException = storeEx;
} else if (e instanceof BackendException) {
throw (BackendException) e;
} else {
throw new PermanentBackendException("Permanent exception while executing backend operation " + exe.toString(), e);
}
}
//Wait and retry
assert lastException != null;
if (System.currentTimeMillis() + waitTime.toMillis() < maxTime) {
log.info("Temporary exception during backend operation [" + exe.toString() + "]. Attempting backoff retry.", lastException);
try {
Thread.sleep(waitTime.toMillis());
} catch (InterruptedException r) {
throw new PermanentBackendException("Interrupted while waiting to retry failed backend operation", r);
}
} else {
break;
}
waitTime = pertubateTime(waitTime.multipliedBy(2));
}
throw new TemporaryBackendException("Could not successfully complete backend operation due to repeated temporary exceptions after " + totalWaitTime, lastException);
}
use of com.thinkaurelius.titan.diskstorage.PermanentBackendException in project atlas by apache.
the class Solr5Index method query.
@Override
public Iterable<RawQuery.Result<String>> query(RawQuery query, KeyInformation.IndexRetriever informations, BaseTransaction tx) throws BackendException {
List<RawQuery.Result<String>> result;
String collection = query.getStore();
String keyIdField = getKeyFieldId(collection);
SolrQuery solrQuery = new SolrQuery(query.getQuery()).addField(keyIdField).setIncludeScore(true).setStart(query.getOffset()).setRows(query.hasLimit() ? query.getLimit() : maxResults);
try {
QueryResponse response = solrClient.query(collection, solrQuery);
if (logger.isDebugEnabled())
logger.debug("Executed query [{}] in {} ms", query.getQuery(), response.getElapsedTime());
int totalHits = response.getResults().size();
if (!query.hasLimit() && totalHits >= maxResults) {
logger.warn("Query result set truncated to first [{}] elements for query: {}", maxResults, query);
}
result = new ArrayList<>(totalHits);
for (SolrDocument hit : response.getResults()) {
double score = Double.parseDouble(hit.getFieldValue("score").toString());
result.add(new RawQuery.Result<>(hit.getFieldValue(keyIdField).toString(), score));
}
} catch (IOException e) {
logger.error("Query did not complete : ", e);
throw new PermanentBackendException(e);
} catch (SolrServerException e) {
logger.error("Unable to query Solr index.", e);
throw new PermanentBackendException(e);
}
return result;
}
Aggregations