Repository: nifi
Updated Branches:
  refs/heads/master f47af1ce8 -> c6af6be44


NIFI-1754 Rollback log messages should include the flowfile filename and UUID 
to assist in flow management. Incorporates debug logging into 
StandardProcessSession.rollback() to list Flowfile records retreived from the 
session.

Reviewed with slight style amendment (see Jira for details) by Tony Kurc 
([email protected]). This closes #478.


Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/c6af6be4
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/c6af6be4
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/c6af6be4

Branch: refs/heads/master
Commit: c6af6be44cc64b851d8d1c3888e6d2c3f9bf6e05
Parents: f47af1c
Author: Joe Skora <[email protected]>
Authored: Wed May 25 15:51:02 2016 -0400
Committer: trkurc <[email protected]>
Committed: Wed Jun 1 08:43:54 2016 -0700

----------------------------------------------------------------------
 .../repository/StandardProcessSession.java      | 44 ++++++++++++++++++++
 1 file changed, 44 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/c6af6be4/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/StandardProcessSession.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/StandardProcessSession.java
 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/StandardProcessSession.java
index cb789e2..0071fed 100644
--- 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/StandardProcessSession.java
+++ 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/repository/StandardProcessSession.java
@@ -99,6 +99,7 @@ public final class StandardProcessSession implements 
ProcessSession, ProvenanceE
 
     private static final Logger LOG = 
LoggerFactory.getLogger(StandardProcessSession.class);
     private static final Logger claimLog = 
LoggerFactory.getLogger(StandardProcessSession.class.getSimpleName() + 
".claims");
+    private static final int MAX_ROLLBACK_FLOWFILES_TO_LOG = 5;
 
     private final Map<FlowFileRecord, StandardRepositoryRecord> records = new 
HashMap<>();
     private final Map<Connection, StandardFlowFileEvent> connectionCounts = 
new HashMap<>();
@@ -861,6 +862,11 @@ public final class StandardProcessSession implements 
ProcessSession, ProvenanceE
     }
 
     private void rollback(final boolean penalize, final boolean 
rollbackCheckpoint) {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("{} session rollback called, FlowFile records are {} {}",
+                    this, loggableFlowfileInfo(), new Throwable("Stack Trace 
on rollback"));
+        }
+
         deleteOnCommit.clear();
 
         final Set<StandardRepositoryRecord> recordsToHandle = new HashSet<>();
@@ -950,6 +956,44 @@ public final class StandardProcessSession implements 
ProcessSession, ProvenanceE
         resetState();
     }
 
+    private String loggableFlowfileInfo() {
+        final StringBuilder details = new StringBuilder(1024).append("[");
+        final int initLen = details.length();
+        int filesListed = 0;
+        for (Map.Entry<FlowFileRecord, StandardRepositoryRecord> entry : 
records.entrySet()) {
+            if (filesListed >= MAX_ROLLBACK_FLOWFILES_TO_LOG) {
+                break;
+            }
+            filesListed++;
+            final FlowFileRecord entryKey = entry.getKey();
+            final StandardRepositoryRecord entryValue = entry.getValue();
+            if (details.length() > initLen) {
+                details.append(", ");
+            }
+            if (entryValue.getOriginalQueue() != null && 
entryValue.getOriginalQueue().getIdentifier() != null) {
+                details.append("queue=")
+                        .append(entryValue.getOriginalQueue().getIdentifier())
+                        .append("/");
+            }
+            details.append("filename=")
+                    
.append(entryKey.getAttribute(CoreAttributes.FILENAME.key()))
+                    .append("/uuid=")
+                    .append(entryKey.getAttribute(CoreAttributes.UUID.key()));
+        }
+        if (records.entrySet().size() > MAX_ROLLBACK_FLOWFILES_TO_LOG) {
+            if (details.length() > initLen) {
+                details.append(", ");
+            }
+            details.append(records.entrySet().size() - 
MAX_ROLLBACK_FLOWFILES_TO_LOG)
+                    .append(" additional Flowfiles not listed");
+        } else if (filesListed == 0) {
+            details.append("none");
+        }
+        details.append("]");
+        return details.toString();
+    }
+
+
     private void removeContent(final ContentClaim claim) {
         if (claim == null) {
             return;

Reply via email to