You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "mjsax (via GitHub)" <gi...@apache.org> on 2026/04/26 23:24:02 UTC
Re: [PR] KAFKA-17251: Avoid WARN on cleanup when state directory only contains process metadata. [kafka]
mjsax commented on code in PR #20969:
URL: https://github.com/apache/kafka/pull/20969#discussion_r3144339468
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StateDirectory.java:
##########
@@ -577,10 +577,41 @@ public synchronized void clean() {
try {
if (hasPersistentStores && stateDir.exists() && !stateDir.delete()) {
- log.warn(
- String.format("%s Failed to delete state store directory of %s for it is not empty",
- logPrefix(), stateDir.getAbsolutePath())
- );
+ final File[] remainingFiles = stateDir.listFiles();
+ if (remainingFiles == null) {
+ log.warn("{} Failed to delete state store directory of {}. It is not a directory, or is inaccessible.",
+ logPrefix(), stateDir.getAbsolutePath());
+ return;
+ }
+
+ boolean hasProcessOrLockFiles = false;
+ boolean hasNonProcessOrLockFiles = false;
+
+ for (final File file : remainingFiles) {
+ final String name = file.getName();
+ if (PROCESS_FILE_NAME.equals(name) || LOCK_FILE_NAME.equals(name)) {
+ hasProcessOrLockFiles = true;
+ } else {
+ hasNonProcessOrLockFiles = true;
+ break;
+ }
+ }
+
+ if (hasProcessOrLockFiles && !hasNonProcessOrLockFiles) {
+ // KAFKA-10716: The processId file is persisted in the state directory to keep the
+ // processId stable across restarts. Removing it would cause a new processId to be
+ // generated and may lead to unnecessary task movements during rebalances.
+ log.debug(
+ "{} State store directory {} was not deleted because it still contains only expected metadata files ({} and/or {}).",
Review Comment:
```suggestion
"{} State store directory {} was not deleted because it still contains expected metadata files ({} and/or {}).",
```
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StateDirectory.java:
##########
@@ -577,10 +577,41 @@ public synchronized void clean() {
try {
if (hasPersistentStores && stateDir.exists() && !stateDir.delete()) {
- log.warn(
- String.format("%s Failed to delete state store directory of %s for it is not empty",
- logPrefix(), stateDir.getAbsolutePath())
- );
+ final File[] remainingFiles = stateDir.listFiles();
+ if (remainingFiles == null) {
+ log.warn("{} Failed to delete state store directory of {}. It is not a directory, or is inaccessible.",
Review Comment:
```suggestion
log.warn("{} Failed to delete state store directory {}. It is not a directory, or it is inaccessible.",
```
##########
streams/src/main/java/org/apache/kafka/streams/processor/internals/StateDirectory.java:
##########
@@ -577,10 +577,41 @@ public synchronized void clean() {
try {
if (hasPersistentStores && stateDir.exists() && !stateDir.delete()) {
- log.warn(
- String.format("%s Failed to delete state store directory of %s for it is not empty",
- logPrefix(), stateDir.getAbsolutePath())
- );
+ final File[] remainingFiles = stateDir.listFiles();
+ if (remainingFiles == null) {
+ log.warn("{} Failed to delete state store directory of {}. It is not a directory, or is inaccessible.",
+ logPrefix(), stateDir.getAbsolutePath());
+ return;
+ }
+
+ boolean hasProcessOrLockFiles = false;
+ boolean hasNonProcessOrLockFiles = false;
Review Comment:
```suggestion
boolean hasUnexpectedFiles = false;
```
--
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