From 043e2dd3fff51605f210ada9a5ffab655eafc30a Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 18 Jan 2024 20:32:32 +0100 Subject: [PATCH] NIFI-12633 Avoid resetting state in GetSolr on restart This closes #8267 Signed-off-by: David Handermann --- .../java/org/apache/nifi/processors/solr/GetSolr.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/nifi-nar-bundles/nifi-solr-bundle/nifi-solr-processors/src/main/java/org/apache/nifi/processors/solr/GetSolr.java b/nifi-nar-bundles/nifi-solr-bundle/nifi-solr-processors/src/main/java/org/apache/nifi/processors/solr/GetSolr.java index ce88e2d53e..22252ad380 100644 --- a/nifi-nar-bundles/nifi-solr-bundle/nifi-solr-processors/src/main/java/org/apache/nifi/processors/solr/GetSolr.java +++ b/nifi-nar-bundles/nifi-solr-bundle/nifi-solr-processors/src/main/java/org/apache/nifi/processors/solr/GetSolr.java @@ -41,6 +41,7 @@ import org.apache.nifi.annotation.behavior.Stateful; import org.apache.nifi.annotation.configuration.DefaultSchedule; import org.apache.nifi.annotation.documentation.CapabilityDescription; import org.apache.nifi.annotation.documentation.Tags; +import org.apache.nifi.annotation.lifecycle.OnConfigurationRestored; import org.apache.nifi.annotation.lifecycle.OnScheduled; import org.apache.nifi.components.AllowableValue; import org.apache.nifi.components.PropertyDescriptor; @@ -154,6 +155,7 @@ public class GetSolr extends SolrProcessor { private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US); + private final AtomicBoolean configurationRestored = new AtomicBoolean(false); private final AtomicBoolean clearState = new AtomicBoolean(false); private final AtomicBoolean dateFieldNotInSpecifiedFieldsList = new AtomicBoolean(false); private volatile String id_field = null; @@ -211,10 +213,15 @@ public class GetSolr extends SolrProcessor { @Override public void onPropertyModified(PropertyDescriptor descriptor, String oldValue, String newValue) { - if (propertyNamesForActivatingClearState.contains(descriptor.getName())) + if (configurationRestored.get() && propertyNamesForActivatingClearState.contains(descriptor.getName())) clearState.set(true); } + @OnConfigurationRestored + public void onConfigurationRestored() { + configurationRestored.set(true); + } + @OnScheduled public void clearState(final ProcessContext context) throws IOException { if (clearState.getAndSet(false))