I want to update 2000 corda states of CarState while migrating from V1 to V2. In order to write a flow for that, two ways I can think of:
Write two flows, which first flow get all the 2000 carstates and call the second flow passing each Carstate in loop by subFlow() function and in second flow, we can do the creation of newstate,Txn builder & Transaction finalization etc.
Write a single flow, which get all 2000 carstates and in loop inside the same flow create newstate, txn builder, txn finalisation steps etc.
I would like to know which one is the best way to do, Please help.
There isn't much difference in both the ways mentioned above. All the states eventually will end up on the call stack anyway.
But if you are worried about OOM errors, you might want to retrieve the IDs of the cars first, then fetch each car state one by one inside a loop. This would reduce the memory over head.