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

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

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


##########
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 and the given suffix

Review Comment:
   This constructor doesn't provide `suffix`. Please update the java doc.  



##########
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 and the given suffix
+     *
+     * @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 and the given suffix
+     *
+     * @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 and the given suffix
+     *
+     * @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 and the given suffix
+     *
+     * @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 for the given file. The file name is of the form: {number}.{suffix}. This method extracts

Review Comment:
   nit: Returns the offset for the given file. -> Return the offset from the given file.



##########
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 and the given suffix
+     *
+     * @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 and the given suffix

Review Comment:
   ditto, here and below



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