Search in sources :

Example 1 with LogStream

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

the class ClusterManager method createPartition.

/**
 * Creates log stream and sets up raft service to participate in raft group
 */
protected void createPartition(DirectBuffer topicName, int partitionId, List<SocketAddress> members) {
    final LogStream logStream = logStreamsManager.createLogStream(topicName, partitionId);
    final SocketBindingCfg replicationApi = transportComponentCfg.replicationApi;
    final SocketAddress socketAddress = new SocketAddress(replicationApi.getHost(transportComponentCfg.host), replicationApi.port);
    createRaft(socketAddress, logStream, members);
}
Also used : LogStream(io.zeebe.logstreams.log.LogStream) SocketBindingCfg(io.zeebe.broker.transport.cfg.SocketBindingCfg)

Example 2 with LogStream

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

the class ClusterManager method inviteMemberToRaft.

/**
 * Invites the member to the RAFT group.
 */
protected void inviteMemberToRaft(SocketAddress member, Raft raft) {
    // TODO(menski): implement replication factor
    // TODO: if this should be garbage free, we have to limit
    // the number of concurrent invitations.
    final List<SocketAddress> members = new ArrayList<>();
    members.add(raft.getSocketAddress());
    raft.getMembers().forEach(raftMember -> members.add(raftMember.getRemoteAddress().getAddress()));
    final LogStream logStream = raft.getLogStream();
    final InvitationRequest invitationRequest = new InvitationRequest().topicName(logStream.getTopicName()).partitionId(logStream.getPartitionId()).term(raft.getTerm()).members(members);
    LOG.debug("Send invitation request to {} for partition {} in term {}", member, logStream.getPartitionId(), raft.getTerm());
    final RemoteAddress remoteAddress = context.getManagementClient().registerRemoteAddress(member);
    final ActorFuture<ClientResponse> clientResponse = context.getManagementClient().getOutput().sendRequest(remoteAddress, invitationRequest);
    actor.runOnCompletion(clientResponse, (request, throwable) -> {
        if (throwable == null) {
            request.close();
            LOG.debug("Got invitation response from {} for partition id {}.", member, logStream.getPartitionId());
        } else {
            LOG.debug("Invitation request failed");
        }
    });
}
Also used : CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) LogStream(io.zeebe.logstreams.log.LogStream)

Example 3 with LogStream

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

the class TaskSubscriptionManager method createStreamProcessorService.

protected ActorFuture<Void> createStreamProcessorService(final LockTaskStreamProcessor factory, DirectBuffer newTaskTypeBuffer, final LogStreamBucket logStreamBucket, final DirectBuffer taskType) {
    final TypedStreamEnvironment env = new TypedStreamEnvironment(logStreamBucket.getLogStream(), transport.getOutput());
    final TypedStreamProcessor streamProcessor = factory.createStreamProcessor(env);
    final ServiceName<LogStream> logStreamServiceName = logStreamBucket.getLogServiceName();
    final String logName = logStreamBucket.getLogStream().getLogName();
    final ServiceName<StreamProcessorController> streamProcessorServiceName = taskQueueLockStreamProcessorServiceName(logName, bufferAsString(taskType));
    final String streamProcessorName = streamProcessorServiceName.getName();
    final StreamProcessorService streamProcessorService = new StreamProcessorService(streamProcessorName, TASK_LOCK_STREAM_PROCESSOR_ID, streamProcessor).eventFilter(streamProcessor.buildTypeFilter());
    return serviceContext.createService(streamProcessorServiceName, streamProcessorService).dependency(logStreamServiceName, streamProcessorService.getLogStreamInjector()).dependency(SNAPSHOT_STORAGE_SERVICE, streamProcessorService.getSnapshotStorageInjector()).install();
}
Also used : StreamProcessorController(io.zeebe.logstreams.processor.StreamProcessorController) LogStream(io.zeebe.logstreams.log.LogStream) BufferUtil.bufferAsString(io.zeebe.util.buffer.BufferUtil.bufferAsString) TypedStreamEnvironment(io.zeebe.broker.logstreams.processor.TypedStreamEnvironment) TypedStreamProcessor(io.zeebe.broker.logstreams.processor.TypedStreamProcessor) StreamProcessorService(io.zeebe.broker.logstreams.processor.StreamProcessorService)

Example 4 with LogStream

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

the class ClientApiMessageHandler method handleExecuteCommandRequest.

