You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by jp...@apache.org on 2016/07/14 18:49:51 UTC

nifi git commit: NIFI-2087: Do not update the lucene index to delete expired events. Instead, just wait for the entire index to expire and remove the files for that index. This is much more efficient.

Repository: nifi
Updated Branches:
  refs/heads/master b83d9bde1 -> 2540573d7


NIFI-2087: Do not update the lucene index to delete expired events. Instead, just wait for the entire index to expire and remove the files for that index. This is much more efficient.

This closes #652

Signed-off-by: jpercivall <jo...@yahoo.com>


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

Branch: refs/heads/master
Commit: 2540573d77c026585eed03bf0d7cd2f042bb1df2
Parents: b83d9bd
Author: Mark Payne <ma...@hotmail.com>
Authored: Thu Jun 30 16:06:24 2016 -0400
Committer: jpercivall <jo...@yahoo.com>
Committed: Thu Jul 14 14:49:30 2016 -0400

----------------------------------------------------------------------
 .../PersistentProvenanceRepository.java         | 14 +++--
 .../provenance/lucene/UpdateMinimumEventId.java | 57 ++++++++++++++++++++
 2 files changed, 63 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/2540573d/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/PersistentProvenanceRepository.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/PersistentProvenanceRepository.java b/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/PersistentProvenanceRepository.java
index 0d7886d..bdeb218 100644
--- a/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/PersistentProvenanceRepository.java
+++ b/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/PersistentProvenanceRepository.java
@@ -45,6 +45,7 @@ import org.apache.nifi.provenance.lucene.IndexSearch;
 import org.apache.nifi.provenance.lucene.IndexingAction;
 import org.apache.nifi.provenance.lucene.LineageQuery;
 import org.apache.nifi.provenance.lucene.LuceneUtil;
+import org.apache.nifi.provenance.lucene.UpdateMinimumEventId;
 import org.apache.nifi.provenance.search.Query;
 import org.apache.nifi.provenance.search.QueryResult;
 import org.apache.nifi.provenance.search.QuerySubmission;
@@ -262,7 +263,7 @@ public class PersistentProvenanceRepository implements ProvenanceEventRepository
                     }
                 }, rolloverCheckMillis, rolloverCheckMillis, TimeUnit.MILLISECONDS);
 
-                expirationActions.add(new DeleteIndexAction(this, indexConfig, indexManager));
+                expirationActions.add(new UpdateMinimumEventId(indexConfig));
                 expirationActions.add(new FileRemovalAction());
 
                 scheduledExecService.scheduleWithFixedDelay(new RemoveExpiredQueryResults(), 30L, 3L, TimeUnit.SECONDS);
@@ -1041,13 +1042,10 @@ public class PersistentProvenanceRepository implements ProvenanceEventRepository
         try (final RecordReader reader = RecordReaders.newRecordReader(firstLogFile, null, Integer.MAX_VALUE)) {
             final StandardProvenanceEventRecord event = reader.nextRecord();
             earliestEventTime = event.getEventTime();
-
-            try {
-                maxEventId = reader.getMaxEventId();
-            } catch (final IOException ioe) {
-                logger.warn("Unable to determine the maximum ID for Provenance Event Log File {}; values reported for the number of "
-                    + "events in the Provenance Repository may be inaccurate.", firstLogFile);
-            }
+            maxEventId = reader.getMaxEventId();
+        } catch (final IOException ioe) {
+            logger.warn("Unable to determine the maximum ID for Provenance Event Log File {}; values reported for the number of "
+                + "events in the Provenance Repository may be inaccurate.", firstLogFile);
         }
 
         // check if we can delete the index safely.

http://git-wip-us.apache.org/repos/asf/nifi/blob/2540573d/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/lucene/UpdateMinimumEventId.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/lucene/UpdateMinimumEventId.java b/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/lucene/UpdateMinimumEventId.java
new file mode 100644
index 0000000..042a1fe
--- /dev/null
+++ b/nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/lucene/UpdateMinimumEventId.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nifi.provenance.lucene;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.nifi.provenance.IndexConfiguration;
+import org.apache.nifi.provenance.expiration.ExpirationAction;
+import org.apache.nifi.provenance.serialization.RecordReader;
+import org.apache.nifi.provenance.serialization.RecordReaders;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class UpdateMinimumEventId implements ExpirationAction {
+    private static final Logger logger = LoggerFactory.getLogger(UpdateMinimumEventId.class);
+
+    private final IndexConfiguration indexConfig;
+
+    public UpdateMinimumEventId(final IndexConfiguration indexConfig) {
+        this.indexConfig = indexConfig;
+    }
+
+    @Override
+    public File execute(final File expiredFile) throws IOException {
+        try (final RecordReader reader = RecordReaders.newRecordReader(expiredFile, null, Integer.MAX_VALUE)) {
+            final long maxEventId = reader.getMaxEventId();
+            indexConfig.setMinIdIndexed(maxEventId);
+
+            logger.info("Updated Minimum Event ID for Provenance Event Repository - Minimum Event ID now {}", maxEventId);
+        } catch (final IOException ioe) {
+            logger.warn("Failed to obtain max ID present in journal file {}", expiredFile.getAbsolutePath());
+        }
+
+        return expiredFile;
+    }
+
+    @Override
+    public boolean hasBeenPerformed(final File expiredFile) throws IOException {
+        return !expiredFile.exists();
+    }
+}