refactor: arrange lease kvs randomly in lease_based selector (#2028)

* refactor: arrange lease kvs randomly in lease_based selector

* fix: cr
This commit is contained in:
fys
2023-07-25 15:32:10 +08:00
committed by GitHub
parent 9c1f0234de
commit 0b4ac987cd

View File

@@ -13,6 +13,8 @@
// limitations under the License.
use api::v1::meta::Peer;
use rand::seq::SliceRandom;
use rand::thread_rng;
use crate::error::Result;
use crate::lease;
@@ -34,9 +36,7 @@ impl Selector for LeaseBasedSelector {
.into_iter()
.collect();
// TODO(jiachun): At the moment we are just pushing the latest to the forefront,
// and it is better to use load-based strategies in the future.
lease_kvs.sort_by(|a, b| b.1.timestamp_millis.cmp(&a.1.timestamp_millis));
lease_kvs.shuffle(&mut thread_rng());
let peers = lease_kvs
.into_iter()