Search in sources :

Example 1 with TemporaryBackendException

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

the class AbstractLocker method checkLocks.

@Override
public void checkLocks(StoreTransaction tx) throws TemporaryLockingException, PermanentLockingException {
    if (null != tx.getConfiguration().getGroupName()) {
        MetricManager.INSTANCE.getCounter(tx.getConfiguration().getGroupName(), M_LOCKS, M_CHECK, M_CALLS).inc();
    }
    Map<KeyColumn, S> m = lockState.getLocksForTx(tx);
    if (m.isEmpty()) {
        // no locks for this tx
        return;
    }
    // We never receive interrupts in normal operation; one can only appear
    // during Thread.sleep(), and in that case it probably means the entire
    // Titan process is shutting down; for this reason, we return ASAP on an
    // interrupt
    boolean ok = false;
    try {
        for (KeyColumn kc : m.keySet()) {
            checkSingleLock(kc, m.get(kc), tx);
        }
        ok = true;
    } catch (TemporaryLockingException tle) {
        throw tle;
    } catch (PermanentLockingException ple) {
        throw ple;
    } catch (AssertionError ae) {
        // Concession to ease testing with mocks & behavior verification
        throw ae;
    } catch (InterruptedException e) {
        throw new TemporaryLockingException(e);
    } catch (TemporaryBackendException tse) {
        throw new TemporaryLockingException(tse);
    } catch (Throwable t) {
        throw new PermanentLockingException(t);
    } finally {
        if (!ok && null != tx.getConfiguration().getGroupName()) {
            MetricManager.INSTANCE.getCounter(tx.getConfiguration().getGroupName(), M_LOCKS, M_CHECK, M_CALLS).inc();
        }
    }
}
Also used : TemporaryBackendException(com.thinkaurelius.titan.diskstorage.TemporaryBackendException) KeyColumn(com.thinkaurelius.titan.diskstorage.util.KeyColumn)

Example 2 with TemporaryBackendException

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

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

the class HBaseStoreManager method ensureTableExists.

private HTableDescriptor ensureTableExists(String tableName, String initialCFName, int ttlInSeconds) throws BackendException {
    AdminMask adm = null;
    HTableDescriptor desc;
    try {
        // Create our table, if necessary
        adm = getAdminInterface();
        /*
             * Some HBase versions/impls respond badly to attempts to create a
             * table without at least one CF. See #661. Creating a CF along with
             * the table avoids HBase carping.
             */
        if (adm.tableExists(tableName)) {
            desc = adm.getTableDescriptor(tableName);
        } else {
            desc = createTable(tableName, initialCFName, ttlInSeconds, adm);
        }
    } catch (IOException e) {
        throw new TemporaryBackendException(e);
    } finally {
        IOUtils.closeQuietly(adm);
    }
    return desc;
}
Also used : TemporaryBackendException(com.thinkaurelius.titan.diskstorage.TemporaryBackendException) IOException(java.io.IOException) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor)

Example 4 with TemporaryBackendException

use of com.thinkaurelius.titan.diskstorage.TemporaryBackendException 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);
    }
}
Also used : KeyspaceDefinition(com.netflix.astyanax.ddl.KeyspaceDefinition) TemporaryBackendException(com.thinkaurelius.titan.diskstorage.TemporaryBackendException) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException)

Example 5 with TemporaryBackendException

use of com.thinkaurelius.titan.diskstorage.TemporaryBackendException in project incubator-atlas by apache.

the class HBaseStoreManager method ensureColumnFamilyExists.

private void ensureColumnFamilyExists(String tableName, String columnFamily, int ttlInSeconds) throws BackendException {
    AdminMask adm = null;
    try {
        adm = getAdminInterface();
        HTableDescriptor desc = ensureTableExists(tableName, columnFamily, ttlInSeconds);
        Preconditions.checkNotNull(desc);
        HColumnDescriptor cf = desc.getFamily(columnFamily.getBytes());
        // Create our column family, if necessary
        if (cf == null) {
            try {
                if (!adm.isTableDisabled(tableName)) {
                    adm.disableTable(tableName);
                }
            } catch (TableNotEnabledException e) {
                logger.debug("Table {} already disabled", tableName);
            } catch (IOException e) {
                throw new TemporaryBackendException(e);
            }
            try {
                HColumnDescriptor cdesc = new HColumnDescriptor(columnFamily);
                setCFOptions(cdesc, ttlInSeconds);
                adm.addColumn(tableName, cdesc);
                logger.debug("Added HBase ColumnFamily {}, waiting for 1 sec. to propogate.", columnFamily);
                adm.enableTable(tableName);
            } catch (TableNotFoundException ee) {
                logger.error("TableNotFoundException", ee);
                throw new PermanentBackendException(ee);
            } catch (org.apache.hadoop.hbase.TableExistsException ee) {
                logger.debug("Swallowing exception {}", ee);
            } catch (IOException ee) {
                throw new TemporaryBackendException(ee);
            }
        }
    } finally {
        IOUtils.closeQuietly(adm);
    }
}
Also used : TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) TemporaryBackendException(com.thinkaurelius.titan.diskstorage.TemporaryBackendException) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) PermanentBackendException(com.thinkaurelius.titan.diskstorage.PermanentBackendException) IOException(java.io.IOException) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) TableNotEnabledException(org.apache.hadoop.hbase.TableNotEnabledException)

Aggregations

TemporaryBackendException (com.thinkaurelius.titan.diskstorage.TemporaryBackendException)13 IOException (java.io.IOException)7 PermanentBackendException (com.thinkaurelius.titan.diskstorage.PermanentBackendException)4 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)4 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)3 BackendException (com.thinkaurelius.titan.diskstorage.BackendException)3 StaticBuffer (com.thinkaurelius.titan.diskstorage.StaticBuffer)3 ArrayList (java.util.ArrayList)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 KeyspaceDefinition (com.netflix.astyanax.ddl.KeyspaceDefinition)2 Duration (java.time.Duration)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)2 TableNotEnabledException (org.apache.hadoop.hbase.TableNotEnabledException)2 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)2 Delete (org.apache.hadoop.hbase.client.Delete)2 Put (org.apache.hadoop.hbase.client.Put)2 Row (org.apache.hadoop.hbase.client.Row)2