Search in sources :

Example 6 with Node

use of io.dingodb.raft.Node in project dingo by dingodb.

the class CoordinatorServer method start.

public void start(final CoordinatorOptions opts) throws Exception {
    this.svrOpts = opts;
    log.info("Coordinator all configuration: {}.", this.svrOpts);
    log.info("instance configuration: {}.", DingoOptions.instance());
    this.context = new CoordinatorContext();
    final String raftId = svrOpts.getRaft().getGroup();
    final Endpoint endpoint = new Endpoint(svrOpts.getIp(), svrOpts.getRaft().getPort());
    final RocksRawKVStore rawKVStore = createRocksDB();
    final CoordinatorStateMachine stateMachine = createStateMachine(raftId, rawKVStore, context);
    final Node node = RaftServiceFactory.createRaftNode(raftId, new PeerId(endpoint, 0));
    final AsyncKeyValueStore keyValueStore = createStore(rawKVStore, node);
    final ScheduleMetaAdaptor scheduleMetaAdaptor = createScheduleMetaAdaptor(keyValueStore);
    final TableMetaAdaptor tableMetaAdaptor = createTableMetaAdaptor(keyValueStore, scheduleMetaAdaptor);
    final CoordinatorMetaService metaService = createMetaService();
    final RowStoreMetaAdaptor rowStoreMetaAdaptor = createRowStoreMetaAdaptor(scheduleMetaAdaptor);
    context.coordOpts(svrOpts).endpoint(endpoint).netService(createNetService()).rocksKVStore(rawKVStore).stateMachine(stateMachine).keyValueStore(keyValueStore).node(node).scheduleMetaAdaptor(scheduleMetaAdaptor).serviceProvider(createServiceProvider()).tableMetaAdaptor(tableMetaAdaptor).rowStoreMetaAdaptor(rowStoreMetaAdaptor).metaService(metaService);
    NodeManager.getInstance().addAddress(endpoint);
    stateMachine.init();
    final NodeOptions nodeOptions = initNodeOptions(stateMachine);
    node.init(nodeOptions);
    keyValueStore.init();
}
Also used : RowStoreMetaAdaptor(io.dingodb.server.coordinator.meta.RowStoreMetaAdaptor) CoordinatorStateMachine(io.dingodb.server.coordinator.state.CoordinatorStateMachine) Node(io.dingodb.raft.Node) RocksRawKVStore(io.dingodb.store.row.storage.RocksRawKVStore) ScheduleMetaAdaptor(io.dingodb.server.coordinator.meta.ScheduleMetaAdaptor) NodeOptions(io.dingodb.raft.option.NodeOptions) CoordinatorContext(io.dingodb.server.coordinator.context.CoordinatorContext) AsyncKeyValueStore(io.dingodb.server.coordinator.store.AsyncKeyValueStore) RaftAsyncKeyValueStore(io.dingodb.server.coordinator.store.RaftAsyncKeyValueStore) TableMetaAdaptor(io.dingodb.server.coordinator.meta.TableMetaAdaptor) Endpoint(io.dingodb.raft.util.Endpoint) CoordinatorMetaService(io.dingodb.server.coordinator.meta.service.CoordinatorMetaService) PeerId(io.dingodb.raft.entity.PeerId)

Example 7 with Node

use of io.dingodb.raft.Node in project dingo by dingodb.

the class NodeImpl method shutdown.

