use of io.zeebe.logstreams.fs.FsLogStreamBuilder 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