public void checkChangedConfigGrayMigrateState()

in config/src/main/java/com/alibaba/nacos/config/server/service/ConfigMigrateService.java [321:377]


    public void checkChangedConfigGrayMigrateState(ConfigInfoGrayWrapper changedConfigInfoGrayWrapper) {
        String tenant = changedConfigInfoGrayWrapper.getTenant();
        if (!ConfigCompatibleConfig.getInstance().isNamespaceCompatibleMode()) {
            return;
        }
        if (!StringUtils.equals(tenant, namespacePublic) && StringUtils.isNotBlank(tenant)) {
            return;
        }
        String targetTenant = StringUtils.EMPTY;
        if (StringUtils.isBlank(tenant)) {
            targetTenant = namespacePublic;
        }
        ConfigInfoGrayWrapper targetConfigInfoGrayWrapper = configInfoGrayPersistService.findConfigInfo4Gray(
                changedConfigInfoGrayWrapper.getDataId(), changedConfigInfoGrayWrapper.getGroup(), targetTenant,
                changedConfigInfoGrayWrapper.getGrayName());
        try {
            GRAY_MIGRATE_FLAG.set(true);
            if (StringUtils.equals(targetConfigInfoGrayWrapper.getSrcUser(), NAMESPACE_MIGRATE_SRC_USER)) {
                if (targetConfigInfoGrayWrapper == null) {
                    configInfoGrayPersistService.removeConfigInfoGray(changedConfigInfoGrayWrapper.getDataId(),
                            changedConfigInfoGrayWrapper.getGroup(), tenant, changedConfigInfoGrayWrapper.getGrayName(),
                            null, NAMESPACE_MIGRATE_SRC_USER);
                } else if (!targetConfigInfoGrayWrapper.getMd5().equals(changedConfigInfoGrayWrapper.getMd5())
                        || targetConfigInfoGrayWrapper.getGrayRule()
                        .equals(changedConfigInfoGrayWrapper.getGrayRule())) {
                    if (targetConfigInfoGrayWrapper.getLastModified() > changedConfigInfoGrayWrapper.getLastModified()
                            || !StringUtils.equals(targetConfigInfoGrayWrapper.getSrcUser(),
                            NAMESPACE_MIGRATE_SRC_USER)) {
                        targetConfigInfoGrayWrapper.setTenant(tenant);
                        configInfoGrayPersistService.updateConfigInfo4Gray(targetConfigInfoGrayWrapper,
                                targetConfigInfoGrayWrapper.getGrayName(), targetConfigInfoGrayWrapper.getGrayRule(),
                                null, NAMESPACE_MIGRATE_SRC_USER);
                    }
                }
            } else {
                if (targetConfigInfoGrayWrapper == null) {
                    changedConfigInfoGrayWrapper.setTenant(targetTenant);
                    configInfoGrayPersistService.addConfigInfo4Gray(changedConfigInfoGrayWrapper,
                            changedConfigInfoGrayWrapper.getGrayName(), changedConfigInfoGrayWrapper.getGrayRule(),
                            null, NAMESPACE_MIGRATE_SRC_USER);
                } else if (!targetConfigInfoGrayWrapper.getMd5().equals(changedConfigInfoGrayWrapper.getMd5())
                        || targetConfigInfoGrayWrapper.getGrayRule()
                        .equals(changedConfigInfoGrayWrapper.getGrayRule())) {
                    if (targetConfigInfoGrayWrapper.getLastModified() > changedConfigInfoGrayWrapper.getLastModified()
                            && !StringUtils.equals(targetConfigInfoGrayWrapper.getSrcUser(),
                            NAMESPACE_MIGRATE_SRC_USER)) {
                        targetConfigInfoGrayWrapper.setTenant(tenant);
                        configInfoGrayPersistService.updateConfigInfo4Gray(targetConfigInfoGrayWrapper,
                                targetConfigInfoGrayWrapper.getGrayName(), targetConfigInfoGrayWrapper.getGrayRule(),
                                null, NAMESPACE_MIGRATE_SRC_USER);
                    }
                }
            }
        } finally {
            GRAY_MIGRATE_FLAG.set(false);
        }
    }