Search in sources :

Example 1 with EventTranslator

use of com.lmax.disruptor.EventTranslator in project ignite-3 by apache.

the class ReadOnlyServiceImpl method addRequest.

@Override
public void addRequest(final byte[] reqCtx, final ReadIndexClosure closure) {
    if (this.shutdownLatch != null) {
        Utils.runClosureInThread(this.node.getOptions().getCommonExecutor(), closure, new Status(RaftError.EHOSTDOWN, "Was stopped"));
        throw new IllegalStateException("Service already shutdown.");
    }
    try {
        EventTranslator<ReadIndexEvent> translator = (event, sequence) -> {
            event.groupId = this.groupId;
            event.done = closure;
            event.requestContext = new Bytes(reqCtx);
            event.startTime = Utils.monotonicMs();
        };
        int retryTimes = 0;
        while (true) {
            if (this.readIndexQueue.tryPublishEvent(translator)) {
                break;
            } else {
                retryTimes++;
                if (retryTimes > MAX_ADD_REQUEST_RETRY_TIMES) {
                    Utils.runClosureInThread(this.node.getOptions().getCommonExecutor(), closure, new Status(RaftError.EBUSY, "Node is busy, has too many read-only requests."));
                    this.nodeMetrics.recordTimes("read-index-overload-times", 1);
                    LOG.warn("Node {} ReadOnlyServiceImpl readIndexQueue is overload.", this.node.getNodeId());
                    return;
                }
                ThreadHelper.onSpinWait();
            }
        }
    } catch (final Exception e) {
        Utils.runClosureInThread(this.node.getOptions().getCommonExecutor(), closure, new Status(RaftError.EPERM, "Node is down."));
    }
}
Also used : Status(org.apache.ignite.raft.jraft.Status) ReadIndexStatus(org.apache.ignite.raft.jraft.entity.ReadIndexStatus) ReadIndexClosure(org.apache.ignite.raft.jraft.closure.ReadIndexClosure) RaftException(org.apache.ignite.raft.jraft.error.RaftException) IgniteLogger(org.apache.ignite.lang.IgniteLogger) ArrayList(java.util.ArrayList) LastAppliedLogIndexListener(org.apache.ignite.raft.jraft.FSMCaller.LastAppliedLogIndexListener) StripedDisruptor(org.apache.ignite.raft.jraft.disruptor.StripedDisruptor) Map(java.util.Map) RpcResponseClosureAdapter(org.apache.ignite.raft.jraft.rpc.RpcResponseClosureAdapter) EventHandler(com.lmax.disruptor.EventHandler) ReadOnlyServiceOptions(org.apache.ignite.raft.jraft.option.ReadOnlyServiceOptions) ReadIndexResponse(org.apache.ignite.raft.jraft.rpc.RpcRequests.ReadIndexResponse) ReadOnlyService(org.apache.ignite.raft.jraft.ReadOnlyService) ReadIndexRequestBuilder(org.apache.ignite.raft.jraft.rpc.ReadIndexRequestBuilder) Iterator(java.util.Iterator) ReentrantLock(java.util.concurrent.locks.ReentrantLock) RingBuffer(com.lmax.disruptor.RingBuffer) Status(org.apache.ignite.raft.jraft.Status) ThreadHelper(org.apache.ignite.raft.jraft.util.ThreadHelper) GroupAware(org.apache.ignite.raft.jraft.disruptor.GroupAware) OnlyForTest(org.apache.ignite.raft.jraft.util.OnlyForTest) TimeUnit(java.util.concurrent.TimeUnit) Utils(org.apache.ignite.raft.jraft.util.Utils) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) Lock(java.util.concurrent.locks.Lock) ReadIndexStatus(org.apache.ignite.raft.jraft.entity.ReadIndexStatus) EventTranslator(com.lmax.disruptor.EventTranslator) TreeMap(java.util.TreeMap) FSMCaller(org.apache.ignite.raft.jraft.FSMCaller) ReadIndexRequest(org.apache.ignite.raft.jraft.rpc.RpcRequests.ReadIndexRequest) ReadIndexState(org.apache.ignite.raft.jraft.entity.ReadIndexState) DisruptorMetricSet(org.apache.ignite.raft.jraft.util.DisruptorMetricSet) ByteString(org.apache.ignite.raft.jraft.util.ByteString) Bytes(org.apache.ignite.raft.jraft.util.Bytes) EventFactory(com.lmax.disruptor.EventFactory) RaftOptions(org.apache.ignite.raft.jraft.option.RaftOptions) RaftError(org.apache.ignite.raft.jraft.error.RaftError) Bytes(org.apache.ignite.raft.jraft.util.Bytes) RaftException(org.apache.ignite.raft.jraft.error.RaftException)

