Search in sources :

Example 1 with Bytes

use of io.dingodb.raft.util.Bytes 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)

Aggregations

ZeroByteStringHelper (com.google.protobuf.ZeroByteStringHelper)1 BlockingWaitStrategy (com.lmax.disruptor.BlockingWaitStrategy)1 EventFactory (com.lmax.disruptor.EventFactory)1 EventHandler (com.lmax.disruptor.EventHandler)1 EventTranslator (com.lmax.disruptor.EventTranslator)1 RingBuffer (com.lmax.disruptor.RingBuffer)1 Disruptor (com.lmax.disruptor.dsl.Disruptor)1 ProducerType (com.lmax.disruptor.dsl.ProducerType)1 FSMCaller (io.dingodb.raft.FSMCaller)1 ReadOnlyService (io.dingodb.raft.ReadOnlyService)1 Status (io.dingodb.raft.Status)1 ReadIndexClosure (io.dingodb.raft.closure.ReadIndexClosure)1 ReadIndexState (io.dingodb.raft.entity.ReadIndexState)1 ReadIndexStatus (io.dingodb.raft.entity.ReadIndexStatus)1 RaftError (io.dingodb.raft.error.RaftError)1 RaftException (io.dingodb.raft.error.RaftException)1 RaftOptions (io.dingodb.raft.option.RaftOptions)1 ReadOnlyServiceOptions (io.dingodb.raft.option.ReadOnlyServiceOptions)1 RpcRequests (io.dingodb.raft.rpc.RpcRequests)1 RpcResponseClosureAdapter (io.dingodb.raft.rpc.RpcResponseClosureAdapter)1