You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2019/12/13 16:12:32 UTC

[skywalking] branch reduce-register-load created (now fafb737)

This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a change to branch reduce-register-load
in repository https://gitbox.apache.org/repos/asf/skywalking.git.


      at fafb737  Remove the local span and exit span register mechanism in Java agent scenario.

This branch includes the following new commits:

     new fafb737  Remove the local span and exit span register mechanism in Java agent scenario.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[skywalking] 01/01: Remove the local span and exit span register mechanism in Java agent scenario.

Posted by wu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch reduce-register-load
in repository https://gitbox.apache.org/repos/asf/skywalking.git

commit fafb7374e077bb40165e1431285f900ed6a7f609
Author: Wu Sheng <wu...@foxmail.com>
AuthorDate: Sat Dec 14 00:12:18 2019 +0800

    Remove the local span and exit span register mechanism in Java agent scenario.
---
 .../apm/agent/core/context/TracingContext.java     | 69 +++++++++++-----------
 .../core/context/trace/StackBasedTracingSpan.java  | 33 ++++++-----
 .../apm/agent/core/dictionary/DictionaryUtil.java  |  7 +++
 .../core/dictionary/EndpointNameDictionary.java    | 45 +++-----------
 .../apache/skywalking/oap/server/core/Const.java   |  1 +
 .../handler/v6/grpc/RegisterServiceHandler.java    | 21 ++++---
 .../trace/provider/parser/SegmentParse.java        |  2 +-
 .../trace/provider/parser/SegmentParseV2.java      |  2 +-
 .../listener/endpoint/MultiScopesSpanListener.java | 19 ++++--
 .../standardization/ReferenceIdExchanger.java      | 20 +++++--
 .../{SpanIdExchanger.java => SpanExchanger.java}   | 43 ++++++++------
 .../server/receiver/trace/mock/ServiceAMock.java   |  9 +--
 .../server/receiver/trace/mock/ServiceBMock.java   |  6 +-
 13 files changed, 142 insertions(+), 135 deletions(-)

diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/TracingContext.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/TracingContext.java
index f8db130..71ca00a 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/TracingContext.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/TracingContext.java
@@ -74,7 +74,7 @@ public class TracingContext implements AbstractTracerContext {
     /**
      * Active spans stored in a Stack, usually called 'ActiveSpanStack'. This {@link LinkedList} is the in-memory
      * storage-structure. <p> I use {@link LinkedList#removeLast()}, {@link LinkedList#addLast(Object)} and {@link
-     * LinkedList#last} instead of {@link #pop()}, {@link #push(AbstractSpan)}, {@link #peek()}
+     * LinkedList#getLast()} instead of {@link #pop()}, {@link #push(AbstractSpan)}, {@link #peek()}
      */
     private LinkedList<AbstractSpan> activeSpanStack = new LinkedList<AbstractSpan>();
 
@@ -131,34 +131,57 @@ public class TracingContext implements AbstractTracerContext {
         } else {
             carrier.setPeerId(peerId);
         }
+
+        AbstractSpan firstSpan = first();
+        String firstSpanOperationName = firstSpan.getOperationName();
+
         List<TraceSegmentRef> refs = this.segment.getRefs();
-        int operationId;
-        String operationName;
+        int operationId = DictionaryUtil.inexistence();
+        String operationName = "";
         int entryApplicationInstanceId;
+
         if (refs != null && refs.size() > 0) {
             TraceSegmentRef ref = refs.get(0);
             operationId = ref.getEntryEndpointId();
             operationName = ref.getEntryEndpointName();
             entryApplicationInstanceId = ref.getEntryServiceInstanceId();
         } else {
-            AbstractSpan firstSpan = first();
-            operationId = firstSpan.getOperationId();
-            operationName = firstSpan.getOperationName();
+            if (firstSpan.isEntry()) {
+                /**
+                 * Since 6.6.0, if first span is not entry span, then this is an internal segment(no RPC),
+                 * this is not an endpoint.
+                 */
+                operationId = firstSpan.getOperationId();
+                operationName = firstSpanOperationName;
+            }
             entryApplicationInstanceId = this.segment.getApplicationInstanceId();
+
         }
         carrier.setEntryServiceInstanceId(entryApplicationInstanceId);
 
         if (operationId == DictionaryUtil.nullValue()) {
             if (!StringUtil.isEmpty(operationName)) {
                 carrier.setEntryEndpointName(operationName);
+            } else {
+                /**
+                 * Since 6.6.0, if first span is not entry span, then this is an internal segment(no RPC),
+                 * this is not an endpoint.
+                 */
             }
         } else {
             carrier.setEntryEndpointId(operationId);
         }
 
-        int parentOperationId = first().getOperationId();
+        int parentOperationId = firstSpan.getOperationId();
         if (parentOperationId == DictionaryUtil.nullValue()) {
-            carrier.setParentEndpointName(first().getOperationName());
+            if (!StringUtil.isEmpty(firstSpanOperationName)) {
+                carrier.setParentEndpointName(firstSpanOperationName);
+            } else {
+                /**
+                 * Since 6.6.0, if first span is not entry span, then this is an internal segment(no RPC),
+                 * this is not an endpoint.
+                 */
+            }
         } else {
             carrier.setParentEndpointId(parentOperationId);
         }
@@ -341,39 +364,13 @@ public class TracingContext implements AbstractTracerContext {
                     new PossibleFound.FoundAndObtain() {
                         @Override
                         public Object doProcess(final int peerId) {
-                            return DictionaryManager.findEndpointSection()
-                                .findOnly(segment.getServiceId(), operationName)
-                                .doInCondition(
-                                    new PossibleFound.FoundAndObtain() {
-                                        @Override
-                                        public Object doProcess(int operationId) {
-                                            return new ExitSpan(spanIdGenerator++, parentSpanId, operationId, peerId);
-                                        }
-                                    }, new PossibleFound.NotFoundAndObtain() {
-                                        @Override
-                                        public Object doProcess() {
-                                            return new ExitSpan(spanIdGenerator++, parentSpanId, operationName, peerId);
-                                        }
-                                    });
+                            return new ExitSpan(spanIdGenerator++, parentSpanId, operationName, peerId);
                         }
                     },
                     new PossibleFound.NotFoundAndObtain() {
                         @Override
                         public Object doProcess() {
-                            return DictionaryManager.findEndpointSection()
-                                .findOnly(segment.getServiceId(), operationName)
-                                .doInCondition(
-                                    new PossibleFound.FoundAndObtain() {
-                                        @Override
-                                        public Object doProcess(int operationId) {
-                                            return new ExitSpan(spanIdGenerator++, parentSpanId, operationId, remotePeer);
-                                        }
-                                    }, new PossibleFound.NotFoundAndObtain() {
-                                        @Override
-                                        public Object doProcess() {
-                                            return new ExitSpan(spanIdGenerator++, parentSpanId, operationName, remotePeer);
-                                        }
-                                    });
+                            return new ExitSpan(spanIdGenerator++, parentSpanId, operationName, remotePeer);
                         }
                     });
             push(exitSpan);
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/StackBasedTracingSpan.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/StackBasedTracingSpan.java
index afb0dfa..cdf26a8 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/StackBasedTracingSpan.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/StackBasedTracingSpan.java
@@ -89,21 +89,26 @@ public abstract class StackBasedTracingSpan extends AbstractTracingSpan {
     @Override
     public boolean finish(TraceSegment owner) {
         if (--stackDepth == 0) {
-            if (this.operationId == DictionaryUtil.nullValue()) {
-                this.operationId = (Integer)DictionaryManager.findEndpointSection()
-                    .findOrPrepare4Register(owner.getServiceId(), operationName, this.isEntry(), this.isExit())
-                    .doInCondition(
-                        new PossibleFound.FoundAndObtain() {
-                            @Override public Object doProcess(int value) {
-                                return value;
+            /**
+             * Since 6.6.0, only entry span requires the op name register, which is endpoint.
+             */
+            if (this.isEntry()) {
+                if (this.operationId == DictionaryUtil.nullValue()) {
+                    this.operationId = (Integer)DictionaryManager.findEndpointSection()
+                        .findOrPrepare4Register(owner.getServiceId(), operationName)
+                        .doInCondition(
+                            new PossibleFound.FoundAndObtain() {
+                                @Override public Object doProcess(int value) {
+                                    return value;
+                                }
+                            },
+                            new PossibleFound.NotFoundAndObtain() {
+                                @Override public Object doProcess() {
+                                    return DictionaryUtil.nullValue();
+                                }
                             }
-                        },
-                        new PossibleFound.NotFoundAndObtain() {
-                            @Override public Object doProcess() {
-                                return DictionaryUtil.nullValue();
-                            }
-                        }
-                    );
+                        );
+                }
             }
             return super.finish(owner);
         } else {
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/dictionary/DictionaryUtil.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/dictionary/DictionaryUtil.java
index 2f5b357..d8ac1d5 100644
--- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/dictionary/DictionaryUtil.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/dictionary/DictionaryUtil.java
@@ -30,4 +30,11 @@ public class DictionaryUtil {
     public static boolean isNull(int id) {
         return id == nullValue();
     }
+
+    /**
+     * @return -1 represent the object doesn't exist.
+     */
+    public static int inexistence() {
+        return -1;
+    }
 }
diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/dictionary/EndpointNameDictionary.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/dictionary/EndpointNameDictionary.java
index 1f28a80..3447d8a 100755
--- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/dictionary/EndpointNameDictionary.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/dictionary/EndpointNameDictionary.java
@@ -37,21 +37,20 @@ public enum EndpointNameDictionary {
     private Map<OperationNameKey, Integer> endpointDictionary = new ConcurrentHashMap<OperationNameKey, Integer>();
     private Set<OperationNameKey> unRegisterEndpoints = new ConcurrentSet<OperationNameKey>();
 
-    public PossibleFound findOrPrepare4Register(int serviceId, String endpointName,
-        boolean isEntry, boolean isExit) {
-        return find0(serviceId, endpointName, isEntry, isExit, true);
+    public PossibleFound findOrPrepare4Register(int serviceId, String endpointName) {
+        return find0(serviceId, endpointName, true);
     }
 
     public PossibleFound findOnly(int serviceId, String endpointName) {
-        return find0(serviceId, endpointName, false, false, false);
+        return find0(serviceId, endpointName, false);
     }
 
     private PossibleFound find0(int serviceId, String endpointName,
-        boolean isEntry, boolean isExit, boolean registerWhenNotFound) {
+        boolean registerWhenNotFound) {
         if (endpointName == null || endpointName.length() == 0) {
             return new NotFound();
         }
-        OperationNameKey key = new OperationNameKey(serviceId, endpointName, isEntry, isExit);
+        OperationNameKey key = new OperationNameKey(serviceId, endpointName);
         Integer operationId = endpointDictionary.get(key);
         if (operationId != null) {
             return new Found(operationId);
@@ -72,7 +71,7 @@ public enum EndpointNameDictionary {
                 Endpoint endpoint = Endpoint.newBuilder()
                     .setServiceId(operationNameKey.getServiceId())
                     .setEndpointName(operationNameKey.getEndpointName())
-                    .setFrom(operationNameKey.getSpanType())
+                    .setFrom(DetectPoint.server)
                     .build();
                 builder.addEndpoints(endpoint);
             }
@@ -81,9 +80,7 @@ public enum EndpointNameDictionary {
                 for (EndpointMappingElement element : serviceNameMappingCollection.getElementsList()) {
                     OperationNameKey key = new OperationNameKey(
                         element.getServiceId(),
-                        element.getEndpointName(),
-                        DetectPoint.server.equals(element.getFrom()),
-                        DetectPoint.client.equals(element.getFrom()));
+                        element.getEndpointName());
                     unRegisterEndpoints.remove(key);
                     endpointDictionary.put(key, element.getEndpointId());
                 }
@@ -98,14 +95,10 @@ public enum EndpointNameDictionary {
     private class OperationNameKey {
         private int serviceId;
         private String endpointName;
-        private boolean isEntry;
-        private boolean isExit;
 
-        public OperationNameKey(int serviceId, String endpointName, boolean isEntry, boolean isExit) {
+        public OperationNameKey(int serviceId, String endpointName) {
             this.serviceId = serviceId;
             this.endpointName = endpointName;
-            this.isEntry = isEntry;
-            this.isExit = isExit;
         }
 
         public int getServiceId() {
@@ -128,8 +121,7 @@ public enum EndpointNameDictionary {
             if (serviceId == key.serviceId && endpointName.equals(key.endpointName)) {
                 isServiceEndpointMatch = true;
             }
-            return isServiceEndpointMatch && isEntry == key.isEntry
-                && isExit == key.isExit;
+            return isServiceEndpointMatch;
         }
 
         @Override public int hashCode() {
@@ -138,30 +130,11 @@ public enum EndpointNameDictionary {
             return result;
         }
 
-        boolean isEntry() {
-            return isEntry;
-        }
-
-        boolean isExit() {
-            return isExit;
-        }
-
-        DetectPoint getSpanType() {
-            if (isEntry) {
-                return DetectPoint.server;
-            } else if (isExit) {
-                return DetectPoint.client;
-            } else {
-                return DetectPoint.UNRECOGNIZED;
-            }
-        }
 
         @Override public String toString() {
             return "OperationNameKey{" +
                 "serviceId=" + serviceId +
                 ", endpointName='" + endpointName + '\'' +
-                ", isEntry=" + isEntry +
-                ", isExit=" + isExit +
                 '}';
         }
     }
diff --git a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/Const.java b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/Const.java
index d91a47a..f7e7bf3 100644
--- a/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/Const.java
+++ b/oap-server/server-core/src/main/java/org/apache/skywalking/oap/server/core/Const.java
@@ -32,6 +32,7 @@ public class Const {
     public static final int USER_SERVICE_ID = 1;
     public static final int USER_INSTANCE_ID = 1;
     public static final int USER_ENDPOINT_ID = 1;
+    public static final int INEXISTENCE_ENDPOINT_ID = -1;
     public static final String USER_CODE = "User";
     public static final String SEGMENT_SPAN_SPLIT = "S";
     public static final String UNKNOWN = "Unknown";
diff --git a/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v6/grpc/RegisterServiceHandler.java b/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v6/grpc/RegisterServiceHandler.java
index e8d46bc..3e9a605 100644
--- a/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v6/grpc/RegisterServiceHandler.java
+++ b/oap-server/server-receiver-plugin/skywalking-register-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/register/provider/handler/v6/grpc/RegisterServiceHandler.java
@@ -163,14 +163,19 @@ public class RegisterServiceHandler extends RegisterGrpc.RegisterImplBase implem
             int serviceId = endpoint.getServiceId();
             String endpointName = endpoint.getEndpointName();
 
-            int endpointId = inventoryService.getOrCreate(serviceId, endpointName, DetectPoint.fromNetworkProtocolDetectPoint(endpoint.getFrom()));
-
-            if (endpointId != Const.NONE) {
-                builder.addElements(EndpointMappingElement.newBuilder()
-                    .setServiceId(serviceId)
-                    .setEndpointName(endpointName)
-                    .setEndpointId(endpointId)
-                    .setFrom(endpoint.getFrom()));
+            DetectPoint detectPoint = DetectPoint.fromNetworkProtocolDetectPoint(endpoint.getFrom());
+            if (DetectPoint.SERVER.equals(detectPoint)) {
+                int endpointId = inventoryService.getOrCreate(serviceId, endpointName, detectPoint);
+
+                if (endpointId != Const.NONE) {
+                    builder.addElements(EndpointMappingElement.newBuilder()
+                        .setServiceId(serviceId)
+                        .setEndpointName(endpointName)
+                        .setEndpointId(endpointId)
+                        .setFrom(endpoint.getFrom()));
+                }
+            } else {
+                logger.warn("Unexpected endpoint register, endpoint isn't detected from server side. {}", request);
             }
         });
 
diff --git a/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/SegmentParse.java b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/SegmentParse.java
index 726adb0..1b527bc 100644
--- a/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/SegmentParse.java
+++ b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/SegmentParse.java
@@ -141,7 +141,7 @@ public class SegmentParse {
         for (int i = 0; i < segmentDecorator.getSpansCount(); i++) {
             SpanDecorator spanDecorator = segmentDecorator.getSpans(i);
 
-            if (!SpanIdExchanger.getInstance(moduleManager).exchange(spanDecorator, segmentCoreInfo.getServiceId())) {
+            if (!SpanExchanger.getInstance(moduleManager).exchange(spanDecorator, segmentCoreInfo.getServiceId())) {
                 exchanged = false;
             } else {
                 for (int j = 0; j < spanDecorator.getRefsCount(); j++) {
diff --git a/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/SegmentParseV2.java b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/SegmentParseV2.java
index 06018c4..583301b 100755
--- a/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/SegmentParseV2.java
+++ b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/SegmentParseV2.java
@@ -158,7 +158,7 @@ public class SegmentParseV2 {
         for (int i = 0; i < segmentDecorator.getSpansCount(); i++) {
             SpanDecorator spanDecorator = segmentDecorator.getSpans(i);
 
-            if (!SpanIdExchanger.getInstance(moduleManager).exchange(spanDecorator, segmentCoreInfo.getServiceId())) {
+            if (!SpanExchanger.getInstance(moduleManager).exchange(spanDecorator, segmentCoreInfo.getServiceId())) {
                 exchanged = false;
             } else {
                 for (int j = 0; j < spanDecorator.getRefsCount(); j++) {
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/endpoint/MultiScopesSpanListener.java b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/listener/endpoint/MultiScopesSpanListener.java
index 7cb31c2..705c782 100755
--- a/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/listener/endpoint/MultiScopesSpanListener.java
+++ b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/listener/endpoint/MultiScopesSpanListener.java
@@ -106,7 +106,11 @@ public class MultiScopesSpanListener implements EntrySpanListener, ExitSpanListe
             for (int i = 0; i < spanDecorator.getRefsCount(); i++) {
                 ReferenceDecorator reference = spanDecorator.getRefs(i);
                 SourceBuilder sourceBuilder = new SourceBuilder();
-                sourceBuilder.setSourceEndpointId(reference.getParentEndpointId());
+                if (reference.getParentEndpointId() == Const.INEXISTENCE_ENDPOINT_ID) {
+                    sourceBuilder.setSourceEndpointId(Const.USER_ENDPOINT_ID);
+                } else {
+                    sourceBuilder.setSourceEndpointId(reference.getParentEndpointId());
+                }
 
                 final int networkAddressId = reference.getNetworkAddressId();
                 final int serviceIdByPeerId = serviceInventoryCache.getServiceId(networkAddressId);
@@ -161,10 +165,8 @@ public class MultiScopesSpanListener implements EntrySpanListener, ExitSpanListe
         int destInstanceId = instanceInventoryCache.getServiceInstanceId(destServiceId, peerId);
         int mappingServiceInstanceId = instanceInventoryCache.get(destInstanceId).getMappingServiceInstanceId();
 
-        sourceBuilder.setSourceEndpointId(Const.USER_ENDPOINT_ID);
         sourceBuilder.setSourceServiceInstanceId(segmentCoreInfo.getServiceInstanceId());
         sourceBuilder.setSourceServiceId(segmentCoreInfo.getServiceId());
-        sourceBuilder.setDestEndpointId(spanDecorator.getOperationNameId());
         if (Const.NONE == mappingServiceId) {
             sourceBuilder.setDestServiceId(destServiceId);
         } else {
@@ -235,10 +237,14 @@ public class MultiScopesSpanListener implements EntrySpanListener, ExitSpanListe
 
         sourceBuilder.setSourceServiceName(serviceInventoryCache.get(sourceBuilder.getSourceServiceId()).getName());
         sourceBuilder.setSourceServiceInstanceName(instanceInventoryCache.get(sourceBuilder.getSourceServiceInstanceId()).getName());
-        sourceBuilder.setSourceEndpointName(endpointInventoryCache.get(sourceBuilder.getSourceEndpointId()).getName());
+        if (sourceBuilder.getSourceEndpointId() != Const.NONE) {
+            sourceBuilder.setSourceEndpointName(endpointInventoryCache.get(sourceBuilder.getSourceEndpointId()).getName());
+        }
         sourceBuilder.setDestServiceName(serviceInventoryCache.get(sourceBuilder.getDestServiceId()).getName());
         sourceBuilder.setDestServiceInstanceName(instanceInventoryCache.get(sourceBuilder.getDestServiceInstanceId()).getName());
-        sourceBuilder.setDestEndpointName(endpointInventoryCache.get(sourceBuilder.getDestEndpointId()).getName());
+        if (sourceBuilder.getDestEndpointId() != Const.NONE) {
+            sourceBuilder.setDestEndpointName(endpointInventoryCache.get(sourceBuilder.getDestEndpointId()).getName());
+        }
     }
 
     @Override public void build() {
@@ -255,6 +261,9 @@ public class MultiScopesSpanListener implements EntrySpanListener, ExitSpanListe
              * Parent endpoint could be none, because in SkyWalking Cross Process Propagation Headers Protocol v2,
              * endpoint in ref could be empty, based on that, endpoint relation maybe can't be established.
              * So, I am making this source as optional.
+             *
+             * Also, since 6.6.0, source endpoint could be none, if this trace begins by an internal task(local span or exit span), such as Timer,
+             * rather than, normally begin as an entry span, like a RPC server side.
              */
             if (endpointRelation != null) {
                 sourceReceiver.receive(endpointRelation);
diff --git a/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/standardization/ReferenceIdExchanger.java b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/standardization/ReferenceIdExchanger.java
index f1d72ae..0fcff21 100644
--- a/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/standardization/ReferenceIdExchanger.java
+++ b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/standardization/ReferenceIdExchanger.java
@@ -70,6 +70,10 @@ public class ReferenceIdExchanger implements IdExchanger<ReferenceDecorator> {
                 standardBuilder.setEntryEndpointId(entryEndpointId);
                 standardBuilder.setEntryEndpointName(Const.EMPTY_STRING);
             }
+        } else {
+            /**
+             * Since 6.6.0, endpoint id could be -1, as it is not an endpoint. Such as local span and exist span.
+             */
         }
 
         if (standardBuilder.getParentEndpointId() == 0) {
@@ -88,6 +92,10 @@ public class ReferenceIdExchanger implements IdExchanger<ReferenceDecorator> {
                 standardBuilder.setParentEndpointId(parentEndpointId);
                 standardBuilder.setParentEndpointName(Const.EMPTY_STRING);
             }
+        } else {
+            /**
+             * Since 6.6.0, endpoint id could be -1, as it is not an endpoint. Such as local span and exist span.
+             */
         }
 
         if (standardBuilder.getNetworkAddressId() == 0 && !Strings.isNullOrEmpty(standardBuilder.getNetworkAddress())) {
@@ -104,16 +112,18 @@ public class ReferenceIdExchanger implements IdExchanger<ReferenceDecorator> {
                 standardBuilder.setNetworkAddressId(networkAddressId);
                 standardBuilder.setNetworkAddress(Const.EMPTY_STRING);
             }
+        } else {
+            /**
+             * Since 6.6.0, endpoint id could be -1, as it is not an endpoint. Such as local span and exist span.
+             */
         }
         return exchanged;
     }
 
     /**
-     * Endpoint in ref could be local or exit span's operation name.
-     * Especially if it is local span operation name,
-     * exchange may not happen at agent, such as Java agent,
-     * then put literal endpoint string in the header,
-     * Need to try to get the id by assuming the endpoint name is detected at server, local or client.
+     * Endpoint in ref could be local or exit span's operation name. Especially if it is local span operation name,
+     * exchange may not happen at agent, such as Java agent, then put literal endpoint string in the header, Need to try
+     * to get the id by assuming the endpoint name is detected at server, local or client.
      *
      * If agent does the exchange, then always use endpoint id.
      */
diff --git a/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/standardization/SpanIdExchanger.java b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/standardization/SpanExchanger.java
similarity index 84%
rename from oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/standardization/SpanIdExchanger.java
rename to oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/standardization/SpanExchanger.java
index 7fcbb9e..b351883 100644
--- a/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/standardization/SpanIdExchanger.java
+++ b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/trace/provider/parser/standardization/SpanExchanger.java
@@ -22,6 +22,7 @@ import com.google.common.base.Strings;
 import com.google.gson.JsonObject;
 import org.apache.skywalking.apm.network.common.KeyStringValuePair;
 import org.apache.skywalking.apm.network.language.agent.SpanLayer;
+import org.apache.skywalking.apm.network.language.agent.SpanType;
 import org.apache.skywalking.oap.server.core.Const;
 import org.apache.skywalking.oap.server.core.CoreModule;
 import org.apache.skywalking.oap.server.core.cache.ServiceInstanceInventoryCache;
@@ -45,11 +46,11 @@ import java.util.List;
 /**
  * @author peng-yongsheng
  */
-public class SpanIdExchanger implements IdExchanger<SpanDecorator> {
+public class SpanExchanger implements IdExchanger<SpanDecorator> {
 
-    private static final Logger logger = LoggerFactory.getLogger(SpanIdExchanger.class);
+    private static final Logger logger = LoggerFactory.getLogger(SpanExchanger.class);
 
-    private static SpanIdExchanger EXCHANGER;
+    private static SpanExchanger EXCHANGER;
     private final ServiceInventoryCache serviceInventoryCacheDAO;
     private final IServiceInventoryRegister serviceInventoryRegister;
     private final ServiceInstanceInventoryCache serviceInstanceInventoryCacheDAO;
@@ -58,14 +59,14 @@ public class SpanIdExchanger implements IdExchanger<SpanDecorator> {
     private final INetworkAddressInventoryRegister networkAddressInventoryRegister;
     private final IComponentLibraryCatalogService componentLibraryCatalogService;
 
-    public static SpanIdExchanger getInstance(ModuleManager moduleManager) {
+    public static SpanExchanger getInstance(ModuleManager moduleManager) {
         if (EXCHANGER == null) {
-            EXCHANGER = new SpanIdExchanger(moduleManager);
+            EXCHANGER = new SpanExchanger(moduleManager);
         }
         return EXCHANGER;
     }
 
-    private SpanIdExchanger(ModuleManager moduleManager) {
+    private SpanExchanger(ModuleManager moduleManager) {
         this.serviceInventoryCacheDAO = moduleManager.find(CoreModule.NAME).provider().getService(ServiceInventoryCache.class);
         this.serviceInventoryRegister = moduleManager.find(CoreModule.NAME).provider().getService(IServiceInventoryRegister.class);
         this.serviceInstanceInventoryCacheDAO = moduleManager.find(CoreModule.NAME).provider().getService(ServiceInstanceInventoryCache.class);
@@ -135,19 +136,25 @@ public class SpanIdExchanger implements IdExchanger<SpanDecorator> {
         }
 
         if (standardBuilder.getOperationNameId() == Const.NONE) {
-            String endpointName = Strings.isNullOrEmpty(standardBuilder.getOperationName()) ? Const.DOMAIN_OPERATION_NAME : standardBuilder.getOperationName();
-            int endpointId = endpointInventoryRegister.getOrCreate(serviceId, endpointName, DetectPoint.fromSpanType(standardBuilder.getSpanType()));
-
-            if (endpointId == 0) {
-                if (logger.isDebugEnabled()) {
-                    logger.debug("endpoint name: {} from service id: {} exchange failed", endpointName, serviceId);
+            /**
+             * Only operation name of entry span is being treated as an endpoint,
+             * so, since 6.6.0, only it triggers register.
+             */
+            if (SpanType.Entry.equals(standardBuilder.getSpanType())) {
+                String endpointName = Strings.isNullOrEmpty(standardBuilder.getOperationName()) ? Const.DOMAIN_OPERATION_NAME : standardBuilder.getOperationName();
+                int endpointId = endpointInventoryRegister.getOrCreate(serviceId, endpointName, DetectPoint.fromSpanType(standardBuilder.getSpanType()));
+
+                if (endpointId == 0) {
+                    if (logger.isDebugEnabled()) {
+                        logger.debug("endpoint name: {} from service id: {} exchange failed", endpointName, serviceId);
+                    }
+
+                    exchanged = false;
+                } else {
+                    standardBuilder.toBuilder();
+                    standardBuilder.setOperationNameId(endpointId);
+                    standardBuilder.setOperationName(Const.EMPTY_STRING);
                 }
-
-                exchanged = false;
-            } else {
-                standardBuilder.toBuilder();
-                standardBuilder.setOperationNameId(endpointId);
-                standardBuilder.setOperationName(Const.EMPTY_STRING);
             }
         }
         return exchanged;
diff --git a/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/test/java/org/apache/skywalking/oap/server/receiver/trace/mock/ServiceAMock.java b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/test/java/org/apache/skywalking/oap/server/receiver/trace/mock/ServiceAMock.java
index 4da1f80..dd6d25a 100644
--- a/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/test/java/org/apache/skywalking/oap/server/receiver/trace/mock/ServiceAMock.java
+++ b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/test/java/org/apache/skywalking/oap/server/receiver/trace/mock/ServiceAMock.java
@@ -90,11 +90,7 @@ class ServiceAMock {
         span.setParentSpanId(0);
         span.setStartTime(startTimestamp + 100);
         span.setEndTime(startTimestamp + 500);
-        if (isPrepare) {
-            span.setOperationName("org.apache.skywalking.Local.do");
-        } else {
-            span.setOperationNameId(3);
-        }
+        span.setOperationName("org.apache.skywalking.Local.do");
         span.setIsError(false);
         return span;
     }
@@ -108,12 +104,11 @@ class ServiceAMock {
         span.setStartTime(startTimestamp + 120);
         span.setEndTime(startTimestamp + 5800);
         span.setComponentId(ComponentsDefine.DUBBO.getId());
+        span.setOperationName(DUBBO_ENDPOINT);
         if (isPrepare) {
             span.setPeer(DUBBO_ADDRESS);
-            span.setOperationName(DUBBO_ENDPOINT);
         } else {
             span.setPeerId(2);
-            span.setOperationNameId(6);
         }
         span.setIsError(false);
         return span;
diff --git a/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/test/java/org/apache/skywalking/oap/server/receiver/trace/mock/ServiceBMock.java b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/test/java/org/apache/skywalking/oap/server/receiver/trace/mock/ServiceBMock.java
index 9496815..73893ee 100644
--- a/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/test/java/org/apache/skywalking/oap/server/receiver/trace/mock/ServiceBMock.java
+++ b/oap-server/server-receiver-plugin/skywalking-trace-receiver-plugin/src/test/java/org/apache/skywalking/oap/server/receiver/trace/mock/ServiceBMock.java
@@ -119,11 +119,10 @@ class ServiceBMock {
         span.addTags(KeyWithStringValue.newBuilder().setKey("db.statement").setValue("select * from database where complex = 1;").build());
         span.addTags(KeyWithStringValue.newBuilder().setKey("db.type").setValue("mongodb").build());
 
+        span.setOperationName("mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]");
         if (isPrepare) {
-            span.setOperationName("mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]");
             span.setPeer("localhost:27017");
         } else {
-            span.setOperationNameId(7);
             span.setPeerId(3);
         }
         return span;
@@ -140,11 +139,10 @@ class ServiceBMock {
         span.setComponentId(ComponentsDefine.ROCKET_MQ_PRODUCER.getId());
         span.setIsError(false);
 
+        span.setOperationName(ROCKET_MQ_ENDPOINT);
         if (isPrepare) {
-            span.setOperationName(ROCKET_MQ_ENDPOINT);
             span.setPeer(ROCKET_MQ_ADDRESS);
         } else {
-            span.setOperationNameId(8);
             span.setPeerId(4);
         }
         return span;