Search in sources :

Example 6 with TimeoutException

use of io.aeron.exceptions.TimeoutException in project Aeron by real-logic.

the class ReplicationSession method replay.

private int replay() {
    int workCount = 0;
    if (NULL_VALUE == activeCorrelationId) {
        final String resolvedEndpoint = recordingSubscription.resolvedEndpoint();
        if (null == resolvedEndpoint) {
            if (epochClock.time() >= (timeOfLastActionMs + actionTimeoutMs)) {
                throw new TimeoutException("failed to resolve subscription endpoint: channel=" + recordingSubscription.channel());
            }
            return workCount;
        }
        final ChannelUri channelUri = ChannelUri.parse(replicationChannel);
        channelUri.put(CommonContext.SESSION_ID_PARAM_NAME, Integer.toString(replaySessionId));
        final String endpoint = channelUri.get(CommonContext.ENDPOINT_PARAM_NAME);
        if (null != endpoint && endpoint.endsWith(":0")) {
            final int i = resolvedEndpoint.lastIndexOf(':');
            channelUri.put(CommonContext.ENDPOINT_PARAM_NAME, endpoint.substring(0, endpoint.length() - 2) + resolvedEndpoint.substring(i));
        }
        if (null != liveDestination) {
            channelUri.put(CommonContext.LINGER_PARAM_NAME, "0");
            channelUri.put(CommonContext.EOS_PARAM_NAME, "false");
        }
        final long correlationId = aeron.nextCorrelationId();
        if (srcArchive.archiveProxy().replay(srcRecordingId, replayPosition, NULL_POSITION == dstStopPosition ? AeronArchive.NULL_LENGTH : dstStopPosition - replayPosition, channelUri.toString(), replayStreamId, correlationId, srcArchive.controlSessionId())) {
            workCount += trackAction(correlationId);
        } else if (epochClock.time() >= (timeOfLastActionMs + actionTimeoutMs)) {
            throw new TimeoutException("failed to send replay request");
        }
    } else {
        final ControlResponsePoller poller = srcArchive.controlResponsePoller();
        workCount += poller.poll();
        if (hasResponse(poller)) {
            srcReplaySessionId = poller.relevantId();
            state(State.AWAIT_IMAGE);
        } else if (epochClock.time() >= (timeOfLastActionMs + actionTimeoutMs)) {
            throw new TimeoutException("failed get acknowledgement of replay request to: " + replicationChannel);
        }
    }
    return workCount;
}
Also used : TimeoutException(io.aeron.exceptions.TimeoutException)

Example 7 with TimeoutException

use of io.aeron.exceptions.TimeoutException in project Aeron by real-logic.

the class ClusterBackupAgent method doWork.

/**
 * {@inheritDoc}
 */
public int doWork() {
    final long nowMs = epochClock.time();
    int workCount = 0;
    try {
        if (nowMs > slowTickDeadlineMs) {
            slowTickDeadlineMs = nowMs + SLOW_TICK_INTERVAL_MS;
            workCount += slowTick(nowMs);
        }
        workCount += consensusSubscription.poll(fragmentAssembler, ConsensusAdapter.FRAGMENT_LIMIT);
        switch(state) {
            case BACKUP_QUERY:
                workCount += backupQuery(nowMs);
                break;
            case SNAPSHOT_RETRIEVE:
                workCount += snapshotRetrieve(nowMs);
                break;
            case LIVE_LOG_RECORD:
                workCount += liveLogRecord(nowMs);
                break;
            case LIVE_LOG_REPLAY:
                workCount += liveLogReplay(nowMs);
                break;
            case UPDATE_RECORDING_LOG:
                workCount += updateRecordingLog(nowMs);
                break;
            case BACKING_UP:
                workCount += backingUp(nowMs);
                break;
            case RESET_BACKUP:
                workCount += resetBackup(nowMs);
                break;
        }
        if (hasProgressStalled(nowMs)) {
            if (null != eventsListener) {
                eventsListener.onPossibleFailure(new TimeoutException("progress has stalled", Category.WARN));
            }
            state(RESET_BACKUP, nowMs);
        }
    } catch (final AgentTerminationException ex) {
        runTerminationHook(ex);
    } catch (final Exception ex) {
        if (null != eventsListener) {
            eventsListener.onPossibleFailure(ex);
        }
        state(RESET_BACKUP, nowMs);
        throw ex;
    }
    return workCount;
}
Also used : AgentTerminationException(org.agrona.concurrent.AgentTerminationException) ClusterException(io.aeron.cluster.client.ClusterException) TimeoutException(io.aeron.exceptions.TimeoutException) AgentTerminationException(org.agrona.concurrent.AgentTerminationException) TimeoutException(io.aeron.exceptions.TimeoutException)

