Skip to content

Commit 61a1c5d

Browse files
committed
[fix](catalog) Convert remote Doris metadata timeout to milliseconds
1 parent 37f71c9 commit 61a1c5d

2 files changed

Lines changed: 89 additions & 5 deletions

File tree

‎fe/fe-core/src/main/java/org/apache/doris/datasource/doris/FeServiceClient.java‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,17 @@ public class FeServiceClient {
5656
private final String user;
5757
private final String password;
5858
private final int retryCount;
59-
private final int timeout;
59+
private final int timeoutMs;
6060

6161
public FeServiceClient(String name, List<TNetworkAddress> addresses, String user, String password,
62-
int retryCount, int timeout) {
62+
int retryCount, int timeoutSeconds) {
6363
this.name = name;
6464
this.addresses = addresses;
6565
this.user = user;
6666
this.password = password;
6767
this.retryCount = retryCount;
68-
this.timeout = timeout;
68+
// Catalog metadata timeouts are in seconds, but pooled Thrift sockets require milliseconds.
69+
this.timeoutMs = Math.multiplyExact(timeoutSeconds, 1000);
6970
}
7071

7172
private List<TNetworkAddress> getAddresses() {
@@ -127,7 +128,7 @@ public List<Backend> listBackends() {
127128
return result.getBackends().stream()
128129
.map(b -> Backend.fromThrift(b))
129130
.collect(Collectors.toList());
130-
}, msg, timeout);
131+
}, msg, timeoutMs);
131132
}
132133

133134
public RemoteOlapTable getOlapTable(String dbName, String table, long tableId, List<Partition> partitions) {
@@ -174,7 +175,7 @@ public RemoteOlapTable getOlapTable(String dbName, String table, long tableId, L
174175
}
175176
remoteOlapTable.rebuildPartitions(partitions, updatedPartitions, removedPartitions);
176177
return remoteOlapTable;
177-
}, msg, timeout);
178+
}, msg, timeoutMs);
178179
}
179180

180181
private interface ThriftCall<T> {
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.doris.datasource.doris;
19+
20+
import org.apache.doris.common.ClientPool;
21+
import org.apache.doris.thrift.FrontendService;
22+
import org.apache.doris.thrift.TGetBackendMetaResult;
23+
import org.apache.doris.thrift.TNetworkAddress;
24+
import org.apache.doris.thrift.TStatus;
25+
import org.apache.doris.thrift.TStatusCode;
26+
27+
import org.apache.thrift.protocol.TBinaryProtocol;
28+
import org.apache.thrift.transport.TSocket;
29+
import org.junit.jupiter.api.Assertions;
30+
import org.junit.jupiter.api.Test;
31+
import org.mockito.Mockito;
32+
33+
import java.net.InetAddress;
34+
import java.net.ServerSocket;
35+
import java.util.Collections;
36+
import java.util.concurrent.ExecutorService;
37+
import java.util.concurrent.Executors;
38+
import java.util.concurrent.Future;
39+
import java.util.concurrent.TimeUnit;
40+
41+
class FeServiceClientTest {
42+
@Test
43+
void rejectsTimeoutThatCannotFitInSocketMilliseconds() {
44+
Assertions.assertThrows(ArithmeticException.class, () -> new FeServiceClient("remote_catalog",
45+
Collections.emptyList(), "test_user", "", 1, Integer.MAX_VALUE));
46+
}
47+
48+
@Test
49+
void metadataReadTimeoutUsesSeconds() throws Exception {
50+
FrontendService.Iface handler = Mockito.mock(FrontendService.Iface.class);
51+
Mockito.when(handler.getBackendMeta(Mockito.any())).thenAnswer(invocation -> {
52+
// Ordinary metadata latency must remain within the configured seconds-based timeout.
53+
Thread.sleep(100);
54+
return new TGetBackendMetaResult().setStatus(new TStatus(TStatusCode.OK))
55+
.setBackends(Collections.emptyList());
56+
});
57+
ExecutorService executor = Executors.newSingleThreadExecutor();
58+
try (ServerSocket server = new ServerSocket(0, 1, InetAddress.getLoopbackAddress())) {
59+
server.setSoTimeout(5000);
60+
Future<?> response = executor.submit(() -> {
61+
try (TSocket socket = new TSocket(server.accept())) {
62+
TBinaryProtocol protocol = new TBinaryProtocol(socket);
63+
new FrontendService.Processor<>(handler).process(protocol, protocol);
64+
} catch (Exception e) {
65+
throw new RuntimeException(e);
66+
}
67+
});
68+
TNetworkAddress address = new TNetworkAddress(server.getInetAddress().getHostAddress(),
69+
server.getLocalPort());
70+
try {
71+
FeServiceClient client = new FeServiceClient("remote_catalog", Collections.singletonList(address),
72+
"test_user", "", 1, 10);
73+
Assertions.assertTrue(client.listBackends().isEmpty());
74+
response.get(5, TimeUnit.SECONDS);
75+
} finally {
76+
ClientPool.frontendPool.clearPool(address);
77+
}
78+
} finally {
79+
executor.shutdownNow();
80+
Assertions.assertTrue(executor.awaitTermination(5, TimeUnit.SECONDS));
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)