Skip to content

fix triple service uninstall do not clean completely issue in serverless scene #1487

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

Open
wants to merge 1 commit into
base: v5.13.4_dev
Choose a base branch
from
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 @@ -57,7 +57,6 @@
import triple.Response;

import java.lang.reflect.Method;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand All @@ -66,7 +65,6 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

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

/**
* The mapping relationship between BindableService and ServerServiceDefinition
* The mapping relationship between interface BindableService and ServerServiceDefinition
*/
protected ConcurrentHashMap<ProviderConfig, ServerServiceDefinition> serviceInfo = new ConcurrentHashMap<ProviderConfig,
ServerServiceDefinition>();
protected ConcurrentHashMap<String, ServerServiceDefinition> serviceInfo = new ConcurrentHashMap<>();
/**
* The mapping relationship between service name and unique id invoker
*/
protected Map<String, UniqueIdInvoker> invokerMap = new ConcurrentHashMap<>();

/**
* invoker count
*/
protected AtomicInteger invokerCnt = new AtomicInteger();

/**
* Thread pool
* @param serverConfig ServerConfig
Expand Down Expand Up @@ -274,17 +266,15 @@ public void registerProcessor(ProviderConfig providerConfig, Invoker instance) {
}

ServerServiceDefinition serviceDefinition = getServerServiceDefinition(providerConfig, uniqueIdInvoker);
this.serviceInfo.put(providerConfig, serviceDefinition);
this.serviceInfo.put(providerConfig.getInterfaceId(), serviceDefinition);
ServerServiceDefinition ssd = this.handlerRegistry.addService(serviceDefinition);
if (ssd != null) {
throw new IllegalStateException("Can not expose service with same name:" +
serviceDefinition.getServiceDescriptor().getName());
}
this.invokerCnt.incrementAndGet();
} catch (Exception e) {
String msg = "Register triple service error";
LOGGER.error(msg, e);
this.serviceInfo.remove(providerConfig);
throw new SofaRpcRuntimeException(msg, e);
} finally {
this.lock.unlock();
Expand Down Expand Up @@ -413,24 +403,24 @@ public void unRegisterProcessor(ProviderConfig providerConfig, boolean closeIfNo
this.lock.lock();
cleanReflectCache(providerConfig);
try {
ServerServiceDefinition serverServiceDefinition = this.serviceInfo.get(providerConfig);
ServerServiceDefinition serverServiceDefinition = this.serviceInfo.get(providerConfig.getInterfaceId());
UniqueIdInvoker uniqueIdInvoker = this.invokerMap.get(providerConfig.getInterfaceId());
if (null != uniqueIdInvoker) {
uniqueIdInvoker.unRegisterInvoker(providerConfig);
if (!uniqueIdInvoker.hasInvoker()) {
this.invokerMap.remove(providerConfig.getInterfaceId());
this.handlerRegistry.removeService(serverServiceDefinition);
this.serviceInfo.remove(providerConfig.getInterfaceId());
}
} else {
this.handlerRegistry.removeService(serverServiceDefinition);
}
invokerCnt.decrementAndGet();
} catch (Exception e) {
LOGGER.error("Unregister triple service error", e);
} finally {
this.lock.unlock();
}
if (closeIfNoEntry && invokerCnt.get() == 0) {
if (closeIfNoEntry && invokerMap.isEmpty()) {
stop();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void test() throws InterruptedException {
.setApplication(serverApp)
.setRegister(false)
.setUniqueId("anotherHelloService");
providerConfig2.export();
providerConfig3.export();

Thread.currentThread().setContextClassLoader(clientClassloader2);
ConsumerConfig<HelloService> consumerConfig3 = new ConsumerConfig<>();
Expand Down
Loading