Search in sources :

Example 6 with Closure

use of org.apache.ignite.raft.jraft.Closure in project ignite-3 by apache.

the class AddLearnersRequestProcessorTest method verify.

@Override
public void verify(final String interest, final Node node, final ArgumentCaptor<Closure> doneArg) {
    assertEquals(AddLearnersRequest.class.getName(), interest);
    Mockito.verify(node).addLearners(eq(Arrays.asList(new PeerId("learner", 8082), new PeerId("test", 8182), new PeerId("test", 8183))), doneArg.capture());
    Closure done = doneArg.getValue();
    assertNotNull(done);
    done.run(Status.OK());
    assertNotNull(this.asyncContext.getResponseObject());
    assertEquals("[learner:8081, learner:8082, learner:8083]", this.asyncContext.as(LearnersOpResponse.class).oldLearnersList().toString());
    assertEquals("[learner:8081, learner:8082, learner:8083, test:8182, test:8183]", this.asyncContext.as(LearnersOpResponse.class).newLearnersList().toString());
}
Also used : Closure(org.apache.ignite.raft.jraft.Closure) LearnersOpResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.LearnersOpResponse) AddLearnersRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.AddLearnersRequest) PeerId(org.apache.ignite.raft.jraft.entity.PeerId)

Example 7 with Closure

use of org.apache.ignite.raft.jraft.Closure in project ignite-3 by apache.

the class BallotBoxTest method testCommitAt.

@Test
public void testCommitAt() {
    assertFalse(this.box.commitAt(1, 3, new PeerId("localhost", 8081)));
    assertTrue(box.resetPendingIndex(1));
    assertTrue(this.box.appendPendingTask(JRaftUtils.getConfiguration("localhost:8081,localhost:8082,localhost:8083"), JRaftUtils.getConfiguration("localhost:8081"), new Closure() {

        @Override
        public void run(Status status) {
        }
    }));
    assertEquals(0, this.box.getLastCommittedIndex());
    try {
        this.box.commitAt(1, 3, new PeerId("localhost", 8081));
        fail();
    } catch (ArrayIndexOutOfBoundsException e) {
    // No-op.
    }
    assertTrue(this.box.commitAt(1, 1, new PeerId("localhost", 8081)));
    assertEquals(0, this.box.getLastCommittedIndex());
    assertEquals(1, this.box.getPendingIndex());
    assertTrue(this.box.commitAt(1, 1, new PeerId("localhost", 8082)));
    assertEquals(1, this.box.getLastCommittedIndex());
    assertEquals(2, this.box.getPendingIndex());
    Mockito.verify(this.waiter, Mockito.only()).onCommitted(1);
}
Also used : Status(org.apache.ignite.raft.jraft.Status) Closure(org.apache.ignite.raft.jraft.Closure) PeerId(org.apache.ignite.raft.jraft.entity.PeerId) Test(org.junit.jupiter.api.Test)

Example 8 with Closure

use of org.apache.ignite.raft.jraft.Closure in project ignite-3 by apache.

the class NodeImpl method shutdown.

@Override
public void shutdown(final Closure done) {
    this.writeLock.lock();
    try {
        LOG.info("Node {} shutdown, currTerm={} state={}.", getNodeId(), this.currTerm, this.state);
        if (this.state.compareTo(State.STATE_SHUTTING) < 0) {
            // If it is follower, call on_stop_following in step_down
            if (this.state.compareTo(State.STATE_FOLLOWER) <= 0) {
                stepDown(this.currTerm, this.state == State.STATE_LEADER, new Status(RaftError.ESHUTDOWN, "Raft node is going to quit."));
            }
            this.state = State.STATE_SHUTTING;
            // Stop all pending timer callbacks.
            stopAllTimers();
            if (this.readOnlyService != null) {
                this.readOnlyService.shutdown();
            }
            if (this.logManager != null) {
                this.logManager.shutdown();
            }
            if (this.metaStorage != null) {
                this.metaStorage.shutdown();
            }
            if (this.snapshotExecutor != null) {
                this.snapshotExecutor.shutdown();
            }
            if (this.wakingCandidate != null) {
                Replicator.stop(this.wakingCandidate);
            }
            if (this.fsmCaller != null) {
                this.fsmCaller.shutdown();
            }
            if (this.rpcClientService != null) {
                this.rpcClientService.shutdown();
            }
            if (this.applyQueue != null) {
                final CountDownLatch latch = new CountDownLatch(1);
                this.shutdownLatch = latch;
                Utils.runInThread(this.getOptions().getCommonExecutor(), () -> this.applyQueue.publishEvent((event, sequence) -> {
                    event.groupId = groupId;
                    event.shutdownLatch = latch;
                }));
            }
        }
        if (this.state != State.STATE_SHUTDOWN) {
            if (done != null) {
                this.shutdownContinuations.add(done);
            }
            return;
        }
        // a writeLock which is already held by the caller
        if (done != null) {
            Utils.runClosureInThread(this.getOptions().getCommonExecutor(), done);
        }
    } finally {
        this.writeLock.unlock();
    }
}
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) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 9 with Closure

use of org.apache.ignite.raft.jraft.Closure in project ignite-3 by apache.

the class NodeImpl method executeApplyingTasks.

