Search in sources :

Example 6 with BackendException

use of com.thinkaurelius.titan.diskstorage.BackendException in project titan by thinkaurelius.

the class MetricInstrumentedStoreManager method mutateMany.

@Override
public void mutateMany(Map<String, Map<StaticBuffer, KCVMutation>> mutations, StoreTransaction txh) throws BackendException {
    if (!txh.getConfiguration().hasGroupName()) {
        backend.mutateMany(mutations, txh);
    }
    String prefix = txh.getConfiguration().getGroupName();
    final MetricManager mgr = MetricManager.INSTANCE;
    mgr.getCounter(prefix, managerMetricsName, M_MUTATE, M_CALLS).inc();
    final Timer.Context tc = mgr.getTimer(prefix, managerMetricsName, M_MUTATE, M_TIME).time();
    try {
        backend.mutateMany(mutations, txh);
    } catch (BackendException e) {
        mgr.getCounter(prefix, managerMetricsName, M_MUTATE, M_EXCEPTIONS).inc();
        throw e;
    } catch (RuntimeException e) {
        mgr.getCounter(prefix, managerMetricsName, M_MUTATE, M_EXCEPTIONS).inc();
        throw e;
    } finally {
        tc.stop();
    }
}
Also used : MetricManager(com.thinkaurelius.titan.util.stats.MetricManager) Timer(com.codahale.metrics.Timer) BackendException(com.thinkaurelius.titan.diskstorage.BackendException)

Example 7 with BackendException

use of com.thinkaurelius.titan.diskstorage.BackendException 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 8 with BackendException

use of com.thinkaurelius.titan.diskstorage.BackendException in project titan by thinkaurelius.

the class MapReduceIndexManagement method updateIndex.

/**
     * Updates the provided index according to the given {@link SchemaAction}.
     * Only {@link SchemaAction#REINDEX} and {@link SchemaAction#REMOVE_INDEX} are supported.
     *
     * @param index the index to process
     * @param updateAction either {@code REINDEX} or {@code REMOVE_INDEX}
     * @return a future that returns immediately;
     *         this method blocks until the Hadoop MapReduce job completes
     */
// TODO make this future actually async and update javadoc @return accordingly
public TitanManagement.IndexJobFuture updateIndex(TitanIndex index, SchemaAction updateAction) throws BackendException {
    Preconditions.checkNotNull(index, "Index parameter must not be null", index);
    Preconditions.checkNotNull(updateAction, "%s parameter must not be null", SchemaAction.class.getSimpleName());
    Preconditions.checkArgument(SUPPORTED_ACTIONS.contains(updateAction), "Only these %s parameters are supported: %s (was given %s)", SchemaAction.class.getSimpleName(), SUPPORTED_ACTIONS_STRING, updateAction);
    Preconditions.checkArgument(RelationTypeIndex.class.isAssignableFrom(index.getClass()) || TitanGraphIndex.class.isAssignableFrom(index.getClass()), "Index %s has class %s: must be a %s or %s (or subtype)", index.getClass(), RelationTypeIndex.class.getSimpleName(), TitanGraphIndex.class.getSimpleName());
    org.apache.hadoop.conf.Configuration hadoopConf = new org.apache.hadoop.conf.Configuration();
    ModifiableHadoopConfiguration titanmrConf = ModifiableHadoopConfiguration.of(TitanHadoopConfiguration.MAPRED_NS, hadoopConf);
    // The job we'll execute to either REINDEX or REMOVE_INDEX
    final Class<? extends IndexUpdateJob> indexJobClass;
    final Class<? extends Mapper> mapperClass;
    // The class of the IndexUpdateJob and the Mapper that will be used to run it (VertexScanJob vs ScanJob)
    if (updateAction.equals(SchemaAction.REINDEX)) {
        indexJobClass = IndexRepairJob.class;
        mapperClass = HadoopVertexScanMapper.class;
    } else if (updateAction.equals(SchemaAction.REMOVE_INDEX)) {
        indexJobClass = IndexRemoveJob.class;
        mapperClass = HadoopScanMapper.class;
    } else {
        // Shouldn't get here -- if this exception is ever thrown, update SUPPORTED_ACTIONS
        throw new IllegalStateException("Unrecognized " + SchemaAction.class.getSimpleName() + ": " + updateAction);
    }
    // The column family that serves as input to the IndexUpdateJob
    final String readCF;
    if (RelationTypeIndex.class.isAssignableFrom(index.getClass())) {
        readCF = Backend.EDGESTORE_NAME;
    } else {
        TitanGraphIndex gindex = (TitanGraphIndex) index;
        if (gindex.isMixedIndex() && !updateAction.equals(SchemaAction.REINDEX))
            throw new UnsupportedOperationException("External mixed indexes must be removed in the indexing system directly.");
        Preconditions.checkState(TitanGraphIndex.class.isAssignableFrom(index.getClass()));
        if (updateAction.equals(SchemaAction.REMOVE_INDEX))
            readCF = Backend.INDEXSTORE_NAME;
        else
            readCF = Backend.EDGESTORE_NAME;
    }
    titanmrConf.set(TitanHadoopConfiguration.COLUMN_FAMILY_NAME, readCF);
    // The MapReduce InputFormat class based on the open graph's store manager
    final Class<? extends InputFormat> inputFormat;
    final Class<? extends KeyColumnValueStoreManager> storeManagerClass = graph.getBackend().getStoreManagerClass();
    if (CASSANDRA_STORE_MANAGER_CLASSES.contains(storeManagerClass)) {
        inputFormat = CassandraBinaryInputFormat.class;
        // Set the partitioner
        IPartitioner part = ((AbstractCassandraStoreManager) graph.getBackend().getStoreManager()).getCassandraPartitioner();
        hadoopConf.set("cassandra.input.partitioner.class", part.getClass().getName());
    } else if (HBASE_STORE_MANAGER_CLASSES.contains(storeManagerClass)) {
        inputFormat = HBaseBinaryInputFormat.class;
    } else {
        throw new IllegalArgumentException("Store manager class " + storeManagerClass + "is not supported");
    }
    // The index name and relation type name (if the latter is applicable)
    final String indexName = index.name();
    final String relationTypeName = RelationTypeIndex.class.isAssignableFrom(index.getClass()) ? ((RelationTypeIndex) index).getType().name() : "";
    Preconditions.checkNotNull(indexName);
    // Set the class of the IndexUpdateJob
    titanmrConf.set(TitanHadoopConfiguration.SCAN_JOB_CLASS, indexJobClass.getName());
    // Set the configuration of the IndexUpdateJob
    copyIndexJobKeys(hadoopConf, indexName, relationTypeName);
    titanmrConf.set(TitanHadoopConfiguration.SCAN_JOB_CONFIG_ROOT, GraphDatabaseConfiguration.class.getName() + "#JOB_NS");
    // Copy the StandardTitanGraph configuration under TitanHadoopConfiguration.GRAPH_CONFIG_KEYS
    org.apache.commons.configuration.Configuration localbc = graph.getConfiguration().getLocalConfiguration();
    localbc.clearProperty(Graph.GRAPH);
    copyInputKeys(hadoopConf, localbc);
    String jobName = HadoopScanMapper.class.getSimpleName() + "[" + indexJobClass.getSimpleName() + "]";
    try {
        return new CompletedJobFuture(HadoopScanRunner.runJob(hadoopConf, inputFormat, jobName, mapperClass));
    } catch (Exception e) {
        return new FailedJobFuture(e);
    }
}
Also used : GraphDatabaseConfiguration(com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration) TitanHadoopConfiguration(com.thinkaurelius.titan.hadoop.config.TitanHadoopConfiguration) ModifiableHadoopConfiguration(com.thinkaurelius.titan.hadoop.config.ModifiableHadoopConfiguration) SchemaAction(com.thinkaurelius.titan.core.schema.SchemaAction) HBaseBinaryInputFormat(com.thinkaurelius.titan.hadoop.formats.hbase.HBaseBinaryInputFormat) ModifiableHadoopConfiguration(com.thinkaurelius.titan.hadoop.config.ModifiableHadoopConfiguration) RelationTypeIndex(com.thinkaurelius.titan.core.schema.RelationTypeIndex) TitanGraphIndex(com.thinkaurelius.titan.core.schema.TitanGraphIndex) AbstractCassandraStoreManager(com.thinkaurelius.titan.diskstorage.cassandra.AbstractCassandraStoreManager) IPartitioner(org.apache.cassandra.dht.IPartitioner) HadoopScanMapper(com.thinkaurelius.titan.hadoop.scan.HadoopScanMapper) TimeoutException(java.util.concurrent.TimeoutException) BackendException(com.thinkaurelius.titan.diskstorage.BackendException) ExecutionException(java.util.concurrent.ExecutionException) IndexRemoveJob(com.thinkaurelius.titan.graphdb.olap.job.IndexRemoveJob)

