Github user olegz commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/840#discussion_r74786994
  
    --- Diff: 
nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/PersistentProvenanceRepository.java
 ---
    @@ -1302,27 +1301,35 @@ public void run() {
                                 }
     
                                 logger.info("Successfully Rolled over 
Provenance Event file containing {} records", recordsWritten);
    +                        }
    +
    +                        //if files were rolled over or if out of retries 
stop the future
    +                        if(fileRolledOver != null || 
retryAttempts.decrementAndGet() == 0) {
    +
    +                            if(fileRolledOver== null && 
retryAttempts.get() == 0){
    +                                logger.error("Failed to merge Journal 
Files {} after {} attempts. ",journalsToMerge, MAX_JOURNAL_ROLLOVER_RETRIES);
    +                            }
    +
                                 rolloverCompletions.getAndIncrement();
     
    -                            // We have finished successfully. Cancel the 
future so that we don't run anymore
    +                            // Cancel the future so that we don't run 
anymore
                                 Future<?> future;
                                 while ((future = futureReference.get()) == 
null) {
    --- End diff --
    
    Also, realizing it is not your code, I am now even more concerned about 
this loop.
    1. We are wasting thread with Thread.sleep() while we are also executing 
something repeatedly using executor with delay
    2. We are relying on the Future that caries no meaning other gives us an 
ability to cancel it
    This could be greatly simplified. Foe example:
    ```
    final Runnable rolloverRunnable = new Runnable() {
                        @Override
                        public void run() {
                            try {
                                final File fileRolledOver;
                                . . .
                                rolloverCompletions.getAndIncrement();
                            } catch (Exception e) {
                                logger.error("Failed to rollover Provenance 
repository due to {}", t.toString());
                                logger.error("", t);
                                rolloverExecutor.schedule(this, 10, 
TimeUnit.MILLISECONDS);
                            }
                        }
                   }
                   rolloverExecutor.execute(rolloverRunnable);
    ```
    In this case we:
    1. No longer have to schedule it 
    2. No need to keep Atomic Reference to hold Future
    3. No need to Thread.sleep essentially allowing the executor to share that 
thread with whatever else may/does use it.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to