<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: State Manager not persisting/retrieving data in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/State-Manager-not-persisting-retrieving-data/m-p/164934#M57478</link>
    <description>&lt;P&gt;Can you edit your question to include the code you're using to store the value into the state map (and update the StateManager with it)?&lt;/P&gt;</description>
    <pubDate>Mon, 20 Mar 2017 21:20:04 GMT</pubDate>
    <dc:creator>mburgess</dc:creator>
    <dc:date>2017-03-20T21:20:04Z</dc:date>
    <item>
      <title>State Manager not persisting/retrieving data</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/State-Manager-not-persisting-retrieving-data/m-p/164933#M57477</link>
      <description>&lt;P&gt;NiFi 1.1.1&lt;/P&gt;&lt;P&gt;I am trying to persist a byte [] using the &lt;A target="_blank" href="https://nifi.apache.org/developer-guide.html"&gt;State Manager&lt;/A&gt;.&lt;/P&gt;&lt;PRE&gt;private byte[] lsnUsedDuringLastLoad;


@Override
	public void onTrigger(final ProcessContext context,
			final ProcessSession session) throws ProcessException {
...

...

...
final StateManager stateManager = context.getStateManager();
try {
StateMap stateMap = stateManager.getState(Scope.CLUSTER);
final Map&amp;lt;String, String&amp;gt; newStateMapProperties = new HashMap&amp;lt;&amp;gt;();
newStateMapProperties.put(ProcessorConstants.LAST_MAX_LSN,
new String(lsnUsedDuringLastLoad));
logger.debug("Persisting stateMap : "
+ newStateMapProperties);
stateManager.replace(stateMap, newStateMapProperties,
Scope.CLUSTER);
} catch (IOException ioException) {
logger.error("Error while persisting the state to NiFi",
ioException);
throw new ProcessException(
"The state(LSN) couldn't be persisted", ioException);
}

...
...
...
}&lt;/PRE&gt;&lt;P&gt;I don't get any exception or even a log error entry, the processor continues to run.&lt;/P&gt;&lt;P&gt;The following load code always returns a null value(Retrieved the statemap : {})for the persisted field :&lt;/P&gt;&lt;PRE&gt;try {
					stateMap = stateManager.getState(Scope.CLUSTER);
					stateMapProperties = new HashMap&amp;lt;&amp;gt;(stateMap.toMap());
					
					logger.debug("Retrieved the statemap : "+stateMapProperties);


					lastMaxLSN = (stateMapProperties
							.get(ProcessorConstants.LAST_MAX_LSN) == null || stateMapProperties
							.get(ProcessorConstants.LAST_MAX_LSN).isEmpty()) ? null
							: stateMapProperties.get(
									ProcessorConstants.LAST_MAX_LSN).getBytes();


					logger.debug("Attempted to load the previous lsn from NiFi state : "
							+ lastMaxLSN);
				} catch (IOException ioe) {
					logger.error("Couldn't load the state map", ioe);
					throw new ProcessException(ioe);
				}
&lt;/PRE&gt;&lt;P&gt;I am wondering if the ZK is at fault or have I missed something while using the State Map !&lt;/P&gt;</description>
      <pubDate>Mon, 20 Mar 2017 18:41:25 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/State-Manager-not-persisting-retrieving-data/m-p/164933#M57477</guid>
      <dc:creator>kaliyugantagoni</dc:creator>
      <dc:date>2017-03-20T18:41:25Z</dc:date>
    </item>
    <item>
      <title>Re: State Manager not persisting/retrieving data</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/State-Manager-not-persisting-retrieving-data/m-p/164934#M57478</link>
      <description>&lt;P&gt;Can you edit your question to include the code you're using to store the value into the state map (and update the StateManager with it)?&lt;/P&gt;</description>
      <pubDate>Mon, 20 Mar 2017 21:20:04 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/State-Manager-not-persisting-retrieving-data/m-p/164934#M57478</guid>
      <dc:creator>mburgess</dc:creator>
      <dc:date>2017-03-20T21:20:04Z</dc:date>
    </item>
    <item>
      <title>Re: State Manager not persisting/retrieving data</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/State-Manager-not-persisting-retrieving-data/m-p/164935#M57479</link>
      <description>&lt;P&gt;I believe you need to set an initial state. It looks like you only call the `replace` method on the state manager. I believe it is necessary to initially call `setState`. An example of this can be found &lt;A href="https://github.com/apache/nifi/blob/d838f61291d2582592754a37314911b701c6891b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ListDatabaseTables.java#L307"&gt;here&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Mar 2017 21:55:13 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/State-Manager-not-persisting-retrieving-data/m-p/164935#M57479</guid>
      <dc:creator>jmeyer</dc:creator>
      <dc:date>2017-03-20T21:55:13Z</dc:date>
    </item>
    <item>
      <title>Re: State Manager not persisting/retrieving data</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/State-Manager-not-persisting-retrieving-data/m-p/164936#M57480</link>
      <description>&lt;P&gt;I answered this question on stackoverflow:&lt;/P&gt;&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/42902718/state-manager-not-persisting-retrieving-data" target="_blank"&gt;https://stackoverflow.com/questions/42902718/state-manager-not-persisting-retrieving-data&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Mar 2017 21:56:09 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/State-Manager-not-persisting-retrieving-data/m-p/164936#M57480</guid>
      <dc:creator>bbende</dc:creator>
      <dc:date>2017-03-20T21:56:09Z</dc:date>
    </item>
  </channel>
</rss>

