migrate blocks in batches (rework db iterator impl) (#3450)

* rework db iterator
more robust block migration based on low level iterator

* cleanup

* cleanup

* fixup
This commit is contained in:
Antioch Peverell
2020-10-07 11:47:25 +01:00
committed by GitHub
parent eab26b3ae4
commit e7bbda81a0
10 changed files with 187 additions and 128 deletions
+8 -9
View File
@@ -19,8 +19,7 @@
use chrono::prelude::{DateTime, Utc};
use chrono::{Duration, MIN_DATE};
use rand::seq::SliceRandom;
use rand::thread_rng;
use rand::prelude::*;
use std::collections::HashMap;
use std::net::ToSocketAddrs;
use std::sync::{mpsc, Arc};
@@ -145,14 +144,14 @@ fn monitor_peers(
tx: mpsc::Sender<PeerAddr>,
preferred_peers: &[PeerAddr],
) {
// regularly check if we need to acquire more peers and if so, gets
// regularly check if we need to acquire more peers and if so, gets
// them from db
let total_count = peers.all_peers().len();
let mut total_count = 0;
let mut healthy_count = 0;
let mut banned_count = 0;
let mut defuncts = vec![];
for x in peers.all_peers() {
for x in peers.all_peers().into_iter() {
match x.flags {
p2p::State::Banned => {
let interval = Utc::now().timestamp() - x.last_banned;
@@ -172,6 +171,7 @@ fn monitor_peers(
p2p::State::Healthy => healthy_count += 1,
p2p::State::Defunct => defuncts.push(x),
}
total_count += 1;
}
debug!(
@@ -223,11 +223,10 @@ fn monitor_peers(
}
}
// take a random defunct peer and mark it healthy: over a long period any
// take a random defunct peer and mark it healthy: over a long enough period any
// peer will see another as defunct eventually, gives us a chance to retry
if !defuncts.is_empty() {
defuncts.shuffle(&mut thread_rng());
let _ = peers.update_state(defuncts[0].addr, p2p::State::Healthy);
if let Some(peer) = defuncts.into_iter().choose(&mut thread_rng()) {
let _ = peers.update_state(peer.addr, p2p::State::Healthy);
}
// find some peers from our db