The second half of the function is to calculate region move plan for regions which have been already placed according to the rsgroup assignment, and it is calculated one rsgroup after another.
The following logic to check if a server belongs to the rsgroup is not quite efficient, as it does not make good use of the fact that servers in RSGroupInfo is a TreeSet.
Given there are m region servers in the cluster and n region servers for each rsgroup in average, the code above has time complexity as O(m * n), while using TreeSet's contains(), the time complexity could be reduced to O (m * logn).
Another improvement is we do not need to scan every server for each rsgroup. If the processed server could be recorded, we could skip those.