java errors_Java Errors.exception方法代码示例

import org.apache.kafka.common.protocol.Errors; //导入方法依赖的package包/类

/**

* Complete or retry the given batch of records.

*

* @param batch The record batch

* @param response The produce response

* @param correlationId The correlation id for the request

* @param now The current POSIX timestamp in milliseconds

*/

private void completeBatch(ProducerBatch batch, ProduceResponse.PartitionResponse response, long correlationId,

long now) {

Errors error = response.error;

// 不能重试,则将RecordBatch都标记为异常完成,并释放ProducerBatch

if (error == Errors.MESSAGE_TOO_LARGE && batch.recordCount > 1 &&

(batch.magic() >= RecordBatch.MAGIC_VALUE_V2 || batch.isCompressed())) {

// If the batch is too large, we split the batch and send the split batches again. We do not decrement

// the retry attempts in this case.

log.warn("Got error produce response in correlation id {} on topic-partition {}, spitting and retrying ({} attempts left). Error: {}",

correlationId,

batch.topicPartition,

this.retries - batch.attempts(),

error);

this.accumulator.splitAndReenqueue(batch);

this.accumulator.deallocate(batch);

this.sensors.recordBatchSplit();

} else if (error != Errors.NONE) {

if (canRetry(batch, error)) {

log.warn("Got error produce response with correlation id {} on topic-partition {}, retrying ({} attempts left). Error: {}",

correlationId,

batch.topicPartition,

this.retries - batch.attempts() - 1,

error);

if (transactionManager == null) {

reenqueueBatch(batch, now);

} else if (transactionManager.hasProducerIdAndEpoch(batch.producerId(), batch.producerEpoch())) {

// If idempotence is enabled only retry the request if the current producer id is the same as

// the producer id of the batch.

log.debug("Retrying batch to topic-partition {}. Sequence number : {}", batch.topicPartition,

transactionManager.sequenceNumber(batch.topicPartition));

reenqueueBatch(batch, now);

} else {

failBatch(batch, response, new OutOfOrderSequenceException("Attempted to retry sending a " +

"batch but the producer id changed from " + batch.producerId() + " to " +

transactionManager.producerIdAndEpoch().producerId + " in the mean time. This batch will be dropped."));

this.sensors.recordErrors(batch.topicPartition.topic(), batch.recordCount);

}

} else {

final RuntimeException exception;

if (error == Errors.TOPIC_AUTHORIZATION_FAILED)

exception = new TopicAuthorizationException(batch.topicPartition.topic());

else if (error == Errors.CLUSTER_AUTHORIZATION_FAILED)

exception = new ClusterAuthorizationException("The producer is not authorized to do idempotent sends");

else

exception = error.exception();

// tell the user the result of their request

failBatch(batch, response, exception);

this.sensors.recordErrors(batch.topicPartition.topic(), batch.recordCount);

}

if (error.exception() instanceof InvalidMetadataException) {

if (error.exception() instanceof UnknownTopicOrPartitionException)

log.warn("Received unknown topic or partition error in produce request on partition {}. The " +

"topic/partition may not exist or the user may not have Describe access to it", batch.topicPartition);

metadata.requestUpdate();

}

} else {

completeBatch(batch, response);

}

// Unmute the completed partition.

if (guaranteeMessageOrder)

this.accumulator.unmutePartition(batch.topicPartition);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值