Skip to content

Commit

Permalink
retry for scan for leader change (vesoft-inc#605)
Browse files Browse the repository at this point in the history
* retry for scan for leader change

* code fmt

* set storage address mapping for scan

* fix get leader

* update the default config for allow_read_follower to false
  • Loading branch information
Nicole00 committed Oct 22, 2024
1 parent aa1dd13 commit b5a6803
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions client/src/main/java/com/vesoft/nebula/client/meta/MetaClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -505,4 +505,38 @@ public synchronized Set<HostItem> getHostItems() {
}
return hostItems;
}

/**
* get the leader parts for all storaged address
*/
public synchronized Set<HostItem> getHostItems() {
int retry = RETRY_TIMES;
ListHostsReq request = new ListHostsReq();
request.setType(ListHostType.ALLOC);
ListHostsResp resp = null;
try {
while (retry-- >= 0) {
resp = client.listHosts(request);
if (resp.getCode() == ErrorCode.E_LEADER_CHANGED) {
freshClient(resp.getLeader());
} else {
break;
}
}
} catch (TException e) {
LOGGER.error("listHosts error", e);
return null;
}
if (resp.getCode() != ErrorCode.SUCCEEDED) {
LOGGER.error("listHosts execute failed, errorCode: " + resp.getCode());
return null;
}
Set<HostItem> hostItems = new HashSet<>();
for (HostItem hostItem : resp.hosts) {
if (hostItem.getStatus().getValue() == HostStatus.ONLINE.getValue()) {
hostItems.add(hostItem);
}
}
return hostItems;
}
}

0 comments on commit b5a6803

Please sign in to comment.