private void addPartition(final ServiceName<Partition> sericeName, final Partition partition) { actor.submit(() -> leaderPartitions.put(partition.getInfo().getPartitionId(), partition)); }
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(); } }
public Builder(Partition partition, ServiceName<Partition> serviceName) { this.logStream = partition.getLogStream(); this.additionalDependencies.add(serviceName); }
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(); }
public void startStreamProcessors( final ServiceName<Partition> partitionServiceName, final Partition partition) { final int partitionId = partition.getInfo().getPartitionId(); final Builder streamProcessorServiceBuilder = streamProcessorServiceFactory .createService(partition, partitionServiceName) .processorId(partitionId) .processorName(PROCESSOR_NAME); final StateStorage stateStorage = partition.getStateStorageFactory().create(partitionId, PROCESSOR_NAME); final StateSnapshotController stateSnapshotController = new StateSnapshotController(DefaultZeebeDbFactory.DEFAULT_DB_FACTORY, stateStorage); streamProcessorServiceBuilder .snapshotController(stateSnapshotController) .streamProcessorFactory( (zeebeDb) -> { final ZeebeState zeebeState = new ZeebeState(partitionId, zeebeDb); final TypedStreamEnvironment streamEnvironment = new TypedStreamEnvironment( partition.getLogStream(), clientApiTransport.getOutput()); return createTypedStreamProcessor( partitionServiceName, partitionId, streamEnvironment, zeebeState); }) .build(); }
private void startExporter(ServiceName<Partition> partitionName, Partition partition) { final StateStorage stateStorage = partition.getStateStorageFactory().create(EXPORTER_PROCESSOR_ID, PROCESSOR_NAME); final SnapshotController snapshotController = new StateSnapshotController( DefaultZeebeDbFactory.defaultFactory(ExporterColumnFamilies.class), stateStorage); streamProcessorServiceFactory .createService(partition, partitionName) .processorId(EXPORTER_PROCESSOR_ID) .processorName(PROCESSOR_NAME) .snapshotController(snapshotController) .streamProcessorFactory( (zeebeDb) -> new ExporterStreamProcessor( zeebeDb, partition.getInfo().getPartitionId(), exporterRepository.getExporters().values())) .build(); }
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(); }
public void startStreamProcessors( final ServiceName<Partition> partitionServiceName, final Partition partition) { final int partitionId = partition.getInfo().getPartitionId(); final Builder streamProcessorServiceBuilder = streamProcessorServiceFactory .createService(partition, partitionServiceName) .processorId(partitionId) .processorName(PROCESSOR_NAME); final StateStorage stateStorage = partition.getStateStorageFactory().create(partitionId, PROCESSOR_NAME); final StateSnapshotController stateSnapshotController = new StateSnapshotController(DefaultZeebeDbFactory.DEFAULT_DB_FACTORY, stateStorage); streamProcessorServiceBuilder .snapshotController(stateSnapshotController) .streamProcessorFactory( (zeebeDb) -> { final ZeebeState zeebeState = new ZeebeState(partitionId, zeebeDb); final TypedStreamEnvironment streamEnvironment = new TypedStreamEnvironment( partition.getLogStream(), clientApiTransport.getOutput()); return createTypedStreamProcessor( partitionServiceName, partitionId, streamEnvironment, zeebeState); }) .build(); }
private void startExporter(ServiceName<Partition> partitionName, Partition partition) { final StateStorage stateStorage = partition.getStateStorageFactory().create(EXPORTER_PROCESSOR_ID, PROCESSOR_NAME); final SnapshotController snapshotController = new StateSnapshotController( DefaultZeebeDbFactory.defaultFactory(ExporterColumnFamilies.class), stateStorage); streamProcessorServiceFactory .createService(partition, partitionName) .processorId(EXPORTER_PROCESSOR_ID) .processorName(PROCESSOR_NAME) .snapshotController(snapshotController) .streamProcessorFactory( (zeebeDb) -> new ExporterStreamProcessor( zeebeDb, partition.getInfo().getPartitionId(), exporterRepository.getExporters().values())) .build(); }
public void startBroker() { startTime = System.currentTimeMillis(); broker = new Broker(brokerCfg, newTemporaryFolder.getAbsolutePath(), controlledActorClock); final ServiceContainer serviceContainer = broker.getBrokerContext().getServiceContainer(); try { // Hack: block until the system stream processor is available // this is required in the broker-test suite, because the client rule does not perform request // retries // How to make it better: https://github.com/zeebe-io/zeebe/issues/196 final String partitionName = Partition.getPartitionName(Protocol.DEPLOYMENT_PARTITION); serviceContainer .createService(TestService.NAME, new TestService()) .dependency(ClusterBaseLayerServiceNames.leaderPartitionServiceName(partitionName)) .dependency( TransportServiceNames.serverTransport(TransportServiceNames.CLIENT_API_SERVER_NAME)) .dependency(WORKFLOW_REPOSITORY_SERVICE) .install() .get(timeout, TimeUnit.SECONDS); } catch (final InterruptedException | ExecutionException | TimeoutException e) { stopBroker(); throw new RuntimeException( String.format( "System partition not installed into the container withing %d seconds.", timeout), e); } dataDirectories = broker.getBrokerContext().getBrokerConfiguration().getData().getDirectories(); }
private void removePartition(final Partition partition) { actor.submit(() -> leaderForPartitions.remove(partition.getInfo().getPartitionId())); }
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(); } }
public Builder(Partition partition, ServiceName<Partition> serviceName) { this.logStream = partition.getLogStream(); this.additionalDependencies.add(serviceName); }
public void startBroker() { startTime = System.currentTimeMillis(); broker = new Broker(brokerCfg, newTemporaryFolder.getAbsolutePath(), controlledActorClock); final ServiceContainer serviceContainer = broker.getBrokerContext().getServiceContainer(); try { // Hack: block until the system stream processor is available // this is required in the broker-test suite, because the client rule does not perform request // retries // How to make it better: https://github.com/zeebe-io/zeebe/issues/196 final String partitionName = Partition.getPartitionName(Protocol.DEPLOYMENT_PARTITION); serviceContainer .createService(TestService.NAME, new TestService()) .dependency(ClusterBaseLayerServiceNames.leaderPartitionServiceName(partitionName)) .dependency( TransportServiceNames.serverTransport(TransportServiceNames.CLIENT_API_SERVER_NAME)) .dependency(WORKFLOW_REPOSITORY_SERVICE) .install() .get(timeout, TimeUnit.SECONDS); } catch (final InterruptedException | ExecutionException | TimeoutException e) { stopBroker(); throw new RuntimeException( String.format( "System partition not installed into the container withing %d seconds.", timeout), e); } dataDirectories = broker.getBrokerContext().getBrokerConfiguration().getData().getDirectories(); }
public void removePartition(final Partition partition) { cmdQueue.add(() -> leaderPartitions.remove(partition.getInfo().getPartitionId())); }
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 boolean writeCreatingDeployment( final Partition partition, final long key, final UnpackedObject event) { final RecordType recordType = RecordType.COMMAND; final ValueType valueType = ValueType.DEPLOYMENT; final Intent intent = DeploymentIntent.CREATE; logStreamWriter.wrap(partition.getLogStream()); recordMetadata.reset().recordType(recordType).valueType(valueType).intent(intent); final long position = logStreamWriter.key(key).metadataWriter(recordMetadata).valueWriter(event).tryWrite(); return position > 0; } }
public static void printRecords(final Broker broker, final int partitionId) { try { final ServiceContainer serviceContainer = broker.getBrokerContext().getServiceContainer(); final ServiceName<LogStream> logStreamServiceName = LogStreamServiceNames.logStreamServiceName(Partition.getPartitionName(partitionId)); final PrinterService printerService = new PrinterService(); serviceContainer .createService(PRINTER_SERVICE_NAME, printerService) .dependency(logStreamServiceName, printerService.getLogStreamInjector()) .install() .join(); serviceContainer.removeService(PRINTER_SERVICE_NAME).join(); } catch (final Exception e) { LOGGER.error( "Could not print log entries. This exception is not propagated to avoid interference with the test.", e); } }
public void addPartition(final Partition partition) { cmdQueue.add(() -> leaderPartitions.put(partition.getInfo().getPartitionId(), partition)); }
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); } } }