Example 2 with EventTranslator

use of com.lmax.disruptor.EventTranslator in project dingo by dingodb.

the class ReadOnlyServiceImpl method addRequest.

@Override
public void addRequest(final byte[] reqCtx, final ReadIndexClosure closure) {
    if (this.shutdownLatch != null) {
        Utils.runClosureInThread(closure, new Status(RaftError.EHOSTDOWN, "Was stopped"));
        throw new IllegalStateException("Service already shutdown.");
    }
    try {
        EventTranslator<ReadIndexEvent> translator = (event, sequence) -> {
            event.done = closure;
            event.requestContext = new Bytes(reqCtx);
            event.startTime = Utils.monotonicMs();
        };
        int retryTimes = 0;
        while (true) {
            if (this.readIndexQueue.tryPublishEvent(translator)) {
                break;
            } else {
                retryTimes++;
                if (retryTimes > MAX_ADD_REQUEST_RETRY_TIMES) {
                    Utils.runClosureInThread(closure, new Status(RaftError.EBUSY, "Node is busy, has too many read-only requests."));
                    this.nodeMetrics.recordTimes("read-index-overload-times", 1);
                    LOG.warn("Node {} ReadOnlyServiceImpl readIndexQueue is overload.", this.node.getNodeId());
                    return;
                }
                ThreadHelper.onSpinWait();
            }
        }
    } catch (final Exception e) {
        Utils.runClosureInThread(closure, new Status(RaftError.EPERM, "Node is down."));
    }
}
Also used : Status(io.dingodb.raft.Status) ReadIndexStatus(io.dingodb.raft.entity.ReadIndexStatus) RaftException(io.dingodb.raft.error.RaftException) RaftError(io.dingodb.raft.error.RaftError) LoggerFactory(org.slf4j.LoggerFactory) LogExceptionHandler(io.dingodb.raft.util.LogExceptionHandler) ArrayList(java.util.ArrayList) Bytes(io.dingodb.raft.util.Bytes) BlockingWaitStrategy(com.lmax.disruptor.BlockingWaitStrategy) Map(java.util.Map) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ThreadHelper(io.dingodb.raft.util.ThreadHelper) ReadOnlyService(io.dingodb.raft.ReadOnlyService) OnlyForTest(io.dingodb.raft.util.OnlyForTest) EventHandler(com.lmax.disruptor.EventHandler) RaftOptions(io.dingodb.raft.option.RaftOptions) ReadIndexClosure(io.dingodb.raft.closure.ReadIndexClosure) ZeroByteStringHelper(com.google.protobuf.ZeroByteStringHelper) DisruptorMetricSet(io.dingodb.raft.util.DisruptorMetricSet) Logger(org.slf4j.Logger) NamedThreadFactory(io.dingodb.raft.util.NamedThreadFactory) Iterator(java.util.Iterator) ReentrantLock(java.util.concurrent.locks.ReentrantLock) RingBuffer(com.lmax.disruptor.RingBuffer) ProducerType(com.lmax.disruptor.dsl.ProducerType) Status(io.dingodb.raft.Status) Utils(io.dingodb.raft.util.Utils) Executors(java.util.concurrent.Executors) FSMCaller(io.dingodb.raft.FSMCaller) ReadIndexStatus(io.dingodb.raft.entity.ReadIndexStatus) DisruptorBuilder(io.dingodb.raft.util.DisruptorBuilder) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) RpcResponseClosureAdapter(io.dingodb.raft.rpc.RpcResponseClosureAdapter) List(java.util.List) Lock(java.util.concurrent.locks.Lock) EventTranslator(com.lmax.disruptor.EventTranslator) TreeMap(java.util.TreeMap) ReadOnlyServiceOptions(io.dingodb.raft.option.ReadOnlyServiceOptions) ReadIndexState(io.dingodb.raft.entity.ReadIndexState) RpcRequests(io.dingodb.raft.rpc.RpcRequests) EventFactory(com.lmax.disruptor.EventFactory) Disruptor(com.lmax.disruptor.dsl.Disruptor) Bytes(io.dingodb.raft.util.Bytes) RaftException(io.dingodb.raft.error.RaftException)

Example 3 with EventTranslator

