Uploaded image for project: 'Apache NiFi'
  1. Apache NiFi
  2. NIFI-11472

Improve PutFTP Handling of Remote Directory Creation for Multiple Concurrent Tasks

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 1.21.0
    • 2.0.0-M1, 1.22.0
    • Core Framework
    • None
    • CentOS server, Java 11

    Description

      Problem happens when a PutFTP is set to run several concurrent tasks and two (or more ) FlowFiles come in and both need to create the same directory. One of them will create directory and succeed immediately while the other will try to create directory, but fail since it already exist, throw an error, the FlowFile will then be penalized and on second run will succeed.

      While it is not the biggest error, as files are getting transferred in the end, but the bulletins and errors are annoying, especially in production environment where you don't want to get unnecessary errors.

      We found that the solution involves a simple change to the FTPTransfer.java class in:
      nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/FTPTransfer.java
      On line 398 and ensureDirectoryExists method you can simply add another if check which double checks that the directory exists when it fails to create one.

      final boolean cdSuccessful = setWorkingDirectory(remoteDirectory);
      
      if (!cdSuccessful) {    
        if (client.makeDirectory(remoteDirectory)) {        
          logger.debug("Remote Directory not found: created directory [{}]", remoteDirectory);    
        } else if (!setWorkingDirectory(remoteDirectory)) { 
               // Double check that the dir exists as it might have been created in another thread        
          throw new IOException("Failed to create remote directory " + remoteDirectory);    
        }
      }

      We have created a fix and will submit it as a Pull Request on GitHub

      Attachments

        Issue Links

          Activity

            People

              daniel.salwerowicz Daniel Salwerowicz
              daniel.salwerowicz Daniel Salwerowicz
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h 10m
                  1h 10m