I have a storm topology with a spout and a bolt(numTasks = 16). I want to execute a particular piece of code(only once) in only one task of the bolt. How can i achieve this?
I thought of doing that in the prepare method of the bolt, but i don't know the task ids that will be assigned to the bolts beforehand.
Is it possible to do an election and store in it zookeeper and later in the prepare method of the bolt retrieve the election leader and match with the current task id. If the task id matches the election leader execute that particular piece of code in that bolt task instance ? If this is an appropriate approach, how do i go about it ?