Search in sources :

Example 11 with LogStream

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

the class RaftService method onStateChange.

@Override
public void onStateChange(int partitionId, DirectBuffer topicName, SocketAddress socketAddress, RaftState raftState) {
    actor.call(() -> {
        currentRaftState = raftState;
        if (currentRaftState == RaftState.LEADER) {
            Loggers.CLUSTERING_LOGGER.debug("Start log stream...topic {}", BufferUtil.bufferAsString(raft.getLogStream().getTopicName()));
            final LogStream logStream = raft.getLogStream();
            final LogStreamService service = new LogStreamService(logStream);
            final ServiceName<LogStream> streamGroup = Protocol.SYSTEM_TOPIC_BUF.equals(logStream.getTopicName()) ? LogStreamServiceNames.SYSTEM_STREAM_GROUP : LogStreamServiceNames.WORKFLOW_STREAM_GROUP;
            final ActorFuture<Void> future = startContext.createService(logStreamServiceName, service).dependency(CLUSTER_MANAGER_SERVICE).dependency(raftServiceName).group(streamGroup).install();
            actor.runOnCompletion(future, (v, throwable) -> {
                if (throwable == null) {
                    actor.submit(() -> {
                        onOpenLogStreamListener.onOpenLogStreamService(raft.getLogStream());
                    });
                } else {
                    LOG.error("Failed to install log stream service '{}'", logStreamServiceName);
                }
            });
        } else if (currentRaftState == RaftState.FOLLOWER && startContext.hasService(logStreamServiceName)) {
            startContext.removeService(logStreamServiceName);
        }
    });
}
Also used : LogStreamService(io.zeebe.broker.logstreams.LogStreamService) LogStream(io.zeebe.logstreams.log.LogStream)

Example 12 with LogStream

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

the class LogStreamsManager method createLogStream.

public LogStream createLogStream(final DirectBuffer topicName, final int partitionId, final String logDirectory) {
    final LogStream logStream = LogStreams.createFsLogStream(topicName, partitionId).deleteOnClose(false).logDirectory(logDirectory).actorScheduler(actorScheduler).logSegmentSize(logStreamsCfg.defaultLogSegmentSize * 1024 * 1024).build();
    addLogStream(logStream);
    return logStream;
}
Also used : LogStream(io.zeebe.logstreams.log.LogStream)

Example 13 with LogStream

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

the class LogStreamsManager method createLogStream.

/**
 * Creates a new log stream but does not open it. The caller has to call {@link LogStream#openAsync()} or
 * {@link LogStream#open()} before using it.
 *
 * @return the newly created log stream
 */
public LogStream createLogStream(final DirectBuffer topicName, final int partitionId) {
    ensureNotNullOrEmpty("topic name", topicName);
    ensureGreaterThanOrEqual("partition id", partitionId, 0);
    ensureLessThanOrEqual("partition id", partitionId, Short.MAX_VALUE);
    final FsLogStreamBuilder logStreamBuilder = LogStreams.createFsLogStream(topicName, partitionId);
    final String logName = logStreamBuilder.getLogName();
    final String logDirectory;
    final boolean deleteOnExit = false;
    int assignedLogDirectory = 0;
    if (logStreamsCfg.directories.length == 0) {
        throw new RuntimeException(String.format("Cannot start log %s, no log directory provided.", logName));
    } else if (logStreamsCfg.directories.length > 1) {
        assignedLogDirectory = new Random().nextInt(logStreamsCfg.directories.length - 1);
    }
    logDirectory = logStreamsCfg.directories[assignedLogDirectory] + File.separator + logName;
    final int logSegmentSize = logStreamsCfg.defaultLogSegmentSize * 1024 * 1024;
    final LogStream logStream = logStreamBuilder.deleteOnClose(deleteOnExit).logDirectory(logDirectory).actorScheduler(actorScheduler).logSegmentSize(logSegmentSize).build();
    addLogStream(logStream);
    return logStream;
}
Also used : FsLogStreamBuilder(io.zeebe.logstreams.fs.FsLogStreamBuilder) Random(java.util.Random) LogStream(io.zeebe.logstreams.log.LogStream)

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