init instance state only if the topology is stateful and the component is a stateful component (#3229)
diff --git a/heron/instance/src/java/org/apache/heron/instance/bolt/BoltInstance.java b/heron/instance/src/java/org/apache/heron/instance/bolt/BoltInstance.java
index 893ed01..9cc177a 100644
--- a/heron/instance/src/java/org/apache/heron/instance/bolt/BoltInstance.java
+++ b/heron/instance/src/java/org/apache/heron/instance/bolt/BoltInstance.java
@@ -183,8 +183,8 @@
boltMetrics.registerMetrics(topologyContext);
- // Initialize the instanceState if the bolt is stateful
- if (bolt instanceof IStatefulComponent) {
+ // Initialize the instanceState if the topology is stateful and bolt is a stateful component
+ if (isTopologyStateful && bolt instanceof IStatefulComponent) {
this.instanceState = state;
((IStatefulComponent<Serializable, Serializable>) bolt).initState(instanceState);
diff --git a/heron/instance/src/java/org/apache/heron/instance/spout/SpoutInstance.java b/heron/instance/src/java/org/apache/heron/instance/spout/SpoutInstance.java
index 348a641..53675c4 100644
--- a/heron/instance/src/java/org/apache/heron/instance/spout/SpoutInstance.java
+++ b/heron/instance/src/java/org/apache/heron/instance/spout/SpoutInstance.java
@@ -188,8 +188,8 @@
spoutMetrics.registerMetrics(topologyContext);
- // Initialize the instanceState if the spout is stateful
- if (spout instanceof IStatefulComponent) {
+ // Initialize the instanceState if the topology is stateful and spout is a stateful component
+ if (isTopologyStateful && spout instanceof IStatefulComponent) {
this.instanceState = state;
((IStatefulComponent<Serializable, Serializable>) spout).initState(instanceState);