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();
}
}
}
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);
}
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;
}
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);
}
}
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);
}
}
Aggregations