Skip to content

Commit 679e266

Browse files
committed
remove instance healthcheck
1 parent e390f8d commit 679e266

File tree

1 file changed

+0
-60
lines changed

1 file changed

+0
-60
lines changed

clients/service-center-client/src/main/java/org/apache/servicecomb/service/center/client/ServiceCenterDiscovery.java

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,11 @@
1717

1818
package org.apache.servicecomb.service.center.client;
1919

20-
import java.io.IOException;
21-
import java.net.InetSocketAddress;
22-
import java.net.Socket;
23-
import java.util.ArrayList;
2420
import java.util.Collections;
2521
import java.util.List;
2622
import java.util.Map;
2723
import java.util.Objects;
2824
import java.util.concurrent.ConcurrentHashMap;
29-
import java.util.concurrent.Executors;
30-
import java.util.concurrent.ScheduledExecutorService;
31-
import java.util.concurrent.TimeUnit;
3225

3326
import org.apache.servicecomb.http.client.task.AbstractTask;
3427
import org.apache.servicecomb.http.client.task.Task;
@@ -129,7 +122,6 @@ public void startDiscovery() {
129122
if (!started) {
130123
started = true;
131124
startTask(new PullInstanceTask());
132-
startCheckInstancesHealth();
133125
}
134126
}
135127

@@ -237,30 +229,6 @@ private synchronized void pullAllInstance() {
237229
});
238230
}
239231

240-
private void startCheckInstancesHealth() {
241-
ScheduledExecutorService executor =
242-
Executors.newScheduledThreadPool(1, (t) -> new Thread(t, "instance-health-check"));
243-
executor.scheduleWithFixedDelay(new CheckInstancesHealthTask(), 0, pollInterval, TimeUnit.MILLISECONDS);
244-
}
245-
246-
class CheckInstancesHealthTask implements Runnable {
247-
@Override
248-
public void run() {
249-
if (instancesCache.isEmpty()) {
250-
return;
251-
}
252-
List<SubscriptionKey> failedInstances = new ArrayList<>();
253-
instancesCache.forEach((k, v) -> {
254-
v.instancesCache.removeIf(item -> isInstanceUnavailable(item.getServiceName(), item.getEndpoints()));
255-
if (v.instancesCache.isEmpty()) {
256-
failedInstances.add(k);
257-
}
258-
});
259-
failedInstances.forEach(instancesCache::remove);
260-
failedInstances.clear();
261-
}
262-
}
263-
264232
private static String instanceToString(List<MicroserviceInstance> instances) {
265233
if (instances == null) {
266234
return "";
@@ -278,32 +246,4 @@ private static String instanceToString(List<MicroserviceInstance> instances) {
278246
sb.append("#");
279247
return sb.toString();
280248
}
281-
282-
protected boolean isInstanceUnavailable(String serviceName, List<String> endpoints) {
283-
for (String endpoint : endpoints) {
284-
String[] hostPort = getHostPort(endpoint);
285-
if (hostPort == null) {
286-
continue;
287-
}
288-
for (int k = 0; k < 3; k++) {
289-
try (Socket s = new Socket()) {
290-
s.connect(new InetSocketAddress(hostPort[0], Integer.parseInt(hostPort[1])), 3000);
291-
return false;
292-
} catch (IOException e) {
293-
LOGGER.warn("telnet endpoint [{}] failed, It will be try again.", endpoint);
294-
}
295-
}
296-
LOGGER.warn("telnet three times failed, remove service [{}] endpoint [{}].", serviceName, endpoint);
297-
return true;
298-
}
299-
return true;
300-
}
301-
302-
private String[] getHostPort(String endpoint) {
303-
String hostPort = endpoint.substring("rest://".length());
304-
if (hostPort.split(":").length == 2) {
305-
return hostPort.split(":");
306-
}
307-
return null;
308-
}
309249
}

0 commit comments

Comments
 (0)