This is an automated email from the ASF dual-hosted git repository. kezhenxu94 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/skywalking.git
The following commit(s) were added to refs/heads/master by this push: new 6fd85c8 Avoid unnecessary resetting when service mapping id is already 0 (#3383) 6fd85c8 is described below commit 6fd85c83031d2c210717a1be9bb2c0f965c546ce Author: kezhenxu94 <kezhenx...@apache.org> AuthorDate: Fri Aug 30 23:54:54 2019 +0800 Avoid unnecessary resetting when service mapping id is already 0 (#3383) * Avoid unnecessary resetting when service mapping id is already 0 * Avoid as early as possible and minor optimization * Remove unused import * Polish --- .../core/register/service/ServiceInventoryRegister.java | 10 ++++++---- .../parser/listener/service/ServiceMappingSpanListener.java | 13 +++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/register/service/ServiceInventoryRegister.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/register/service/ServiceInventoryRegister.java index 8b276b2..e560fed 100644 --- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/register/service/ServiceInventoryRegister.java +++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/register/service/ServiceInventoryRegister.java @@ -139,11 +139,13 @@ public class ServiceInventoryRegister implements IServiceInventoryRegister { @Override public void resetMapping(int serviceId) { ServiceInventory serviceInventory = getServiceInventoryCache().get(serviceId); if (Objects.nonNull(serviceInventory)) { - serviceInventory = serviceInventory.getClone(); - serviceInventory.setLastUpdateTime(System.currentTimeMillis()); - serviceInventory.setResetServiceMapping(true); + if (serviceInventory.getMappingServiceId() != Const.NONE) { + serviceInventory = serviceInventory.getClone(); + serviceInventory.setLastUpdateTime(System.currentTimeMillis()); + serviceInventory.setResetServiceMapping(true); - InventoryStreamProcessor.getInstance().in(serviceInventory); + InventoryStreamProcessor.getInstance().in(serviceInventory); + } } else { logger.warn("Service {} mapping update, but not found in storage.", serviceId); } diff --git a/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/listener/service/ServiceMappingSpanListener.java b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/listener/service/ServiceMappingSpanListener.java index 7010b88..0604754 100755 --- a/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/listener/service/ServiceMappingSpanListener.java +++ b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/listener/service/ServiceMappingSpanListener.java @@ -21,9 +21,11 @@ package org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener import lombok.Getter; import lombok.Setter; import org.apache.skywalking.apm.network.language.agent.SpanLayer; +import org.apache.skywalking.oap.server.core.Const; import org.apache.skywalking.oap.server.core.CoreModule; import org.apache.skywalking.oap.server.core.cache.NetworkAddressInventoryCache; import org.apache.skywalking.oap.server.core.cache.ServiceInventoryCache; +import org.apache.skywalking.oap.server.core.register.ServiceInventory; import org.apache.skywalking.oap.server.core.register.service.IServiceInventoryRegister; import org.apache.skywalking.oap.server.library.module.ModuleManager; import org.apache.skywalking.oap.server.receiver.trace.provider.TraceServiceModuleConfig; @@ -35,7 +37,7 @@ import org.apache.skywalking.oap.server.receiver.trace.provider.parser.listener. import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; /** @@ -49,8 +51,8 @@ public class ServiceMappingSpanListener implements EntrySpanListener { private final TraceServiceModuleConfig config; private final ServiceInventoryCache serviceInventoryCache; private final NetworkAddressInventoryCache networkAddressInventoryCache; - private final List<ServiceMapping> serviceMappings = new LinkedList<>(); - private final List<Integer> servicesToResetMapping = new LinkedList<>(); + private final List<ServiceMapping> serviceMappings = new ArrayList<>(); + private final List<Integer> servicesToResetMapping = new ArrayList<>(); private ServiceMappingSpanListener(ModuleManager moduleManager, TraceServiceModuleConfig config) { this.serviceInventoryCache = moduleManager.find(CoreModule.NAME).provider().getService(ServiceInventoryCache.class); @@ -79,7 +81,10 @@ public class ServiceMappingSpanListener implements EntrySpanListener { if (logger.isDebugEnabled()) { logger.debug("{} is configured as gateway, will reset its mapping service id", serviceId); } - servicesToResetMapping.add(serviceId); + ServiceInventory serviceInventory = serviceInventoryCache.get(serviceId); + if (serviceInventory.getMappingServiceId() != Const.NONE && !servicesToResetMapping.contains(serviceId)) { + servicesToResetMapping.add(serviceId); + } } else { ServiceMapping serviceMapping = new ServiceMapping(); serviceMapping.setServiceId(serviceId);