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