Search in sources :

Example 1 with LogStream

use of io.camunda.zeebe.logstreams.log.LogStream in project zeebe by zeebe-io.

the class EngineProcessors method createEngineProcessors.

public static TypedRecordProcessors createEngineProcessors(final ProcessingContext processingContext, final int partitionsCount, final SubscriptionCommandSender subscriptionCommandSender, final DeploymentDistributor deploymentDistributor, final DeploymentResponder deploymentResponder, final Consumer<String> onJobsAvailableCallback) {
    final var actor = processingContext.getActor();
    final MutableZeebeState zeebeState = processingContext.getZeebeState();
    final var writers = processingContext.getWriters();
    final TypedRecordProcessors typedRecordProcessors = TypedRecordProcessors.processors(zeebeState.getKeyGenerator(), writers);
    // register listener that handles migrations immediately, so it is the first to be called
    typedRecordProcessors.withListener(new DbMigrationController());
    typedRecordProcessors.withListener(processingContext.getZeebeState());
    final LogStream stream = processingContext.getLogStream();
    final int partitionId = stream.getPartitionId();
    final var variablesState = zeebeState.getVariableState();
    final var expressionProcessor = new ExpressionProcessor(ExpressionLanguageFactory.createExpressionLanguage(), variablesState::getVariable);
    final DueDateTimerChecker timerChecker = new DueDateTimerChecker(zeebeState.getTimerState());
    final CatchEventBehavior catchEventBehavior = new CatchEventBehavior(zeebeState, expressionProcessor, subscriptionCommandSender, writers.state(), timerChecker, partitionsCount);
    final var eventTriggerBehavior = new EventTriggerBehavior(zeebeState.getKeyGenerator(), catchEventBehavior, writers, zeebeState);
    final var eventPublicationBehavior = new BpmnEventPublicationBehavior(zeebeState, zeebeState.getKeyGenerator(), eventTriggerBehavior, writers);
    addDeploymentRelatedProcessorAndServices(catchEventBehavior, partitionId, zeebeState, typedRecordProcessors, deploymentResponder, expressionProcessor, writers, partitionsCount, actor, deploymentDistributor, zeebeState.getKeyGenerator());
    addMessageProcessors(eventTriggerBehavior, subscriptionCommandSender, zeebeState, typedRecordProcessors, writers);
    final var jobMetrics = new JobMetrics(partitionId);
    final TypedRecordProcessor<ProcessInstanceRecord> bpmnStreamProcessor = addProcessProcessors(zeebeState, expressionProcessor, typedRecordProcessors, subscriptionCommandSender, catchEventBehavior, eventTriggerBehavior, writers, timerChecker, jobMetrics);
    JobEventProcessors.addJobProcessors(typedRecordProcessors, zeebeState, onJobsAvailableCallback, eventPublicationBehavior, writers, jobMetrics, eventTriggerBehavior);
    addIncidentProcessors(zeebeState, bpmnStreamProcessor, typedRecordProcessors, writers, zeebeState.getKeyGenerator());
    return typedRecordProcessors;
}
Also used : MutableZeebeState(io.camunda.zeebe.engine.state.mutable.MutableZeebeState) BpmnEventPublicationBehavior(io.camunda.zeebe.engine.processing.bpmn.behavior.BpmnEventPublicationBehavior) LogStream(io.camunda.zeebe.logstreams.log.LogStream) DueDateTimerChecker(io.camunda.zeebe.engine.processing.timer.DueDateTimerChecker) JobMetrics(io.camunda.zeebe.engine.metrics.JobMetrics) CatchEventBehavior(io.camunda.zeebe.engine.processing.common.CatchEventBehavior) TypedRecordProcessors(io.camunda.zeebe.engine.processing.streamprocessor.TypedRecordProcessors) ExpressionProcessor(io.camunda.zeebe.engine.processing.common.ExpressionProcessor) EventTriggerBehavior(io.camunda.zeebe.engine.processing.common.EventTriggerBehavior) ProcessInstanceRecord(io.camunda.zeebe.protocol.impl.record.value.processinstance.ProcessInstanceRecord) DbMigrationController(io.camunda.zeebe.engine.state.migration.DbMigrationController)

Example 2 with LogStream

use of io.camunda.zeebe.logstreams.log.LogStream in project zeebe-process-test by camunda.

the class EngineFactory method create.

