- There is no direct way of stopping a map-reduce script while running.
- If the script is in queue and it is not started then we can stop it by using the ‘Cancel’ option in Map/Reduce Script Status page. To get this page, go to script deployment of the map-reduce script and click on ‘Status Page’ under ‘SEE INSTANCES’. Now we can see all map-reduce script currently running. If the required map-reduce is in queue and some other scheduled map-reduce is running, we can cancel it before it get started. For this click on the ‘Cancel’ button on the right side of the map-reduce script name.
- Stopping a map-reduce script while running
Unlike many other scripts, map-reduce cannot be stopped by removing the script deployment or checking ‘inactive’ check-box in the deployment page.
One possible way of stopping a map-reduce script in running is by modifying the script file itself. If the map-reduce is still in getInputData() stage we can replace the ‘return’ statement at the getInputData() stage with “return null;”.
This will return null value to the next stage in script(shuffle or map or reduce) and cause no data in those stages to operate making it to stop quickly.
If the script has completed the getInputData() stage and is in map or reduce stage, we can remove the whole code in that stage. It is recommended to keep a copy or backup of the original file for finding the reason of error. For example if code is in reduce() stage, modify the reduce function to ‘reduce: function (reduceContext) {}’. This will stop the map-reduce instance once current iteration is completed.