use of com.lmax.disruptor.EventTranslator in project sofa-jraft by sofastack.

the class NodeImpl method apply.

@Override
public void apply(final Task task) {
    if (this.shutdownLatch != null) {
        Utils.runClosureInThread(task.getDone(), new Status(RaftError.ENODESHUTDOWN, "Node is shutting down."));
        throw new IllegalStateException("Node is shutting down");
    }
    Requires.requireNonNull(task, "Null task");
    final LogEntry entry = new LogEntry();
    entry.setData(task.getData());
    final EventTranslator<LogEntryAndClosure> translator = (event, sequence) -> {
        event.reset();
        event.done = task.getDone();
        event.entry = entry;
        event.expectedTerm = task.getExpectedTerm();
    };
    switch(this.options.getApplyTaskMode()) {
        case Blocking:
            this.applyQueue.publishEvent(translator);
            break;
        case NonBlocking:
        default:
            if (!this.applyQueue.tryPublishEvent(translator)) {
                String errorMsg = "Node is busy, has too many tasks, queue is full and bufferSize=" + this.applyQueue.getBufferSize();
                Utils.runClosureInThread(task.getDone(), new Status(RaftError.EBUSY, errorMsg));
                LOG.warn("Node {} applyQueue is overload.", getNodeId());
                this.metrics.recordTimes("apply-task-overload-times", 1);
                if (task.getDone() == null) {
                    throw new OverloadException(errorMsg);
                }
            }
            break;
    }
}
Also used : Status(com.alipay.sofa.jraft.Status) SnapshotExecutorImpl(com.alipay.sofa.jraft.storage.snapshot.SnapshotExecutorImpl) Platform(com.alipay.sofa.jraft.util.Platform) StringUtils(org.apache.commons.lang.StringUtils) Ballot(com.alipay.sofa.jraft.entity.Ballot) RaftOptions(com.alipay.sofa.jraft.option.RaftOptions) LeaderChangeContext(com.alipay.sofa.jraft.entity.LeaderChangeContext) SystemPropertyUtil(com.alipay.sofa.jraft.util.SystemPropertyUtil) InstallSnapshotResponse(com.alipay.sofa.jraft.rpc.RpcRequests.InstallSnapshotResponse) ReplicatorGroup(com.alipay.sofa.jraft.ReplicatorGroup) RaftMetaStorageOptions(com.alipay.sofa.jraft.option.RaftMetaStorageOptions) RaftMetaStorage(com.alipay.sofa.jraft.storage.RaftMetaStorage) AppendEntriesResponse(com.alipay.sofa.jraft.rpc.RpcRequests.AppendEntriesResponse) RpcFactoryHelper(com.alipay.sofa.jraft.util.RpcFactoryHelper) ConfigurationEntry(com.alipay.sofa.jraft.conf.ConfigurationEntry) RpcResponseClosure(com.alipay.sofa.jraft.rpc.RpcResponseClosure) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ConfigurationManager(com.alipay.sofa.jraft.conf.ConfigurationManager) PeerId(com.alipay.sofa.jraft.entity.PeerId) Set(java.util.Set) RaftServerService(com.alipay.sofa.jraft.rpc.RaftServerService) JRaftServiceFactory(com.alipay.sofa.jraft.JRaftServiceFactory) JRaftUtils(com.alipay.sofa.jraft.JRaftUtils) CountDownLatch(java.util.concurrent.CountDownLatch) ReadOnlyServiceOptions(com.alipay.sofa.jraft.option.ReadOnlyServiceOptions) RequestVoteResponse(com.alipay.sofa.jraft.rpc.RpcRequests.RequestVoteResponse) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) LogId(com.alipay.sofa.jraft.entity.LogId) FSMCallerOptions(com.alipay.sofa.jraft.option.FSMCallerOptions) ReadIndexResponse(com.alipay.sofa.jraft.rpc.RpcRequests.ReadIndexResponse) ReadOnlyOption(com.alipay.sofa.jraft.option.ReadOnlyOption) JRaftSignalHandler(com.alipay.sofa.jraft.util.JRaftSignalHandler) ArrayList(java.util.ArrayList) LogManagerOptions(com.alipay.sofa.jraft.option.LogManagerOptions) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) LogManagerImpl(com.alipay.sofa.jraft.storage.impl.LogManagerImpl) RaftError(com.alipay.sofa.jraft.error.RaftError) EventHandler(com.lmax.disruptor.EventHandler) LinkedHashSet(java.util.LinkedHashSet) SignalHelper(com.alipay.sofa.jraft.util.SignalHelper) SnapshotExecutorOptions(com.alipay.sofa.jraft.option.SnapshotExecutorOptions) RaftOutter(com.alipay.sofa.jraft.entity.RaftOutter) NamedThreadFactory(com.alipay.sofa.jraft.util.NamedThreadFactory) DisruptorBuilder(com.alipay.sofa.jraft.util.DisruptorBuilder) ClosureQueue(com.alipay.sofa.jraft.closure.ClosureQueue) TimeoutNowRequest(com.alipay.sofa.jraft.rpc.RpcRequests.TimeoutNowRequest) RaftClientService(com.alipay.sofa.jraft.rpc.RaftClientService) Lock(java.util.concurrent.locks.Lock) FSMCaller(com.alipay.sofa.jraft.FSMCaller) RequestVoteRequest(com.alipay.sofa.jraft.rpc.RpcRequests.RequestVoteRequest) InstallSnapshotRequest(com.alipay.sofa.jraft.rpc.RpcRequests.InstallSnapshotRequest) CatchUpClosure(com.alipay.sofa.jraft.closure.CatchUpClosure) Disruptor(com.lmax.disruptor.dsl.Disruptor) OverloadException(com.alipay.sofa.jraft.error.OverloadException) ScheduledFuture(java.util.concurrent.ScheduledFuture) LoggerFactory(org.slf4j.LoggerFactory) ByteBuffer(java.nio.ByteBuffer) JRaftServiceLoader(com.alipay.sofa.jraft.util.JRaftServiceLoader) Describer(com.alipay.sofa.jraft.util.Describer) BlockingWaitStrategy(com.lmax.disruptor.BlockingWaitStrategy) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LogManager(com.alipay.sofa.jraft.storage.LogManager) RaftTimerFactory(com.alipay.sofa.jraft.util.timer.RaftTimerFactory) LogExceptionHandler(com.alipay.sofa.jraft.util.LogExceptionHandler) OnlyForTest(com.alipay.sofa.jraft.util.OnlyForTest) TimeoutNowResponse(com.alipay.sofa.jraft.rpc.RpcRequests.TimeoutNowResponse) Configuration(com.alipay.sofa.jraft.conf.Configuration) Collection(java.util.Collection) SynchronizedClosure(com.alipay.sofa.jraft.closure.SynchronizedClosure) BootstrapOptions(com.alipay.sofa.jraft.option.BootstrapOptions) RpcRequestClosure(com.alipay.sofa.jraft.rpc.RpcRequestClosure) ReadIndexClosure(com.alipay.sofa.jraft.closure.ReadIndexClosure) LogStorage(com.alipay.sofa.jraft.storage.LogStorage) Collectors(java.util.stream.Collectors) List(java.util.List) RaftException(com.alipay.sofa.jraft.error.RaftException) Requires(com.alipay.sofa.jraft.util.Requires) LogIndexOutOfBoundsException(com.alipay.sofa.jraft.error.LogIndexOutOfBoundsException) AppendEntriesRequest(com.alipay.sofa.jraft.rpc.RpcRequests.AppendEntriesRequest) UserLog(com.alipay.sofa.jraft.entity.UserLog) LogNotFoundException(com.alipay.sofa.jraft.error.LogNotFoundException) ReadIndexRequest(com.alipay.sofa.jraft.rpc.RpcRequests.ReadIndexRequest) LongHeldDetectingReadWriteLock(com.alipay.sofa.jraft.util.concurrent.LongHeldDetectingReadWriteLock) Utils(com.alipay.sofa.jraft.util.Utils) EnumOutter(com.alipay.sofa.jraft.entity.EnumOutter) SnapshotExecutor(com.alipay.sofa.jraft.storage.SnapshotExecutor) DefaultRaftClientService(com.alipay.sofa.jraft.rpc.impl.core.DefaultRaftClientService) HashSet(java.util.HashSet) NodeManager(com.alipay.sofa.jraft.NodeManager) Closure(com.alipay.sofa.jraft.Closure) ThreadId(com.alipay.sofa.jraft.util.ThreadId) ClosureQueueImpl(com.alipay.sofa.jraft.closure.ClosureQueueImpl) Logger(org.slf4j.Logger) DisruptorMetricSet(com.alipay.sofa.jraft.util.DisruptorMetricSet) NodeId(com.alipay.sofa.jraft.entity.NodeId) RingBuffer(com.lmax.disruptor.RingBuffer) ProducerType(com.lmax.disruptor.dsl.ProducerType) Status(com.alipay.sofa.jraft.Status) NodeOptions(com.alipay.sofa.jraft.option.NodeOptions) TimeUnit(java.util.concurrent.TimeUnit) Task(com.alipay.sofa.jraft.entity.Task) EventTranslator(com.lmax.disruptor.EventTranslator) Node(com.alipay.sofa.jraft.Node) LogEntry(com.alipay.sofa.jraft.entity.LogEntry) ReplicatorGroupOptions(com.alipay.sofa.jraft.option.ReplicatorGroupOptions) Message(com.google.protobuf.Message) ReadOnlyService(com.alipay.sofa.jraft.ReadOnlyService) BallotBoxOptions(com.alipay.sofa.jraft.option.BallotBoxOptions) EventFactory(com.lmax.disruptor.EventFactory) RepeatedTimer(com.alipay.sofa.jraft.util.RepeatedTimer) RpcResponseClosureAdapter(com.alipay.sofa.jraft.rpc.RpcResponseClosureAdapter) OverloadException(com.alipay.sofa.jraft.error.OverloadException) LogEntry(com.alipay.sofa.jraft.entity.LogEntry)

