This is an automated email from the ASF dual-hosted git repository.

exceptionfactory pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/main by this push:
     new ecd4dbbda7 NIFI-14111 Added File.exists check to 
WriteAheadStorePartition before logging and deleting (#9744)
ecd4dbbda7 is described below

commit ecd4dbbda73ad63dd1bb7093de7f0675435724c8
Author: Homer Rich <[email protected]>
AuthorDate: Wed Feb 26 12:25:28 2025 -0500

    NIFI-14111 Added File.exists check to WriteAheadStorePartition before 
logging and deleting (#9744)
    
    Signed-off-by: David Handermann <[email protected]>
---
 .../nifi/provenance/store/WriteAheadStorePartition.java      | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git 
a/nifi-framework-bundle/nifi-framework-extensions/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/store/WriteAheadStorePartition.java
 
b/nifi-framework-bundle/nifi-framework-extensions/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/store/WriteAheadStorePartition.java
index 255a6991bf..fb97f29bb8 100644
--- 
a/nifi-framework-bundle/nifi-framework-extensions/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/store/WriteAheadStorePartition.java
+++ 
b/nifi-framework-bundle/nifi-framework-extensions/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/store/WriteAheadStorePartition.java
@@ -76,7 +76,7 @@ public class WriteAheadStorePartition implements 
EventStorePartition {
     private final EventFileManager eventFileManager;
     private volatile boolean closed = false;
 
-    private AtomicReference<RecordWriterLease> eventWriterLeaseRef = new 
AtomicReference<>();
+    private final AtomicReference<RecordWriterLease> eventWriterLeaseRef = new 
AtomicReference<>();
 
     private final SortedMap<Long, File> minEventIdToPathMap = new TreeMap<>(); 
 // guarded by synchronizing on object
 
@@ -561,7 +561,7 @@ public class WriteAheadStorePartition implements 
EventStorePartition {
 
         eventFileManager.obtainWriteLock(file);
         try {
-            if (!file.delete()) {
+            if (file.exists() && !file.delete()) {
                 logger.warn("Failed to remove Provenance Event file {}; this 
file should be cleaned up manually", file);
                 return false;
             }
@@ -617,11 +617,7 @@ public class WriteAheadStorePartition implements 
EventStorePartition {
         int fileCount = 0;
         for (final File eventFile : eventFilesToReindex) {
             final boolean skipToEvent;
-            if (fileCount++ == 0) {
-                skipToEvent = true;
-            } else {
-                skipToEvent = false;
-            }
+            skipToEvent = fileCount++ == 0;
 
             final Runnable reindexTask = () -> {
                 final Map<ProvenanceEventRecord, StorageSummary> storageMap = 
new HashMap<>(1000);
@@ -702,7 +698,7 @@ public class WriteAheadStorePartition implements 
EventStorePartition {
         // within the given time range. If we then reach a file whose first 
event comes before our minTimestamp,
         // this means that all other files that we later encounter will have a 
max timestamp that comes before
         // our earliest event time, so we can stop adding files at that point.
-        final List<File> eventFiles = 
getEventFilesFromDisk().sorted(DirectoryUtils.LARGEST_ID_FIRST).collect(Collectors.toList());
+        final List<File> eventFiles = 
getEventFilesFromDisk().sorted(DirectoryUtils.LARGEST_ID_FIRST).toList();
         if (eventFiles.isEmpty()) {
             return EventIterator.EMPTY;
         }

Reply via email to