Skip to content

Commit 340d266

Browse files
EvenLjjliujianjun.ljj
and
liujianjun.ljj
authored
fix TripleServer uninstall issue in Serverless scene (#1487)
Co-authored-by: liujianjun.ljj <liujianjun.ljj@antgroup.com>
1 parent 168d998 commit 340d266

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

remoting/remoting-triple/src/main/java/com/alipay/sofa/rpc/server/triple/TripleServer.java

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
import triple.Response;
5858

5959
import java.lang.reflect.Method;
60-
6160
import java.util.ArrayList;
6261
import java.util.Collection;
6362
import java.util.List;
@@ -66,7 +65,6 @@
6665
import java.util.concurrent.ConcurrentHashMap;
6766
import java.util.concurrent.ThreadPoolExecutor;
6867
import java.util.concurrent.TimeUnit;
69-
import java.util.concurrent.atomic.AtomicInteger;
7068
import java.util.concurrent.locks.Lock;
7169
import java.util.concurrent.locks.ReentrantLock;
7270

@@ -107,20 +105,14 @@ public class TripleServer implements Server {
107105
protected MutableHandlerRegistry handlerRegistry = new MutableHandlerRegistry();
108106

109107
/**
110-
* The mapping relationship between BindableService and ServerServiceDefinition
108+
* The mapping relationship between interface BindableService and ServerServiceDefinition
111109
*/
112-
protected ConcurrentHashMap<ProviderConfig, ServerServiceDefinition> serviceInfo = new ConcurrentHashMap<ProviderConfig,
113-
ServerServiceDefinition>();
110+
protected ConcurrentHashMap<String, ServerServiceDefinition> serviceInfo = new ConcurrentHashMap<>();
114111
/**
115112
* The mapping relationship between service name and unique id invoker
116113
*/
117114
protected Map<String, UniqueIdInvoker> invokerMap = new ConcurrentHashMap<>();
118115

119-
/**
120-
* invoker count
121-
*/
122-
protected AtomicInteger invokerCnt = new AtomicInteger();
123-
124116
/**
125117
* Thread pool
126118
* @param serverConfig ServerConfig
@@ -274,17 +266,15 @@ public void registerProcessor(ProviderConfig providerConfig, Invoker instance) {
274266
}
275267

276268
ServerServiceDefinition serviceDefinition = getServerServiceDefinition(providerConfig, uniqueIdInvoker);
277-
this.serviceInfo.put(providerConfig, serviceDefinition);
269+
this.serviceInfo.put(providerConfig.getInterfaceId(), serviceDefinition);
278270
ServerServiceDefinition ssd = this.handlerRegistry.addService(serviceDefinition);
279271
if (ssd != null) {
280272
throw new IllegalStateException("Can not expose service with same name:" +
281273
serviceDefinition.getServiceDescriptor().getName());
282274
}
283-
this.invokerCnt.incrementAndGet();
284275
} catch (Exception e) {
285276
String msg = "Register triple service error";
286277
LOGGER.error(msg, e);
287-
this.serviceInfo.remove(providerConfig);
288278
throw new SofaRpcRuntimeException(msg, e);
289279
} finally {
290280
this.lock.unlock();
@@ -413,24 +403,24 @@ public void unRegisterProcessor(ProviderConfig providerConfig, boolean closeIfNo
413403
this.lock.lock();
414404
cleanReflectCache(providerConfig);
415405
try {
416-
ServerServiceDefinition serverServiceDefinition = this.serviceInfo.get(providerConfig);
406+
ServerServiceDefinition serverServiceDefinition = this.serviceInfo.get(providerConfig.getInterfaceId());
417407
UniqueIdInvoker uniqueIdInvoker = this.invokerMap.get(providerConfig.getInterfaceId());
418408
if (null != uniqueIdInvoker) {
419409
uniqueIdInvoker.unRegisterInvoker(providerConfig);
420410
if (!uniqueIdInvoker.hasInvoker()) {
421411
this.invokerMap.remove(providerConfig.getInterfaceId());
422412
this.handlerRegistry.removeService(serverServiceDefinition);
413+
this.serviceInfo.remove(providerConfig.getInterfaceId());
423414
}
424415
} else {
425416
this.handlerRegistry.removeService(serverServiceDefinition);
426417
}
427-
invokerCnt.decrementAndGet();
428418
} catch (Exception e) {
429419
LOGGER.error("Unregister triple service error", e);
430420
} finally {
431421
this.lock.unlock();
432422
}
433-
if (closeIfNoEntry && invokerCnt.get() == 0) {
423+
if (closeIfNoEntry && invokerMap.isEmpty()) {
434424
stop();
435425
}
436426
}

test/test-integration/src/test/java/com/alipay/sofa/rpc/triple/ark/MultiClassLoaderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public void test() throws InterruptedException {
152152
.setApplication(serverApp)
153153
.setRegister(false)
154154
.setUniqueId("anotherHelloService");
155-
providerConfig2.export();
155+
providerConfig3.export();
156156

157157
Thread.currentThread().setContextClassLoader(clientClassloader2);
158158
ConsumerConfig<HelloService> consumerConfig3 = new ConsumerConfig<>();

0 commit comments

Comments
 (0)