fix(script): oprimizations for pegasus_rolling_update.sh (#708)

diff --git a/scripts/pegasus_rolling_update.sh b/scripts/pegasus_rolling_update.sh
index ecb6002..cb86f9f 100755
--- a/scripts/pegasus_rolling_update.sh
+++ b/scripts/pegasus_rolling_update.sh
@@ -22,7 +22,8 @@
 PID=$$
 
 if [ $# -le 3 ]; then
-  echo "USAGE: $0 <cluster-name> <cluster-meta-list> <type> <start_task_id>"
+  echo "USAGE: $0 <cluster-name> <cluster-meta-list> <type> <start_task_id> "
+       "<rebalance_cluster_after_rolling>(default false) <rebalance_only_move_primary>(default true)"
   echo
   echo "The type may be 'one' or 'all':"
   echo "  - one: rolling update only one task of replica server."
@@ -48,6 +49,18 @@
   exit 1
 fi
 
+if [ -z $5 ]; then
+  rebalance_cluster_after_rolling=false
+else
+  rebalance_cluster_after_rolling=$5
+fi
+
+if [ -z $6 ]; then
+  rebalance_only_move_primary=true
+else
+  rebalance_only_move_primary=$6
+fi
+
 pwd="$( cd "$( dirname "$0"  )" && pwd )"
 shell_dir="$( cd $pwd/.. && pwd )"
 cd $shell_dir
@@ -222,14 +235,6 @@
 
   echo "remote_command -l $node flush-log" | ./run.sh shell --cluster $meta_list &>/dev/null
 
-  echo "Set lb.add_secondary_max_count_for_one_node to 100..."
-  echo "remote_command -l $pmeta meta.lb.add_secondary_max_count_for_one_node 100" | ./run.sh shell --cluster $meta_list &>/tmp/$UID.$PID.pegasus.rolling_update.add_secondary_max_count_for_one_node
-  set_ok=`grep OK /tmp/$UID.$PID.pegasus.rolling_update.add_secondary_max_count_for_one_node | wc -l`
-  if [ $set_ok -ne 1 ]; then
-    echo "ERROR: set lb.add_secondary_max_count_for_one_node to 100 failed"
-    exit 1
-  fi
-
   echo "Rolling update by minos..."
   minos_rolling_update $cluster replica $task_id
   echo "Rolling update by minos done."
@@ -250,6 +255,14 @@
   echo
   sleep 1
 
+  echo "Set lb.add_secondary_max_count_for_one_node to 100..."
+  echo "remote_command -l $pmeta meta.lb.add_secondary_max_count_for_one_node 100" | ./run.sh shell --cluster $meta_list &>/tmp/$UID.$PID.pegasus.rolling_update.add_secondary_max_count_for_one_node
+  set_ok=`grep OK /tmp/$UID.$PID.pegasus.rolling_update.add_secondary_max_count_for_one_node | wc -l`
+  if [ $set_ok -ne 1 ]; then
+    echo "ERROR: set lb.add_secondary_max_count_for_one_node to 100 failed"
+    exit 1
+  fi
+
   echo "Wait cluster to become healthy..."
   while true
   do
@@ -294,8 +307,11 @@
   minos_rolling_update $cluster collector
   echo "Rolling update collectors done."
   echo
+fi
 
-  ./scripts/pegasus_rebalance_cluster.sh $cluster $meta_list
+if [ "$rebalance_cluster_after_rolling" == "true" ]; then
+  echo "Start to rebalance cluster..."
+  ./scripts/pegasus_rebalance_cluster.sh $cluster $meta_list $rebalance_only_move_primary
 fi
 
 echo "Finish time: `date`"