Example 4 with EventTranslator

use of com.lmax.disruptor.EventTranslator in project sofa-jraft by sofastack.

the class ReadOnlyServiceImpl method addRequest.

@Override
public void addRequest(final byte[] reqCtx, final ReadIndexClosure closure) {
    if (this.shutdownLatch != null) {
        Utils.runClosureInThread(closure, new Status(RaftError.EHOSTDOWN, "Was stopped"));
        throw new IllegalStateException("Service already shutdown.");
    }
    try {
        EventTranslator<ReadIndexEvent> translator = (event, sequence) -> {
            event.done = closure;
            event.requestContext = new Bytes(reqCtx);
            event.startTime = Utils.monotonicMs();
        };
        switch(this.node.getOptions().getApplyTaskMode()) {
            case Blocking:
                this.readIndexQueue.publishEvent(translator);
                break;
            case NonBlocking:
            default:
                if (!this.readIndexQueue.tryPublishEvent(translator)) {
                    final String errorMsg = "Node is busy, has too many read-index requests, queue is full and bufferSize=" + this.readIndexQueue.getBufferSize();
                    Utils.runClosureInThread(closure, new Status(RaftError.EBUSY, errorMsg));
                    this.nodeMetrics.recordTimes("read-index-overload-times", 1);
                    LOG.warn("Node {} ReadOnlyServiceImpl readIndexQueue is overload.", this.node.getNodeId());
                    if (closure == null) {
                        throw new OverloadException(errorMsg);
                    }
                }
                break;
        }
    } catch (final Exception e) {
        Utils.runClosureInThread(closure, new Status(RaftError.EPERM, "Node is down."));
    }
}
Also used : Status(com.alipay.sofa.jraft.Status) ReadIndexStatus(com.alipay.sofa.jraft.entity.ReadIndexStatus) OverloadException(com.alipay.sofa.jraft.error.OverloadException) ReadIndexState(com.alipay.sofa.jraft.entity.ReadIndexState) RaftOptions(com.alipay.sofa.jraft.option.RaftOptions) ReadIndexResponse(com.alipay.sofa.jraft.rpc.RpcRequests.ReadIndexResponse) LoggerFactory(org.slf4j.LoggerFactory) ReadIndexRequest(com.alipay.sofa.jraft.rpc.RpcRequests.ReadIndexRequest) LastAppliedLogIndexListener(com.alipay.sofa.jraft.FSMCaller.LastAppliedLogIndexListener) Utils(com.alipay.sofa.jraft.util.Utils) ArrayList(java.util.ArrayList) BlockingWaitStrategy(com.lmax.disruptor.BlockingWaitStrategy) Map(java.util.Map) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) RaftError(com.alipay.sofa.jraft.error.RaftError) EventHandler(com.lmax.disruptor.EventHandler) LogExceptionHandler(com.alipay.sofa.jraft.util.LogExceptionHandler) OnlyForTest(com.alipay.sofa.jraft.util.OnlyForTest) ZeroByteStringHelper(com.google.protobuf.ZeroByteStringHelper) Logger(org.slf4j.Logger) DisruptorMetricSet(com.alipay.sofa.jraft.util.DisruptorMetricSet) Iterator(java.util.Iterator) ReentrantLock(java.util.concurrent.locks.ReentrantLock) NamedThreadFactory(com.alipay.sofa.jraft.util.NamedThreadFactory) RingBuffer(com.lmax.disruptor.RingBuffer) DisruptorBuilder(com.alipay.sofa.jraft.util.DisruptorBuilder) ProducerType(com.lmax.disruptor.dsl.ProducerType) Status(com.alipay.sofa.jraft.Status) ReadIndexClosure(com.alipay.sofa.jraft.closure.ReadIndexClosure) ReadIndexStatus(com.alipay.sofa.jraft.entity.ReadIndexStatus) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) ReadOnlyServiceOptions(com.alipay.sofa.jraft.option.ReadOnlyServiceOptions) List(java.util.List) Lock(java.util.concurrent.locks.Lock) TreeMap(java.util.TreeMap) EventTranslator(com.lmax.disruptor.EventTranslator) FSMCaller(com.alipay.sofa.jraft.FSMCaller) Bytes(com.alipay.sofa.jraft.util.Bytes) ReadOnlyService(com.alipay.sofa.jraft.ReadOnlyService) EventFactory(com.lmax.disruptor.EventFactory) RaftException(com.alipay.sofa.jraft.error.RaftException) Disruptor(com.lmax.disruptor.dsl.Disruptor) RpcResponseClosureAdapter(com.alipay.sofa.jraft.rpc.RpcResponseClosureAdapter) Bytes(com.alipay.sofa.jraft.util.Bytes) OverloadException(com.alipay.sofa.jraft.error.OverloadException) OverloadException(com.alipay.sofa.jraft.error.OverloadException) RaftException(com.alipay.sofa.jraft.error.RaftException)

