NiFi Conflict Resoultion Strategies to put files on SFTP

When working with NiFi, conflicts can arise when attempting to put multiple flowfiles with the same name on an SFTP server. This can lead to issues and inconsistencies in file management. To overcome this challenge, NiFi provides several conflict resolution strategies that can be implemented in conjunction with the PutSFTP processor. Here, we will explore some effective strategies to handle conflicts and ensure smooth file transfer to an SFTP server.

Timestamp-based Conflict Resolution:
One common approach to resolving conflicts is by incorporating a timestamp into the filenames using the UpdateAttribute processor. NiFi’s expression language provides the now() function, which can be utilized to add a timestamp to the filenames. It is crucial to include milliseconds in the timestamp format to ensure uniqueness for each filename.
However, a potential issue arises when the UpdateAttribute processor operates so quickly that it can rename multiple files within the same millisecond. This results in conflicts once again. To mitigate this problem, we can leverage the ‘Conflict Resolution’ property available in the PutSFTP processor.

Leveraging ‘Conflict Resolution’ Property:
The ‘Conflict Resolution’ property of the PutSFTP processor offers a built-in mechanism to handle conflicts by appending an integer to the filename. This property can be set to “RENAME,” which ensures that conflicting filenames are automatically modified to maintain uniqueness.
While this approach is convenient, it comes with a couple of limitations. Firstly, if the number of conflicts exceeds 99, the processor will start rejecting flowfiles. This restriction requires careful consideration, especially when dealing with a high volume of files. Secondly, the ‘Conflict Resolution’ property alters the filename format, which might pose challenges for external systems that expect a specific naming convention.

An Alternative Solution:
An alternative strategy to address conflicts is by modifying the scheduling behavior of the UpdateAttribute processor. By setting the processor to “Timer Driven” and configuring the Run Schedule to 1 millisecond, we introduce a pause before each run of the processor. This slight delay ensures that a new millisecond is included in the filename generated by the now() function, eliminating the possibility of conflicts altogether.

Advantages of the Alternative Solution:
The alternative solution offers superior performance in scenarios where a large number of flowfiles with conflicting names are encountered. By preventing conflicts from occurring in the first place, we avoid the need for resolution mechanisms. This approach ensures seamless and efficient file transfer to the SFTP server.

4 Likes

@Vinayak Thanks for sharing this, very helpful.

How are the file names generated when OOTB Conflict Resolution property is used of PutSFTP? Can you share some sample file names for this.

Hello @Gurveen
When we use the OOTB Conflict Resolution property of PutSFTP processor, it automatically prepends an integer with a dot to the filename. And this integer increases by one everytime a conflict is encountered.
As mentioned above, this integer will increase till 99 and will start to reject the conflict instead of renaming it.
Like, if there are multiple files named as OrderDetails.json, Nifi will store the first file and the next file will be stored as 1.OrderDetails.json then the next as 2.OrderDetails.json and so on.

Below is a screesshot of the files stored after the conflict resolution by PutSFTP processor-

1 Like