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

[improve] Check the status of fe and be before connect #311

Merged
merged 6 commits into from
Jan 30, 2024
Merged
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 @@ -38,6 +38,7 @@
import org.apache.doris.flink.rest.models.QueryPlan;
import org.apache.doris.flink.rest.models.Schema;
import org.apache.doris.flink.rest.models.Tablet;
import org.apache.doris.flink.sink.BackendUtil;
import org.apache.http.HttpStatus;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
Expand Down Expand Up @@ -280,7 +281,13 @@ public static String randomEndpoint(String feNodes, Logger logger)
}
List<String> nodes = Arrays.asList(feNodes.split(","));
Collections.shuffle(nodes);
return nodes.get(0).trim();
for (String feNode : nodes) {
if (BackendUtil.tryHttpConnection(feNode)) {
return feNode;
}
}
throw new DorisRuntimeException(
"No Doris FE is available, please check configuration or cluster status.");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,18 @@ public String getAvailableBackend() {
throw new DorisRuntimeException("no available backend.");
}

public static boolean tryHttpConnection(String backend) {
public static boolean tryHttpConnection(String host) {
try {
backend = "http://" + backend;
URL url = new URL(backend);
LOG.info("try to connect host {}", host);
host = "http://" + host;
URL url = new URL(host);
HttpURLConnection co = (HttpURLConnection) url.openConnection();
co.setConnectTimeout(60000);
co.connect();
co.disconnect();
return true;
} catch (Exception ex) {
LOG.warn("Failed to connect to backend:{}", backend, ex);
LOG.warn("Failed to connect to host:{}", host, ex);
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.doris.flink.catalog.doris.FieldSchema;
import org.apache.doris.flink.cfg.DorisOptions;
import org.apache.doris.flink.exception.IllegalArgumentException;
import org.apache.doris.flink.sink.BackendUtil;
import org.apache.doris.flink.sink.HttpEntityMock;
import org.apache.doris.flink.sink.OptionUtils;
import org.apache.http.ProtocolVersion;
Expand All @@ -28,6 +29,7 @@
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicStatusLine;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -70,7 +72,8 @@ public class SchemaManagerTest {

HttpEntityMock entityMock;
SchemaChangeManager schemaChangeManager;
static MockedStatic<HttpClients> httpClientMockedStatic = mockStatic(HttpClients.class);
static MockedStatic<HttpClients> httpClientMockedStatic;
static MockedStatic<BackendUtil> backendUtilMockedStatic;

@Before
public void setUp() throws IOException {
Expand All @@ -89,7 +92,11 @@ public void setUp() throws IOException {
when(httpResponse.getStatusLine()).thenReturn(normalLine);
when(httpResponse.getEntity()).thenReturn(entityMock);

httpClientMockedStatic = mockStatic(HttpClients.class);
httpClientMockedStatic.when(() -> HttpClients.createDefault()).thenReturn(httpClient);

backendUtilMockedStatic = mockStatic(BackendUtil.class);
backendUtilMockedStatic.when(() -> BackendUtil.tryHttpConnection(any())).thenReturn(true);
}

@Test
Expand Down Expand Up @@ -128,4 +135,10 @@ public void testRenameColumn() {
Assert.assertEquals(
"ALTER TABLE `test`.`test_flink` RENAME COLUMN `col` `col_new`", renameColumnDDL);
}

@After
public void after() {
httpClientMockedStatic.close();
backendUtilMockedStatic.close();
}
}
Loading