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
This commit is contained in:
kezhenxu94 2019-08-30 23:54:54 +08:00 committed by GitHub
parent 77736c5e7d
commit 6fd85c8303
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 8 deletions

View File

@ -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);
}

View File

@ -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);