public static ZeebeTestEngine create(final int port) {
    final int partitionId = 1;
    final int partitionCount = 1;
    final ControlledActorClock clock = createActorClock();
    final ActorScheduler scheduler = createAndStartActorScheduler(clock);
    final InMemoryLogStorage logStorage = new InMemoryLogStorage();
    final LogStream logStream = createLogStream(logStorage, scheduler, partitionId);
    final SubscriptionCommandSenderFactory subscriptionCommandSenderFactory = new SubscriptionCommandSenderFactory(logStream.newLogStreamRecordWriter().join(), partitionId);
    final GrpcToLogStreamGateway gateway = new GrpcToLogStreamGateway(logStream.newLogStreamRecordWriter().join(), partitionId, partitionCount, port);
    final Server grpcServer = ServerBuilder.forPort(port).addService(gateway).build();
    final GrpcResponseWriter grpcResponseWriter = new GrpcResponseWriter(gateway);
    final ZeebeDb<ZbColumnFamilies> zeebeDb = createDatabase();
    final EngineStateMonitor engineStateMonitor = new EngineStateMonitor(logStorage, logStream.newLogStreamReader().join());
    final StreamProcessor streamProcessor = createStreamProcessor(logStream, zeebeDb, scheduler, grpcResponseWriter, engineStateMonitor, partitionCount, subscriptionCommandSenderFactory);
    final LogStreamReader reader = logStream.newLogStreamReader().join();
    final RecordStreamSourceImpl recordStream = new RecordStreamSourceImpl(reader, partitionId);
    return new InMemoryEngine(grpcServer, streamProcessor, gateway, zeebeDb, logStream, scheduler, recordStream, clock, engineStateMonitor);
}
Also used : StreamProcessor(io.camunda.zeebe.engine.processing.streamprocessor.StreamProcessor) ControlledActorClock(io.camunda.zeebe.util.sched.clock.ControlledActorClock) Server(io.grpc.Server) LogStream(io.camunda.zeebe.logstreams.log.LogStream) ZbColumnFamilies(io.camunda.zeebe.engine.state.ZbColumnFamilies) ActorScheduler(io.camunda.zeebe.util.sched.ActorScheduler) LogStreamReader(io.camunda.zeebe.logstreams.log.LogStreamReader)

Example 3 with LogStream

use of io.camunda.zeebe.logstreams.log.LogStream in project zeebe-process-test by camunda.

the class EngineFactory method createLogStream.

private static LogStream createLogStream(final LogStorage logStorage, final ActorSchedulingService scheduler, final int partitionId) {
    final LogStreamBuilder builder = LogStream.builder().withPartitionId(partitionId).withLogStorage(logStorage).withActorSchedulingService(scheduler);
    final CompletableFuture<LogStream> theFuture = new CompletableFuture<>();
    scheduler.submitActor(Actor.wrap((control) -> builder.buildAsync().onComplete((logStream, failure) -> {
        if (failure != null) {
            theFuture.completeExceptionally(failure);
        } else {
            theFuture.complete(logStream);
        }
    })));
    return theFuture.join();
}
Also used : ControlledActorClock(io.camunda.zeebe.util.sched.clock.ControlledActorClock) StreamProcessor(io.camunda.zeebe.engine.processing.streamprocessor.StreamProcessor) LogStreamBuilder(io.camunda.zeebe.logstreams.log.LogStreamBuilder) LogStorage(io.camunda.zeebe.logstreams.storage.LogStorage) InMemoryDbFactory(io.camunda.zeebe.process.test.engine.db.InMemoryDbFactory) CompletableFuture(java.util.concurrent.CompletableFuture) ZeebeTestEngine(io.camunda.zeebe.process.test.api.ZeebeTestEngine) EngineProcessors(io.camunda.zeebe.engine.processing.EngineProcessors) ZbColumnFamilies(io.camunda.zeebe.engine.state.ZbColumnFamilies) LogStreamReader(io.camunda.zeebe.logstreams.log.LogStreamReader) ZeebeDb(io.camunda.zeebe.db.ZeebeDb) LogStream(io.camunda.zeebe.logstreams.log.LogStream) EventAppliers(io.camunda.zeebe.engine.state.appliers.EventAppliers) ServerBuilder(io.grpc.ServerBuilder) ActorClock(io.camunda.zeebe.util.sched.clock.ActorClock) ActorSchedulingService(io.camunda.zeebe.util.sched.ActorSchedulingService) Actor(io.camunda.zeebe.util.sched.Actor) Server(io.grpc.Server) ActorScheduler(io.camunda.zeebe.util.sched.ActorScheduler) CompletableFuture(java.util.concurrent.CompletableFuture) LogStreamBuilder(io.camunda.zeebe.logstreams.log.LogStreamBuilder) LogStream(io.camunda.zeebe.logstreams.log.LogStream)

Example 4 with LogStream

use of io.camunda.zeebe.logstreams.log.LogStream in project zeebe by camunda.

the class SyncLogStreamBuilder method build.

