MAPREDUCE-4930. Backport MAPREDUCE-4678 and MAPREDUCE-4925 to branch-1. Contributed by Karthik Kambatla and Chris McConnell. (harsh)