Commit 884dd8c5 authored by 彭勇升 pengys's avatar 彭勇升 pengys Committed by 吴晟
Browse files

Add detect point to be a part of unique key of the endpoint id. (#1874)

parent e9d4c52a
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -60,13 +60,13 @@ public class EndpointInventoryCache implements Service {
        return cacheDAO;
    }

    public int getEndpointId(int serviceId, String endpointName) {
        String id = EndpointInventory.buildId(serviceId, endpointName);
    public int getEndpointId(int serviceId, String endpointName, int detectPoint) {
        String id = EndpointInventory.buildId(serviceId, endpointName, detectPoint);

        Integer endpointId = endpointNameCache.getIfPresent(id);

        if (Objects.isNull(endpointId) || endpointId == Const.NONE) {
            endpointId = getCacheDAO().getEndpointId(serviceId, endpointName);
            endpointId = getCacheDAO().getEndpointId(serviceId, endpointName, detectPoint);
            if (endpointId != Const.NONE) {
                endpointNameCache.put(id, endpointId);
            }
+9 −9
Original line number Diff line number Diff line
@@ -18,18 +18,15 @@

package org.apache.skywalking.oap.server.core.register;

import java.util.HashMap;
import java.util.Map;
import lombok.Getter;
import lombok.Setter;
import java.util.*;
import lombok.*;
import org.apache.skywalking.oap.server.core.Const;
import org.apache.skywalking.oap.server.core.register.annotation.InventoryType;
import org.apache.skywalking.oap.server.core.remote.annotation.StreamData;
import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData;
import org.apache.skywalking.oap.server.core.source.Scope;
import org.apache.skywalking.oap.server.core.storage.StorageBuilder;
import org.apache.skywalking.oap.server.core.storage.annotation.Column;
import org.apache.skywalking.oap.server.core.storage.annotation.StorageEntity;
import org.apache.skywalking.oap.server.core.storage.annotation.*;
import org.apache.skywalking.oap.server.library.util.StringUtils;

/**
@@ -50,18 +47,19 @@ public class EndpointInventory extends RegisterSource {
    @Setter @Getter @Column(columnName = NAME, matchQuery = true) private String name = Const.EMPTY_STRING;
    @Setter @Getter @Column(columnName = DETECT_POINT) private int detectPoint;

    public static String buildId(int serviceId, String endpointName) {
        return serviceId + Const.ID_SPLIT + endpointName;
    public static String buildId(int serviceId, String endpointName, int detectPoint) {
        return serviceId + Const.ID_SPLIT + endpointName + Const.ID_SPLIT + detectPoint;
    }

    @Override public String id() {
        return buildId(serviceId, name);
        return buildId(serviceId, name, detectPoint);
    }

    @Override public int hashCode() {
        int result = 17;
        result = 31 * result + serviceId;
        result = 31 * result + name.hashCode();
        result = 31 * result + detectPoint;
        return result;
    }

@@ -78,6 +76,8 @@ public class EndpointInventory extends RegisterSource {
            return false;
        if (!name.equals(source.getName()))
            return false;
        if (detectPoint != source.getDetectPoint())
            return false;

        return true;
    }
+3 −3
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ public class EndpointInventoryRegister implements IEndpointInventoryRegister {
    }

    @Override public int getOrCreate(int serviceId, String endpointName, DetectPoint detectPoint) {
        int endpointId = getCacheService().getEndpointId(serviceId, endpointName);
        int endpointId = getCacheService().getEndpointId(serviceId, endpointName, detectPoint.ordinal());

        if (endpointId == Const.NONE) {
            EndpointInventory endpointInventory = new EndpointInventory();
@@ -68,8 +68,8 @@ public class EndpointInventoryRegister implements IEndpointInventoryRegister {
        return endpointId;
    }

    @Override public int get(int serviceId, String endpointName) {
        return getCacheService().getEndpointId(serviceId, endpointName);
    @Override public int get(int serviceId, String endpointName, int detectPoint) {
        return getCacheService().getEndpointId(serviceId, endpointName, detectPoint);
    }

    @Override public void heartbeat(int endpointId, long heartBeatTime) {
+1 −1
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ public interface IEndpointInventoryRegister extends Service {

    int getOrCreate(int serviceId, String endpointName, DetectPoint detectPoint);

    int get(int serviceId, String endpointName);
    int get(int serviceId, String endpointName, int detectPoint);

    void heartbeat(int endpointId, long heartBeatTime);
}
+1 −1
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ import org.apache.skywalking.oap.server.core.storage.DAO;
 */
public interface IEndpointInventoryCacheDAO extends DAO {

    int getEndpointId(int serviceId, String endpointName);
    int getEndpointId(int serviceId, String endpointName, int detectPoint);

    EndpointInventory get(int endpointId);
}
Loading