Example 9 with BackendException

use of com.thinkaurelius.titan.diskstorage.BackendException in project titan by thinkaurelius.

the class TitanGraphBaseTest method closeLogs.

private void closeLogs() {
    try {
        for (LogManager lm : logManagers.values()) lm.close();
        logManagers.clear();
        if (logStoreManager != null) {
            logStoreManager.close();
            logStoreManager = null;
        }
    } catch (BackendException e) {
        throw new TitanException(e);
    }
}
Also used : LogManager(com.thinkaurelius.titan.diskstorage.log.LogManager) KCVSLogManager(com.thinkaurelius.titan.diskstorage.log.kcvs.KCVSLogManager) BackendException(com.thinkaurelius.titan.diskstorage.BackendException)

Example 10 with BackendException

use of com.thinkaurelius.titan.diskstorage.BackendException in project titan by thinkaurelius.

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);
    }
}
Also used : PermanentBackendException(com.thinkaurelius.titan.diskstorage.PermanentBackendException) RetryPolicy(com.netflix.astyanax.retry.RetryPolicy) TemporaryBackendException(com.thinkaurelius.titan.diskstorage.TemporaryBackendException) PermanentBackendException(com.thinkaurelius.titan.diskstorage.PermanentBackendException) BackendException(com.thinkaurelius.titan.diskstorage.BackendException) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException)

Aggregations

BackendException (com.thinkaurelius.titan.diskstorage.BackendException)25 ArrayList (java.util.ArrayList)7 PermanentBackendException (com.thinkaurelius.titan.diskstorage.PermanentBackendException)6 TemporaryBackendException (com.thinkaurelius.titan.diskstorage.TemporaryBackendException)6 CTConnection (com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnection)6 TException (org.apache.thrift.TException)6 List (java.util.List)5 TitanException (com.thinkaurelius.titan.core.TitanException)4 BackendOperation (com.thinkaurelius.titan.diskstorage.util.BackendOperation)4 StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 SolrServerException (org.apache.solr.client.solrj.SolrServerException)3 KeeperException (org.apache.zookeeper.KeeperException)3 Timer (com.codahale.metrics.Timer)2 RelationTypeIndex (com.thinkaurelius.titan.core.schema.RelationTypeIndex)2 TitanGraphIndex (com.thinkaurelius.titan.core.schema.TitanGraphIndex)2 Entry (com.thinkaurelius.titan.diskstorage.Entry)2 IndexEntry (com.thinkaurelius.titan.diskstorage.indexing.IndexEntry)2