Search in sources :

Example 1 with LogStreamRecordWriter

use of io.camunda.zeebe.logstreams.log.LogStreamRecordWriter in project zeebe by camunda.

the class PushDeploymentRequestHandler method handleValidRequest.

private void handleValidRequest(final CompletableFuture<byte[]> responseFuture, final DirectBuffer buffer, final int offset, final int length) {
    final PushDeploymentRequest pushDeploymentRequest = new PushDeploymentRequest();
    pushDeploymentRequest.wrap(buffer, offset, length);
    final long deploymentKey = pushDeploymentRequest.deploymentKey();
    final int partitionId = pushDeploymentRequest.partitionId();
    final DirectBuffer deployment = pushDeploymentRequest.deployment();
    final LogStreamRecordWriter logStreamWriter = leaderPartitions.get(partitionId);
    if (logStreamWriter != null) {
        LOG.trace("Handling deployment {} for partition {} as leader", deploymentKey, partitionId);
        handlePushDeploymentRequest(responseFuture, deployment, deploymentKey, partitionId);
    } else {
        LOG.debug("Rejecting deployment {} for partition {} as not leader", deploymentKey, partitionId);
        sendNotLeaderRejection(responseFuture, partitionId);
    }
}
Also used : DirectBuffer(org.agrona.DirectBuffer) LogStreamRecordWriter(io.camunda.zeebe.logstreams.log.LogStreamRecordWriter)

Example 2 with LogStreamRecordWriter

use of io.camunda.zeebe.logstreams.log.LogStreamRecordWriter in project zeebe by zeebe-io.

the class PushDeploymentRequestHandler method handlePushDeploymentRequest.

private void handlePushDeploymentRequest(final CompletableFuture<byte[]> responseFuture, final DirectBuffer deployment, final long deploymentKey, final int partitionId) {
    final DeploymentRecord deploymentRecord = new DeploymentRecord();
    deploymentRecord.wrap(deployment);
    actor.runUntilDone(() -> {
        final LogStreamRecordWriter logStream = leaderPartitions.get(partitionId);
        if (logStream == null) {
            LOG.debug("Leader change on partition {}, ignore push deployment request", partitionId);
            actor.done();
            return;
        }
        final boolean success = writeDistributeDeployment(logStream, deploymentKey, deploymentRecord);
        if (success) {
            LOG.debug("Deployment DISTRIBUTE command for deployment {} was written on partition {}", deploymentKey, partitionId);
            actor.done();
            sendResponse(responseFuture, deploymentKey, partitionId);
        } else {
            actor.yieldThread();
        }
    });
}
Also used : DeploymentRecord(io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord) LogStreamRecordWriter(io.camunda.zeebe.logstreams.log.LogStreamRecordWriter)

Example 3 with LogStreamRecordWriter

use of io.camunda.zeebe.logstreams.log.LogStreamRecordWriter in project zeebe by zeebe-io.

the class SubscriptionCommandMessageHandler method writeCommand.

private boolean writeCommand(final int partitionId, final ValueType valueType, final Intent intent, final UnpackedObject command) {
    final LogStreamRecordWriter logStreamRecordWriter = logstreamRecordWriterSupplier.apply(partitionId);
    if (logStreamRecordWriter == null) {
        // ignore message if you are not the leader of the partition
        return true;
    }
    logStreamRecordWriter.reset();
    recordMetadata.reset().recordType(RecordType.COMMAND).valueType(valueType).intent(intent);
    final long position = logStreamRecordWriter.key(-1).metadataWriter(recordMetadata).valueWriter(command).tryWrite();
    return position > 0;
}
Also used : LogStreamRecordWriter(io.camunda.zeebe.logstreams.log.LogStreamRecordWriter)

Example 4 with LogStreamRecordWriter

use of io.camunda.zeebe.logstreams.log.LogStreamRecordWriter in project zeebe by camunda-cloud.

the class PushDeploymentRequestHandler method handleValidRequest.

private void handleValidRequest(final CompletableFuture<byte[]> responseFuture, final DirectBuffer buffer, final int offset, final int length) {
    final PushDeploymentRequest pushDeploymentRequest = new PushDeploymentRequest();
    pushDeploymentRequest.wrap(buffer, offset, length);
    final long deploymentKey = pushDeploymentRequest.deploymentKey();
    final int partitionId = pushDeploymentRequest.partitionId();
    final DirectBuffer deployment = pushDeploymentRequest.deployment();
    final LogStreamRecordWriter logStreamWriter = leaderPartitions.get(partitionId);
    if (logStreamWriter != null) {
        LOG.trace("Handling deployment {} for partition {} as leader", deploymentKey, partitionId);
        handlePushDeploymentRequest(responseFuture, deployment, deploymentKey, partitionId);
    } else {
        LOG.debug("Rejecting deployment {} for partition {} as not leader", deploymentKey, partitionId);
        sendNotLeaderRejection(responseFuture, partitionId);
    }
}
Also used : DirectBuffer(org.agrona.DirectBuffer) LogStreamRecordWriter(io.camunda.zeebe.logstreams.log.LogStreamRecordWriter)

Example 5 with LogStreamRecordWriter

use of io.camunda.zeebe.logstreams.log.LogStreamRecordWriter in project zeebe by camunda-cloud.

the class SubscriptionCommandMessageHandler method writeCommand.

private boolean writeCommand(final int partitionId, final ValueType valueType, final Intent intent, final UnpackedObject command) {
    final LogStreamRecordWriter logStreamRecordWriter = logstreamRecordWriterSupplier.apply(partitionId);
    if (logStreamRecordWriter == null) {
        // ignore message if you are not the leader of the partition
        return true;
    }
    logStreamRecordWriter.reset();
    recordMetadata.reset().recordType(RecordType.COMMAND).valueType(valueType).intent(intent);
    final long position = logStreamRecordWriter.key(-1).metadataWriter(recordMetadata).valueWriter(command).tryWrite();
    return position > 0;
}
Also used : LogStreamRecordWriter(io.camunda.zeebe.logstreams.log.LogStreamRecordWriter)

Aggregations

LogStreamRecordWriter (io.camunda.zeebe.logstreams.log.LogStreamRecordWriter)9 DeploymentRecord (io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord)3 DirectBuffer (org.agrona.DirectBuffer)3