This is an automated email from the ASF dual-hosted git repository.
chia7712 pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git
The following commit(s) were added to refs/heads/trunk by this push:
new e4f75dfb8bb MINOR: Use getAbsolutePath in LocalLog#exception (#21891)
e4f75dfb8bb is described below
commit e4f75dfb8bb6a44acd021edd2c17e6a7ed24cb98
Author: PoAn Yang <[email protected]>
AuthorDate: Mon Mar 30 06:46:23 2026 +0900
MINOR: Use getAbsolutePath in LocalLog#exception (#21891)
Followup for
https://github.com/apache/kafka/pull/21834#discussion_r3006236930
Reviewers: Chia-Ping Tsai <[email protected]>
---
.../kafka/storage/internals/log/LocalLog.java | 6 ++--
.../kafka/storage/internals/log/LogManager.java | 6 +---
.../kafka/storage/internals/log/UnifiedLog.java | 2 +-
.../kafka/storage/internals/log/LocalLogTest.java | 38 +++++++++++-----------
4 files changed, 24 insertions(+), 28 deletions(-)
diff --git
a/storage/src/main/java/org/apache/kafka/storage/internals/log/LocalLog.java
b/storage/src/main/java/org/apache/kafka/storage/internals/log/LocalLog.java
index 786673db1dd..0cc7f704d22 100644
--- a/storage/src/main/java/org/apache/kafka/storage/internals/log/LocalLog.java
+++ b/storage/src/main/java/org/apache/kafka/storage/internals/log/LocalLog.java
@@ -741,8 +741,8 @@ public class LocalLog {
return topicPartition.topic() + "-" + topicPartition.partition();
}
- private static KafkaException exception(File dir) throws IOException {
- return new KafkaException("Found directory " + dir.getCanonicalPath()
+ ", '" + dir.getName() + "' is not in the form of " +
+ private static KafkaException exception(File dir) {
+ return new KafkaException("Found directory " + dir.getAbsolutePath() +
", '" + dir.getName() + "' is not in the form of " +
"topic-partition or topic-partition.uniqueId-delete (if marked
for deletion).\n" +
"Kafka's log directories (and children) should only contain
Kafka topic data.");
}
@@ -750,7 +750,7 @@ public class LocalLog {
/**
* Parse the topic and partition out of the directory name of a log
*/
- public static TopicPartition parseTopicPartitionName(File dir) throws
IOException {
+ public static TopicPartition parseTopicPartitionName(File dir) {
if (dir == null) {
throw new KafkaException("dir should not be null");
}
diff --git
a/storage/src/main/java/org/apache/kafka/storage/internals/log/LogManager.java
b/storage/src/main/java/org/apache/kafka/storage/internals/log/LogManager.java
index 14fda5895ee..17ad60e455e 100644
---
a/storage/src/main/java/org/apache/kafka/storage/internals/log/LogManager.java
+++
b/storage/src/main/java/org/apache/kafka/storage/internals/log/LogManager.java
@@ -656,11 +656,7 @@ public class LogManager {
// Ignore remote-log-index-cache directory as that
is index cache maintained by tiered storage subsystem
// but not any topic-partition dir.
if
(logDir.getName().equals(RemoteIndexCache.DIR_NAME)) return false;
- try {
- return
!UnifiedLog.parseTopicPartitionName(logDir).topic().equals(Topic.CLUSTER_METADATA_TOPIC_NAME);
- } catch (IOException e) {
- return false;
- }
+ return
!UnifiedLog.parseTopicPartitionName(logDir).topic().equals(Topic.CLUSTER_METADATA_TOPIC_NAME);
})
.toList();
numTotalLogs += logsToLoad.size();
diff --git
a/storage/src/main/java/org/apache/kafka/storage/internals/log/UnifiedLog.java
b/storage/src/main/java/org/apache/kafka/storage/internals/log/UnifiedLog.java
index 65f5042c41a..b358edd1392 100644
---
a/storage/src/main/java/org/apache/kafka/storage/internals/log/UnifiedLog.java
+++
b/storage/src/main/java/org/apache/kafka/storage/internals/log/UnifiedLog.java
@@ -2781,7 +2781,7 @@ public class UnifiedLog implements AutoCloseable {
return LogSegments.sizeInBytes(segments);
}
- public static TopicPartition parseTopicPartitionName(File dir) throws
IOException {
+ public static TopicPartition parseTopicPartitionName(File dir) {
return LocalLog.parseTopicPartitionName(dir);
}
}
diff --git
a/storage/src/test/java/org/apache/kafka/storage/internals/log/LocalLogTest.java
b/storage/src/test/java/org/apache/kafka/storage/internals/log/LocalLogTest.java
index f0c5192611f..e91058e6b14 100644
---
a/storage/src/test/java/org/apache/kafka/storage/internals/log/LocalLogTest.java
+++
b/storage/src/test/java/org/apache/kafka/storage/internals/log/LocalLogTest.java
@@ -504,7 +504,7 @@ class LocalLogTest {
}
@Test
- public void testParseTopicPartitionName() throws IOException {
+ public void testParseTopicPartitionName() {
String topic = "test_topic";
String partition = "143";
File dir = new File(logDir, topicPartitionName(topic, partition));
@@ -518,7 +518,7 @@ class LocalLogTest {
* are parsed correctly by `Log.parseTopicPartitionName` (see KAFKA-5232
for details).
*/
@Test
- public void testParseTopicPartitionNameWithPeriodForDeletedTopic() throws
IOException {
+ public void testParseTopicPartitionNameWithPeriodForDeletedTopic() {
String topic = "foo.bar-testtopic";
String partition = "42";
File dir = new File(logDir, LocalLog.logDeleteDirName(new
TopicPartition(topic, Integer.parseInt(partition))));
@@ -528,9 +528,9 @@ class LocalLogTest {
}
@Test
- public void testParseTopicPartitionNameForEmptyName() throws IOException {
+ public void testParseTopicPartitionNameForEmptyName() {
File dir = new File("");
- String msg = "KafkaException should have been thrown for dir: " +
dir.getCanonicalPath();
+ String msg = "KafkaException should have been thrown for dir: " +
dir.getAbsolutePath();
assertThrows(KafkaException.class, () ->
LocalLog.parseTopicPartitionName(dir), msg);
}
@@ -542,68 +542,68 @@ class LocalLogTest {
}
@Test
- public void testParseTopicPartitionNameForMissingSeparator() throws
IOException {
+ public void testParseTopicPartitionNameForMissingSeparator() {
String topic = "test_topic";
String partition = "1999";
File dir = new File(logDir, topic + partition);
- String msg = "KafkaException should have been thrown for dir: " +
dir.getCanonicalPath();
+ String msg = "KafkaException should have been thrown for dir: " +
dir.getAbsolutePath();
assertThrows(KafkaException.class, () ->
LocalLog.parseTopicPartitionName(dir), msg);
// also test the "-delete" marker case
File deleteMarkerDir = new File(logDir, topic + partition + "." +
LogFileUtils.DELETE_DIR_SUFFIX);
- msg = "KafkaException should have been thrown for dir: " +
deleteMarkerDir.getCanonicalPath();
+ msg = "KafkaException should have been thrown for dir: " +
deleteMarkerDir.getAbsolutePath();
assertThrows(KafkaException.class, () ->
LocalLog.parseTopicPartitionName(deleteMarkerDir), msg);
}
@Test
- public void testParseTopicPartitionNameForMissingTopic() throws
IOException {
+ public void testParseTopicPartitionNameForMissingTopic() {
String topic = "";
String partition = "1999";
File dir = new File(logDir, topicPartitionName(topic, partition));
- String msg = "KafkaException should have been thrown for dir: " +
dir.getCanonicalPath();
+ String msg = "KafkaException should have been thrown for dir: " +
dir.getAbsolutePath();
assertThrows(KafkaException.class, () ->
LocalLog.parseTopicPartitionName(dir), msg);
// also test the "-delete" marker case
File deleteMarkerDir = new File(logDir, LocalLog.logDeleteDirName(new
TopicPartition(topic, Integer.parseInt(partition))));
- msg = "KafkaException should have been thrown for dir: " +
deleteMarkerDir.getCanonicalPath();
+ msg = "KafkaException should have been thrown for dir: " +
deleteMarkerDir.getAbsolutePath();
assertThrows(KafkaException.class, () ->
LocalLog.parseTopicPartitionName(deleteMarkerDir), msg);
}
@Test
- public void testParseTopicPartitionNameForMissingPartition() throws
IOException {
+ public void testParseTopicPartitionNameForMissingPartition() {
String topic = "test_topic";
String partition = "";
File dir = new File(logDir.getPath() + topicPartitionName(topic,
partition));
- String msg = "KafkaException should have been thrown for dir: " +
dir.getCanonicalPath();
+ String msg = "KafkaException should have been thrown for dir: " +
dir.getAbsolutePath();
assertThrows(KafkaException.class, () ->
LocalLog.parseTopicPartitionName(dir), msg);
// also test the "-delete" marker case
File deleteMarkerDir = new File(logDir, topicPartitionName(topic,
partition) + "." + LogFileUtils.DELETE_DIR_SUFFIX);
- msg = "KafkaException should have been thrown for dir: " +
deleteMarkerDir.getCanonicalPath();
+ msg = "KafkaException should have been thrown for dir: " +
deleteMarkerDir.getAbsolutePath();
assertThrows(KafkaException.class, () ->
LocalLog.parseTopicPartitionName(deleteMarkerDir), msg);
}
@Test
- public void testParseTopicPartitionNameForInvalidPartition() throws
IOException {
+ public void testParseTopicPartitionNameForInvalidPartition() {
String topic = "test_topic";
String partition = "1999a";
File dir = new File(logDir, topicPartitionName(topic, partition));
- String msg = "KafkaException should have been thrown for dir: " +
dir.getCanonicalPath();
+ String msg = "KafkaException should have been thrown for dir: " +
dir.getAbsolutePath();
assertThrows(KafkaException.class, () ->
LocalLog.parseTopicPartitionName(dir), msg);
// also test the "-delete" marker case
File deleteMarkerDir = new File(logDir, topic + partition + "." +
LogFileUtils.DELETE_DIR_SUFFIX);
- msg = "KafkaException should have been thrown for dir: " +
deleteMarkerDir.getCanonicalPath();
+ msg = "KafkaException should have been thrown for dir: " +
deleteMarkerDir.getAbsolutePath();
assertThrows(KafkaException.class, () ->
LocalLog.parseTopicPartitionName(deleteMarkerDir), msg);
}
@Test
- public void testParseTopicPartitionNameForExistingInvalidDir() throws
IOException {
+ public void testParseTopicPartitionNameForExistingInvalidDir() {
File dir1 = new File(logDir.getPath() + "/non_kafka_dir");
- String msg = "KafkaException should have been thrown for dir: " +
dir1.getCanonicalPath();
+ String msg = "KafkaException should have been thrown for dir: " +
dir1.getAbsolutePath();
assertThrows(KafkaException.class, () ->
LocalLog.parseTopicPartitionName(dir1), msg);
File dir2 = new File(logDir.getPath() + "/non_kafka_dir-delete");
- msg = "KafkaException should have been thrown for dir: " +
dir2.getCanonicalPath();
+ msg = "KafkaException should have been thrown for dir: " +
dir2.getAbsolutePath();
assertThrows(KafkaException.class, () ->
LocalLog.parseTopicPartitionName(dir2), msg);
}