Search in sources :

Example 31 with IgniteSpiException

use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.

the class TcpCommunicationSpi method spiStart.

/**
 * {@inheritDoc}
 */
@Override
public void spiStart(String igniteInstanceName) throws IgniteSpiException {
    final Function<UUID, ClusterNode> nodeGetter = (nodeId) -> getSpiContext().node(nodeId);
    final Supplier<ClusterNode> locNodeSupplier = () -> getSpiContext().localNode();
    final Supplier<Ignite> igniteExSupplier = this::ignite;
    final Function<UUID, Boolean> pingNode = (nodeId) -> getSpiContext().pingNode(nodeId);
    final Supplier<FailureProcessor> failureProcessorSupplier = () -> ignite instanceof IgniteEx ? ((IgniteEx) ignite).context().failure() : null;
    final Supplier<Boolean> isStopped = () -> getSpiContext().isStopping();
    this.igniteInstanceName = igniteInstanceName;
    cfg.failureDetectionTimeout(ignite.configuration().getFailureDetectionTimeout());
    attributeNames = new AttributeNames(createSpiAttributeName(ATTR_PAIRED_CONN), createSpiAttributeName(ATTR_ADDRS), createSpiAttributeName(ATTR_HOST_NAMES), createSpiAttributeName(ATTR_EXT_ADDRS), createSpiAttributeName(ATTR_PORT), createSpiAttributeName(ATTR_FORCE_CLIENT_SERVER_CONNECTIONS));
    boolean client = Boolean.TRUE.equals(ignite().configuration().isClientMode());
    this.stateProvider = new ClusterStateProvider(ignite, locNodeSupplier, this, isStopped, () -> super.getSpiContext(), log, igniteExSupplier);
    try {
        cfg.localHost(U.resolveLocalHost(cfg.localAddress()));
    } catch (IOException e) {
        throw new IgniteSpiException("Failed to initialize local address: " + cfg.localAddress(), e);
    }
    if (cfg.connectionsPerNode() > 1)
        connPlc = new RoundRobinConnectionPolicy(cfg);
    else
        connPlc = new FirstConnectionPolicy();
    this.srvLsnr = resolve(ignite, new InboundConnectionHandler(log, cfg, nodeGetter, locNodeSupplier, stateProvider, clientPool, commWorker, connectGate, failureProcessorSupplier, attributeNames, metricsLsnr, nioSrvWrapper, ctxInitLatch, client, igniteExSupplier, new CommunicationListener<Message>() {

        @Override
        public void onMessage(UUID nodeId, Message msg, IgniteRunnable msgC) {
            notifyListener(nodeId, msg, msgC);
        }

        @Override
        public void onDisconnected(UUID nodeId) {
            if (lsnr != null)
                lsnr.onDisconnected(nodeId);
        }
    }));
    TcpHandshakeExecutor tcpHandshakeExecutor = resolve(ignite, new TcpHandshakeExecutor(log, stateProvider, cfg.directBuffer()));
    this.nioSrvWrapper = resolve(ignite, new GridNioServerWrapper(log, cfg, attributeNames, tracing, nodeGetter, locNodeSupplier, connectGate, stateProvider, this::getExceptionRegistry, commWorker, ignite.configuration(), this.srvLsnr, getName(), getWorkersRegistry(ignite), ignite instanceof IgniteEx ? ((IgniteEx) ignite).context().metric() : null, this::createTcpClient, new CommunicationListenerEx<Message>() {

        @Override
        public void onMessage(UUID nodeId, Message msg, IgniteRunnable msgC) {
            notifyListener(nodeId, msg, msgC);
        }

        @Override
        public void onDisconnected(UUID nodeId) {
            if (lsnr != null)
                lsnr.onDisconnected(nodeId);
        }

        @Override
        public void onChannelOpened(UUID rmtNodeId, Message initMsg, Channel channel) {
            if (lsnr instanceof CommunicationListenerEx)
                ((CommunicationListenerEx<Message>) lsnr).onChannelOpened(rmtNodeId, initMsg, channel);
        }
    }, tcpHandshakeExecutor));
    this.srvLsnr.setNioSrvWrapper(nioSrvWrapper);
    this.clientPool = resolve(ignite, new ConnectionClientPool(cfg, attributeNames, log, metricsLsnr, locNodeSupplier, nodeGetter, null, getWorkersRegistry(ignite), this, stateProvider, nioSrvWrapper, getName()));
    this.srvLsnr.setClientPool(clientPool);
    nioSrvWrapper.clientPool(clientPool);
    discoLsnr = new CommunicationDiscoveryEventListener(clientPool, metricsLsnr);
    try {
        // This method potentially resets local port to the value
        // local node was bound to.
        nioSrvWrapper.nio(nioSrvWrapper.resetNioServer());
    } catch (IgniteCheckedException e) {
        throw new IgniteSpiException("Failed to initialize TCP server: " + cfg.localHost(), e);
    }
    boolean forceClientToSrvConnections = forceClientToServerConnections() || cfg.localPort() == -1;
    if (cfg.usePairedConnections() && forceClientToSrvConnections) {
        throw new IgniteSpiException("Node using paired connections " + "is not allowed to start in forced client to server connections mode.");
    }
    assert cfg.localHost() != null;
    // Start SPI start stopwatch.
    startStopwatch();
    if (log.isDebugEnabled()) {
        log.debug(configInfo("locAddr", cfg.localAddress()));
        log.debug(configInfo("locPort", cfg.localPort()));
        log.debug(configInfo("locPortRange", cfg.localPortRange()));
        log.debug(configInfo("idleConnTimeout", cfg.idleConnectionTimeout()));
        log.debug(configInfo("directBuf", cfg.directBuffer()));
        log.debug(configInfo("directSendBuf", cfg.directSendBuffer()));
        log.debug(configInfo("selectorsCnt", cfg.selectorsCount()));
        log.debug(configInfo("tcpNoDelay", cfg.tcpNoDelay()));
        log.debug(configInfo("sockSndBuf", cfg.socketSendBuffer()));
        log.debug(configInfo("sockRcvBuf", cfg.socketReceiveBuffer()));
        log.debug(configInfo("msgQueueLimit", cfg.messageQueueLimit()));
        log.debug(configInfo("connectionsPerNode", cfg.connectionsPerNode()));
        if (failureDetectionTimeoutEnabled()) {
            log.debug(configInfo("connTimeout", cfg.connectionTimeout()));
            log.debug(configInfo("maxConnTimeout", cfg.maxConnectionTimeout()));
            log.debug(configInfo("reconCnt", cfg.reconCount()));
        } else
            log.debug(configInfo("failureDetectionTimeout", failureDetectionTimeout()));
        log.debug(configInfo("sockWriteTimeout", cfg.socketWriteTimeout()));
        log.debug(configInfo("ackSndThreshold", cfg.ackSendThreshold()));
        log.debug(configInfo("unackedMsgsBufSize", cfg.unackedMsgsBufferSize()));
    }
    if (!cfg.tcpNoDelay())
        U.quietAndWarn(log, "'TCP_NO_DELAY' for communication is off, which should be used with caution " + "since may produce significant delays with some scenarios.");
    if (cfg.slowClientQueueLimit() > 0 && cfg.messageQueueLimit() > 0 && cfg.slowClientQueueLimit() >= cfg.messageQueueLimit()) {
        U.quietAndWarn(log, "Slow client queue limit is set to a value greater than or equal to message " + "queue limit (slow client queue limit will have no effect) [msgQueueLimit=" + cfg.messageQueueLimit() + ", slowClientQueueLimit=" + cfg.slowClientQueueLimit() + ']');
    }
    if (cfg.messageQueueLimit() == 0)
        U.quietAndWarn(log, "Message queue limit is set to 0 which may lead to " + "potential OOMEs when running cache operations in FULL_ASYNC or PRIMARY_SYNC modes " + "due to message queues growth on sender and receiver sides.");
    nioSrvWrapper.start();
    this.commWorker = new CommunicationWorker(igniteInstanceName, log, cfg, attributeNames, clientPool, failureProcessorSupplier, nodeGetter, pingNode, this::getExceptionRegistry, nioSrvWrapper, getWorkersRegistry(ignite), getName());
    this.srvLsnr.communicationWorker(commWorker);
    this.nioSrvWrapper.communicationWorker(commWorker);
    new IgniteSpiThread(igniteInstanceName, commWorker.name(), log) {

        @Override
        protected void body() {
            commWorker.run();
        }
    }.start();
    // Ack start.
    if (log.isDebugEnabled())
        log.debug(startInfo());
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) CommunicationWorker(org.apache.ignite.spi.communication.tcp.internal.CommunicationWorker) TcpHandshakeExecutor(org.apache.ignite.spi.communication.tcp.internal.TcpHandshakeExecutor) GridNioSession(org.apache.ignite.internal.util.nio.GridNioSession) TcpCommunicationSpiMBeanImpl(org.apache.ignite.spi.communication.tcp.internal.TcpCommunicationSpiMBeanImpl) EVT_NODE_LEFT(org.apache.ignite.events.EventType.EVT_NODE_LEFT) AddressResolver(org.apache.ignite.configuration.AddressResolver) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) CommunicationListenerEx(org.apache.ignite.spi.communication.tcp.internal.CommunicationListenerEx) IgniteEx(org.apache.ignite.internal.IgniteEx) TcpCommunicationConfigInitializer(org.apache.ignite.spi.communication.tcp.internal.TcpCommunicationConfigInitializer) ClusterStateProvider(org.apache.ignite.spi.communication.tcp.internal.ClusterStateProvider) ByteBuffer(java.nio.ByteBuffer) GridNioSessionMetaKey(org.apache.ignite.internal.util.nio.GridNioSessionMetaKey) Map(java.util.Map) FirstConnectionPolicy(org.apache.ignite.spi.communication.tcp.internal.FirstConnectionPolicy) ConnectionClientPool(org.apache.ignite.spi.communication.tcp.internal.ConnectionClientPool) FailureProcessor(org.apache.ignite.internal.processors.failure.FailureProcessor) WorkersRegistry(org.apache.ignite.internal.worker.WorkersRegistry) LoggerResource(org.apache.ignite.resources.LoggerResource) RoundRobinConnectionPolicy(org.apache.ignite.spi.communication.tcp.internal.RoundRobinConnectionPolicy) Channel(java.nio.channels.Channel) IgniteKernal(org.apache.ignite.internal.IgniteKernal) NOOP(org.apache.ignite.spi.communication.tcp.internal.CommunicationTcpUtils.NOOP) IgniteFuture(org.apache.ignite.lang.IgniteFuture) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) GridNioServer(org.apache.ignite.internal.util.nio.GridNioServer) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) CommunicationTcpUtils(org.apache.ignite.spi.communication.tcp.internal.CommunicationTcpUtils) TcpConnectionIndexAwareMessage(org.apache.ignite.spi.communication.tcp.internal.TcpConnectionIndexAwareMessage) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) UNDEFINED_CONNECTION_INDEX(org.apache.ignite.spi.communication.tcp.internal.TcpConnectionIndexAwareMessage.UNDEFINED_CONNECTION_INDEX) UUID(java.util.UUID) InetSocketAddress(java.net.InetSocketAddress) GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) CountDownLatch(java.util.concurrent.CountDownLatch) GridResourceProcessor(org.apache.ignite.internal.processors.resource.GridResourceProcessor) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) EVT_NODE_FAILED(org.apache.ignite.events.EventType.EVT_NODE_FAILED) MTC(org.apache.ignite.internal.processors.tracing.MTC) Message(org.apache.ignite.plugin.extensions.communication.Message) GridCommunicationClient(org.apache.ignite.internal.util.nio.GridCommunicationClient) IgniteFutureImpl(org.apache.ignite.internal.util.future.IgniteFutureImpl) ConnectGateway(org.apache.ignite.spi.communication.tcp.internal.ConnectGateway) CommunicationListener(org.apache.ignite.spi.communication.CommunicationListener) IgniteSpiContext(org.apache.ignite.spi.IgniteSpiContext) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) IgniteSpiThread(org.apache.ignite.spi.IgniteSpiThread) U(org.apache.ignite.internal.util.typedef.internal.U) IgnitePortProtocol(org.apache.ignite.spi.IgnitePortProtocol) InboundConnectionHandler(org.apache.ignite.spi.communication.tcp.internal.InboundConnectionHandler) IgniteLogger(org.apache.ignite.IgniteLogger) GridIoManager(org.apache.ignite.internal.managers.communication.GridIoManager) Function(java.util.function.Function) Supplier(java.util.function.Supplier) CommunicationDiscoveryEventListener(org.apache.ignite.spi.communication.tcp.internal.CommunicationDiscoveryEventListener) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) IgniteSpiConsistencyChecked(org.apache.ignite.spi.IgniteSpiConsistencyChecked) IgniteSpiMultipleInstancesSupport(org.apache.ignite.spi.IgniteSpiMultipleInstancesSupport) S(org.apache.ignite.internal.util.typedef.internal.S) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) GridNioServerWrapper(org.apache.ignite.spi.communication.tcp.internal.GridNioServerWrapper) IOException(java.io.IOException) Ignite(org.apache.ignite.Ignite) ConnectionKey(org.apache.ignite.spi.communication.tcp.internal.ConnectionKey) TestOnly(org.jetbrains.annotations.TestOnly) CommunicationSpi(org.apache.ignite.spi.communication.CommunicationSpi) TcpCommunicationConnectionCheckFuture(org.apache.ignite.spi.communication.tcp.internal.TcpCommunicationConnectionCheckFuture) NodeUnreachableException(org.apache.ignite.spi.communication.tcp.internal.NodeUnreachableException) MetricUtils(org.apache.ignite.internal.processors.metric.impl.MetricUtils) BitSet(java.util.BitSet) GridNioRecoveryDescriptor(org.apache.ignite.internal.util.nio.GridNioRecoveryDescriptor) GridLocalEventListener(org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener) TcpConnectionIndexAwareMessage(org.apache.ignite.spi.communication.tcp.internal.TcpConnectionIndexAwareMessage) GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) GridNioServerWrapper(org.apache.ignite.spi.communication.tcp.internal.GridNioServerWrapper) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) CommunicationDiscoveryEventListener(org.apache.ignite.spi.communication.tcp.internal.CommunicationDiscoveryEventListener) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) RoundRobinConnectionPolicy(org.apache.ignite.spi.communication.tcp.internal.RoundRobinConnectionPolicy) Ignite(org.apache.ignite.Ignite) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) UUID(java.util.UUID) ClusterNode(org.apache.ignite.cluster.ClusterNode) FirstConnectionPolicy(org.apache.ignite.spi.communication.tcp.internal.FirstConnectionPolicy) TcpHandshakeExecutor(org.apache.ignite.spi.communication.tcp.internal.TcpHandshakeExecutor) ClusterStateProvider(org.apache.ignite.spi.communication.tcp.internal.ClusterStateProvider) CommunicationListenerEx(org.apache.ignite.spi.communication.tcp.internal.CommunicationListenerEx) Channel(java.nio.channels.Channel) IOException(java.io.IOException) CommunicationWorker(org.apache.ignite.spi.communication.tcp.internal.CommunicationWorker) IgniteSpiThread(org.apache.ignite.spi.IgniteSpiThread) IgniteEx(org.apache.ignite.internal.IgniteEx) ConnectionClientPool(org.apache.ignite.spi.communication.tcp.internal.ConnectionClientPool) InboundConnectionHandler(org.apache.ignite.spi.communication.tcp.internal.InboundConnectionHandler) FailureProcessor(org.apache.ignite.internal.processors.failure.FailureProcessor)

