chia7712 commented on code in PR #23716:
URL: https://github.com/apache/kafka/pull/23716#discussion_r4241684235
##########
clients/src/main/java/org/apache/kafka/clients/admin/Admin.java:
##########
@@ -697,6 +697,15 @@ default DeleteRecordsResult
deleteRecords(Map<TopicPartition, RecordsToDelete> r
/**
* Delete records whose offset is smaller than the given offset of the
corresponding partition.
* <p>
+ * The following exceptions can be anticipated when calling {@code get()}
on the futures obtained from
+ * the returned {@link DeleteRecordsResult}:
+ * <ul>
+ * <li>{@link org.apache.kafka.common.errors.PolicyViolationException}
+ * if the records of the partition can not be deleted due to the
configured {@code cleanup.policy},
+ * for example because the topic's {@code cleanup.policy} is {@code
compact} and does not include
Review Comment:
```java
def deleteRecordsOnLeader(offset: Long): LogDeleteRecordsResult =
inReadLock(leaderIsrUpdateLock, () => {
leaderLogIfLocal match {
case Some(leaderLog) =>
if (!leaderLog.config.delete && leaderLog.config.compact)
throw new PolicyViolationException(s"Records of partition
$topicPartition can not be deleted due to the configured policy")
val convertedOffset = if (offset ==
DeleteRecordsRequest.HIGH_WATERMARK)
leaderLog.highWatermark
else
offset
if (convertedOffset < 0)
throw new OffsetOutOfRangeException(s"The offset $convertedOffset
for partition $topicPartition is not valid")
leaderLog.maybeIncrementLogStartOffset(convertedOffset,
LogStartOffsetIncrementReason.ClientRecordDeletion)
new LogDeleteRecordsResult(convertedOffset, lowWatermarkIfLeader,
Optional.empty())
case None =>
throw new NotLeaderOrFollowerException(s"Leader not local for
partition $topicPartition on broker $localBrokerId")
}
})
```
The scenario you described is the only case in trunk now, but this client
may target brokers of other versions. Hence, let’s keep it as it is :)
--
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]