Example 5 with EventTranslator

use of com.lmax.disruptor.EventTranslator in project ignite-3 by apache.

the class NodeImpl method apply.

@Override
public void apply(final Task task) {
    if (this.shutdownLatch != null) {
        Utils.runClosureInThread(this.getOptions().getCommonExecutor(), task.getDone(), new Status(RaftError.ENODESHUTDOWN, "Node is shutting down."));
        throw new IllegalStateException("Node is shutting down");
    }
    Requires.requireNonNull(task, "Null task");
    final LogEntry entry = new LogEntry();
    entry.setData(task.getData());
    int retryTimes = 0;
    try {
        final EventTranslator<LogEntryAndClosure> translator = (event, sequence) -> {
            event.reset();
            event.groupId = groupId;
            event.done = task.getDone();
            event.entry = entry;
            event.expectedTerm = task.getExpectedTerm();
        };
        while (true) {
            if (this.applyQueue.tryPublishEvent(translator)) {
                break;
            } else {
                retryTimes++;
                if (retryTimes > MAX_APPLY_RETRY_TIMES) {
                    Utils.runClosureInThread(this.getOptions().getCommonExecutor(), task.getDone(), new Status(RaftError.EBUSY, "Node is busy, has too many tasks."));
                    LOG.warn("Node {} applyQueue is overload.", getNodeId());
                    this.metrics.recordTimes("apply-task-overload-times", 1);
                    return;
                }
                ThreadHelper.onSpinWait();
            }
        }
    } catch (final Exception e) {
        LOG.error("Fail to apply task.", e);
        Utils.runClosureInThread(this.getOptions().getCommonExecutor(), task.getDone(), new Status(RaftError.EPERM, "Node is down."));
    }
}
Also used : Status(org.apache.ignite.raft.jraft.Status) SynchronizedClosure(org.apache.ignite.raft.jraft.closure.SynchronizedClosure) SnapshotExecutorImpl(org.apache.ignite.raft.jraft.storage.snapshot.SnapshotExecutorImpl) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) Set(java.util.Set) AppendEntriesResponse(org.apache.ignite.raft.jraft.rpc.RpcRequests.AppendEntriesResponse) ExecutorServiceHelper(org.apache.ignite.raft.jraft.util.ExecutorServiceHelper) AppendEntriesRequest(org.apache.ignite.raft.jraft.rpc.RpcRequests.AppendEntriesRequest) CountDownLatch(java.util.concurrent.CountDownLatch) ConfigurationEntry(org.apache.ignite.raft.jraft.conf.ConfigurationEntry) SnapshotExecutorOptions(org.apache.ignite.raft.jraft.option.SnapshotExecutorOptions) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) RaftError(org.apache.ignite.raft.jraft.error.RaftError) LogManagerImpl(org.apache.ignite.raft.jraft.storage.impl.LogManagerImpl) StringUtils(org.apache.ignite.raft.jraft.util.StringUtils) RpcRequestClosure(org.apache.ignite.raft.jraft.rpc.RpcRequestClosure) RaftException(org.apache.ignite.raft.jraft.error.RaftException) RaftMetaStorageOptions(org.apache.ignite.raft.jraft.option.RaftMetaStorageOptions) ArrayList(java.util.ArrayList) Task(org.apache.ignite.raft.jraft.entity.Task) TimeoutStrategy(org.apache.ignite.raft.jraft.util.TimeoutStrategy) SnapshotExecutor(org.apache.ignite.raft.jraft.storage.SnapshotExecutor) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) CatchUpClosure(org.apache.ignite.raft.jraft.closure.CatchUpClosure) BallotBoxOptions(org.apache.ignite.raft.jraft.option.BallotBoxOptions) EventHandler(com.lmax.disruptor.EventHandler) ReadOnlyServiceOptions(org.apache.ignite.raft.jraft.option.ReadOnlyServiceOptions) ReadIndexResponse(org.apache.ignite.raft.jraft.rpc.RpcRequests.ReadIndexResponse) LinkedHashSet(java.util.LinkedHashSet) LogIndexOutOfBoundsException(org.apache.ignite.raft.jraft.error.LogIndexOutOfBoundsException) SystemPropertyUtil(org.apache.ignite.raft.jraft.util.SystemPropertyUtil) TimeoutNowResponse(org.apache.ignite.raft.jraft.rpc.RpcRequests.TimeoutNowResponse) Closure(org.apache.ignite.raft.jraft.Closure) ClosureQueue(org.apache.ignite.raft.jraft.closure.ClosureQueue) LogNotFoundException(org.apache.ignite.raft.jraft.error.LogNotFoundException) DefaultRaftClientService(org.apache.ignite.raft.jraft.rpc.impl.core.DefaultRaftClientService) RaftRpcFactory(org.apache.ignite.raft.jraft.rpc.RaftRpcFactory) Lock(java.util.concurrent.locks.Lock) LogManagerOptions(org.apache.ignite.raft.jraft.option.LogManagerOptions) FSMCaller(org.apache.ignite.raft.jraft.FSMCaller) ReadIndexRequest(org.apache.ignite.raft.jraft.rpc.RpcRequests.ReadIndexRequest) TimeoutNowRequest(org.apache.ignite.raft.jraft.rpc.RpcRequests.TimeoutNowRequest) LeaderChangeContext(org.apache.ignite.raft.jraft.entity.LeaderChangeContext) NamedThreadFactory(org.apache.ignite.internal.thread.NamedThreadFactory) RaftOptions(org.apache.ignite.raft.jraft.option.RaftOptions) RaftServerService(org.apache.ignite.raft.jraft.rpc.RaftServerService) LogManager(org.apache.ignite.raft.jraft.storage.LogManager) ScheduledFuture(java.util.concurrent.ScheduledFuture) EnumOutter(org.apache.ignite.raft.jraft.entity.EnumOutter) Requires(org.apache.ignite.raft.jraft.util.Requires) LogEntry(org.apache.ignite.raft.jraft.entity.LogEntry) IgniteLogger(org.apache.ignite.lang.IgniteLogger) ByteBuffer(java.nio.ByteBuffer) ConfigurationManager(org.apache.ignite.raft.jraft.conf.ConfigurationManager) ReadIndexResponseBuilder(org.apache.ignite.raft.jraft.rpc.ReadIndexResponseBuilder) ReplicatorGroupOptions(org.apache.ignite.raft.jraft.option.ReplicatorGroupOptions) ReadOnlyOption(org.apache.ignite.raft.jraft.option.ReadOnlyOption) AppendEntriesResponseBuilder(org.apache.ignite.raft.jraft.rpc.AppendEntriesResponseBuilder) StripedDisruptor(org.apache.ignite.raft.jraft.disruptor.StripedDisruptor) RpcResponseClosureAdapter(org.apache.ignite.raft.jraft.rpc.RpcResponseClosureAdapter) Node(org.apache.ignite.raft.jraft.Node) LogId(org.apache.ignite.raft.jraft.entity.LogId) ReadOnlyService(org.apache.ignite.raft.jraft.ReadOnlyService) Collection(java.util.Collection) Status(org.apache.ignite.raft.jraft.Status) GroupAware(org.apache.ignite.raft.jraft.disruptor.GroupAware) NodeId(org.apache.ignite.raft.jraft.entity.NodeId) BootstrapOptions(org.apache.ignite.raft.jraft.option.BootstrapOptions) Collectors(java.util.stream.Collectors) OnlyForTest(org.apache.ignite.raft.jraft.util.OnlyForTest) Utils(org.apache.ignite.raft.jraft.util.Utils) List(java.util.List) LogStorage(org.apache.ignite.raft.jraft.storage.LogStorage) LongHeldDetectingReadWriteLock(org.apache.ignite.raft.jraft.util.concurrent.LongHeldDetectingReadWriteLock) RpcResponseClosure(org.apache.ignite.raft.jraft.rpc.RpcResponseClosure) DisruptorMetricSet(org.apache.ignite.raft.jraft.util.DisruptorMetricSet) RaftOutter(org.apache.ignite.raft.jraft.entity.RaftOutter) RequestVoteRequest(org.apache.ignite.raft.jraft.rpc.RpcRequests.RequestVoteRequest) Configuration(org.apache.ignite.raft.jraft.conf.Configuration) ReadIndexClosure(org.apache.ignite.raft.jraft.closure.ReadIndexClosure) NodeOptions(org.apache.ignite.raft.jraft.option.NodeOptions) HashSet(java.util.HashSet) RepeatedTimer(org.apache.ignite.raft.jraft.util.RepeatedTimer) RequestVoteResponse(org.apache.ignite.raft.jraft.rpc.RpcRequests.RequestVoteResponse) JRaftServiceFactory(org.apache.ignite.raft.jraft.JRaftServiceFactory) Describer(org.apache.ignite.raft.jraft.util.Describer) RaftClientService(org.apache.ignite.raft.jraft.rpc.RaftClientService) ClosureQueueImpl(org.apache.ignite.raft.jraft.closure.ClosureQueueImpl) JRaftUtils(org.apache.ignite.raft.jraft.JRaftUtils) RingBuffer(com.lmax.disruptor.RingBuffer) FSMCallerOptions(org.apache.ignite.raft.jraft.option.FSMCallerOptions) RaftMetaStorage(org.apache.ignite.raft.jraft.storage.RaftMetaStorage) ThreadHelper(org.apache.ignite.raft.jraft.util.ThreadHelper) TimeUnit(java.util.concurrent.TimeUnit) PeerId(org.apache.ignite.raft.jraft.entity.PeerId) Peer(org.apache.ignite.raft.client.Peer) Ballot(org.apache.ignite.raft.jraft.entity.Ballot) InstallSnapshotRequest(org.apache.ignite.raft.jraft.rpc.RpcRequests.InstallSnapshotRequest) EventTranslator(com.lmax.disruptor.EventTranslator) UserLog(org.apache.ignite.raft.jraft.entity.UserLog) Message(org.apache.ignite.raft.jraft.rpc.Message) ThreadId(org.apache.ignite.raft.jraft.util.ThreadId) ReplicatorGroup(org.apache.ignite.raft.jraft.ReplicatorGroup) ByteString(org.apache.ignite.raft.jraft.util.ByteString) LogEntry(org.apache.ignite.raft.jraft.entity.LogEntry) RaftException(org.apache.ignite.raft.jraft.error.RaftException) LogIndexOutOfBoundsException(org.apache.ignite.raft.jraft.error.LogIndexOutOfBoundsException) LogNotFoundException(org.apache.ignite.raft.jraft.error.LogNotFoundException)

Aggregations

EventHandler (com.lmax.disruptor.EventHandler)7 EventTranslator (com.lmax.disruptor.EventTranslator)7 RingBuffer (com.lmax.disruptor.RingBuffer)7 ArrayList (java.util.ArrayList)7 List (java.util.List)7 CountDownLatch (java.util.concurrent.CountDownLatch)7 Lock (java.util.concurrent.locks.Lock)7 TimeUnit (java.util.concurrent.TimeUnit)6 EventFactory (com.lmax.disruptor.EventFactory)5 BlockingWaitStrategy (com.lmax.disruptor.BlockingWaitStrategy)4 Disruptor (com.lmax.disruptor.dsl.Disruptor)4 ProducerType (com.lmax.disruptor.dsl.ProducerType)4 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)4 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)4 ByteBuffer (java.nio.ByteBuffer)3 Collection (java.util.Collection)3 HashSet (java.util.HashSet)3 LinkedHashSet (java.util.LinkedHashSet)3 Set (java.util.Set)3 ScheduledFuture (java.util.concurrent.ScheduledFuture)3