use of org.apache.ignite.internal.IgniteInterruptedCheckedException in project ignite by apache.
the class S3CheckpointSpi method spiStart.
/** {@inheritDoc} */
@SuppressWarnings({ "BusyWait" })
@Override
public void spiStart(String igniteInstanceName) throws IgniteSpiException {
// Start SPI start stopwatch.
startStopwatch();
assertParameter(cred != null, "awsCredentials != null");
if (log.isDebugEnabled()) {
log.debug(configInfo("awsCredentials", cred));
log.debug(configInfo("clientConfiguration", cfg));
log.debug(configInfo("bucketNameSuffix", bucketNameSuffix));
}
if (cfg == null)
U.warn(log, "Amazon client configuration is not set (will use default).");
if (F.isEmpty(bucketNameSuffix)) {
U.warn(log, "Bucket name suffix is null or empty (will use default bucket name).");
bucketName = BUCKET_NAME_PREFIX + DFLT_BUCKET_NAME_SUFFIX;
} else
bucketName = BUCKET_NAME_PREFIX + bucketNameSuffix;
s3 = cfg != null ? new AmazonS3Client(cred, cfg) : new AmazonS3Client(cred);
if (!s3.doesBucketExist(bucketName)) {
try {
s3.createBucket(bucketName);
if (log.isDebugEnabled())
log.debug("Created S3 bucket: " + bucketName);
while (!s3.doesBucketExist(bucketName)) try {
U.sleep(200);
} catch (IgniteInterruptedCheckedException e) {
throw new IgniteSpiException("Thread has been interrupted.", e);
}
} catch (AmazonClientException e) {
try {
if (!s3.doesBucketExist(bucketName))
throw new IgniteSpiException("Failed to create bucket: " + bucketName, e);
} catch (AmazonClientException ignored) {
throw new IgniteSpiException("Failed to create bucket: " + bucketName, e);
}
}
}
Collection<S3TimeData> s3TimeDataLst = new LinkedList<>();
try {
ObjectListing list = s3.listObjects(bucketName);
while (true) {
for (S3ObjectSummary sum : list.getObjectSummaries()) {
S3CheckpointData data = read(sum.getKey());
if (data != null) {
s3TimeDataLst.add(new S3TimeData(data.getExpireTime(), data.getKey()));
if (log.isDebugEnabled())
log.debug("Registered existing checkpoint from key: " + data.getKey());
}
}
if (list.isTruncated())
list = s3.listNextBatchOfObjects(list);
else
break;
}
} catch (AmazonClientException e) {
throw new IgniteSpiException("Failed to read checkpoint bucket: " + bucketName, e);
} catch (IgniteCheckedException e) {
throw new IgniteSpiException("Failed to marshal/unmarshal objects in bucket: " + bucketName, e);
}
// Track expiration for only those data that are made by this node
timeoutWrk = new S3TimeoutWorker();
timeoutWrk.add(s3TimeDataLst);
timeoutWrk.start();
registerMBean(igniteInstanceName, new S3CheckpointSpiMBeanImpl(this), S3CheckpointSpiMBean.class);
// Ack ok start.
if (log.isDebugEnabled())
log.debug(startInfo());
}
use of org.apache.ignite.internal.IgniteInterruptedCheckedException in project ignite by apache.
the class CacheJdbcBlobStore method init.
/**
* Initializes store.
*
* @throws IgniteException If failed to initialize.
*/
private void init() {
if (initLatch.getCount() > 0) {
if (initGuard.compareAndSet(false, true)) {
if (log.isDebugEnabled())
log.debug("Initializing cache store.");
if (F.isEmpty(connUrl))
throw new IgniteException("Failed to initialize cache store (connection URL is not provided).");
if (!initSchema) {
initLatch.countDown();
return;
}
if (F.isEmpty(createTblQry))
throw new IgniteException("Failed to initialize cache store (create table query is not provided).");
Connection conn = null;
Statement stmt = null;
try {
conn = openConnection(false);
stmt = conn.createStatement();
stmt.execute(createTblQry);
conn.commit();
initOk = true;
} catch (SQLException e) {
throw new IgniteException("Failed to create database table.", e);
} finally {
U.closeQuiet(stmt);
closeConnection(conn);
initLatch.countDown();
}
} else {
try {
U.await(initLatch);
} catch (IgniteInterruptedCheckedException e) {
throw new IgniteException(e);
}
}
}
if (!initOk)
throw new IgniteException("Cache store was not properly initialized.");
}
use of org.apache.ignite.internal.IgniteInterruptedCheckedException in project ignite by apache.
the class TcpDiscoveryCloudIpFinder method initComputeService.
/**
* Initializes Apache jclouds compute service.
*/
private void initComputeService() {
if (initGuard.compareAndSet(false, true))
try {
if (provider == null)
throw new IgniteSpiException("Cloud provider is not set.");
if (identity == null)
throw new IgniteSpiException("Cloud identity is not set.");
if (credential != null && credentialPath != null)
throw new IgniteSpiException("Both credential and credentialPath are set. Use only one method.");
if (credentialPath != null)
credential = getCredentialFromFile();
try {
ContextBuilder ctxBuilder = ContextBuilder.newBuilder(provider);
ctxBuilder.credentials(identity, credential);
Properties properties = new Properties();
properties.setProperty(Constants.PROPERTY_SO_TIMEOUT, JCLOUD_CONNECTION_TIMEOUT);
properties.setProperty(Constants.PROPERTY_CONNECTION_TIMEOUT, JCLOUD_CONNECTION_TIMEOUT);
if (!F.isEmpty(regions))
properties.setProperty(LocationConstants.PROPERTY_REGIONS, keysSetToStr(regions));
if (!F.isEmpty(zones))
properties.setProperty(LocationConstants.PROPERTY_ZONES, keysSetToStr(zones));
ctxBuilder.overrides(properties);
computeService = ctxBuilder.buildView(ComputeServiceContext.class).getComputeService();
if (!F.isEmpty(zones) || !F.isEmpty(regions)) {
nodesFilter = new Predicate<ComputeMetadata>() {
@Override
public boolean apply(ComputeMetadata computeMetadata) {
String region = null;
String zone = null;
Location location = computeMetadata.getLocation();
while (location != null) {
switch(location.getScope()) {
case ZONE:
zone = location.getId();
break;
case REGION:
region = location.getId();
break;
}
location = location.getParent();
}
if (regions != null && region != null && !regions.contains(region))
return false;
if (zones != null && zone != null && !zones.contains(zone))
return false;
return true;
}
};
}
} catch (Exception e) {
throw new IgniteSpiException("Failed to connect to the provider: " + provider, e);
}
} finally {
initLatch.countDown();
}
else {
try {
U.await(initLatch);
} catch (IgniteInterruptedCheckedException e) {
throw new IgniteSpiException("Thread has been interrupted.", e);
}
if (computeService == null)
throw new IgniteSpiException("Ip finder has not been initialized properly.");
}
}
use of org.apache.ignite.internal.IgniteInterruptedCheckedException in project ignite by apache.
the class GridClientAbstractProjection method withReconnectHandling.
/**
* This method executes request to a communication layer and handles connection error, if it occurs.
* In case of communication exception client instance is notified and new instance of client is created.
* If none of the grid servers can be reached, an exception is thrown.
*
* @param c Closure to be executed.
* @param <R> Result future type.
* @return Future returned by closure.
*/
protected <R> GridClientFuture<R> withReconnectHandling(ClientProjectionClosure<R> c) {
try {
GridClientNode node = null;
boolean changeNode = false;
Throwable cause = null;
for (int i = 0; i < RETRY_CNT; i++) {
if (node == null || changeNode)
try {
node = balancedNode(node);
} catch (GridClientException e) {
if (node == null)
throw e;
else
throw new GridServerUnreachableException("All nodes in projection failed when retrying to perform request. Attempts made: " + i, cause);
}
GridClientConnection conn = null;
try {
conn = client.connectionManager().connection(node);
return c.apply(conn, node.nodeId());
} catch (GridConnectionIdleClosedException e) {
client.connectionManager().terminateConnection(conn, node, e);
// It's ok, just reconnect to the same node.
changeNode = false;
cause = e;
} catch (GridClientConnectionResetException e) {
client.connectionManager().terminateConnection(conn, node, e);
changeNode = true;
cause = e;
} catch (GridServerUnreachableException e) {
changeNode = true;
cause = e;
}
U.sleep(RETRY_DELAY);
}
assert cause != null;
throw new GridServerUnreachableException("Failed to communicate with grid nodes " + "(maximum count of retries reached).", cause);
} catch (GridClientException e) {
return new GridClientFutureAdapter<>(e);
} catch (IgniteInterruptedCheckedException | InterruptedException e) {
Thread.currentThread().interrupt();
return new GridClientFutureAdapter<>(new GridClientException("Interrupted when (re)trying to perform request.", e));
}
}
use of org.apache.ignite.internal.IgniteInterruptedCheckedException in project ignite by apache.
the class GridCacheAdapter method syncOp.
/**
* @param op Cache operation.
* @param <T> Return type.
* @return Operation result.
* @throws IgniteCheckedException If operation failed.
*/
@SuppressWarnings({ "TypeMayBeWeakened", "ErrorNotRethrown", "AssignmentToCatchBlockParameter" })
@Nullable
private <T> T syncOp(SyncOp<T> op) throws IgniteCheckedException {
checkJta();
awaitLastFut();
GridNearTxLocal tx = ctx.tm().threadLocalTx(ctx);
if (tx == null || tx.implicit()) {
TransactionConfiguration tCfg = CU.transactionConfiguration(ctx, ctx.kernalContext().config());
CacheOperationContext opCtx = ctx.operationContextPerCall();
int retries = opCtx != null && opCtx.noRetries() ? 1 : MAX_RETRIES;
for (int i = 0; i < retries; i++) {
tx = ctx.tm().newTx(true, op.single(), ctx.systemTx() ? ctx : null, OPTIMISTIC, READ_COMMITTED, tCfg.getDefaultTxTimeout(), !ctx.skipStore(), 0);
assert tx != null;
try {
T t = op.op(tx);
assert tx.done() : "Transaction is not done: " + tx;
return t;
} catch (IgniteInterruptedCheckedException | IgniteTxHeuristicCheckedException e) {
throw e;
} catch (IgniteCheckedException e) {
if (!(e instanceof IgniteTxRollbackCheckedException)) {
try {
tx.rollback();
e = new IgniteTxRollbackCheckedException("Transaction has been rolled back: " + tx.xid(), e);
} catch (IgniteCheckedException | AssertionError | RuntimeException e1) {
U.error(log, "Failed to rollback transaction (cache may contain stale locks): " + tx, e1);
U.addLastCause(e, e1, log);
}
}
if (X.hasCause(e, ClusterTopologyCheckedException.class) && i != retries - 1) {
ClusterTopologyCheckedException topErr = e.getCause(ClusterTopologyCheckedException.class);
if (!(topErr instanceof ClusterTopologyServerNotFoundException)) {
AffinityTopologyVersion topVer = tx.topologyVersion();
assert topVer != null && topVer.topologyVersion() > 0 : tx;
ctx.affinity().affinityReadyFuture(topVer.topologyVersion() + 1).get();
continue;
}
}
throw e;
} finally {
ctx.tm().resetContext();
if (ctx.isNear())
ctx.near().dht().context().tm().resetContext();
}
}
// Should not happen.
throw new IgniteCheckedException("Failed to perform cache operation (maximum number of retries exceeded).");
} else
return op.op(tx);
}
Aggregations