I don't think what you have is quite the right fix, because when a node has space to launch more than one task, the scheduler will still assign multiple tasks of the same type rather than alternating between them. In the pre-0.21 fair scheduler, where only one task of each type was assigned per heartbeat, this solution would've worked okay. However, in the current trunk, the scheduler can launch multiple tasks per heartbeat, and with your code, it will launch many maps or many reduces (depending on which one it had fewer of), but not both.
The right thing would be to add a while loop outside the current for loop. On each iteration of the while loop, you'd order the task types (as
) and then look for a single task to launch. You then stop the while loop when neither maps nor reduces have been launched in a particular iteration. That's what I tried to describe in my post on MAPREDUCE-961, sorry if it wasn't clear.