private boolean handleExecuteCommandRequest(final ServerOutput output, final RemoteAddress requestAddress, final long requestId, final BrokerEventMetadata eventMetadata, final DirectBuffer buffer, final int messageOffset, final int messageLength) {
    executeCommandRequestDecoder.wrap(buffer, messageOffset + messageHeaderDecoder.encodedLength(), messageHeaderDecoder.blockLength(), messageHeaderDecoder.version());
    final int partitionId = executeCommandRequestDecoder.partitionId();
    final long key = executeCommandRequestDecoder.key();
    final LogStream logStream = logStreams.get(partitionId);
    if (logStream == null) {
        return errorResponseWriter.errorCode(ErrorCode.PARTITION_NOT_FOUND).errorMessage("Cannot execute command. Partition with id '%d' not found", partitionId).tryWriteResponseOrLogFailure(output, requestAddress.getStreamId(), requestId);
    }
    final EventType eventType = executeCommandRequestDecoder.eventType();
    final UnpackedObject event = eventsByType.get(eventType);
    if (event == null) {
        return errorResponseWriter.errorCode(ErrorCode.MESSAGE_NOT_SUPPORTED).errorMessage("Cannot execute command. Invalid event type '%s'.", eventType.name()).tryWriteResponseOrLogFailure(output, requestAddress.getStreamId(), requestId);
    }
    final int eventOffset = executeCommandRequestDecoder.limit() + ExecuteCommandRequestDecoder.commandHeaderLength();
    final int eventLength = executeCommandRequestDecoder.commandLength();
    event.reset();
    try {
        // verify that the event / command is valid
        event.wrap(buffer, eventOffset, eventLength);
    } catch (Throwable t) {
        return errorResponseWriter.errorCode(ErrorCode.INVALID_MESSAGE).errorMessage("Cannot deserialize command: '%s'.", concatErrorMessages(t)).tryWriteResponseOrLogFailure(output, requestAddress.getStreamId(), requestId);
    }
    eventMetadata.eventType(eventType);
    logStreamWriter.wrap(logStream);
    if (key != ExecuteCommandRequestDecoder.keyNullValue()) {
        logStreamWriter.key(key);
    } else {
        logStreamWriter.positionAsKey();
    }
    final long eventPosition = logStreamWriter.metadataWriter(eventMetadata).value(buffer, eventOffset, eventLength).tryWrite();
    return eventPosition >= 0;
}
Also used : LogStream(io.zeebe.logstreams.log.LogStream) UnpackedObject(io.zeebe.msgpack.UnpackedObject)

Example 5 with LogStream

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

the class WorkflowQueueManagerService method installIncidentStreamProcessor.

private void installIncidentStreamProcessor(final LogStream logStream) {
    final ServiceName<StreamProcessorController> streamProcessorServiceName = incidentStreamProcessorServiceName(logStream.getLogName());
    final String streamProcessorName = streamProcessorServiceName.getName();
    final ServerTransport transport = clientApiTransportInjector.getValue();
    final ServiceName<LogStream> logStreamServiceName = logStreamServiceName(logStream.getLogName());
    final TypedStreamEnvironment env = new TypedStreamEnvironment(logStream, transport.getOutput());
    final IncidentStreamProcessor incidentProcessorFactory = new IncidentStreamProcessor();
    final TypedStreamProcessor streamProcessor = incidentProcessorFactory.createStreamProcessor(env);
    final StreamProcessorService incidentStreamProcessorService = new StreamProcessorService(streamProcessorName, INCIDENT_PROCESSOR_ID, streamProcessor).eventFilter(streamProcessor.buildTypeFilter());
    serviceContext.createService(streamProcessorServiceName, incidentStreamProcessorService).dependency(logStreamServiceName, incidentStreamProcessorService.getLogStreamInjector()).dependency(SNAPSHOT_STORAGE_SERVICE, incidentStreamProcessorService.getSnapshotStorageInjector()).install();
}
Also used : ServerTransport(io.zeebe.transport.ServerTransport) IncidentStreamProcessor(io.zeebe.broker.incident.processor.IncidentStreamProcessor) StreamProcessorController(io.zeebe.logstreams.processor.StreamProcessorController) LogStream(io.zeebe.logstreams.log.LogStream) TypedStreamEnvironment(io.zeebe.broker.logstreams.processor.TypedStreamEnvironment) TypedStreamProcessor(io.zeebe.broker.logstreams.processor.TypedStreamProcessor) StreamProcessorService(io.zeebe.broker.logstreams.processor.StreamProcessorService)

Aggregations

LogStream (io.zeebe.logstreams.log.LogStream)13 StreamProcessorService (io.zeebe.broker.logstreams.processor.StreamProcessorService)3 StreamProcessorController (io.zeebe.logstreams.processor.StreamProcessorController)3 TypedStreamEnvironment (io.zeebe.broker.logstreams.processor.TypedStreamEnvironment)2 TypedStreamProcessor (io.zeebe.broker.logstreams.processor.TypedStreamProcessor)2 SocketBindingCfg (io.zeebe.broker.transport.cfg.SocketBindingCfg)2 ServerTransport (io.zeebe.transport.ServerTransport)2 RaftPersistentFileStorage (io.zeebe.broker.clustering.raft.RaftPersistentFileStorage)1 IncidentStreamProcessor (io.zeebe.broker.incident.processor.IncidentStreamProcessor)1 LogStreamService (io.zeebe.broker.logstreams.LogStreamService)1 LogStreamsManager (io.zeebe.broker.logstreams.LogStreamsManager)1 CreateWorkflowResponseSender (io.zeebe.broker.system.deployment.handler.CreateWorkflowResponseSender)1 CommandResponseWriter (io.zeebe.broker.transport.clientapi.CommandResponseWriter)1 WorkflowInstanceStreamProcessor (io.zeebe.broker.workflow.processor.WorkflowInstanceStreamProcessor)1 FsLogStreamBuilder (io.zeebe.logstreams.fs.FsLogStreamBuilder)1 LogStreamReader (io.zeebe.logstreams.log.LogStreamReader)1 SnapshotStorage (io.zeebe.logstreams.spi.SnapshotStorage)1 UnpackedObject (io.zeebe.msgpack.UnpackedObject)1 Raft (io.zeebe.raft.Raft)1 BufferUtil.bufferAsString (io.zeebe.util.buffer.BufferUtil.bufferAsString)1