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