Skip to content
Open
Show file tree
Hide file tree
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 @@ -93,6 +93,10 @@ public static List<Pair<String, Integer>> getFrontendWithRpcPort(Env env, boolea
}

public static void getFrontendsInfo(Env env, List<List<String>> infos) {
getFrontendsInfo(env, infos, null);
}

public static void getFrontendsInfo(Env env, List<List<String>> infos, String currentConnectedFeHost) {
InetSocketAddress master = null;
try {
master = env.getHaProtocol().getLeader();
Expand All @@ -109,7 +113,10 @@ public static void getFrontendsInfo(Env env, List<List<String>> infos) {
// Because the `show frontend` stmt maybe forwarded from other FE.
// if we only get self node from currrent catalog, the "CurrentConnected" field will always points to Msater FE.
String selfNode = Env.getCurrentEnv().getSelfNode().getHost();
if (ConnectContext.get() != null && !Strings.isNullOrEmpty(ConnectContext.get().getCurrentConnectedFEIp())) {
if (!Strings.isNullOrEmpty(currentConnectedFeHost)) {
selfNode = currentConnectedFeHost;
} else if (ConnectContext.get() != null
&& !Strings.isNullOrEmpty(ConnectContext.get().getCurrentConnectedFEIp())) {
selfNode = ConnectContext.get().getCurrentConnectedFEIp();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.doris.thrift.TMetaScanRange;
import org.apache.doris.thrift.TMetadataType;

import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;

Expand Down Expand Up @@ -105,7 +106,12 @@ public TMetaScanRange getMetaScanRange(List<String> requiredFileds) {
TMetaScanRange metaScanRange = new TMetaScanRange();
metaScanRange.setMetadataType(TMetadataType.FRONTENDS);
TFrontendsMetadataParams frontendsMetadataParams = new TFrontendsMetadataParams();
frontendsMetadataParams.setClusterName("");
String currentConnectedFe = Env.getCurrentEnv().getSelfNode().getHost();
if (ConnectContext.get() != null
&& !Strings.isNullOrEmpty(ConnectContext.get().getCurrentConnectedFEIp())) {
currentConnectedFe = ConnectContext.get().getCurrentConnectedFEIp();
}
frontendsMetadataParams.setCurrentConnectedFeHost(currentConnectedFe);
metaScanRange.setFrontendsParams(frontendsMetadataParams);
return metaScanRange;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
import org.apache.doris.thrift.TCell;
import org.apache.doris.thrift.TFetchSchemaTableDataRequest;
import org.apache.doris.thrift.TFetchSchemaTableDataResult;
import org.apache.doris.thrift.TFrontendsMetadataParams;
import org.apache.doris.thrift.THudiMetadataParams;
import org.apache.doris.thrift.THudiQueryType;
import org.apache.doris.thrift.TJobsMetadataParams;
Expand Down Expand Up @@ -533,11 +534,12 @@ private static TFetchSchemaTableDataResult frontendsMetadataResult(TMetadataTabl
return errorResult("frontends metadata param is not set.");
}

TFrontendsMetadataParams frontendsParam = params.getFrontendsMetadataParams();
TFetchSchemaTableDataResult result = new TFetchSchemaTableDataResult();

List<TRow> dataBatch = Lists.newArrayList();
List<List<String>> infos = Lists.newArrayList();
FrontendsProcNode.getFrontendsInfo(Env.getCurrentEnv(), infos);
FrontendsProcNode.getFrontendsInfo(Env.getCurrentEnv(), infos, frontendsParam.getCurrentConnectedFeHost());
for (List<String> info : infos) {
TRow trow = new TRow();
for (String item : info) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.apache.doris.tablefunction;

import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.InfoSchemaDb;
import org.apache.doris.datasource.InternalCatalog;
import org.apache.doris.mysql.privilege.AccessControllerManager;
import org.apache.doris.mysql.privilege.PrivPredicate;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.system.SystemInfoService.HostInfo;
import org.apache.doris.thrift.TMetaScanRange;

import mockit.Expectations;
import mockit.Mocked;
import org.junit.Assert;
import org.junit.Test;

import java.util.Collections;
import java.util.HashMap;

public class FrontendsTableValuedFunctionTest {
private static final String INTERNAL_CTL = InternalCatalog.INTERNAL_CATALOG_NAME;
private static final String INFO_DB = InfoSchemaDb.DATABASE_NAME;

@Mocked
private Env env;
@Mocked
private AccessControllerManager accessControllerManager;
@Mocked
private ConnectContext ctx;

private void mockContext(String selfHost, String currentConnectedFe) {
new Expectations() {
{
Env.getCurrentEnv();
minTimes = 0;
result = env;

env.getAccessManager();
minTimes = 0;
result = accessControllerManager;

ConnectContext.get();
minTimes = 0;
result = ctx;

accessControllerManager.checkDbPriv(ctx, INTERNAL_CTL, INFO_DB, PrivPredicate.SELECT);
minTimes = 0;
result = true;

env.getSelfNode();
minTimes = 0;
result = new HostInfo(selfHost, 9010);

ctx.getCurrentConnectedFEIp();
minTimes = 0;
result = currentConnectedFe;
}
};
}

@Test
public void testGetMetaScanRangeUseCurrentConnectedFe() throws Exception {
mockContext("self-fe-host", "connected-fe-host");
FrontendsTableValuedFunction tvf = new FrontendsTableValuedFunction(new HashMap<>());
TMetaScanRange range = tvf.getMetaScanRange(Collections.emptyList());
Assert.assertEquals("connected-fe-host", range.getFrontendsParams().getCurrentConnectedFeHost());
}

@Test
public void testGetMetaScanRangeFallbackToSelfNode() throws Exception {
mockContext("self-fe-host", "");
FrontendsTableValuedFunction tvf = new FrontendsTableValuedFunction(new HashMap<>());
TMetaScanRange range = tvf.getMetaScanRange(Collections.emptyList());
Assert.assertEquals("self-fe-host", range.getFrontendsParams().getCurrentConnectedFeHost());
}
}
1 change: 1 addition & 0 deletions gensrc/thrift/PlanNodes.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ struct TBackendsMetadataParams {

struct TFrontendsMetadataParams {
1: optional string cluster_name
2: optional string current_connected_fe_host
}

struct TMaterializedViewsMetadataParams {
Expand Down