All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.zeebe.broker.system.partitions.impl.steps.LogStreamPartitionStep Maven / Gradle / Ivy

/*
 * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH under
 * one or more contributor license agreements. See the NOTICE file distributed
 * with this work for additional information regarding copyright ownership.
 * Licensed under the Zeebe Community License 1.1. You may not use this file
 * except in compliance with the Zeebe Community License 1.1.
 */
package io.zeebe.broker.system.partitions.impl.steps;

import io.zeebe.broker.system.partitions.PartitionContext;
import io.zeebe.broker.system.partitions.PartitionStep;
import io.zeebe.logstreams.log.LogStream;
import io.zeebe.util.sched.future.ActorFuture;
import io.zeebe.util.sched.future.CompletableActorFuture;

public class LogStreamPartitionStep implements PartitionStep {

  @Override
  public ActorFuture open(final PartitionContext context) {
    final CompletableActorFuture openFuture = new CompletableActorFuture<>();
    buildLogstream(context)
        .onComplete(
            ((logStream, err) -> {
              if (err == null) {
                context.setLogStream(logStream);

                if (context.getDeferredCommitPosition() > 0) {
                  context.getLogStream().setCommitPosition(context.getDeferredCommitPosition());
                  context.setDeferredCommitPosition(-1);
                }
                context
                    .getComponentHealthMonitor()
                    .registerComponent(logStream.getLogName(), logStream);
                openFuture.complete(null);
              } else {
                openFuture.completeExceptionally(err);
              }
            }));

    return openFuture;
  }

  @Override
  public ActorFuture close(final PartitionContext context) {
    context.getComponentHealthMonitor().removeComponent(context.getLogStream().getLogName());
    final ActorFuture future = context.getLogStream().closeAsync();
    context.setLogStream(null);
    return future;
  }

  @Override
  public String getName() {
    return "logstream";
  }

  private ActorFuture buildLogstream(final PartitionContext context) {
    return LogStream.builder()
        .withLogStorage(context.getAtomixLogStorage())
        .withLogName("logstream-" + context.getRaftPartition().name())
        .withNodeId(context.getNodeId())
        .withPartitionId(context.getRaftPartition().id().id())
        .withMaxFragmentSize(context.getMaxFragmentSize())
        .withActorScheduler(context.getScheduler())
        .buildAsync();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy