Search in sources :

Example 1 with PermanentBackendException

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);
    }
}
Also used : MergedConfiguration(com.thinkaurelius.titan.diskstorage.configuration.MergedConfiguration) StoreTransaction(com.thinkaurelius.titan.diskstorage.keycolumnvalue.StoreTransaction) Configuration(com.thinkaurelius.titan.diskstorage.configuration.Configuration) MergedConfiguration(com.thinkaurelius.titan.diskstorage.configuration.MergedConfiguration) GraphDatabaseConfiguration(com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration) PermanentBackendException(com.thinkaurelius.titan.diskstorage.PermanentBackendException)

Example 2 with PermanentBackendException

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);
        }
    }
}
Also used : RecordIterator(com.thinkaurelius.titan.diskstorage.util.RecordIterator) PermanentBackendException(com.thinkaurelius.titan.diskstorage.PermanentBackendException) ArrayList(java.util.ArrayList) KeySelector(com.thinkaurelius.titan.diskstorage.keycolumnvalue.keyvalue.KeySelector) BackendException(com.thinkaurelius.titan.diskstorage.BackendException) PermanentBackendException(com.thinkaurelius.titan.diskstorage.PermanentBackendException) StoreTransaction(com.thinkaurelius.titan.diskstorage.keycolumnvalue.StoreTransaction) RecordIterator(com.thinkaurelius.titan.diskstorage.util.RecordIterator) Iterator(java.util.Iterator) StaticBuffer(com.thinkaurelius.titan.diskstorage.StaticBuffer) KeyValueEntry(com.thinkaurelius.titan.diskstorage.keycolumnvalue.keyvalue.KeyValueEntry)

Example 3 with PermanentBackendException

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);
}
Also used : TableMapReduceUtil(org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil) PermanentBackendException(com.thinkaurelius.titan.diskstorage.PermanentBackendException) Scan(org.apache.hadoop.hbase.client.Scan) Method(java.lang.reflect.Method) PermanentBackendException(com.thinkaurelius.titan.diskstorage.PermanentBackendException) IOException(java.io.IOException)

Example 4 with PermanentBackendException

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);
}
Also used : TemporaryBackendException(com.thinkaurelius.titan.diskstorage.TemporaryBackendException) PermanentBackendException(com.thinkaurelius.titan.diskstorage.PermanentBackendException) Duration(java.time.Duration) BackendException(com.thinkaurelius.titan.diskstorage.BackendException) TemporaryBackendException(com.thinkaurelius.titan.diskstorage.TemporaryBackendException) PermanentBackendException(com.thinkaurelius.titan.diskstorage.PermanentBackendException)

Example 5 with PermanentBackendException

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;
}
Also used : PermanentBackendException(com.thinkaurelius.titan.diskstorage.PermanentBackendException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException) SolrQuery(org.apache.solr.client.solrj.SolrQuery) SolrDocument(org.apache.solr.common.SolrDocument) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) RawQuery(com.thinkaurelius.titan.diskstorage.indexing.RawQuery)

Aggregations

PermanentBackendException (com.thinkaurelius.titan.diskstorage.PermanentBackendException)14 IOException (java.io.IOException)10 TemporaryBackendException (com.thinkaurelius.titan.diskstorage.TemporaryBackendException)6 SolrServerException (org.apache.solr.client.solrj.SolrServerException)6 BackendException (com.thinkaurelius.titan.diskstorage.BackendException)4 SolrQuery (org.apache.solr.client.solrj.SolrQuery)4 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)4 SolrDocument (org.apache.solr.common.SolrDocument)4 StoreTransaction (com.thinkaurelius.titan.diskstorage.keycolumnvalue.StoreTransaction)3 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)3 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)3 TableNotEnabledException (org.apache.hadoop.hbase.TableNotEnabledException)3 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)3 IndexQuery (com.thinkaurelius.titan.diskstorage.indexing.IndexQuery)2 RawQuery (com.thinkaurelius.titan.diskstorage.indexing.RawQuery)2 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)2 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)2 ClusterState (org.apache.solr.common.cloud.ClusterState)2 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)2 KeeperException (org.apache.zookeeper.KeeperException)2