Search in sources :

Example 1 with RaftPersistentFileStorage

use of io.zeebe.broker.clustering.raft.RaftPersistentFileStorage in project zeebe by zeebe-io.

the class ClusterManager method createRaft.

public void createRaft(final SocketAddress socketAddress, final LogStream logStream, final List<SocketAddress> members) {
    final FsLogStorage logStorage = (FsLogStorage) logStream.getLogStorage();
    final String path = logStorage.getConfig().getPath();
    final String directory = transportComponentCfg.management.directory;
    final RaftPersistentFileStorage storage = new RaftPersistentFileStorage(String.format("%s%s.meta", directory, logStream.getLogName()));
    storage.setLogStream(logStream).setLogDirectory(path).save();
    createRaft(socketAddress, logStream, members, storage);
}
Also used : RaftPersistentFileStorage(io.zeebe.broker.clustering.raft.RaftPersistentFileStorage) FsLogStorage(io.zeebe.logstreams.impl.log.fs.FsLogStorage)

Example 2 with RaftPersistentFileStorage

use of io.zeebe.broker.clustering.raft.RaftPersistentFileStorage in project zeebe by zeebe-io.

the class ClusterManager method open.

private void open() {
    final List<SocketAddress> collect = Arrays.stream(transportComponentCfg.gossip.initialContactPoints).map(SocketAddress::from).collect(Collectors.toList());
    if (!collect.isEmpty()) {
        context.getGossip().join(collect);
    }
    clusterMemberListManager.publishNodeAPIAddresses();
    final LogStreamsManager logStreamManager = context.getLogStreamsManager();
    final File storageDirectory = new File(transportComponentCfg.management.directory);
    if (!storageDirectory.exists()) {
        try {
            storageDirectory.getParentFile().mkdirs();
            Files.createDirectory(storageDirectory.toPath());
        } catch (final IOException e) {
            LOG.error("Unable to create directory {}", storageDirectory, e);
        }
    }
    final SocketBindingCfg replicationApi = transportComponentCfg.replicationApi;
    final SocketAddress socketAddress = new SocketAddress(replicationApi.getHost(transportComponentCfg.host), replicationApi.port);
    final File[] storageFiles = storageDirectory.listFiles();
    if (storageFiles != null && storageFiles.length > 0) {
        for (int i = 0; i < storageFiles.length; i++) {
            final File storageFile = storageFiles[i];
            final RaftPersistentFileStorage storage = new RaftPersistentFileStorage(storageFile.getAbsolutePath());
            final DirectBuffer topicName = storage.getTopicName();
            final int partitionId = storage.getPartitionId();
            LogStream logStream = logStreamManager.getLogStream(partitionId);
            if (logStream == null) {
                final String directory = storage.getLogDirectory();
                logStream = logStreamManager.createLogStream(topicName, partitionId, directory);
            }
            storage.setLogStream(logStream);
            createRaft(socketAddress, logStream, storage.getMembers(), storage);
        }
    } else {
        if (transportComponentCfg.gossip.initialContactPoints.length == 0) {
            LOG.debug("Broker bootstraps the system topic");
            createPartition(Protocol.SYSTEM_TOPIC_BUF, Protocol.SYSTEM_PARTITION);
        }
    }
}
Also used : RaftPersistentFileStorage(io.zeebe.broker.clustering.raft.RaftPersistentFileStorage) DirectBuffer(org.agrona.DirectBuffer) IOException(java.io.IOException) SocketBindingCfg(io.zeebe.broker.transport.cfg.SocketBindingCfg) LogStream(io.zeebe.logstreams.log.LogStream) LogStreamsManager(io.zeebe.broker.logstreams.LogStreamsManager) File(java.io.File)

Aggregations

RaftPersistentFileStorage (io.zeebe.broker.clustering.raft.RaftPersistentFileStorage)2 LogStreamsManager (io.zeebe.broker.logstreams.LogStreamsManager)1 SocketBindingCfg (io.zeebe.broker.transport.cfg.SocketBindingCfg)1 FsLogStorage (io.zeebe.logstreams.impl.log.fs.FsLogStorage)1 LogStream (io.zeebe.logstreams.log.LogStream)1 File (java.io.File)1 IOException (java.io.IOException)1 DirectBuffer (org.agrona.DirectBuffer)1