Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature][Connector-V2]Support StarRocks Fe Node HA #20

Merged
merged 1 commit into from
May 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;

@Slf4j
Expand All @@ -64,8 +63,7 @@ public StarRocksQueryPlanReadClient(

public List<QueryPartition> findPartitions() {
List<String> nodeUrls = sourceConfig.getNodeUrls();
QueryPlan queryPlan =
getQueryPlan(genQuerySql(), nodeUrls.get(new Random().nextInt(nodeUrls.size())));
QueryPlan queryPlan = getQueryPlan(genQuerySql(), nodeUrls);
Map<String, List<Long>> be2Tablets = selectBeForTablet(queryPlan);
return tabletsMapToPartition(
be2Tablets,
Expand Down Expand Up @@ -136,37 +134,38 @@ private Map<String, List<Long>> selectBeForTablet(QueryPlan queryPlan) {
return beXTablets;
}

private QueryPlan getQueryPlan(String querySQL, String httpNode) {
String url =
new StringBuilder("http://")
.append(httpNode)
.append("/api/")
.append(sourceConfig.getDatabase())
.append("/")
.append(sourceConfig.getTable())
.append("/_query_plan")
.toString();
private QueryPlan getQueryPlan(String querySQL, List<String> nodeUrls) {

Map<String, Object> bodyMap = new HashMap<>();
bodyMap.put("sql", querySQL);
String body = JsonUtils.toJsonString(bodyMap);
String respString;
try {
respString =
RetryUtils.retryWithException(
() -> httpHelper.doHttpPost(url, getQueryPlanHttpHeader(), body),
retryMaterial);
} catch (Exception e) {
throw new StarRocksConnectorException(
StarRocksConnectorErrorCode.QUEST_QUERY_PLAN_FAILED, e);
String respString = "";
for (String feNode : nodeUrls) {
String url =
new StringBuilder("http://")
.append(feNode)
.append("/api/")
.append(sourceConfig.getDatabase())
.append("/")
.append(sourceConfig.getTable())
.append("/_query_plan")
.toString();
try {
respString =
RetryUtils.retryWithException(
() -> httpHelper.doHttpPost(url, getQueryPlanHttpHeader(), body),
retryMaterial);
if (StringUtils.isNoneEmpty(respString)) {
return JsonUtils.parseObject(respString, QueryPlan.class);
}
} catch (Exception e) {
log.error("Request query Plan From {} failed: {}", feNode, e.getMessage());
}
}

if (StringUtils.isEmpty(respString)) {
throw new StarRocksConnectorException(
StarRocksConnectorErrorCode.QUEST_QUERY_PLAN_FAILED,
"query failed with empty response");
}
return JsonUtils.parseObject(respString, QueryPlan.class);
throw new StarRocksConnectorException(
StarRocksConnectorErrorCode.QUEST_QUERY_PLAN_FAILED,
"query failed with empty response");
}

private String getBasicAuthHeader(String username, String password) {
Expand Down
Loading