[Cherry-pick](branch-2.1) Pick "[Enhancement](wal) modify wal api which hard to use (#38895)" (#39188)

## Proposed changes

Pick #38895

Before this pr, this api needs backends' ip and port as param, which is
hard to use. This pr modify it. If there is no param, doris will print
all backends WAL info.

The acceptable usage are as follows 

```
curl -u root: "127.0.0.1:8038/api/get_wal_size?host_ports=127.0.0.1:9058"
{"msg":"success","code":0,"data":["127.0.0.1:9058:0"],"count":0}%                                                                                             

curl -u root: "127.0.0.1:8038/api/get_wal_size?host_ports="         
{"msg":"success","code":0,"data":["127.0.0.1:9058:0"],"count":0}%                                                                                                                                             

curl -u root: "127.0.0.1:8038/api/get_wal_size"            
{"msg":"success","code":0,"data":["127.0.0.1:9058:0"],"count":0}% 
```

<!--Describe your changes.-->

## Proposed changes

Issue Number: close #xxx

<!--Describe your changes.-->
This commit is contained in:
abmdocrt
2024-08-15 09:37:10 +08:00
committed by GitHub
parent c12137a8d6
commit cf089d2cbe

View File

@ -61,36 +61,36 @@ public class CheckWalSizeAction extends RestBaseController {
checkGlobalAuth(ConnectContext.get().getCurrentUserIdentity(), PrivPredicate.OPERATOR);
String hostPorts = request.getParameter(HOST_PORTS);
List<Backend> backends = new ArrayList<>();
if (Strings.isNullOrEmpty(hostPorts)) {
return ResponseEntityBuilder.badRequest("No host:port specified");
}
String[] hostPortArr = hostPorts.split(",");
if (hostPortArr.length == 0) {
return ResponseEntityBuilder.badRequest("No host:port specified");
}
List<HostInfo> hostInfos = Lists.newArrayList();
for (String hostPort : hostPortArr) {
backends = Env.getCurrentSystemInfo().getAllBackends();
} else {
String[] hostPortArr = hostPorts.split(",");
if (hostPortArr.length == 0) {
return ResponseEntityBuilder.badRequest("No host:port specified");
}
List<HostInfo> hostInfos = new ArrayList<>();
for (String hostPort : hostPortArr) {
try {
HostInfo hostInfo = SystemInfoService.getHostAndPort(hostPort);
hostInfos.add(hostInfo);
} catch (AnalysisException e) {
return ResponseEntityBuilder.badRequest(e.getMessage());
}
}
try {
HostInfo hostInfo = SystemInfoService.getHostAndPort(hostPort);
hostInfos.add(hostInfo);
} catch (AnalysisException e) {
return ResponseEntityBuilder.badRequest(e.getMessage());
backends = getBackends(hostInfos);
} catch (DdlException e) {
return ResponseEntityBuilder.okWithCommonError(e.getMessage());
}
}
try {
List<Backend> backends = getBackends(hostInfos);
List<String> backendsList = new ArrayList<>();
for (Backend backend : backends) {
long size = Env.getCurrentEnv().getGroupCommitManager().getAllWalQueueSize(backend);
backendsList.add(backend.getHost() + ":" + backend.getHeartbeatPort() + ":" + size);
}
return ResponseEntityBuilder.ok(backendsList);
} catch (DdlException e) {
return ResponseEntityBuilder.okWithCommonError(e.getMessage());
List<String> backendsList = new ArrayList<>();
for (Backend backend : backends) {
long size = Env.getCurrentEnv().getGroupCommitManager().getAllWalQueueSize(backend);
backendsList.add(backend.getHost() + ":" + backend.getHeartbeatPort() + ":" + size);
}
return ResponseEntityBuilder.ok(backendsList);
}
private List<Backend> getBackends(List<HostInfo> hostInfos) throws DdlException {