[close #736] Select reachable store (#737) (#742)

Signed-off-by: shiyuhang <1136742008@qq.com>
This commit is contained in:
Ti Chi Robot 2023-04-27 22:06:06 +08:00 committed by GitHub
parent a958699e0f
commit 4463abb6c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 2 deletions

View File

@ -228,12 +228,25 @@ public class RegionManager {
TiStore store = null;
if (storeType == TiStoreType.TiKV) {
Peer peer = region.getCurrentReplica();
store = getStoreById(peer.getStoreId(), backOffer);
// check from the first replica in case it recovers
List<Peer> replicaList = region.getReplicaList();
for (int i = 0; i < replicaList.size(); i++) {
Peer peer = replicaList.get(i);
store = getStoreById(peer.getStoreId(), backOffer);
if (store.isReachable()) {
// update replica's index
region.setReplicaIdx(i);
break;
}
logger.info("Store {} is unreachable, try to get the next replica", peer.getStoreId());
}
} else {
List<TiStore> tiflashStores = new ArrayList<>();
for (Peer peer : region.getLearnerList()) {
TiStore s = getStoreById(peer.getStoreId(), backOffer);
if (!s.isReachable()) {
continue;
}
for (Metapb.StoreLabel label : s.getStore().getLabelsList()) {
if (label.getKey().equals(storeType.getLabelKey())
&& label.getValue().equals(storeType.getLabelValue())) {

View File

@ -126,6 +126,14 @@ public class TiRegion implements Serializable {
return getCurrentReplica();
}
public void setReplicaIdx(int idx) {
replicaIdx = idx;
}
public List<Peer> getReplicaList() {
return replicaList;
}
private boolean isLeader(Peer peer) {
return getLeader().equals(peer);
}