@Override public void onRecovered(TypedStreamProcessor streamProcessor) { final WorkflowRepositoryService workflowRepositoryService = new WorkflowRepositoryService(streamProcessor.getActor(), workflowState); startContext .createService(WORKFLOW_REPOSITORY_SERVICE, workflowRepositoryService) .dependency(partitionServiceName) .install(); getWorkflowMessageHandler.setWorkflowRepositoryService(workflowRepositoryService); listWorkflowsControlMessageHandler.setWorkflowRepositoryService(workflowRepositoryService); }
@Override public void onRecovered(TypedStreamProcessor streamProcessor) { final WorkflowRepositoryService workflowRepositoryService = new WorkflowRepositoryService(streamProcessor.getActor(), workflowState); startContext .createService(WORKFLOW_REPOSITORY_SERVICE, workflowRepositoryService) .dependency(partitionServiceName) .install(); getWorkflowMessageHandler.setWorkflowRepositoryService(workflowRepositoryService); listWorkflowsControlMessageHandler.setWorkflowRepositoryService(workflowRepositoryService); }
private void transitionToFollower(final Void value, final Throwable throwable) { final int term = currentTransition.getTerm(); state = null; setTerm(term); final ServiceName<AbstractRaftState> followerServiceName = followerServiceName(raftName, term); final FollowerState followerState = new FollowerState(this, actor); final ServiceName<Void> pollServiceName = pollServiceName(raftName, term); final RaftPollService pollService = new RaftPollService(this, actor); serviceContext .createService(pollServiceName, pollService) .dependency(joinServiceName(raftName)) .dependency(followerServiceName) .install(); final ActorFuture<AbstractRaftState> installFuture = serviceContext.createService(followerServiceName, followerState).install(); actor.runOnCompletion(installFuture, this::onStateTransitionCompleted); currentStateServiceName = followerServiceName; }
private void transitionToFollower(final Void value, final Throwable throwable) { final int term = currentTransition.getTerm(); state = null; setTerm(term); final ServiceName<AbstractRaftState> followerServiceName = followerServiceName(raftName, term); final FollowerState followerState = new FollowerState(this, actor); final ServiceName<Void> pollServiceName = pollServiceName(raftName, term); final RaftPollService pollService = new RaftPollService(this, actor); serviceContext .createService(pollServiceName, pollService) .dependency(joinServiceName(raftName)) .dependency(followerServiceName) .install(); final ActorFuture<AbstractRaftState> installFuture = serviceContext.createService(followerServiceName, followerState).install(); actor.runOnCompletion(installFuture, this::onStateTransitionCompleted); currentStateServiceName = followerServiceName; }
private void installFollowerPartition(final Raft raft) { final Partition partition = new Partition(partitionInfo, RaftState.FOLLOWER); final ServiceName<Partition> partitionServiceName = followerPartitionServiceName(raft.getName()); if (!startContext.hasService(partitionServiceName)) { LOG.debug("Installing follower partition service for {}", partitionInfo); startContext .createService(partitionServiceName, partition) .dependency(logStreamServiceName, partition.getLogStreamInjector()) .dependency(stateStorageFactoryServiceName, partition.getStateStorageFactoryInjector()) .group(FOLLOWER_PARTITION_GROUP_NAME) .install(); } }
private void installFollowerPartition(final Raft raft) { final Partition partition = new Partition(partitionInfo, RaftState.FOLLOWER); final ServiceName<Partition> partitionServiceName = followerPartitionServiceName(raft.getName()); if (!startContext.hasService(partitionServiceName)) { LOG.debug("Installing follower partition service for {}", partitionInfo); startContext .createService(partitionServiceName, partition) .dependency(logStreamServiceName, partition.getLogStreamInjector()) .dependency(stateStorageFactoryServiceName, partition.getStateStorageFactoryInjector()) .group(FOLLOWER_PARTITION_GROUP_NAME) .install(); } }
private void installPartition( final ServiceStartContext startContext, final RaftPersistentConfiguration configuration) { final String partitionName = Partition.getPartitionName(configuration.getPartitionId()); final ServiceName<Void> partitionInstallServiceName = partitionInstallServiceName(partitionName); final PartitionInstallService partitionInstallService = new PartitionInstallService(brokerCfg, configuration); startContext .createService(partitionInstallServiceName, partitionInstallService) .dependency( clientTransport(REPLICATION_API_CLIENT_NAME), partitionInstallService.getClientTransportInjector()) .install(); }
@Override public void start(final ServiceStartContext startContext) { this.logStream = logStreamInjector.getValue(); this.logStream.setTerm(getTerm()); this.serviceContext = startContext; raftJoinedService = new RaftJoinService(this, actor); serviceContext.createService(joinServiceName(raftName), raftJoinedService).install(); startContext.async(startContext.getScheduler().submitActor(this, true)); }
private void installPartition( final ServiceStartContext startContext, final RaftPersistentConfiguration configuration) { final String partitionName = Partition.getPartitionName(configuration.getPartitionId()); final ServiceName<Void> partitionInstallServiceName = partitionInstallServiceName(partitionName); final PartitionInstallService partitionInstallService = new PartitionInstallService(brokerCfg, configuration); startContext .createService(partitionInstallServiceName, partitionInstallService) .dependency( clientTransport(REPLICATION_API_CLIENT_NAME), partitionInstallService.getClientTransportInjector()) .install(); }
/** * Add raft to list of known members of this node and starts the {@link AppendRaftEventController} * to write the new configuration to the log stream */ public boolean joinMember(final int nodeId) { LOG.debug("New member {} joining the cluster", nodeId); final RaftMember newMember = raftMembers.addMember(nodeId); if (newMember != null && state.getState() == RaftState.LEADER) { // start replication final int term = getTerm(); final ServiceName<AbstractRaftState> leaderServiceName = leaderServiceName(raftName, term); final ServiceName<Void> replicateLogControllerServiceName = replicateLogConrollerServiceName(raftName, term, newMember.getNodeId()); serviceContext .createService( replicateLogControllerServiceName, new MemberReplicateLogController(this, newMember, clientTransport)) .dependency(leaderServiceName) .install(); notifyMemberJoinedListeners(); return true; } return false; }
@Override public void start(final ServiceStartContext startContext) { this.logStream = logStreamInjector.getValue(); this.logStream.setTerm(getTerm()); this.serviceContext = startContext; raftJoinedService = new RaftJoinService(this, actor); serviceContext.createService(joinServiceName(raftName), raftJoinedService).install(); startContext.async(startContext.getScheduler().submitActor(this, true)); }
/** * Add raft to list of known members of this node and starts the {@link AppendRaftEventController} * to write the new configuration to the log stream */ public boolean joinMember(final int nodeId) { LOG.debug("New member {} joining the cluster", nodeId); final RaftMember newMember = raftMembers.addMember(nodeId); if (newMember != null && state.getState() == RaftState.LEADER) { // start replication final int term = getTerm(); final ServiceName<AbstractRaftState> leaderServiceName = leaderServiceName(raftName, term); final ServiceName<Void> replicateLogControllerServiceName = replicateLogConrollerServiceName(raftName, term, newMember.getNodeId()); serviceContext .createService( replicateLogControllerServiceName, new MemberReplicateLogController(this, newMember, clientTransport)) .dependency(leaderServiceName) .install(); notifyMemberJoinedListeners(); return true; } return false; }
private void transitionToCandidate(final Void value, final Throwable throwable) { final int term = currentTransition.getTerm(); state = null; setTerm(term); setVotedFor(getNodeId()); final ServiceName<AbstractRaftState> candidateServiceName = candidateServiceName(raftName, term); final CandidateState candidateState = new CandidateState(this, actor); final ActorFuture<AbstractRaftState> whenCandicate = serviceContext .createService(candidateServiceName, candidateState) .dependency(joinServiceName(raftName)) .install(); actor.runOnCompletion(whenCandicate, this::onStateTransitionCompleted); currentStateServiceName = candidateServiceName; }
private void installLeaderPartition(final Raft raft) { final ServiceName<Partition> partitionServiceName = leaderPartitionServiceName(raft.getName()); final int raftMemberSize = raft.getMemberSize() + 1; // raft does not count itself as member final int replicationFactor = partitionInfo.getReplicationFactor(); if (!startContext.hasService(partitionServiceName)) { if (raftMemberSize >= replicationFactor) { LOG.debug( "Installing partition service for {}. Replication factor reached, got {}/{}.", partitionInfo, raftMemberSize, replicationFactor); final Partition partition = new Partition(partitionInfo, RaftState.LEADER); startContext .createService(partitionServiceName, partition) .dependency(leaderInitialEventCommittedServiceName(raft.getName(), raft.getTerm())) .dependency(logStreamServiceName, partition.getLogStreamInjector()) .dependency(stateStorageFactoryServiceName, partition.getStateStorageFactoryInjector()) .group(LEADER_PARTITION_GROUP_NAME) .install(); } else { LOG.debug( "Not installing partition service for {}. Replication factor not reached, got {}/{}.", partitionInfo, raftMemberSize, replicationFactor); } } }
private void transitionToCandidate(final Void value, final Throwable throwable) { final int term = currentTransition.getTerm(); state = null; setTerm(term); setVotedFor(getNodeId()); final ServiceName<AbstractRaftState> candidateServiceName = candidateServiceName(raftName, term); final CandidateState candidateState = new CandidateState(this, actor); final ActorFuture<AbstractRaftState> whenCandicate = serviceContext .createService(candidateServiceName, candidateState) .dependency(joinServiceName(raftName)) .install(); actor.runOnCompletion(whenCandicate, this::onStateTransitionCompleted); currentStateServiceName = candidateServiceName; }
private void installLeaderPartition(final Raft raft) { final ServiceName<Partition> partitionServiceName = leaderPartitionServiceName(raft.getName()); final int raftMemberSize = raft.getMemberSize() + 1; // raft does not count itself as member final int replicationFactor = partitionInfo.getReplicationFactor(); if (!startContext.hasService(partitionServiceName)) { if (raftMemberSize >= replicationFactor) { LOG.debug( "Installing partition service for {}. Replication factor reached, got {}/{}.", partitionInfo, raftMemberSize, replicationFactor); final Partition partition = new Partition(partitionInfo, RaftState.LEADER); startContext .createService(partitionServiceName, partition) .dependency(leaderInitialEventCommittedServiceName(raft.getName(), raft.getTerm())) .dependency(logStreamServiceName, partition.getLogStreamInjector()) .dependency(stateStorageFactoryServiceName, partition.getStateStorageFactoryInjector()) .group(LEADER_PARTITION_GROUP_NAME) .install(); } else { LOG.debug( "Not installing partition service for {}. Replication factor not reached, got {}/{}.", partitionInfo, raftMemberSize, replicationFactor); } } }
new LeaderCommitInitialEvent(this, actor, leaderState); serviceContext .createService(initialEventCommittedServiceName, leaderCommitInitialEventService) .dependency(leaderServiceName) .install();
new LeaderCommitInitialEvent(this, actor, leaderState); serviceContext .createService(initialEventCommittedServiceName, leaderCommitInitialEventService) .dependency(leaderServiceName) .install();