@Override
public void shutdown(Closure done) {
    List<RepeatedTimer> timers = null;
    this.writeLock.lock();
    try {
        LOG.info("Node {} shutdown, currTerm={} state={}.", getNodeId(), this.currTerm, this.state);
        if (this.state.compareTo(State.STATE_SHUTTING) < 0) {
            NodeManager.getInstance().remove(this);
            // 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 timers
            timers = 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.rpcService != null) {
                this.rpcService.shutdown();
            }
            if (this.applyQueue != null) {
                final CountDownLatch latch = new CountDownLatch(1);
                this.shutdownLatch = latch;
                Utils.runInThread(() -> this.applyQueue.publishEvent((event, sequence) -> event.shutdownLatch = latch));
            } else {
                final int num = GLOBAL_NUM_NODES.decrementAndGet();
                LOG.info("The number of active nodes decrement to {}.", num);
            }
            if (this.timerManager != null) {
                this.timerManager.shutdown();
            }
        }
        if (this.state != State.STATE_SHUTDOWN) {
            if (done != null) {
                this.shutdownContinuations.add(done);
                done = null;
            }
            return;
        }
    } finally {
        this.writeLock.unlock();
        // Destroy all timers out of lock
        if (timers != null) {
            destroyAllTimers(timers);
        }
        // Call join() asynchronously
        final Closure shutdownHook = done;
        Utils.runInThread(() -> {
            try {
                join();
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            } finally {
                // a writeLock which is already held by the caller
                if (shutdownHook != null) {
                    shutdownHook.run(Status.OK());
                }
            }
        });
    }
}
Also used : Status(io.dingodb.raft.Status) FSMCallerOptions(io.dingodb.raft.option.FSMCallerOptions) RpcRequestClosure(io.dingodb.raft.rpc.RpcRequestClosure) StringUtils(org.apache.commons.lang.StringUtils) Describer(io.dingodb.raft.util.Describer) LongHeldDetectingReadWriteLock(io.dingodb.raft.util.concurrent.LongHeldDetectingReadWriteLock) ThreadHelper(io.dingodb.raft.util.ThreadHelper) LogManager(io.dingodb.raft.storage.LogManager) RaftClientService(io.dingodb.raft.rpc.RaftClientService) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) SynchronizedClosure(io.dingodb.raft.closure.SynchronizedClosure) LogManagerOptions(io.dingodb.raft.option.LogManagerOptions) Set(java.util.Set) Configuration(io.dingodb.raft.conf.Configuration) Utils(io.dingodb.raft.util.Utils) RaftOutter(io.dingodb.raft.entity.RaftOutter) EnumOutter(io.dingodb.raft.entity.EnumOutter) CountDownLatch(java.util.concurrent.CountDownLatch) RaftTimerFactory(io.dingodb.raft.util.timer.RaftTimerFactory) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) LogId(io.dingodb.raft.entity.LogId) JRaftServiceLoader(io.dingodb.raft.util.JRaftServiceLoader) SystemPropertyUtil(io.dingodb.raft.util.SystemPropertyUtil) JRaftUtils(io.dingodb.raft.JRaftUtils) LogExceptionHandler(io.dingodb.raft.util.LogExceptionHandler) ArrayList(java.util.ArrayList) JRaftServiceFactory(io.dingodb.raft.JRaftServiceFactory) ReadOnlyOption(io.dingodb.raft.option.ReadOnlyOption) BootstrapOptions(io.dingodb.raft.option.BootstrapOptions) LogStorage(io.dingodb.raft.storage.LogStorage) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) EventHandler(com.lmax.disruptor.EventHandler) LinkedHashSet(java.util.LinkedHashSet) DisruptorMetricSet(io.dingodb.raft.util.DisruptorMetricSet) DefaultRaftClientService(io.dingodb.raft.rpc.impl.core.DefaultRaftClientService) SnapshotExecutorImpl(io.dingodb.raft.storage.snapshot.SnapshotExecutorImpl) NodeManager(io.dingodb.raft.NodeManager) BallotBoxOptions(io.dingodb.raft.option.BallotBoxOptions) Lock(java.util.concurrent.locks.Lock) Ballot(io.dingodb.raft.entity.Ballot) PeerId(io.dingodb.raft.entity.PeerId) ReadOnlyServiceOptions(io.dingodb.raft.option.ReadOnlyServiceOptions) ConfigurationManager(io.dingodb.raft.conf.ConfigurationManager) SnapshotExecutor(io.dingodb.raft.storage.SnapshotExecutor) Disruptor(com.lmax.disruptor.dsl.Disruptor) RaftServerService(io.dingodb.raft.rpc.RaftServerService) ThreadId(io.dingodb.raft.util.ThreadId) ScheduledFuture(java.util.concurrent.ScheduledFuture) LoggerFactory(org.slf4j.LoggerFactory) ClosureQueueImpl(io.dingodb.raft.closure.ClosureQueueImpl) ByteBuffer(java.nio.ByteBuffer) RaftMetaStorageOptions(io.dingodb.raft.option.RaftMetaStorageOptions) SignalHelper(io.dingodb.raft.util.SignalHelper) BlockingWaitStrategy(com.lmax.disruptor.BlockingWaitStrategy) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CatchUpClosure(io.dingodb.raft.closure.CatchUpClosure) Task(io.dingodb.raft.entity.Task) RaftOptions(io.dingodb.raft.option.RaftOptions) Collection(java.util.Collection) Status(io.dingodb.raft.Status) ReplicatorGroupOptions(io.dingodb.raft.option.ReplicatorGroupOptions) Collectors(java.util.stream.Collectors) FSMCaller(io.dingodb.raft.FSMCaller) DisruptorBuilder(io.dingodb.raft.util.DisruptorBuilder) RpcResponseClosureAdapter(io.dingodb.raft.rpc.RpcResponseClosureAdapter) List(java.util.List) NodeId(io.dingodb.raft.entity.NodeId) RpcResponseClosure(io.dingodb.raft.rpc.RpcResponseClosure) RaftException(io.dingodb.raft.error.RaftException) Requires(io.dingodb.raft.util.Requires) RaftError(io.dingodb.raft.error.RaftError) UserLog(io.dingodb.raft.entity.UserLog) LogEntry(io.dingodb.raft.entity.LogEntry) HashSet(java.util.HashSet) RaftMetaStorage(io.dingodb.raft.storage.RaftMetaStorage) SnapshotExecutorOptions(io.dingodb.raft.option.SnapshotExecutorOptions) ConfigurationEntry(io.dingodb.raft.conf.ConfigurationEntry) ReadOnlyService(io.dingodb.raft.ReadOnlyService) OnlyForTest(io.dingodb.raft.util.OnlyForTest) ReadIndexClosure(io.dingodb.raft.closure.ReadIndexClosure) LogIndexOutOfBoundsException(io.dingodb.raft.error.LogIndexOutOfBoundsException) Logger(org.slf4j.Logger) NamedThreadFactory(io.dingodb.raft.util.NamedThreadFactory) ClosureQueue(io.dingodb.raft.closure.ClosureQueue) RingBuffer(com.lmax.disruptor.RingBuffer) Closure(io.dingodb.raft.Closure) ProducerType(com.lmax.disruptor.dsl.ProducerType) Node(io.dingodb.raft.Node) Platform(io.dingodb.raft.util.Platform) NodeOptions(io.dingodb.raft.option.NodeOptions) LogNotFoundException(io.dingodb.raft.error.LogNotFoundException) ReplicatorGroup(io.dingodb.raft.ReplicatorGroup) TimeUnit(java.util.concurrent.TimeUnit) JRaftSignalHandler(io.dingodb.raft.util.JRaftSignalHandler) RpcFactoryHelper(io.dingodb.raft.util.RpcFactoryHelper) EventTranslator(com.lmax.disruptor.EventTranslator) LogManagerImpl(io.dingodb.raft.storage.impl.LogManagerImpl) RepeatedTimer(io.dingodb.raft.util.RepeatedTimer) Message(com.google.protobuf.Message) RpcRequests(io.dingodb.raft.rpc.RpcRequests) LeaderChangeContext(io.dingodb.raft.entity.LeaderChangeContext) EventFactory(com.lmax.disruptor.EventFactory) RpcRequestClosure(io.dingodb.raft.rpc.RpcRequestClosure) SynchronizedClosure(io.dingodb.raft.closure.SynchronizedClosure) CatchUpClosure(io.dingodb.raft.closure.CatchUpClosure) RpcResponseClosure(io.dingodb.raft.rpc.RpcResponseClosure) ReadIndexClosure(io.dingodb.raft.closure.ReadIndexClosure) Closure(io.dingodb.raft.Closure) RepeatedTimer(io.dingodb.raft.util.RepeatedTimer) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 8 with Node

