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;
}
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);
}
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();
}
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();
}
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);
}
Aggregations