private void executeApplyingTasks(final List<LogEntryAndClosure> tasks) {
    this.writeLock.lock();
    try {
        final int size = tasks.size();
        if (this.state != State.STATE_LEADER) {
            final Status st = new Status();
            if (this.state != State.STATE_TRANSFERRING) {
                st.setError(RaftError.EPERM, "Is not leader.");
            } else {
                st.setError(RaftError.EBUSY, "Is transferring leadership.");
            }
            LOG.debug("Node {} can't apply, status={}.", getNodeId(), st);
            final List<Closure> dones = tasks.stream().map(ele -> ele.done).collect(Collectors.toList());
            Utils.runInThread(this.getOptions().getCommonExecutor(), () -> {
                for (final Closure done : dones) {
                    done.run(st);
                }
            });
            return;
        }
        final List<LogEntry> entries = new ArrayList<>(size);
        for (int i = 0; i < size; i++) {
            final LogEntryAndClosure task = tasks.get(i);
            if (task.expectedTerm != -1 && task.expectedTerm != this.currTerm) {
                LOG.debug("Node {} can't apply task whose expectedTerm={} doesn't match currTerm={}.", getNodeId(), task.expectedTerm, this.currTerm);
                if (task.done != null) {
                    final Status st = new Status(RaftError.EPERM, "expected_term=%d doesn't match current_term=%d", task.expectedTerm, this.currTerm);
                    Utils.runClosureInThread(this.getOptions().getCommonExecutor(), task.done, st);
                }
                continue;
            }
            if (!this.ballotBox.appendPendingTask(this.conf.getConf(), this.conf.isStable() ? null : this.conf.getOldConf(), task.done)) {
                Utils.runClosureInThread(this.getOptions().getCommonExecutor(), task.done, new Status(RaftError.EINTERNAL, "Fail to append task."));
                continue;
            }
            // set task entry info before adding to list.
            task.entry.getId().setTerm(this.currTerm);
            task.entry.setType(EnumOutter.EntryType.ENTRY_TYPE_DATA);
            entries.add(task.entry);
        }
        this.logManager.appendEntries(entries, new LeaderStableClosure(entries));
        // update conf.first
        checkAndSetConfiguration(true);
    } finally {
        this.writeLock.unlock();
    }
}
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) SynchronizedClosure(org.apache.ignite.raft.jraft.closure.SynchronizedClosure) RpcRequestClosure(org.apache.ignite.raft.jraft.rpc.RpcRequestClosure) CatchUpClosure(org.apache.ignite.raft.jraft.closure.CatchUpClosure) Closure(org.apache.ignite.raft.jraft.Closure) RpcResponseClosure(org.apache.ignite.raft.jraft.rpc.RpcResponseClosure) ReadIndexClosure(org.apache.ignite.raft.jraft.closure.ReadIndexClosure) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) LogEntry(org.apache.ignite.raft.jraft.entity.LogEntry)

Example 10 with Closure

use of org.apache.ignite.raft.jraft.Closure in project ignite-3 by apache.

the class NodeImpl method afterShutdown.

private void afterShutdown() {
    List<Closure> savedDoneList = null;
    this.writeLock.lock();
    try {
        if (!this.shutdownContinuations.isEmpty()) {
            savedDoneList = new ArrayList<>(this.shutdownContinuations);
        }
        if (this.logStorage != null) {
            this.logStorage.shutdown();
        }
        this.state = State.STATE_SHUTDOWN;
    } finally {
        this.writeLock.unlock();
    }
    if (savedDoneList != null) {
        for (final Closure closure : savedDoneList) {
            Utils.runClosureInThread(this.getOptions().getCommonExecutor(), closure);
        }
    }
}
Also used : SynchronizedClosure(org.apache.ignite.raft.jraft.closure.SynchronizedClosure) RpcRequestClosure(org.apache.ignite.raft.jraft.rpc.RpcRequestClosure) CatchUpClosure(org.apache.ignite.raft.jraft.closure.CatchUpClosure) Closure(org.apache.ignite.raft.jraft.Closure) RpcResponseClosure(org.apache.ignite.raft.jraft.rpc.RpcResponseClosure) ReadIndexClosure(org.apache.ignite.raft.jraft.closure.ReadIndexClosure)

Aggregations

Closure (org.apache.ignite.raft.jraft.Closure)18 PeerId (org.apache.ignite.raft.jraft.entity.PeerId)9 Status (org.apache.ignite.raft.jraft.Status)8 Test (org.junit.jupiter.api.Test)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 ArrayList (java.util.ArrayList)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3 CatchUpClosure (org.apache.ignite.raft.jraft.closure.CatchUpClosure)3 ReadIndexClosure (org.apache.ignite.raft.jraft.closure.ReadIndexClosure)3 SynchronizedClosure (org.apache.ignite.raft.jraft.closure.SynchronizedClosure)3 Configuration (org.apache.ignite.raft.jraft.conf.Configuration)3 LogEntry (org.apache.ignite.raft.jraft.entity.LogEntry)3 LogId (org.apache.ignite.raft.jraft.entity.LogId)3 NodeId (org.apache.ignite.raft.jraft.entity.NodeId)3 NodeOptions (org.apache.ignite.raft.jraft.option.NodeOptions)3 LearnersOpResponse (org.apache.ignite.raft.jraft.rpc.CliRequests.LearnersOpResponse)3 RpcRequestClosure (org.apache.ignite.raft.jraft.rpc.RpcRequestClosure)3 RpcResponseClosure (org.apache.ignite.raft.jraft.rpc.RpcResponseClosure)3 EventHandler (com.lmax.disruptor.EventHandler)2 EventTranslator (com.lmax.disruptor.EventTranslator)2