private Void deleteTypeIfExists(StorageAction<Boolean, IOException> delete, String fileType, File file, boolean logIfMissing) throws IOException {
        try {
            if (delete.execute())
                LOGGER.info("Deleted {} {}.", fileType, file.getAbsolutePath());
            else {
                if (logIfMissing) {
                    LOGGER.info("Failed to delete {} {} because it does not exist.", fileType, file.getAbsolutePath());
                }

                // During alter log dir, the log segment may be moved to a new directory, so async delete may fail.
                // Fallback to delete the file in the new directory to avoid orphan file.
                Matcher dirMatcher = FUTURE_DIR_PATTERN.matcher(file.getParent());
                if (dirMatcher.matches()) {
                    String topicPartitionAbsolutePath = dirMatcher.group(1) + "-" + dirMatcher.group(2);
                    File fallbackFile = new File(topicPartitionAbsolutePath, file.getName());
                    if (fallbackFile.exists() && file.getName().endsWith(LogFileUtils.DELETED_FILE_SUFFIX) && fallbackFile.delete()) {
                        LOGGER.info("Fallback to delete {} {}.", fileType, fallbackFile.getAbsolutePath());
                    }
                }
            }
            return null;
        } catch (IOException e) {
            throw new IOException("Delete of " + fileType + " " + file.getAbsolutePath() + " failed.", e);
        }
    }
Delete this log segment from the filesystem.
storage/src/main/java/org/apache/kafka/storage/internals/log/LogSegment.java