public SyncLogStream build() {
    final var scheduler = Objects.requireNonNull(actorSchedulingService, "must provide an actor scheduling service through SyncLogStreamBuilder#withActorSchedulingService");
    final var buildFuture = new CompletableActorFuture<SyncLogStream>();
    scheduler.submitActor(new Actor() {

        @Override
        protected void onActorStarting() {
            actor.runOnCompletionBlockingCurrentPhase(buildAsync(), (logStream, t) -> {
                if (t == null) {
                    buildFuture.complete(new SyncLogStream(logStream));
                } else {
                    buildFuture.completeExceptionally(t);
                }
            });
        }
    });
    return buildFuture.join();
}
Also used : Objects(java.util.Objects) LogStreamBuilder(io.camunda.zeebe.logstreams.log.LogStreamBuilder) LogStorage(io.camunda.zeebe.logstreams.storage.LogStorage) LogStream(io.camunda.zeebe.logstreams.log.LogStream) CompletableActorFuture(io.camunda.zeebe.util.sched.future.CompletableActorFuture) ActorFuture(io.camunda.zeebe.util.sched.future.ActorFuture) ActorSchedulingService(io.camunda.zeebe.util.sched.ActorSchedulingService) Actor(io.camunda.zeebe.util.sched.Actor) CompletableActorFuture(io.camunda.zeebe.util.sched.future.CompletableActorFuture) Actor(io.camunda.zeebe.util.sched.Actor)

Example 5 with LogStream

use of io.camunda.zeebe.logstreams.log.LogStream in project zeebe by camunda.

the class SingleBrokerDataDeletionTest method shouldNotCompactNotExportedEvents.

@Test
public void shouldNotCompactNotExportedEvents() {
    // given
    final LogStream logStream = clusteringRule.getLogStream(1);
    final LogStreamReader reader = logStream.newLogStreamReader().join();
    final Broker broker = clusteringRule.getBroker(0);
    ControllableExporter.updatePosition(true);
    // when - filling the log with messages (updating the position), then a single deployment
    // command, and more messages (all of which do not update the position)
    publishEnoughMessagesForCompaction();
    ControllableExporter.updatePosition(false);
    deployDummyProcess();
    publishEnoughMessagesForCompaction();
    // then - force compaction and ensure we compacted only things before our sentinel command
    reader.seekToFirstEvent();
    long firstPositionPreCompaction = reader.getPosition();
    clusteringRule.getClock().addTime(SNAPSHOT_PERIOD);
    final var firstSnapshot = clusteringRule.waitForSnapshotAtBroker(broker);
    awaitUntilCompaction(reader, firstPositionPreCompaction);
    assertContainsDeploymentCommand(reader);
    // when - re-enabling updating the position
    ControllableExporter.updatePosition(true);
    publishEnoughMessagesForCompaction();
    // then - ensure we can still compact
    reader.seekToFirstEvent();
    firstPositionPreCompaction = reader.getPosition();
    clusteringRule.getClock().addTime(SNAPSHOT_PERIOD);
    clusteringRule.waitForNewSnapshotAtBroker(broker, firstSnapshot);
    awaitUntilCompaction(reader, firstPositionPreCompaction);
}
Also used : LogStreamReader(io.camunda.zeebe.logstreams.log.LogStreamReader) Broker(io.camunda.zeebe.broker.Broker) LogStream(io.camunda.zeebe.logstreams.log.LogStream) Test(org.junit.Test)

Aggregations

LogStream (io.camunda.zeebe.logstreams.log.LogStream)21 LogStreamReader (io.camunda.zeebe.logstreams.log.LogStreamReader)13 Test (org.junit.Test)9 JobMetrics (io.camunda.zeebe.engine.metrics.JobMetrics)5 BpmnEventPublicationBehavior (io.camunda.zeebe.engine.processing.bpmn.behavior.BpmnEventPublicationBehavior)5 CatchEventBehavior (io.camunda.zeebe.engine.processing.common.CatchEventBehavior)5 EventTriggerBehavior (io.camunda.zeebe.engine.processing.common.EventTriggerBehavior)5 ExpressionProcessor (io.camunda.zeebe.engine.processing.common.ExpressionProcessor)5 TypedRecordProcessors (io.camunda.zeebe.engine.processing.streamprocessor.TypedRecordProcessors)5 DueDateTimerChecker (io.camunda.zeebe.engine.processing.timer.DueDateTimerChecker)5 DbMigrationController (io.camunda.zeebe.engine.state.migration.DbMigrationController)5 MutableZeebeState (io.camunda.zeebe.engine.state.mutable.MutableZeebeState)5 LogStreamBuilder (io.camunda.zeebe.logstreams.log.LogStreamBuilder)5 LogStorage (io.camunda.zeebe.logstreams.storage.LogStorage)5 ProcessInstanceRecord (io.camunda.zeebe.protocol.impl.record.value.processinstance.ProcessInstanceRecord)5 Actor (io.camunda.zeebe.util.sched.Actor)5 ActorSchedulingService (io.camunda.zeebe.util.sched.ActorSchedulingService)5 StreamProcessor (io.camunda.zeebe.engine.processing.streamprocessor.StreamProcessor)4 ZbColumnFamilies (io.camunda.zeebe.engine.state.ZbColumnFamilies)4 ActorScheduler (io.camunda.zeebe.util.sched.ActorScheduler)4