use kafka_client_core::{
BatchExecutionId, BatchId, ByteCount, OperationId, PartitionIndex, PayloadId, TopicId,
};
use super::ProducerStore;
use crate::producer::{
ProducerStoreError,
batch_store::{
BatchCancellationPhase, BatchRevisionExpectation, BatchRoute, DriverAcceptancePlan,
EngineBatchRevisionPlan, MaterializationAbort, MaterializationAttempt,
},
};
impl ProducerStore {
pub(crate) fn accumulate(
&mut self,
batch_id: BatchId,
operation_id: OperationId,
payload_id: PayloadId,
) -> Result<ByteCount, ProducerStoreError> {
let (topic_id, partition) = self.records.route(payload_id)?;
let retained = self.records.retained_bytes(payload_id)?;
let sticky_unkeyed = self.records.record(payload_id)?.is_automatic_unkeyed();
self.batches.append_partitioned(
batch_id,
operation_id,
payload_id,
BatchRoute {
topic_id,
partition,
},
sticky_unkeyed,
)?;
Ok(retained)
}
pub(crate) fn remove_member(
&mut self,
batch_id: BatchId,
operation_id: OperationId,
) -> Result<PayloadId, ProducerStoreError> {
self.batches.remove_member(batch_id, operation_id)
}
pub(in crate::producer) fn plan_batch_revision(
&self,
previous: BatchExecutionId,
removed_operation_id: OperationId,
expectation: BatchRevisionExpectation,
) -> Result<EngineBatchRevisionPlan, ProducerStoreError> {
self.batches
.plan_revision(previous, removed_operation_id, expectation)
}
pub(in crate::producer) fn commit_batch_revision(&mut self, plan: EngineBatchRevisionPlan) {
self.batches.commit_revision(plan);
}
pub(in crate::producer) fn start_batch_retry(
&mut self,
previous: BatchExecutionId,
replacement: BatchExecutionId,
) -> Result<(), ProducerStoreError> {
self.batches.start_retry(previous, replacement)
}
pub(in crate::producer) fn activate_batch_retry(
&mut self,
execution: BatchExecutionId,
) -> Result<(), ProducerStoreError> {
self.batches.activate_retry(execution)
}
pub(in crate::producer) fn cancellation_phase(
&self,
operation_id: OperationId,
) -> Result<Option<BatchCancellationPhase>, ProducerStoreError> {
self.batches.cancellation_phase(operation_id)
}
pub(in crate::producer) fn plan_driver_accepted(
&self,
execution: BatchExecutionId,
) -> Result<DriverAcceptancePlan, ProducerStoreError> {
self.batches.plan_driver_accepted(execution)
}
pub(in crate::producer) fn commit_driver_accepted(&mut self, plan: DriverAcceptancePlan) {
self.batches.commit_driver_accepted(plan);
}
pub(crate) fn release_batch(&mut self, batch_id: BatchId) -> Result<(), ProducerStoreError> {
let _members = self.batches.release(batch_id)?;
Ok(())
}
pub(crate) fn execution_route(
&self,
execution: BatchExecutionId,
) -> Result<(TopicId, PartitionIndex), ProducerStoreError> {
let route = self.batches.execution_route(execution)?;
Ok((route.topic_id, route.partition))
}
pub(crate) fn execution_contains_operation(
&self,
execution: BatchExecutionId,
operation_id: OperationId,
) -> Result<bool, ProducerStoreError> {
self.batches
.execution_contains_operation(execution, operation_id)
}
pub(crate) fn commit_materialization(
&mut self,
attempt: MaterializationAttempt,
) -> Result<(), ProducerStoreError> {
self.batches.commit_materialization(attempt)
}
pub(crate) fn abort_materialization(
&mut self,
attempt: MaterializationAttempt,
) -> MaterializationAbort {
self.batches.abort_materialization(attempt)
}
pub(crate) fn batch_execution(
&self,
batch_id: BatchId,
) -> Result<Option<BatchExecutionId>, ProducerStoreError> {
self.batches.execution(batch_id)
}
#[cfg(test)]
pub(crate) fn replace_batch_execution_for_test(
&mut self,
batch_id: BatchId,
replacement: BatchExecutionId,
) {
self.batches.replace_ready_for_test(batch_id, replacement);
}
}