Search in sources :

Example 1 with IgniteInterruptedCheckedException

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());
}
Also used : AmazonClientException(com.amazonaws.AmazonClientException) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) LinkedList(java.util.LinkedList) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException)

Example 2 with IgniteInterruptedCheckedException

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.");
}
Also used : IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) SQLException(java.sql.SQLException) IgniteException(org.apache.ignite.IgniteException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection)

Example 3 with IgniteInterruptedCheckedException

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.");
    }
}
Also used : IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) ContextBuilder(org.jclouds.ContextBuilder) ComputeServiceContext(org.jclouds.compute.ComputeServiceContext) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) ComputeMetadata(org.jclouds.compute.domain.ComputeMetadata) Properties(java.util.Properties) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IOException(java.io.IOException) Predicate(com.google.common.base.Predicate) Location(org.jclouds.domain.Location)

Example 4 with IgniteInterruptedCheckedException

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));
    }
}
Also used : GridClientNode(org.apache.ignite.internal.client.GridClientNode) GridClientException(org.apache.ignite.internal.client.GridClientException) GridConnectionIdleClosedException(org.apache.ignite.internal.client.impl.connection.GridConnectionIdleClosedException) GridClientConnectionResetException(org.apache.ignite.internal.client.impl.connection.GridClientConnectionResetException) GridClientConnection(org.apache.ignite.internal.client.impl.connection.GridClientConnection) GridServerUnreachableException(org.apache.ignite.internal.client.GridServerUnreachableException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException)

Example 5 with IgniteInterruptedCheckedException

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);
}
Also used : TransactionConfiguration(org.apache.ignite.configuration.TransactionConfiguration) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) IgniteTxRollbackCheckedException(org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException) IgniteTxHeuristicCheckedException(org.apache.ignite.internal.transactions.IgniteTxHeuristicCheckedException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) BROADCAST(org.apache.ignite.internal.GridClosureCallMode.BROADCAST) IGNITE_CACHE_RETRIES_COUNT(org.apache.ignite.IgniteSystemProperties.IGNITE_CACHE_RETRIES_COUNT) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)45 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)23 IOException (java.io.IOException)13 IgniteException (org.apache.ignite.IgniteException)10 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)10 ArrayList (java.util.ArrayList)8 File (java.io.File)5 CacheException (javax.cache.CacheException)5 List (java.util.List)4 UUID (java.util.UUID)4 ClusterNode (org.apache.ignite.cluster.ClusterNode)4 InetSocketAddress (java.net.InetSocketAddress)3 HashMap (java.util.HashMap)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 JobContextImpl (org.apache.hadoop.mapred.JobContextImpl)3 OutputFormat (org.apache.hadoop.mapreduce.OutputFormat)3 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)3 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)3 ServerSocket (java.net.ServerSocket)2