use of io.dingodb.raft.Node in project dingo by dingodb.

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());
    int retryTimes = 0;
    try {
        final EventTranslator<LogEntryAndClosure> translator = (event, sequence) -> {
            event.reset();
            event.done = task.getDone();
            event.entry = entry;
            event.expectedTerm = task.getExpectedTerm();
        };
        this.applyQueue.publishEvent(translator);
    /*
            while (true) {
                if (this.applyQueue.tryPublishEvent(translator)) {
                    break;
                } else {
                    retryTimes++;
                    if (retryTimes > MAX_APPLY_RETRY_TIMES) {
                        Utils.runClosureInThread(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(task.getDone(), new Status(RaftError.EPERM, "Node is down."));
    }
}
Also used : Status(io.dingodb.raft.Status) FSMCallerOptions(io.dingodb.raft.option.FSMCallerOptions) RpcRequestClosure(io.dingodb.raft.rpc.RpcRequestClosure) StringUtils(org.apache.commons.lang.StringUtils) Describer(io.dingodb.raft.util.Describer) LongHeldDetectingReadWriteLock(io.dingodb.raft.util.concurrent.LongHeldDetectingReadWriteLock) ThreadHelper(io.dingodb.raft.util.ThreadHelper) LogManager(io.dingodb.raft.storage.LogManager) RaftClientService(io.dingodb.raft.rpc.RaftClientService) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) SynchronizedClosure(io.dingodb.raft.closure.SynchronizedClosure) LogManagerOptions(io.dingodb.raft.option.LogManagerOptions) Set(java.util.Set) Configuration(io.dingodb.raft.conf.Configuration) Utils(io.dingodb.raft.util.Utils) RaftOutter(io.dingodb.raft.entity.RaftOutter) EnumOutter(io.dingodb.raft.entity.EnumOutter) CountDownLatch(java.util.concurrent.CountDownLatch) RaftTimerFactory(io.dingodb.raft.util.timer.RaftTimerFactory) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) LogId(io.dingodb.raft.entity.LogId) JRaftServiceLoader(io.dingodb.raft.util.JRaftServiceLoader) SystemPropertyUtil(io.dingodb.raft.util.SystemPropertyUtil) JRaftUtils(io.dingodb.raft.JRaftUtils) LogExceptionHandler(io.dingodb.raft.util.LogExceptionHandler) ArrayList(java.util.ArrayList) JRaftServiceFactory(io.dingodb.raft.JRaftServiceFactory) ReadOnlyOption(io.dingodb.raft.option.ReadOnlyOption) BootstrapOptions(io.dingodb.raft.option.BootstrapOptions) LogStorage(io.dingodb.raft.storage.LogStorage) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) EventHandler(com.lmax.disruptor.EventHandler) LinkedHashSet(java.util.LinkedHashSet) DisruptorMetricSet(io.dingodb.raft.util.DisruptorMetricSet) DefaultRaftClientService(io.dingodb.raft.rpc.impl.core.DefaultRaftClientService) SnapshotExecutorImpl(io.dingodb.raft.storage.snapshot.SnapshotExecutorImpl) NodeManager(io.dingodb.raft.NodeManager) BallotBoxOptions(io.dingodb.raft.option.BallotBoxOptions) Lock(java.util.concurrent.locks.Lock) Ballot(io.dingodb.raft.entity.Ballot) PeerId(io.dingodb.raft.entity.PeerId) ReadOnlyServiceOptions(io.dingodb.raft.option.ReadOnlyServiceOptions) ConfigurationManager(io.dingodb.raft.conf.ConfigurationManager) SnapshotExecutor(io.dingodb.raft.storage.SnapshotExecutor) Disruptor(com.lmax.disruptor.dsl.Disruptor) RaftServerService(io.dingodb.raft.rpc.RaftServerService) ThreadId(io.dingodb.raft.util.ThreadId) ScheduledFuture(java.util.concurrent.ScheduledFuture) LoggerFactory(org.slf4j.LoggerFactory) ClosureQueueImpl(io.dingodb.raft.closure.ClosureQueueImpl) ByteBuffer(java.nio.ByteBuffer) RaftMetaStorageOptions(io.dingodb.raft.option.RaftMetaStorageOptions) SignalHelper(io.dingodb.raft.util.SignalHelper) BlockingWaitStrategy(com.lmax.disruptor.BlockingWaitStrategy) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CatchUpClosure(io.dingodb.raft.closure.CatchUpClosure) Task(io.dingodb.raft.entity.Task) RaftOptions(io.dingodb.raft.option.RaftOptions) Collection(java.util.Collection) Status(io.dingodb.raft.Status) ReplicatorGroupOptions(io.dingodb.raft.option.ReplicatorGroupOptions) Collectors(java.util.stream.Collectors) FSMCaller(io.dingodb.raft.FSMCaller) DisruptorBuilder(io.dingodb.raft.util.DisruptorBuilder) RpcResponseClosureAdapter(io.dingodb.raft.rpc.RpcResponseClosureAdapter) List(java.util.List) NodeId(io.dingodb.raft.entity.NodeId) RpcResponseClosure(io.dingodb.raft.rpc.RpcResponseClosure) RaftException(io.dingodb.raft.error.RaftException) Requires(io.dingodb.raft.util.Requires) RaftError(io.dingodb.raft.error.RaftError) UserLog(io.dingodb.raft.entity.UserLog) LogEntry(io.dingodb.raft.entity.LogEntry) HashSet(java.util.HashSet) RaftMetaStorage(io.dingodb.raft.storage.RaftMetaStorage) SnapshotExecutorOptions(io.dingodb.raft.option.SnapshotExecutorOptions) ConfigurationEntry(io.dingodb.raft.conf.ConfigurationEntry) ReadOnlyService(io.dingodb.raft.ReadOnlyService) OnlyForTest(io.dingodb.raft.util.OnlyForTest) ReadIndexClosure(io.dingodb.raft.closure.ReadIndexClosure) LogIndexOutOfBoundsException(io.dingodb.raft.error.LogIndexOutOfBoundsException) Logger(org.slf4j.Logger) NamedThreadFactory(io.dingodb.raft.util.NamedThreadFactory) ClosureQueue(io.dingodb.raft.closure.ClosureQueue) RingBuffer(com.lmax.disruptor.RingBuffer) Closure(io.dingodb.raft.Closure) ProducerType(com.lmax.disruptor.dsl.ProducerType) Node(io.dingodb.raft.Node) Platform(io.dingodb.raft.util.Platform) NodeOptions(io.dingodb.raft.option.NodeOptions) LogNotFoundException(io.dingodb.raft.error.LogNotFoundException) ReplicatorGroup(io.dingodb.raft.ReplicatorGroup) TimeUnit(java.util.concurrent.TimeUnit) JRaftSignalHandler(io.dingodb.raft.util.JRaftSignalHandler) RpcFactoryHelper(io.dingodb.raft.util.RpcFactoryHelper) EventTranslator(com.lmax.disruptor.EventTranslator) LogManagerImpl(io.dingodb.raft.storage.impl.LogManagerImpl) RepeatedTimer(io.dingodb.raft.util.RepeatedTimer) Message(com.google.protobuf.Message) RpcRequests(io.dingodb.raft.rpc.RpcRequests) LeaderChangeContext(io.dingodb.raft.entity.LeaderChangeContext) EventFactory(com.lmax.disruptor.EventFactory) LogEntry(io.dingodb.raft.entity.LogEntry) RaftException(io.dingodb.raft.error.RaftException) LogIndexOutOfBoundsException(io.dingodb.raft.error.LogIndexOutOfBoundsException) LogNotFoundException(io.dingodb.raft.error.LogNotFoundException)

Example 9 with Node

use of io.dingodb.raft.Node in project dingo by dingodb.

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(() -> {
                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(task.done, st);
                    task.reset();
                }
                continue;
            }
            if (!this.ballotBox.appendPendingTask(this.conf.getConf(), this.conf.isStable() ? null : this.conf.getOldConf(), task.done)) {
                Utils.runClosureInThread(task.done, new Status(RaftError.EINTERNAL, "Fail to append task."));
                task.reset();
                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);
            task.reset();
        }
        this.logManager.appendEntries(entries, new LeaderStableClosure(entries));
        // update conf.first
        checkAndSetConfiguration(true);
    } finally {
        this.writeLock.unlock();
    }
}
Also used : Status(io.dingodb.raft.Status) FSMCallerOptions(io.dingodb.raft.option.FSMCallerOptions) RpcRequestClosure(io.dingodb.raft.rpc.RpcRequestClosure) StringUtils(org.apache.commons.lang.StringUtils) Describer(io.dingodb.raft.util.Describer) LongHeldDetectingReadWriteLock(io.dingodb.raft.util.concurrent.LongHeldDetectingReadWriteLock) ThreadHelper(io.dingodb.raft.util.ThreadHelper) LogManager(io.dingodb.raft.storage.LogManager) RaftClientService(io.dingodb.raft.rpc.RaftClientService) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) SynchronizedClosure(io.dingodb.raft.closure.SynchronizedClosure) LogManagerOptions(io.dingodb.raft.option.LogManagerOptions) Set(java.util.Set) Configuration(io.dingodb.raft.conf.Configuration) Utils(io.dingodb.raft.util.Utils) RaftOutter(io.dingodb.raft.entity.RaftOutter) EnumOutter(io.dingodb.raft.entity.EnumOutter) CountDownLatch(java.util.concurrent.CountDownLatch) RaftTimerFactory(io.dingodb.raft.util.timer.RaftTimerFactory) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) LogId(io.dingodb.raft.entity.LogId) JRaftServiceLoader(io.dingodb.raft.util.JRaftServiceLoader) SystemPropertyUtil(io.dingodb.raft.util.SystemPropertyUtil) JRaftUtils(io.dingodb.raft.JRaftUtils) LogExceptionHandler(io.dingodb.raft.util.LogExceptionHandler) ArrayList(java.util.ArrayList) JRaftServiceFactory(io.dingodb.raft.JRaftServiceFactory) ReadOnlyOption(io.dingodb.raft.option.ReadOnlyOption) BootstrapOptions(io.dingodb.raft.option.BootstrapOptions) LogStorage(io.dingodb.raft.storage.LogStorage) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) EventHandler(com.lmax.disruptor.EventHandler) LinkedHashSet(java.util.LinkedHashSet) DisruptorMetricSet(io.dingodb.raft.util.DisruptorMetricSet) DefaultRaftClientService(io.dingodb.raft.rpc.impl.core.DefaultRaftClientService) SnapshotExecutorImpl(io.dingodb.raft.storage.snapshot.SnapshotExecutorImpl) NodeManager(io.dingodb.raft.NodeManager) BallotBoxOptions(io.dingodb.raft.option.BallotBoxOptions) Lock(java.util.concurrent.locks.Lock) Ballot(io.dingodb.raft.entity.Ballot) PeerId(io.dingodb.raft.entity.PeerId) ReadOnlyServiceOptions(io.dingodb.raft.option.ReadOnlyServiceOptions) ConfigurationManager(io.dingodb.raft.conf.ConfigurationManager) SnapshotExecutor(io.dingodb.raft.storage.SnapshotExecutor) Disruptor(com.lmax.disruptor.dsl.Disruptor) RaftServerService(io.dingodb.raft.rpc.RaftServerService) ThreadId(io.dingodb.raft.util.ThreadId) ScheduledFuture(java.util.concurrent.ScheduledFuture) LoggerFactory(org.slf4j.LoggerFactory) ClosureQueueImpl(io.dingodb.raft.closure.ClosureQueueImpl) ByteBuffer(java.nio.ByteBuffer) RaftMetaStorageOptions(io.dingodb.raft.option.RaftMetaStorageOptions) SignalHelper(io.dingodb.raft.util.SignalHelper) BlockingWaitStrategy(com.lmax.disruptor.BlockingWaitStrategy) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CatchUpClosure(io.dingodb.raft.closure.CatchUpClosure) Task(io.dingodb.raft.entity.Task) RaftOptions(io.dingodb.raft.option.RaftOptions) Collection(java.util.Collection) Status(io.dingodb.raft.Status) ReplicatorGroupOptions(io.dingodb.raft.option.ReplicatorGroupOptions) Collectors(java.util.stream.Collectors) FSMCaller(io.dingodb.raft.FSMCaller) DisruptorBuilder(io.dingodb.raft.util.DisruptorBuilder) RpcResponseClosureAdapter(io.dingodb.raft.rpc.RpcResponseClosureAdapter) List(java.util.List) NodeId(io.dingodb.raft.entity.NodeId) RpcResponseClosure(io.dingodb.raft.rpc.RpcResponseClosure) RaftException(io.dingodb.raft.error.RaftException) Requires(io.dingodb.raft.util.Requires) RaftError(io.dingodb.raft.error.RaftError) UserLog(io.dingodb.raft.entity.UserLog) LogEntry(io.dingodb.raft.entity.LogEntry) HashSet(java.util.HashSet) RaftMetaStorage(io.dingodb.raft.storage.RaftMetaStorage) SnapshotExecutorOptions(io.dingodb.raft.option.SnapshotExecutorOptions) ConfigurationEntry(io.dingodb.raft.conf.ConfigurationEntry) ReadOnlyService(io.dingodb.raft.ReadOnlyService) OnlyForTest(io.dingodb.raft.util.OnlyForTest) ReadIndexClosure(io.dingodb.raft.closure.ReadIndexClosure) LogIndexOutOfBoundsException(io.dingodb.raft.error.LogIndexOutOfBoundsException) Logger(org.slf4j.Logger) NamedThreadFactory(io.dingodb.raft.util.NamedThreadFactory) ClosureQueue(io.dingodb.raft.closure.ClosureQueue) RingBuffer(com.lmax.disruptor.RingBuffer) Closure(io.dingodb.raft.Closure) ProducerType(com.lmax.disruptor.dsl.ProducerType) Node(io.dingodb.raft.Node) Platform(io.dingodb.raft.util.Platform) NodeOptions(io.dingodb.raft.option.NodeOptions) LogNotFoundException(io.dingodb.raft.error.LogNotFoundException) ReplicatorGroup(io.dingodb.raft.ReplicatorGroup) TimeUnit(java.util.concurrent.TimeUnit) JRaftSignalHandler(io.dingodb.raft.util.JRaftSignalHandler) RpcFactoryHelper(io.dingodb.raft.util.RpcFactoryHelper) EventTranslator(com.lmax.disruptor.EventTranslator) LogManagerImpl(io.dingodb.raft.storage.impl.LogManagerImpl) RepeatedTimer(io.dingodb.raft.util.RepeatedTimer) Message(com.google.protobuf.Message) RpcRequests(io.dingodb.raft.rpc.RpcRequests) LeaderChangeContext(io.dingodb.raft.entity.LeaderChangeContext) EventFactory(com.lmax.disruptor.EventFactory) RpcRequestClosure(io.dingodb.raft.rpc.RpcRequestClosure) SynchronizedClosure(io.dingodb.raft.closure.SynchronizedClosure) CatchUpClosure(io.dingodb.raft.closure.CatchUpClosure) RpcResponseClosure(io.dingodb.raft.rpc.RpcResponseClosure) ReadIndexClosure(io.dingodb.raft.closure.ReadIndexClosure) Closure(io.dingodb.raft.Closure) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) LogEntry(io.dingodb.raft.entity.LogEntry)

Example 10 with Node

use of io.dingodb.raft.Node in project dingo by dingodb.

the class Replicator method notifyReplicatorStatusListener.

/**
 * Notify replicator event(such as created, error, destroyed) to replicatorStateListener which is implemented by users.
 *
 * @param replicator replicator object
 * @param event      replicator's state listener event type
 * @param status     replicator's error detailed status
 */
private static void notifyReplicatorStatusListener(final Replicator replicator, final ReplicatorEvent event, final Status status, final ReplicatorStateListener.ReplicatorState newState) {
    final ReplicatorOptions replicatorOpts = Requires.requireNonNull(replicator.getOpts(), "replicatorOptions");
    final Node node = Requires.requireNonNull(replicatorOpts.getNode(), "node");
    final PeerId peer = Requires.requireNonNull(replicatorOpts.getPeerId(), "peer");
    final List<ReplicatorStateListener> listenerList = node.getReplicatorStatueListeners();
    for (int i = 0; i < listenerList.size(); i++) {
        final ReplicatorStateListener listener = listenerList.get(i);
        if (listener != null) {
            try {
                switch(event) {
                    case CREATED:
                        RpcUtils.runInThread(() -> listener.onCreated(peer));
                        break;
                    case ERROR:
                        RpcUtils.runInThread(() -> listener.onError(peer, status));
                        break;
                    case DESTROYED:
                        RpcUtils.runInThread(() -> listener.onDestroyed(peer));
                        break;
                    case STATE_CHANGED:
                        RpcUtils.runInThread(() -> listener.stateChanged(peer, newState));
                    default:
                        break;
                }
            } catch (final Exception e) {
                LOG.error("Fail to notify ReplicatorStatusListener, listener={}, event={}.", listener, event);
            }
        }
    }
}
Also used : Node(io.dingodb.raft.Node) ReplicatorOptions(io.dingodb.raft.option.ReplicatorOptions) RaftException(io.dingodb.raft.error.RaftException) PeerId(io.dingodb.raft.entity.PeerId)

Aggregations

Node (io.dingodb.raft.Node)10 PeerId (io.dingodb.raft.entity.PeerId)9 Status (io.dingodb.raft.Status)5 Message (com.google.protobuf.Message)4 RaftException (io.dingodb.raft.error.RaftException)4 NodeOptions (io.dingodb.raft.option.NodeOptions)4 ArrayList (java.util.ArrayList)4 BlockingWaitStrategy (com.lmax.disruptor.BlockingWaitStrategy)3 EventFactory (com.lmax.disruptor.EventFactory)3 EventHandler (com.lmax.disruptor.EventHandler)3 EventTranslator (com.lmax.disruptor.EventTranslator)3 RingBuffer (com.lmax.disruptor.RingBuffer)3 Disruptor (com.lmax.disruptor.dsl.Disruptor)3 ProducerType (com.lmax.disruptor.dsl.ProducerType)3 Closure (io.dingodb.raft.Closure)3 FSMCaller (io.dingodb.raft.FSMCaller)3 JRaftServiceFactory (io.dingodb.raft.JRaftServiceFactory)3 JRaftUtils (io.dingodb.raft.JRaftUtils)3 NodeManager (io.dingodb.raft.NodeManager)3 ReadOnlyService (io.dingodb.raft.ReadOnlyService)3