Example 8 with TimeoutException

use of io.aeron.exceptions.TimeoutException in project Aeron by real-logic.

the class Election method followerCatchupAwait.

private int followerCatchupAwait(final long nowNs) {
    int workCount = 0;
    final Image image = logSubscription.imageBySessionId(logSessionId);
    if (null != image) {
        verifyLogImage(image);
        if (consensusModuleAgent.tryJoinLogAsFollower(image, isLeaderStartup)) {
            state(FOLLOWER_CATCHUP, nowNs);
            workCount++;
        } else if (nowNs >= (timeOfLastStateChangeNs + ctx.leaderHeartbeatTimeoutNs())) {
            throw new TimeoutException("failed to join catchup log as follower", AeronException.Category.WARN);
        }
    } else if (nowNs >= (timeOfLastStateChangeNs + ctx.leaderHeartbeatTimeoutNs())) {
        throw new TimeoutException("failed to join catchup log", AeronException.Category.WARN);
    }
    return workCount;
}
Also used : TimeoutException(io.aeron.exceptions.TimeoutException)

Example 9 with TimeoutException

use of io.aeron.exceptions.TimeoutException in project Aeron by real-logic.

the class Election method followerReady.

private int followerReady(final long nowNs) {
    if (consensusPublisher.appendPosition(leaderMember.publication(), leadershipTermId, logPosition, thisMember.id())) {
        consensusModuleAgent.leadershipTermId(leadershipTermId);
        consensusModuleAgent.electionComplete(nowNs);
        state(CLOSED, nowNs);
    } else if (nowNs >= (timeOfLastStateChangeNs + ctx.leaderHeartbeatTimeoutNs())) {
        throw new TimeoutException("ready follower failed to notify leader", AeronException.Category.WARN);
    }
    return 1;
}
Also used : TimeoutException(io.aeron.exceptions.TimeoutException)

Example 10 with TimeoutException

use of io.aeron.exceptions.TimeoutException in project Aeron by real-logic.

the class Election method followerLogReplication.

private int followerLogReplication(final long nowNs) {
    int workCount = 0;
    if (null == logReplication) {
        if (appendPosition < replicationStopPosition) {
            logReplication = consensusModuleAgent.newLogReplication(leaderMember.archiveEndpoint(), leaderRecordingId, replicationStopPosition, nowNs);
            replicationDeadlineNs = nowNs + ctx.leaderHeartbeatTimeoutNs();
            workCount++;
        } else {
            updateRecordingLogForReplication(replicationLeadershipTermId, replicationTermBaseLogPosition, replicationStopPosition, nowNs);
            state(CANVASS, nowNs);
        }
    } else {
        workCount += consensusModuleAgent.pollArchiveEvents();
        workCount += publishFollowerReplicationPosition(nowNs);
        if (logReplication.isDone(nowNs)) {
            if (replicationCommitPosition >= appendPosition) {
                appendPosition = logReplication.position();
                cleanupLogReplication();
                updateRecordingLogForReplication(replicationLeadershipTermId, replicationTermBaseLogPosition, replicationStopPosition, nowNs);
                state(CANVASS, nowNs);
                workCount++;
            } else if (nowNs >= replicationDeadlineNs) {
                throw new TimeoutException("timeout awaiting commit position", AeronException.Category.WARN);
            }
        }
    }
    return workCount;
}
Also used : TimeoutException(io.aeron.exceptions.TimeoutException)

Aggregations

TimeoutException (io.aeron.exceptions.TimeoutException)31 EpochClock (org.agrona.concurrent.EpochClock)4 ClusterException (io.aeron.cluster.client.ClusterException)2 MediaDriver (io.aeron.driver.MediaDriver)2 RedirectingNameResolver (io.aeron.test.driver.RedirectingNameResolver)2 AgentTerminationException (org.agrona.concurrent.AgentTerminationException)2 ReadableCounter (io.aeron.status.ReadableCounter)1