You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "junrao (via GitHub)" <gi...@apache.org> on 2023/02/27 18:28:46 UTC

[GitHub] [kafka] junrao commented on a diff in pull request #13309: MINOR Moved a few log segment util methods from LocalLog to LogFileUtils

junrao commented on code in PR #13309:
URL: https://github.com/apache/kafka/pull/13309#discussion_r1119124556


##########
core/src/main/scala/kafka/log/LocalLog.scala:
##########
@@ -686,40 +685,6 @@ object LocalLog extends Logging {
     s"${topicPartition.topic}-${topicPartition.partition}"
   }
 
-  /**
-   * Construct an index file name in the given dir using the given base offset and the given suffix
-   *
-   * @param dir The directory in which the log will reside
-   * @param offset The base offset of the log file
-   * @param suffix The suffix to be appended to the file name ("", ".deleted", ".cleaned", ".swap", etc.)
-   */
-  private[log] def offsetIndexFile(dir: File, offset: Long, suffix: String = ""): File =
-    new File(dir, filenamePrefixFromOffset(offset) + IndexFileSuffix + suffix)

Review Comment:
   Should we remove IndexFileSuffix in LocalLog now that it's moved to LogFileUtils?



##########
storage/src/main/java/org/apache/kafka/storage/internals/log/LogFileUtils.java:
##########
@@ -72,4 +92,99 @@ private static String filenamePrefixFromOffset(long offset) {
         return nf.format(offset);
     }
 
+    /**
+     * Construct a log file name in the given dir with the given base offset.
+     *
+     * @param dir    The directory in which the log will reside
+     * @param offset The base offset of the log file
+     */
+    public static File logFile(File dir, long offset) {
+        return logFile(dir, offset, "");
+    }
+
+    /**
+     * Construct a log file name in the given dir with the given base offset and the given suffix.
+     *
+     * @param dir    The directory in which the log will reside
+     * @param offset The base offset of the log file
+     * @param suffix The suffix to be appended to the file name (e.g. "", ".deleted", ".cleaned", ".swap", etc.)
+     */
+    public static File logFile(File dir, long offset, String suffix) {
+        return new File(dir, filenamePrefixFromOffset(offset) + LOG_FILE_SUFFIX + suffix);
+    }
+
+    /**
+     * Construct an index file name in the given dir using the given base offset.
+     *
+     * @param dir    The directory in which the log will reside
+     * @param offset The base offset of the log file
+     */
+    public static File offsetIndexFile(File dir, long offset) {
+        return offsetIndexFile(dir, offset, "");
+    }
+
+    /**
+     * Construct an index file name in the given dir using the given base offset and the given suffix.
+     *
+     * @param dir    The directory in which the log will reside
+     * @param offset The base offset of the log file
+     * @param suffix The suffix to be appended to the file name ("", ".deleted", ".cleaned", ".swap", etc.)
+     */
+    public static File offsetIndexFile(File dir, long offset, String suffix) {
+        return new File(dir, filenamePrefixFromOffset(offset) + INDEX_FILE_SUFFIX + suffix);
+    }
+
+    /**
+     * Construct a time index file name in the given dir using the given base offset.
+     *
+     * @param dir    The directory in which the log will reside
+     * @param offset The base offset of the log file
+     */
+    public static File timeIndexFile(File dir, long offset) {
+        return timeIndexFile(dir, offset, "");
+    }
+
+    /**
+     * Construct a time index file name in the given dir using the given base offset and the given suffix.
+     *
+     * @param dir    The directory in which the log will reside
+     * @param offset The base offset of the log file
+     * @param suffix The suffix to be appended to the file name ("", ".deleted", ".cleaned", ".swap", etc.)
+     */
+    public static File timeIndexFile(File dir, long offset, String suffix) {
+        return new File(dir, filenamePrefixFromOffset(offset) + TIME_INDEX_FILE_SUFFIX + suffix);
+    }
+
+    /**
+     * Construct a transaction index file name in the given dir using the given base offset.
+     *
+     * @param dir    The directory in which the log will reside
+     * @param offset The base offset of the log file
+     */
+    public static File transactionIndexFile(File dir, long offset) {
+        return transactionIndexFile(dir, offset, "");
+    }
+
+    /**
+     * Construct a transaction index file name in the given dir using the given base offset and the given suffix.
+     *
+     * @param dir    The directory in which the log will reside
+     * @param offset The base offset of the log file
+     * @param suffix The suffix to be appended to the file name ("", ".deleted", ".cleaned", ".swap", etc.)
+     */
+    public static File transactionIndexFile(File dir, long offset, String suffix) {
+        return new File(dir, filenamePrefixFromOffset(offset) + TXN_INDEX_FILE_SUFFIX + suffix);
+    }
+
+    /**
+     * Returns the offset from the given file. The file name is of the form: {number}.{suffix}. This method extracts
+     * the number from the given file's name.
+     *
+     * @param file file with the offset information as part of its name.
+     * @return offset of the given file
+     */
+    public static Long offsetFromFile(File file) {

Review Comment:
   Should we remove `offsetFromFile` from LocalLog?



##########
storage/src/main/java/org/apache/kafka/storage/internals/log/LogFileUtils.java:
##########
@@ -72,4 +92,99 @@ private static String filenamePrefixFromOffset(long offset) {
         return nf.format(offset);
     }
 
+    /**
+     * Construct a log file name in the given dir with the given base offset.
+     *
+     * @param dir    The directory in which the log will reside
+     * @param offset The base offset of the log file
+     */
+    public static File logFile(File dir, long offset) {

Review Comment:
   Should we remove `logFile` in LocalLog?



-- 
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