markap14 commented on a change in pull request #5042:
URL: https://github.com/apache/nifi/pull/5042#discussion_r625953729
##########
File path: nifi-api/src/main/java/org/apache/nifi/processor/ProcessSession.java
##########
@@ -101,6 +102,105 @@
*/
void commit();
+ /**
+ * <p>
+ * Commits the current session ensuring all operations against FlowFiles
+ * within this session are atomically persisted. All FlowFiles operated on
+ * within this session must be accounted for by transfer or removal or the
+ * commit will fail.
+ * </p>
+ *
+ * <p>
+ * Unlike the {@link #commit()} method, the persistence of data to the
repositories is not
+ * guaranteed to have occurred by the time that this method returns.
Therefore, if any follow-on actions
+ * are necessary after the data has been persisted to the repository (for
example, acknowledging receipt from
+ * a source system, removing a source file, etc.) that logic should be
performed only by invoking {@link #commitAsync(Runnable, Consumer)}
+ * and implementing that action in the provided callback.
+ * </p>
+ *
+ * <p>
+ * If the session cannot be committed, an error will be logged and the
session will be rolled back instead.
+ * </p>
+ *
+ * @throws IllegalStateException if called from within a read or write
callback (See {@link #write(FlowFile, StreamCallback)}, {@link #write(FlowFile,
OutputStreamCallback)},
+ * {@link #read(FlowFile, InputStreamCallback)}).
+ *
+ * @throws FlowFileHandlingException if any FlowFile is not appropriately
accounted for by transferring it to a Relationship (see {@link
#transfer(FlowFile, Relationship)})
+ * or removed (see {@link #remove(FlowFile)}.
+ */
+ void commitAsync();
+
+ /**
+ * <p>
+ * Commits the current session ensuring all operations against FlowFiles
+ * within this session are atomically persisted. All FlowFiles operated on
+ * within this session must be accounted for by transfer or removal or the
+ * commit will fail.
+ * </p>
+ *
+ * <p>
+ * Unlike the {@link #commit()} method, the persistence of data to the
repositories is not
Review comment:
So the session can be reused after calling `commitAsync`. What this is
meant to convey is that with `commit()` we typically see something like:
```
getMessageFromSource();
session.commit();
acknowledgeMessageFromSource();
```
And that CANNOT change to:
```
getMessageFromSource();
session.commitAsync();
acknowledgeMessage();
```
Because when `commitAsync()` returns, the data hasn't necessarily been
stored to the repositories and as a result acknowledging the message could
result in data loss.
--
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:
[email protected]