Example 32 with IgniteSpiException

use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.

the class JobStealingCollisionSpi method checkIdle.

/**
 * Check if the node is idle and steal as many jobs from other nodes
 * as possible.
 *
 * @param waitJobs Waiting jobs.
 * @param activeJobs Active jobs.
 */
private void checkIdle(Collection<CollisionJobContext> waitJobs, Collection<CollisionJobContext> activeJobs) {
    // Check for overflow.
    int max = waitJobsThreshold + activeJobsThreshold;
    if (max < 0)
        max = Integer.MAX_VALUE;
    int jobsToSteal = max - (waitJobs.size() + activeJobs.size());
    if (log.isDebugEnabled())
        log.debug("Total number of jobs to be stolen: " + jobsToSteal);
    if (jobsToSteal > 0) {
        int jobsLeft = jobsToSteal;
        ClusterNode next;
        int nodeCnt = getSpiContext().remoteNodes().size();
        int idx = 0;
        while (jobsLeft > 0 && idx++ < nodeCnt && (next = nodeQueue.poll()) != null) {
            if (getSpiContext().node(next.id()) == null)
                continue;
            // Remote node does not have attributes - do not steal from it.
            if (!F.isEmpty(stealAttrs) && (next.attributes() == null || !U.containsAll(next.attributes(), stealAttrs))) {
                if (log.isDebugEnabled())
                    log.debug("Skip node as it does not have all attributes: " + next.id());
                continue;
            }
            int delta = 0;
            try {
                MessageInfo msgInfo = sndMsgMap.get(next.id());
                if (msgInfo == null) {
                    if (log.isDebugEnabled())
                        log.debug("Failed to find message info for node: " + next.id());
                    // Node left topology or SPI has not received message for it.
                    continue;
                }
                Integer waitThreshold = next.attribute(createSpiAttributeName(WAIT_JOBS_THRESHOLD_NODE_ATTR));
                if (waitThreshold == null) {
                    U.error(log, "Remote node is not configured with GridJobStealingCollisionSpi and " + "jobs will not be stolen from it (you must stop it and update its configuration to use " + "GridJobStealingCollisionSpi): " + next);
                    continue;
                }
                delta = next.metrics().getCurrentWaitingJobs() - waitThreshold;
                if (log.isDebugEnabled())
                    log.debug("Maximum number of jobs to steal from node [jobsToSteal=" + delta + ", node=" + next.id() + ']');
                // Nothing to steal from this node.
                if (delta <= 0)
                    continue;
                synchronized (msgInfo) {
                    if (!msgInfo.expired() && msgInfo.jobsToSteal() > 0) {
                        // Count messages being waited for as present.
                        jobsLeft -= msgInfo.jobsToSteal();
                        continue;
                    }
                    if (jobsLeft < delta)
                        delta = jobsLeft;
                    jobsLeft -= delta;
                    msgInfo.reset(delta);
                }
                // Send request to remote node to steal jobs.
                // Message is a plain integer represented by 'delta'.
                getSpiContext().send(next, new JobStealingRequest(delta), JOB_STEALING_COMM_TOPIC);
            } catch (IgniteSpiException e) {
                U.error(log, "Failed to send job stealing message to node: " + next, e);
                // Rollback.
                jobsLeft += delta;
            } finally {
                // If node is alive, add back to the end of the queue.
                if (getSpiContext().node(next.id()) != null)
                    nodeQueue.offer(next);
            }
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException)

Example 33 with IgniteSpiException

use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.

the class JdbcCheckpointSpi method loadCheckpoint.

/**
 * {@inheritDoc}
 */
@Override
public byte[] loadCheckpoint(String key) throws IgniteSpiException {
    Connection conn = null;
    PreparedStatement st = null;
    ResultSet rs = null;
    try {
        conn = getConnection();
        st = conn.prepareStatement(selSql);
        st.setString(1, key);
        st.setTime(2, new Time(U.currentTimeMillis()));
        rs = st.executeQuery();
        return rs.next() ? rs.getBytes(1) : null;
    } catch (SQLException e) {
        throw new IgniteSpiException("Failed to load checkpoint [tblName=" + tblName + ", key=" + key + ']', e);
    } finally {
        U.close(rs, log);
        U.close(st, log);
        U.close(conn, log);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Time(java.sql.Time) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException)

Example 34 with IgniteSpiException

use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.

the class JdbcCheckpointSpi method saveCheckpoint.

/**
 * {@inheritDoc}
 */
@Override
public boolean saveCheckpoint(String key, byte[] state, long timeout, boolean overwrite) throws IgniteSpiException {
    Time expTime = null;
    if (timeout != NON_EXPIRABLE_TIMEOUT)
        expTime = new Time(U.currentTimeMillis() + timeout);
    Connection conn = null;
    try {
        conn = getConnection();
        int errCnt = 0;
        while (true) {
            if (errCnt >= retryNum) {
                throw new IgniteSpiException("Failed to save checkpoint after pre-configured number of " + "retries [tblName=" + tblName + ", key=" + key + ", retryNum=" + retryNum + ']');
            }
            try {
                if (!isCheckpointExists(conn, key)) {
                    if (createCheckpoint(conn, key, state, expTime) == 0) {
                        ++errCnt;
                        U.warn(log, "Failed to create checkpoint (will try again) [tblName=" + tblName + ", key=" + key + ']');
                        continue;
                    }
                } else {
                    if (!overwrite)
                        return false;
                    if (updateCheckpoint(conn, key, state, expTime) == 0) {
                        ++errCnt;
                        U.warn(log, "Failed to update checkpoint as it may be deleted (will try create) [" + "tblName=" + tblName + ", key=" + key + ']');
                        continue;
                    }
                }
                conn.commit();
                return true;
            } catch (SQLException e) {
                U.rollbackConnection(conn, log);
                if (++errCnt >= retryNum) {
                    throw new IgniteSpiException("Failed to save checkpoint [tblName=" + tblName + ", key=" + key + ']', e);
                }
                U.warn(log, "Failed to save checkpoint (will try again) [tblName=" + tblName + ", key=" + key + ']');
            }
        }
    } catch (SQLException e) {
        throw new IgniteSpiException("Failed to save checkpoint [tblName=" + tblName + ", key=" + key + ']', e);
    } finally {
        U.close(conn, log);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) Time(java.sql.Time) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException)

Example 35 with IgniteSpiException

use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.

the class JdbcCheckpointSpi method spiStart.

/**
 * {@inheritDoc}
 */
@Override
public void spiStart(String igniteInstanceName) throws IgniteSpiException {
    // Start SPI start stopwatch.
    startStopwatch();
    assertParameter(dataSrc != null, "dataSrc != null");
    assertParameter(!F.isEmpty(tblName), "!F.isEmpty(tblName)");
    assertParameter(!F.isEmpty(keyName), "!F.isEmpty(keyName)");
    assertParameter(!F.isEmpty(keyType), "!F.isEmpty(keyType)");
    assertParameter(!F.isEmpty(valName), "!F.isEmpty(valName)");
    assertParameter(!F.isEmpty(valType), "!F.isEmpty(valType)");
    assertParameter(!F.isEmpty(expDateName), "!F.isEmpty(expDateName)");
    assertParameter(!F.isEmpty(expDateType), "!F.isEmpty(expDateType)");
    // Fill SQL template strings.
    crtTblSql = sql(CREATE_TABLE_SQL, tblName, keyName, keyType, valName, valType, expDateName, expDateType);
    chkTblExistsSql = sql(CHECK_TABLE_EXISTS_SQL, tblName);
    chkExistsSql = sql(CHECK_EXISTS_SQL, tblName, keyName);
    updateSql = sql(UPDATE_SQL, tblName, valName, expDateName, keyName);
    insSql = sql(INSERT_SQL, tblName, keyName, valName, expDateName);
    delSql = sql(DELETE_SQL, tblName, keyName, expDateName);
    selSql = sql(SELECT_SQL, valName, tblName, keyName, expDateName);
    delExpSql = sql(DELETE_EXPIRED_SQL, tblName, expDateName);
    selExpSql = sql(SELECT_EXPIRED_SQL, keyName, tblName, expDateName);
    Connection conn = null;
    try {
        conn = getConnection();
        // Check checkpoint table exists.
        int errCnt = 0;
        while (true) {
            try {
                if (!isCheckpointTableExists(conn))
                    createCheckpointTable(conn);
                conn.commit();
                break;
            } catch (SQLException e) {
                U.rollbackConnection(conn, log);
                if (++errCnt >= retryNum)
                    throw new IgniteSpiException("Failed to create checkpoint table: " + tblName, e);
                if (log.isDebugEnabled()) {
                    log.debug("Failed to create checkpoint table as it may already exist (will try again): " + tblName);
                }
            }
        }
    } catch (SQLException e) {
        throw new IgniteSpiException("Failed to start jdbc checkpoint SPI: " + tblName, e);
    } finally {
        U.close(conn, log);
    }
    // Ack ok start.
    if (log.isDebugEnabled())
        log.debug(startInfo());
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException)

Aggregations

IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)131 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)59 IOException (java.io.IOException)32 InetSocketAddress (java.net.InetSocketAddress)22 ClusterNode (org.apache.ignite.cluster.ClusterNode)21 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)21 IgniteException (org.apache.ignite.IgniteException)20 ArrayList (java.util.ArrayList)14 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)14 HashMap (java.util.HashMap)13 UUID (java.util.UUID)13 Nullable (org.jetbrains.annotations.Nullable)12 Test (org.junit.Test)12 File (java.io.File)10 Message (org.apache.ignite.plugin.extensions.communication.Message)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 SSLException (javax.net.ssl.SSLException)8 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)8 SocketTimeoutException (java.net.SocketTimeoutException)7 Ignite (org.apache.ignite.Ignite)7