You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "rishi-rana (via GitHub)" <gi...@apache.org> on 2026/10/05 17:19:57 UTC

[PR] KAFKA-14333: Document PolicyViolationException in Admin#deleteRecords javadoc [kafka]

rishi-rana opened a new pull request, #23716:
URL: https://github.com/apache/kafka/pull/23716

   ## Summary
   
   `Admin#deleteRecords` throws `PolicyViolationException` (surfaced via the
   per-partition future, see `Partition.deleteRecordsOnLeader` in
   `core/src/main/scala/kafka/cluster/Partition.scala`) when a topic's
   `cleanup.policy` does not permit record deletion — e.g. `cleanup.policy=compact`
   without `delete`. This was never documented in the javadoc.
   
   - Added the standard "exceptions anticipated when calling `get()`" block,
     matching the convention already used elsewhere in `Admin.java` (e.g.
     `incrementalAlterConfigs`).
   - No behavior change — documentation only.
   
   Developed with AI assistance.
   
   ## Test plan
   
   - [x] `./gradlew :clients:spotlessCheck :clients:checkstyleMain :clients:javadoc` — clean


-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-14333: Document PolicyViolationException in Admin#deleteRecords javadoc [kafka]

Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-14333: Document PolicyViolationException in Admin#deleteRecords javadoc [kafka]

Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on PR #23716:
URL: https://github.com/apache/kafka/pull/23716#issuecomment-6109380312

   @rishi-rana I have revised the PR description to make it simpler and clearer. It would be good to ask the AI to follow this pattern in the future :)


-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-14333: Document PolicyViolationException in Admin#deleteRecords javadoc [kafka]

Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 merged PR #23716:
URL: https://github.com/apache/kafka/pull/23716


-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org