guozhangwang commented on a change in pull request #10609: URL: https://github.com/apache/kafka/pull/10609#discussion_r644344196
########## File path: streams/src/main/java/org/apache/kafka/streams/processor/internals/StateDirectory.java ########## @@ -462,39 +512,49 @@ private void cleanRemovedTasksCalledByUser() throws Exception { * List all of the task directories that are non-empty * @return The list of all the non-empty local directories for stream tasks */ - File[] listNonEmptyTaskDirectories() { - final File[] taskDirectories; - if (!hasPersistentStores || !stateDir.exists()) { - taskDirectories = new File[0]; - } else { - taskDirectories = - stateDir.listFiles(pathname -> { - if (!pathname.isDirectory() || !TASK_DIR_PATH_NAME.matcher(pathname.getName()).matches()) { - return false; - } else { - return !taskDirIsEmpty(pathname); - } - }); - } - - return taskDirectories == null ? new File[0] : taskDirectories; + List<TaskDirectory> listNonEmptyTaskDirectories() { + return listTaskDirectories(pathname -> { + if (!pathname.isDirectory() || !TASK_DIR_PATH_NAME.matcher(pathname.getName()).matches()) { + return false; + } else { + return !taskDirIsEmpty(pathname); + } + }); } /** - * List all of the task directories + * List all of the task directories along with their parent directory if they belong to a named topology * @return The list of all the existing local directories for stream tasks */ - File[] listAllTaskDirectories() { - final File[] taskDirectories; - if (!hasPersistentStores || !stateDir.exists()) { - taskDirectories = new File[0]; - } else { - taskDirectories = - stateDir.listFiles(pathname -> pathname.isDirectory() - && TASK_DIR_PATH_NAME.matcher(pathname.getName()).matches()); + List<TaskDirectory> listAllTaskDirectories() { + return listTaskDirectories(pathname -> pathname.isDirectory() && TASK_DIR_PATH_NAME.matcher(pathname.getName()).matches()); + } + + private List<TaskDirectory> listTaskDirectories(final FileFilter filter) { + final List<TaskDirectory> taskDirectories = new ArrayList<>(); + if (hasPersistentStores && stateDir.exists()) { + if (hasNamedTopologies) { Review comment: I was asking more for a semantic one -- as long as this is not expected then I'm happy for this piece as 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org