apoorvmittal10 commented on code in PR #18093:
URL: https://github.com/apache/kafka/pull/18093#discussion_r1874735359
##########
core/src/main/java/kafka/server/share/SharePartition.java:
##########
@@ -426,55 +408,50 @@ public CompletableFuture<Void> maybeInitialize() {
.build())
.build()
).whenComplete((result, exception) -> {
+ Throwable throwable = null;
lock.writeLock().lock();
try {
if (exception != null) {
log.error("Failed to initialize the share partition:
{}-{}", groupId, topicIdPartition, exception);
- completeInitializationWithException();
- futureException.set(Optional.of(exception));
+ throwable = exception;
return;
}
if (result == null || result.topicsData() == null ||
result.topicsData().size() != 1) {
log.error("Failed to initialize the share partition:
{}-{}. Invalid state found: {}.",
groupId, topicIdPartition, result);
- completeInitializationWithException();
- futureException.set(Optional.of(new
IllegalStateException(String.format("Failed to initialize the share partition
%s-%s", groupId, topicIdPartition))));
+ throwable = new
IllegalStateException(String.format("Failed to initialize the share partition
%s-%s", groupId, topicIdPartition));
return;
}
TopicData<PartitionAllData> state = result.topicsData().get(0);
if (state.topicId() != topicIdPartition.topicId() ||
state.partitions().size() != 1) {
log.error("Failed to initialize the share partition:
{}-{}. Invalid topic partition response: {}.",
groupId, topicIdPartition, result);
- completeInitializationWithException();
- futureException.set(Optional.of(new
IllegalStateException(String.format("Failed to initialize the share partition
%s-%s", groupId, topicIdPartition))));
+ throwable = new
IllegalStateException(String.format("Failed to initialize the share partition
%s-%s", groupId, topicIdPartition));
return;
}
PartitionAllData partitionData = state.partitions().get(0);
if (partitionData.partition() != topicIdPartition.partition())
{
log.error("Failed to initialize the share partition:
{}-{}. Invalid partition response: {}.",
groupId, topicIdPartition, partitionData);
- completeInitializationWithException();
- futureException.set(Optional.of(new
IllegalStateException(String.format("Failed to initialize the share partition
%s-%s", groupId, topicIdPartition))));
+ throwable = new
IllegalStateException(String.format("Failed to initialize the share partition
%s-%s", groupId, topicIdPartition));
return;
}
if (partitionData.errorCode() != Errors.NONE.code()) {
KafkaException ex =
fetchPersisterError(partitionData.errorCode(), partitionData.errorMessage());
log.error("Failed to initialize the share partition:
{}-{}. Exception occurred: {}.",
groupId, topicIdPartition, partitionData);
- completeInitializationWithException();
- futureException.set(Optional.of(ex));
+ throwable = ex;
return;
}
try {
startOffset =
startOffsetDuringInitialization(partitionData.startOffset());
} catch (Exception e) {
Review Comment:
Agreed, done.
##########
core/src/main/java/kafka/server/share/SharePartition.java:
##########
@@ -426,55 +408,50 @@ public CompletableFuture<Void> maybeInitialize() {
.build())
.build()
).whenComplete((result, exception) -> {
+ Throwable throwable = null;
lock.writeLock().lock();
try {
if (exception != null) {
log.error("Failed to initialize the share partition:
{}-{}", groupId, topicIdPartition, exception);
- completeInitializationWithException();
- futureException.set(Optional.of(exception));
+ throwable = exception;
return;
}
if (result == null || result.topicsData() == null ||
result.topicsData().size() != 1) {
log.error("Failed to initialize the share partition:
{}-{}. Invalid state found: {}.",
groupId, topicIdPartition, result);
- completeInitializationWithException();
- futureException.set(Optional.of(new
IllegalStateException(String.format("Failed to initialize the share partition
%s-%s", groupId, topicIdPartition))));
+ throwable = new
IllegalStateException(String.format("Failed to initialize the share partition
%s-%s", groupId, topicIdPartition));
return;
}
TopicData<PartitionAllData> state = result.topicsData().get(0);
if (state.topicId() != topicIdPartition.topicId() ||
state.partitions().size() != 1) {
log.error("Failed to initialize the share partition:
{}-{}. Invalid topic partition response: {}.",
groupId, topicIdPartition, result);
- completeInitializationWithException();
- futureException.set(Optional.of(new
IllegalStateException(String.format("Failed to initialize the share partition
%s-%s", groupId, topicIdPartition))));
+ throwable = new
IllegalStateException(String.format("Failed to initialize the share partition
%s-%s", groupId, topicIdPartition));
return;
}
PartitionAllData partitionData = state.partitions().get(0);
if (partitionData.partition() != topicIdPartition.partition())
{
log.error("Failed to initialize the share partition:
{}-{}. Invalid partition response: {}.",
groupId, topicIdPartition, partitionData);
- completeInitializationWithException();
- futureException.set(Optional.of(new
IllegalStateException(String.format("Failed to initialize the share partition
%s-%s", groupId, topicIdPartition))));
+ throwable = new
IllegalStateException(String.format("Failed to initialize the share partition
%s-%s", groupId, topicIdPartition));
return;
}
if (partitionData.errorCode() != Errors.NONE.code()) {
KafkaException ex =
fetchPersisterError(partitionData.errorCode(), partitionData.errorMessage());
log.error("Failed to initialize the share partition:
{}-{}. Exception occurred: {}.",
groupId, topicIdPartition, partitionData);
- completeInitializationWithException();
- futureException.set(Optional.of(ex));
+ throwable = ex;
return;
}
try {
startOffset =
startOffsetDuringInitialization(partitionData.startOffset());
} catch (Exception e) {
Review Comment:
Agree, done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]