page = configInfoGrayPersistService.findAllConfigInfoGrayForDumpAll(pageNo, PAGE_SIZE);
if (page != null) {
- for (ConfigInfoTagWrapper cf : page.getPageItems()) {
+ for (ConfigInfoGrayWrapper cf : page.getPageItems()) {
boolean result = ConfigCacheService
- .dumpTag(cf.getDataId(), cf.getGroup(), cf.getTenant(), cf.getTag(), cf.getContent(),
+ .dumpGray(cf.getDataId(), cf.getGroup(), cf.getTenant(), cf.getGrayName(), cf.getGrayRule(), cf.getContent(),
cf.getLastModified(), cf.getEncryptedDataKey());
- LogUtil.DUMP_LOG.info("[dump-all-Tag-ok] result={}, {}, {}, length={}, md5={}", result,
+ LogUtil.DUMP_LOG.info("[dump-all-gray-ok] result={}, {}, {}, length={}, md5={}, grayName={}", result,
GroupKey2.getKey(cf.getDataId(), cf.getGroup()), cf.getLastModified(),
- cf.getContent().length(), cf.getMd5());
+ cf.getContent().length(), cf.getMd5(), cf.getGrayName());
}
actualRowCount += page.getPageItems().size();
- DEFAULT_LOG.info("[all-dump-tag] {} / {}", actualRowCount, rowCount);
+ DEFAULT_LOG.info("[all-dump-gray] {} / {}", actualRowCount, rowCount);
}
}
return true;
}
- static final int PAGE_SIZE = 1000;
+ static final int PAGE_SIZE = getAllDumpPageSize();
- final ConfigInfoTagPersistService configInfoTagPersistService;
+ final ConfigInfoGrayPersistService configInfoGrayPersistService;
}
diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/dump/processor/DumpAllProcessor.java b/config/src/main/java/com/alibaba/nacos/config/server/service/dump/processor/DumpAllProcessor.java
index a6d245011c2..2c07dd8a2d5 100644
--- a/config/src/main/java/com/alibaba/nacos/config/server/service/dump/processor/DumpAllProcessor.java
+++ b/config/src/main/java/com/alibaba/nacos/config/server/service/dump/processor/DumpAllProcessor.java
@@ -20,7 +20,6 @@
import com.alibaba.nacos.common.task.NacosTaskProcessor;
import com.alibaba.nacos.common.utils.MD5Utils;
import com.alibaba.nacos.config.server.model.ConfigInfoWrapper;
-import com.alibaba.nacos.config.server.service.AggrWhitelist;
import com.alibaba.nacos.config.server.service.ClientIpWhiteList;
import com.alibaba.nacos.config.server.service.ConfigCacheService;
import com.alibaba.nacos.config.server.service.SwitchService;
@@ -54,7 +53,9 @@ public DumpAllProcessor(ConfigInfoPersistService configInfoPersistService) {
@Override
public boolean process(NacosTask task) {
if (!(task instanceof DumpAllTask)) {
- DEFAULT_LOG.error("[all-dump-error] ,invalid task type,DumpAllProcessor should process DumpAllTask type.");
+ DEFAULT_LOG.error(
+ "[all-dump-error] ,invalid task type {},DumpAllProcessor should process DumpAllTask type.",
+ task.getClass().getSimpleName());
return false;
}
DumpAllTask dumpAllTask = (DumpAllTask) task;
@@ -106,9 +107,6 @@ public boolean process(NacosTask task) {
if (cf == null) {
continue;
}
- if (cf.getDataId().equals(AggrWhitelist.AGGRIDS_METADATA)) {
- AggrWhitelist.load(cf.getContent());
- }
if (cf.getDataId().equals(ClientIpWhiteList.CLIENT_IP_WHITELIST_METADATA)) {
ClientIpWhiteList.load(cf.getContent());
diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/dump/processor/DumpProcessor.java b/config/src/main/java/com/alibaba/nacos/config/server/service/dump/processor/DumpProcessor.java
index 8c5b2267feb..600ec730fd6 100644
--- a/config/src/main/java/com/alibaba/nacos/config/server/service/dump/processor/DumpProcessor.java
+++ b/config/src/main/java/com/alibaba/nacos/config/server/service/dump/processor/DumpProcessor.java
@@ -19,15 +19,13 @@
import com.alibaba.nacos.common.task.NacosTask;
import com.alibaba.nacos.common.task.NacosTaskProcessor;
import com.alibaba.nacos.common.utils.StringUtils;
-import com.alibaba.nacos.config.server.model.ConfigInfoBetaWrapper;
-import com.alibaba.nacos.config.server.model.ConfigInfoTagWrapper;
+import com.alibaba.nacos.config.server.model.ConfigInfoGrayWrapper;
import com.alibaba.nacos.config.server.model.ConfigInfoWrapper;
import com.alibaba.nacos.config.server.model.event.ConfigDumpEvent;
import com.alibaba.nacos.config.server.service.dump.DumpConfigHandler;
import com.alibaba.nacos.config.server.service.dump.task.DumpTask;
-import com.alibaba.nacos.config.server.service.repository.ConfigInfoBetaPersistService;
+import com.alibaba.nacos.config.server.service.repository.ConfigInfoGrayPersistService;
import com.alibaba.nacos.config.server.service.repository.ConfigInfoPersistService;
-import com.alibaba.nacos.config.server.service.repository.ConfigInfoTagPersistService;
import com.alibaba.nacos.config.server.utils.GroupKey2;
import com.alibaba.nacos.config.server.utils.LogUtil;
@@ -43,16 +41,12 @@ public class DumpProcessor implements NacosTaskProcessor {
final ConfigInfoPersistService configInfoPersistService;
- final ConfigInfoBetaPersistService configInfoBetaPersistService;
-
- final ConfigInfoTagPersistService configInfoTagPersistService;
+ final ConfigInfoGrayPersistService configInfoGrayPersistService;
public DumpProcessor(ConfigInfoPersistService configInfoPersistService,
- ConfigInfoBetaPersistService configInfoBetaPersistService,
- ConfigInfoTagPersistService configInfoTagPersistService) {
+ ConfigInfoGrayPersistService configInfoGrayPersistService) {
this.configInfoPersistService = configInfoPersistService;
- this.configInfoBetaPersistService = configInfoBetaPersistService;
- this.configInfoTagPersistService = configInfoTagPersistService;
+ this.configInfoGrayPersistService = configInfoGrayPersistService;
}
@Override
@@ -64,37 +58,26 @@ public boolean process(NacosTask task) {
String tenant = pair[2];
long lastModifiedOut = dumpTask.getLastModified();
String handleIp = dumpTask.getHandleIp();
- boolean isBeta = dumpTask.isBeta();
- String tag = dumpTask.getTag();
+ String grayName = dumpTask.getGrayName();
+
ConfigDumpEvent.ConfigDumpEventBuilder build = ConfigDumpEvent.builder().namespaceId(tenant).dataId(dataId)
- .group(group).isBeta(isBeta).tag(tag).handleIp(handleIp);
+ .group(group).grayName(grayName).handleIp(handleIp);
String type = "formal";
- if (isBeta) {
- type = "beta";
- } else if (StringUtils.isNotBlank(tag)) {
- type = "tag-" + tag;
+ if (StringUtils.isNotBlank(grayName)) {
+ type = grayName;
}
LogUtil.DUMP_LOG.info("[dump] process {} task. groupKey={}", type, dumpTask.getGroupKey());
- if (isBeta) {
- // if publish beta, then dump config, update beta cache
- ConfigInfoBetaWrapper cf = configInfoBetaPersistService.findConfigInfo4Beta(dataId, group, tenant);
- build.remove(Objects.isNull(cf));
- build.betaIps(Objects.isNull(cf) ? null : cf.getBetaIps());
- build.content(Objects.isNull(cf) ? null : cf.getContent());
- build.type(Objects.isNull(cf) ? null : cf.getType());
- build.encryptedDataKey(Objects.isNull(cf) ? null : cf.getEncryptedDataKey());
- build.lastModifiedTs(Objects.isNull(cf) ? lastModifiedOut : cf.getLastModified());
- return DumpConfigHandler.configDump(build.build());
- }
-
- if (StringUtils.isNotBlank(tag)) {
- ConfigInfoTagWrapper cf = configInfoTagPersistService.findConfigInfo4Tag(dataId, group, tenant, tag);
+ if (StringUtils.isNotBlank(grayName)) {
+ ConfigInfoGrayWrapper cf = configInfoGrayPersistService.findConfigInfo4Gray(dataId, group, tenant,
+ grayName);
build.remove(Objects.isNull(cf));
build.content(Objects.isNull(cf) ? null : cf.getContent());
build.type(Objects.isNull(cf) ? null : cf.getType());
build.encryptedDataKey(Objects.isNull(cf) ? null : cf.getEncryptedDataKey());
build.lastModifiedTs(Objects.isNull(cf) ? lastModifiedOut : cf.getLastModified());
+ build.grayName(grayName);
+ build.grayRule(Objects.isNull(cf) ? null : cf.getGrayRule());
return DumpConfigHandler.configDump(build.build());
}
diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/dump/task/DumpAllGrayTask.java b/config/src/main/java/com/alibaba/nacos/config/server/service/dump/task/DumpAllGrayTask.java
new file mode 100644
index 00000000000..dfdc4ee8c3d
--- /dev/null
+++ b/config/src/main/java/com/alibaba/nacos/config/server/service/dump/task/DumpAllGrayTask.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 1999-2023 Alibaba Group Holding Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.alibaba.nacos.config.server.service.dump.task;
+
+import com.alibaba.nacos.common.task.AbstractDelayTask;
+
+/**
+ * Dump all gray task.
+ *
+ * @author Nacos
+ * @date 2024/3/5
+ */
+public class DumpAllGrayTask extends AbstractDelayTask {
+
+ @Override
+ public void merge(AbstractDelayTask task) {
+ }
+
+ public static final String TASK_ID = "dumpAllGrayConfigTask";
+}
diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/dump/task/DumpTask.java b/config/src/main/java/com/alibaba/nacos/config/server/service/dump/task/DumpTask.java
index 9de5ea4544f..ca83b45eea3 100755
--- a/config/src/main/java/com/alibaba/nacos/config/server/service/dump/task/DumpTask.java
+++ b/config/src/main/java/com/alibaba/nacos/config/server/service/dump/task/DumpTask.java
@@ -25,19 +25,11 @@
*/
public class DumpTask extends AbstractDelayTask {
- public DumpTask(String groupKey, boolean isBeta, boolean isBatch, boolean isTag, String tag, long lastModified,
- String handleIp) {
+ public DumpTask(String groupKey, String grayName, long lastModified, String handleIp) {
this.groupKey = groupKey;
this.lastModified = lastModified;
this.handleIp = handleIp;
- this.isBeta = isBeta;
- if (isTag) {
- this.tag = tag;
- } else {
- this.tag = null;
- }
- this.isBatch = isBatch;
-
+ this.grayName = grayName;
//retry interval: 1s
setTaskInterval(1000L);
}
@@ -52,11 +44,7 @@ public void merge(AbstractDelayTask task) {
final String handleIp;
- final boolean isBeta;
-
- final String tag;
-
- final boolean isBatch;
+ final String grayName;
public String getGroupKey() {
return groupKey;
@@ -70,16 +58,8 @@ public String getHandleIp() {
return handleIp;
}
- public boolean isBeta() {
- return isBeta;
- }
-
- public String getTag() {
- return tag;
- }
-
- public boolean isBatch() {
- return isBatch;
+ public String getGrayName() {
+ return grayName;
}
}
diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/merge/MergeDataTask.java b/config/src/main/java/com/alibaba/nacos/config/server/service/merge/MergeDataTask.java
deleted file mode 100755
index 8ea2d2402d4..00000000000
--- a/config/src/main/java/com/alibaba/nacos/config/server/service/merge/MergeDataTask.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright 1999-2018 Alibaba Group Holding Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.alibaba.nacos.config.server.service.merge;
-
-import com.alibaba.nacos.common.task.AbstractDelayTask;
-
-/**
- * Represents the task of aggregating data.
- *
- * @author jiuRen
- */
-class MergeDataTask extends AbstractDelayTask {
-
- MergeDataTask(String dataId, String groupId, String tenant, String clientIp) {
- this(dataId, groupId, tenant, null, clientIp);
- }
-
- MergeDataTask(String dataId, String groupId, String tenant, String tag, String clientIp) {
- this.dataId = dataId;
- this.groupId = groupId;
- this.tenant = tenant;
- this.tag = tag;
- this.clientIp = clientIp;
-
- // aggregation delay
- setTaskInterval(DELAY);
- setLastProcessTime(System.currentTimeMillis());
- }
-
- @Override
- public void merge(AbstractDelayTask task) {
- }
-
- public String getId() {
- return toString();
- }
-
- @Override
- public String toString() {
- return "MergeTask[" + dataId + ", " + groupId + ", " + tenant + ", " + clientIp + "]";
- }
-
- public String getClientIp() {
- return clientIp;
- }
-
- static final long DELAY = 0L;
-
- final String dataId;
-
- final String groupId;
-
- final String tenant;
-
- final String tag;
-
- private final String clientIp;
-}
diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/merge/MergeDatumService.java b/config/src/main/java/com/alibaba/nacos/config/server/service/merge/MergeDatumService.java
deleted file mode 100644
index cb039bfe75d..00000000000
--- a/config/src/main/java/com/alibaba/nacos/config/server/service/merge/MergeDatumService.java
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * Copyright 1999-2018 Alibaba Group Holding Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.alibaba.nacos.config.server.service.merge;
-
-import com.alibaba.nacos.common.utils.MD5Utils;
-import com.alibaba.nacos.common.utils.StringUtils;
-import com.alibaba.nacos.config.server.constant.Constants;
-import com.alibaba.nacos.config.server.manager.TaskManager;
-import com.alibaba.nacos.config.server.model.ConfigInfo;
-import com.alibaba.nacos.config.server.model.ConfigInfoAggr;
-import com.alibaba.nacos.config.server.model.ConfigInfoChanged;
-import com.alibaba.nacos.config.server.service.ConfigCacheService;
-import com.alibaba.nacos.config.server.service.repository.ConfigInfoAggrPersistService;
-import com.alibaba.nacos.config.server.service.repository.ConfigInfoPersistService;
-import com.alibaba.nacos.config.server.service.repository.ConfigInfoTagPersistService;
-import com.alibaba.nacos.config.server.utils.ContentUtils;
-import com.alibaba.nacos.config.server.utils.GroupKey;
-import com.alibaba.nacos.core.distributed.ProtocolManager;
-import com.alibaba.nacos.persistence.configuration.DatasourceConfiguration;
-import com.alibaba.nacos.persistence.constants.PersistenceConstant;
-import com.alibaba.nacos.persistence.model.Page;
-import com.alibaba.nacos.sys.env.EnvUtil;
-import com.alibaba.nacos.sys.utils.ApplicationUtils;
-import com.alibaba.nacos.sys.utils.InetUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicInteger;
-
-/**
- * Data aggregation service.
- *
- * Full aggregation at startup and single aggregation triggered by data modification.
- *
- * @author jiuRen
- */
-@Service
-public class MergeDatumService {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(MergeDatumService.class);
-
- final TaskManager mergeTasks;
-
- static final int INIT_THREAD_COUNT = 40;
-
- static final AtomicInteger FINISHED = new AtomicInteger();
-
- static int total = 0;
-
- private ConfigInfoPersistService configInfoPersistService;
-
- private ConfigInfoAggrPersistService configInfoAggrPersistService;
-
- @Autowired
- public MergeDatumService(ConfigInfoPersistService configInfoPersistService,
- ConfigInfoAggrPersistService configInfoAggrPersistService,
- ConfigInfoTagPersistService configInfoTagPersistService) {
- this.configInfoPersistService = configInfoPersistService;
- this.configInfoAggrPersistService = configInfoAggrPersistService;
- mergeTasks = new TaskManager("com.alibaba.nacos.MergeDatum");
- mergeTasks.setDefaultTaskProcessor(
- new MergeTaskProcessor(configInfoPersistService, configInfoAggrPersistService,
- configInfoTagPersistService, this));
- }
-
- /**
- * splitList.
- *
- * @param list list to split.
- * @param count count expect to be split.
- * @return
- */
- public List> splitList(List list, int count) {
- List> result = new ArrayList<>(count);
- for (int i = 0; i < count; i++) {
- result.add(new ArrayList<>());
- }
- for (int i = 0; i < list.size(); i++) {
- ConfigInfoChanged config = list.get(i);
- result.get(i % count).add(config);
- }
- return result;
- }
-
- /**
- * Called after data changes to add aggregation tasks.
- */
- public void addMergeTask(String dataId, String groupId, String tenant, String clientIp) {
- if (!canExecute()) {
- return;
- }
- MergeDataTask task = new MergeDataTask(dataId, groupId, tenant, clientIp);
- mergeTasks.addTask(task.getId(), task);
- }
-
- private boolean canExecute() {
- if (!DatasourceConfiguration.isEmbeddedStorage()) {
- return true;
- }
- if (EnvUtil.getStandaloneMode()) {
- return true;
- }
- ProtocolManager protocolManager = ApplicationUtils.getBean(ProtocolManager.class);
- return protocolManager.getCpProtocol().isLeader(PersistenceConstant.CONFIG_MODEL_RAFT_GROUP);
- }
-
- void executeMergeConfigTask(List configInfoList, int pageSize) {
- for (ConfigInfoChanged configInfo : configInfoList) {
- String dataId = configInfo.getDataId();
- String group = configInfo.getGroup();
- String tenant = configInfo.getTenant();
- try {
- List datumList = new ArrayList<>();
- int rowCount = configInfoAggrPersistService.aggrConfigInfoCount(dataId, group, tenant);
- int pageCount = (int) Math.ceil(rowCount * 1.0 / pageSize);
- for (int pageNo = 1; pageNo <= pageCount; pageNo++) {
- Page page = configInfoAggrPersistService.findConfigInfoAggrByPage(dataId, group,
- tenant, pageNo, pageSize);
- if (page != null) {
- datumList.addAll(page.getPageItems());
- LOGGER.info("[merge-query] {}, {}, size/total={}/{}", dataId, group, datumList.size(),
- rowCount);
- }
- }
-
- // merge
- if (datumList.size() > 0) {
- ConfigInfo cf = MergeTaskProcessor.merge(dataId, group, tenant, datumList);
- String aggrContent = cf.getContent();
- String localContentMD5 = ConfigCacheService.getContentMd5(GroupKey.getKey(dataId, group));
- String aggrConetentMD5 = MD5Utils.md5Hex(aggrContent, Constants.ENCODE);
-
- if (!StringUtils.equals(localContentMD5, aggrConetentMD5)) {
- configInfoPersistService.insertOrUpdate(null, null, cf, null);
- LOGGER.info("[merge-ok] {}, {}, size={}, length={}, md5={}, content={}", dataId, group,
- datumList.size(), cf.getContent().length(), cf.getMd5(),
- ContentUtils.truncateContent(cf.getContent()));
- }
- } else {
- // remove config info
- configInfoPersistService.removeConfigInfo(dataId, group, tenant, InetUtils.getSelfIP(), null);
- LOGGER.warn("[merge-delete] delete config info because no datum. dataId=" + dataId + ", groupId="
- + group);
- }
-
- } catch (Throwable e) {
- LOGGER.info("[merge-error] " + dataId + ", " + group + ", " + e.toString(), e);
- }
- FINISHED.incrementAndGet();
- if (FINISHED.get() % 100 == 0) {
- LOGGER.info("[all-merge-dump] {} / {}", FINISHED.get(), total);
- }
- }
- LOGGER.info("[all-merge-dump] {} / {}", FINISHED.get(), total);
- }
-
- public void executeConfigsMerge(List configInfoList) {
- new MergeAllDataWorker(configInfoList).start();
- }
-
- public class MergeAllDataWorker extends Thread {
-
- static final int PAGE_SIZE = 10000;
-
- private List configInfoList;
-
- public MergeAllDataWorker(List configInfoList) {
- super("MergeAllDataWorker");
- this.configInfoList = configInfoList;
- }
-
- @Override
- public void run() {
- executeMergeConfigTask(configInfoList, PAGE_SIZE);
- }
- }
-}
diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/merge/MergeTaskProcessor.java b/config/src/main/java/com/alibaba/nacos/config/server/service/merge/MergeTaskProcessor.java
deleted file mode 100755
index 89745589fdc..00000000000
--- a/config/src/main/java/com/alibaba/nacos/config/server/service/merge/MergeTaskProcessor.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * Copyright 1999-2018 Alibaba Group Holding Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.alibaba.nacos.config.server.service.merge;
-
-import com.alibaba.nacos.common.notify.NotifyCenter;
-import com.alibaba.nacos.common.task.NacosTask;
-import com.alibaba.nacos.config.server.constant.Constants;
-import com.alibaba.nacos.common.task.NacosTaskProcessor;
-import com.alibaba.nacos.config.server.model.ConfigInfo;
-import com.alibaba.nacos.config.server.model.ConfigInfoAggr;
-import com.alibaba.nacos.persistence.model.Page;
-import com.alibaba.nacos.config.server.model.event.ConfigDataChangeEvent;
-import com.alibaba.nacos.config.server.service.repository.ConfigInfoAggrPersistService;
-import com.alibaba.nacos.config.server.service.repository.ConfigInfoPersistService;
-import com.alibaba.nacos.config.server.service.repository.ConfigInfoTagPersistService;
-import com.alibaba.nacos.config.server.service.trace.ConfigTraceService;
-import com.alibaba.nacos.config.server.utils.ContentUtils;
-import com.alibaba.nacos.config.server.utils.TimeUtils;
-import com.alibaba.nacos.sys.utils.InetUtils;
-import com.alibaba.nacos.common.utils.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Merge task processor.
- *
- * @author Nacos
- */
-public class MergeTaskProcessor implements NacosTaskProcessor {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(MergeTaskProcessor.class);
-
- private static final int PAGE_SIZE = 10000;
-
- private ConfigInfoPersistService configInfoPersistService;
-
- private ConfigInfoAggrPersistService configInfoAggrPersistService;
-
- private ConfigInfoTagPersistService configInfoTagPersistService;
-
- private MergeDatumService mergeService;
-
- MergeTaskProcessor(ConfigInfoPersistService configInfoPersistService,
- ConfigInfoAggrPersistService configInfoAggrPersistService,
- ConfigInfoTagPersistService configInfoTagPersistService, MergeDatumService mergeService) {
- this.configInfoPersistService = configInfoPersistService;
- this.configInfoAggrPersistService = configInfoAggrPersistService;
- this.configInfoTagPersistService = configInfoTagPersistService;
- this.mergeService = mergeService;
- }
-
- @Override
- public boolean process(NacosTask task) {
- MergeDataTask mergeTask = (MergeDataTask) task;
- final String dataId = mergeTask.dataId;
- final String group = mergeTask.groupId;
- final String tenant = mergeTask.tenant;
- final String tag = mergeTask.tag;
- final String clientIp = mergeTask.getClientIp();
- try {
- List datumList = new ArrayList<>();
- int rowCount = configInfoAggrPersistService.aggrConfigInfoCount(dataId, group, tenant);
- int pageCount = (int) Math.ceil(rowCount * 1.0 / PAGE_SIZE);
- for (int pageNo = 1; pageNo <= pageCount; pageNo++) {
- Page page = configInfoAggrPersistService.findConfigInfoAggrByPage(dataId, group, tenant,
- pageNo, PAGE_SIZE);
- if (page != null) {
- datumList.addAll(page.getPageItems());
- LOGGER.info("[merge-query] {}, {}, size/total={}/{}", dataId, group, datumList.size(), rowCount);
- }
- }
-
- final Timestamp time = TimeUtils.getCurrentTime();
- if (datumList.size() > 0) {
- // merge
- ConfigInfo cf = merge(dataId, group, tenant, datumList);
-
- configInfoPersistService.insertOrUpdate(null, null, cf, null);
-
- LOGGER.info("[merge-ok] {}, {}, size={}, length={}, md5={}, content={}", dataId, group,
- datumList.size(), cf.getContent().length(), cf.getMd5(),
- ContentUtils.truncateContent(cf.getContent()));
-
- ConfigTraceService.logPersistenceEvent(dataId, group, tenant, null, time.getTime(),
- InetUtils.getSelfIP(), ConfigTraceService.PERSISTENCE_EVENT,
- ConfigTraceService.PERSISTENCE_TYPE_MERGE, cf.getContent());
- } else {
- String eventType;
-
- // remove
- if (StringUtils.isBlank(tag)) {
- eventType = ConfigTraceService.PERSISTENCE_EVENT;
-
- configInfoPersistService.removeConfigInfo(dataId, group, tenant, clientIp, null);
- } else {
- eventType = ConfigTraceService.PERSISTENCE_EVENT_TAG + "-" + tag;
-
- configInfoTagPersistService.removeConfigInfoTag(dataId, group, tenant, tag, clientIp, null);
- }
-
- LOGGER.warn(
- "[merge-delete] delete config info because no datum. dataId=" + dataId + ", groupId=" + group);
-
- ConfigTraceService.logPersistenceEvent(dataId, group, tenant, null, time.getTime(),
- InetUtils.getSelfIP(), eventType, ConfigTraceService.PERSISTENCE_TYPE_REMOVE, null);
- }
- NotifyCenter.publishEvent(new ConfigDataChangeEvent(false, dataId, group, tenant, tag, time.getTime()));
-
- } catch (Exception e) {
- mergeService.addMergeTask(dataId, group, tenant, mergeTask.getClientIp());
- LOGGER.info("[merge-error] " + dataId + ", " + group + ", " + e.toString(), e);
- }
-
- return true;
- }
-
- /**
- * merge datumList {@link ConfigInfoAggr}.
- *
- * @param dataId data id
- * @param group group
- * @param tenant tenant
- * @param datumList datumList
- * @return {@link ConfigInfo}
- */
- public static ConfigInfo merge(String dataId, String group, String tenant, List datumList) {
- StringBuilder sb = new StringBuilder();
- String appName = null;
- for (ConfigInfoAggr aggrInfo : datumList) {
- if (aggrInfo.getAppName() != null) {
- appName = aggrInfo.getAppName();
- }
- sb.append(aggrInfo.getContent());
- sb.append(Constants.NACOS_LINE_SEPARATOR);
- }
- String content = sb.substring(0, sb.lastIndexOf(Constants.NACOS_LINE_SEPARATOR));
- return new ConfigInfo(dataId, group, tenant, appName, content);
- }
-}
diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/notify/AsyncNotifyService.java b/config/src/main/java/com/alibaba/nacos/config/server/service/notify/AsyncNotifyService.java
index cb66c8f4d22..ce9abebc0a9 100644
--- a/config/src/main/java/com/alibaba/nacos/config/server/service/notify/AsyncNotifyService.java
+++ b/config/src/main/java/com/alibaba/nacos/config/server/service/notify/AsyncNotifyService.java
@@ -25,11 +25,14 @@
import com.alibaba.nacos.common.task.AbstractDelayTask;
import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.config.server.model.event.ConfigDataChangeEvent;
+import com.alibaba.nacos.config.server.model.gray.BetaGrayRule;
+import com.alibaba.nacos.config.server.model.gray.TagGrayRule;
import com.alibaba.nacos.config.server.monitor.MetricsMonitor;
import com.alibaba.nacos.config.server.remote.ConfigClusterRpcClientProxy;
import com.alibaba.nacos.config.server.service.trace.ConfigTraceService;
import com.alibaba.nacos.config.server.utils.ConfigExecutor;
import com.alibaba.nacos.config.server.utils.LogUtil;
+import com.alibaba.nacos.config.server.utils.PropertyUtil;
import com.alibaba.nacos.core.cluster.Member;
import com.alibaba.nacos.core.cluster.NodeState;
import com.alibaba.nacos.core.cluster.ServerMemberManager;
@@ -47,6 +50,8 @@
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
+import static com.alibaba.nacos.core.cluster.MemberMetaDataConstants.SUPPORT_GRAY_MODEL;
+
/**
* Async notify service.
*
@@ -101,12 +106,8 @@ public Class extends Event> subscribeType() {
void handleConfigDataChangeEvent(Event event) {
if (event instanceof ConfigDataChangeEvent) {
ConfigDataChangeEvent evt = (ConfigDataChangeEvent) event;
- long dumpTs = evt.lastModifiedTs;
- String dataId = evt.dataId;
- String group = evt.group;
- String tenant = evt.tenant;
- String tag = evt.tag;
- MetricsMonitor.incrementConfigChangeCount(tenant, group, dataId);
+
+ MetricsMonitor.incrementConfigChangeCount(evt.tenant, evt.group, evt.dataId);
Collection ipList = memberManager.allMembersWithoutSelf();
@@ -115,8 +116,11 @@ void handleConfigDataChangeEvent(Event event) {
for (Member member : ipList) {
// grpc report data change only
- rpcQueue.add(
- new NotifySingleRpcTask(dataId, group, tenant, tag, dumpTs, evt.isBeta, evt.isBatch, member));
+ NotifySingleRpcTask notifySingleRpcTask = generateTask(evt, member);
+ if (notifySingleRpcTask != null) {
+ rpcQueue.add(notifySingleRpcTask);
+ }
+
}
if (!rpcQueue.isEmpty()) {
ConfigExecutor.executeAsyncNotify(new AsyncRpcTask(rpcQueue));
@@ -124,6 +128,30 @@ void handleConfigDataChangeEvent(Event event) {
}
}
+ private NotifySingleRpcTask generateTask(ConfigDataChangeEvent configDataChangeEvent, Member member) {
+
+ NotifySingleRpcTask task = new NotifySingleRpcTask(configDataChangeEvent.dataId, configDataChangeEvent.group,
+ configDataChangeEvent.tenant, configDataChangeEvent.grayName, configDataChangeEvent.lastModifiedTs,
+ member);
+
+ if (PropertyUtil.isGrayCompatibleModel() && StringUtils.isNotBlank(configDataChangeEvent.grayName)) {
+
+ // old server should set beta or tag flag
+ if (!(Boolean) member.getExtendInfo().getOrDefault(SUPPORT_GRAY_MODEL, Boolean.FALSE)) {
+ String underLine = "_";
+ task.setBeta(BetaGrayRule.TYPE_BETA.equals(configDataChangeEvent.grayName));
+ if (configDataChangeEvent.grayName.startsWith(TagGrayRule.TYPE_TAG + underLine)) {
+ task.setTag(configDataChangeEvent.grayName.substring(
+ configDataChangeEvent.grayName.indexOf(TagGrayRule.TYPE_TAG + underLine) + 4));
+ }
+
+ }
+ }
+
+ // compatible with gray model
+ return task;
+ }
+
private boolean isUnHealthy(String targetIp) {
return !memberManager.stateCheck(targetIp, HEALTHY_CHECK_STATUS);
}
@@ -134,12 +162,12 @@ void executeAsyncRpcTask(Queue queue) {
ConfigChangeClusterSyncRequest syncRequest = new ConfigChangeClusterSyncRequest();
syncRequest.setDataId(task.getDataId());
+ syncRequest.setTenant(task.getTenant());
syncRequest.setGroup(task.getGroup());
- syncRequest.setBeta(task.isBeta());
syncRequest.setLastModified(task.getLastModified());
+ syncRequest.setGrayName(task.getGrayName());
+ syncRequest.setBeta(task.isBeta());
syncRequest.setTag(task.getTag());
- syncRequest.setBatch(task.isBatch());
- syncRequest.setTenant(task.getTenant());
Member member = task.member;
String event = getNotifyEvent(task);
@@ -200,27 +228,24 @@ public static class NotifySingleRpcTask extends AbstractDelayTask {
private Member member;
+ private String grayName;
+
+ @Deprecated
private boolean isBeta;
+ @Deprecated
private String tag;
- private boolean isBatch;
-
- public NotifySingleRpcTask(String dataId, String group, String tenant, String tag, long lastModified,
- boolean isBeta, boolean isBatch, Member member) {
- this(dataId, group, tenant, lastModified);
- this.member = member;
- this.isBeta = isBeta;
- this.tag = tag;
- this.isBatch = isBatch;
- }
-
- private NotifySingleRpcTask(String dataId, String group, String tenant, long lastModified) {
+ public NotifySingleRpcTask(String dataId, String group, String tenant, String grayName, long lastModified,
+ Member member) {
this.dataId = dataId;
this.group = group;
this.tenant = tenant;
this.lastModified = lastModified;
+ this.member = member;
+ this.grayName = grayName;
setTaskInterval(3000L);
+
}
public boolean isBeta() {
@@ -239,12 +264,12 @@ public void setTag(String tag) {
this.tag = tag;
}
- public boolean isBatch() {
- return isBatch;
+ public String getGrayName() {
+ return grayName;
}
- public void setBatch(boolean batch) {
- isBatch = batch;
+ public void setGrayName(String grayName) {
+ this.grayName = grayName;
}
public String getDataId() {
@@ -293,8 +318,8 @@ private static String getNotifyEvent(NotifySingleRpcTask task) {
event = ConfigTraceService.NOTIFY_EVENT_BETA;
} else if (!StringUtils.isBlank(task.tag)) {
event = ConfigTraceService.NOTIFY_EVENT_TAG + "-" + task.tag;
- } else if (task.isBatch()) {
- event = ConfigTraceService.NOTIFY_EVENT_BATCH;
+ } else if (StringUtils.isNotBlank(task.grayName)) {
+ event = ConfigTraceService.NOTIFY_EVENT + "-" + task.grayName;
}
return event;
}
diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/ConfigInfoAggrPersistService.java b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/ConfigInfoAggrPersistService.java
deleted file mode 100644
index 6a1df0859ea..00000000000
--- a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/ConfigInfoAggrPersistService.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright 1999-2022 Alibaba Group Holding Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.alibaba.nacos.config.server.service.repository;
-
-import com.alibaba.nacos.config.server.model.ConfigInfoAggr;
-import com.alibaba.nacos.config.server.model.ConfigInfoChanged;
-import com.alibaba.nacos.persistence.model.Page;
-import com.alibaba.nacos.persistence.repository.PaginationHelper;
-
-import java.util.List;
-import java.util.Map;
-
-/**
- * Database service, providing access to config_info_aggr in the database.
- *
- * @author lixiaoshuang
- */
-public interface ConfigInfoAggrPersistService {
-
- Object[] EMPTY_ARRAY = new Object[] {};
-
- String PATTERN_STR = "*";
-
- /**
- * create Pagination utils.
- *
- * @param Generic object
- * @return {@link PaginationHelper}
- */
- PaginationHelper createPaginationHelper();
-
- //------------------------------------------insert---------------------------------------------//
-
- /**
- * Add data before aggregation to the database, select -> update or insert .
- *
- * @param dataId data id
- * @param group group
- * @param tenant tenant
- * @param datumId datum id
- * @param appName app name
- * @param content config content
- * @return {@code true} if add success
- */
- boolean addAggrConfigInfo(final String dataId, final String group, String tenant, final String datumId,
- String appName, final String content);
-
- /**
- * Add or update data in batches. Any exception during the transaction will force a TransactionSystemException to be
- * thrown.
- *
- * @param dataId dataId
- * @param group group
- * @param tenant tenant
- * @param appName app name
- * @param datumMap datumMap
- * @return {@code true} if publish success
- */
- boolean batchPublishAggr(final String dataId, final String group, final String tenant,
- final Map datumMap, final String appName);
-
-
- //------------------------------------------select---------------------------------------------//
-
- /**
- * Get count of aggregation config info.
- *
- * @param dataId data id
- * @param group group
- * @param tenant tenant
- * @return count
- */
- int aggrConfigInfoCount(String dataId, String group, String tenant);
-
- /**
- * Query aggregation config info.
- *
- * @param dataId data id
- * @param group group
- * @param tenant tenant
- * @param pageNo page number
- * @param pageSize page size
- * @return {@link Page} with {@link ConfigInfoAggr} generation
- */
- Page findConfigInfoAggrByPage(String dataId, String group, String tenant, final int pageNo,
- final int pageSize);
-
- /**
- * Find all aggregated data sets.
- *
- * @return {@link ConfigInfoChanged} list
- */
- List findAllAggrGroup();
-
-}
diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/ConfigInfoBetaPersistService.java b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/ConfigInfoBetaPersistService.java
index 69d5cd9c892..f98b43a6065 100644
--- a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/ConfigInfoBetaPersistService.java
+++ b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/ConfigInfoBetaPersistService.java
@@ -27,9 +27,10 @@
/**
* Database service, providing access to config_info_beta in the database.
- *
+ * Deprecated since 2.5.0,only support on compatibility,replaced with ConfigInfoGray model, will be soon removed on further version.
* @author lixiaoshuang
*/
+@Deprecated
public interface ConfigInfoBetaPersistService {
/**
diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/ConfigInfoGrayPersistService.java b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/ConfigInfoGrayPersistService.java
new file mode 100644
index 00000000000..791b620d3b5
--- /dev/null
+++ b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/ConfigInfoGrayPersistService.java
@@ -0,0 +1,201 @@
+/*
+ * Copyright 1999-2022 Alibaba Group Holding Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.alibaba.nacos.config.server.service.repository;
+
+import com.alibaba.nacos.config.server.model.ConfigInfo;
+import com.alibaba.nacos.config.server.model.ConfigInfoGrayWrapper;
+import com.alibaba.nacos.config.server.model.ConfigInfoStateWrapper;
+import com.alibaba.nacos.config.server.model.ConfigOperateResult;
+import com.alibaba.nacos.persistence.model.Page;
+import com.alibaba.nacos.persistence.repository.PaginationHelper;
+
+import java.sql.Timestamp;
+import java.util.List;
+
+/**
+ * Database service, providing access to config_info_gray in the database.
+ *
+ * @author rong
+ */
+public interface ConfigInfoGrayPersistService {
+
+ /**
+ * create Pagination utils.
+ *
+ * @param Generic object
+ * @return {@link PaginationHelper}
+ */
+ PaginationHelper createPaginationHelper();
+
+ //------------------------------------------insert---------------------------------------------//
+
+
+ /**
+ * get gray config info state.
+ *
+ * @param dataId dataId.
+ * @param group group.
+ * @param tenant tenant.
+ * @param grayName gray name.
+ * @return config info state.
+ */
+ ConfigInfoStateWrapper findConfigInfo4GrayState(final String dataId, final String group, final String tenant,
+ String grayName);
+
+ /**
+ * Add gray configuration information and publish data change events.
+ *
+ * @param configInfo config info
+ * @param grayName gray name
+ * @param grayRule gray rule
+ * @param srcIp remote ip
+ * @param srcUser user
+ * @return config operation result.
+ */
+ ConfigOperateResult addConfigInfo4Gray(ConfigInfo configInfo, String grayName, String grayRule,
+ String srcIp, String srcUser);
+
+ /**
+ * Adds configuration information with database atomic operations, minimizing SQL actions and avoiding business
+ * encapsulation.
+ *
+ * @param configGrayId the ID for the gray configuration
+ * @param configInfo the configuration information to be added
+ * @param grayName the name of the gray configuration
+ * @param grayRule the rule of the gray configuration
+ * @param srcIp the IP address of the source
+ * @param srcUser the user who performs the addition
+ */
+ void addConfigInfoGrayAtomic(final long configGrayId, final ConfigInfo configInfo, final String grayName, final String grayRule,
+ final String srcIp, final String srcUser);
+
+ /**
+ * insert or update gray config.
+ *
+ * @param configInfo config info
+ * @param grayName gray name
+ * @param grayRule gray rule
+ * @param srcIp remote ip
+ * @param srcUser user
+ * @return config operation result.
+ */
+ ConfigOperateResult insertOrUpdateGray(final ConfigInfo configInfo, final String grayName, final String grayRule,
+ final String srcIp, final String srcUser);
+
+ /**
+ * insert or update gray config cas.
+ *
+ * @param configInfo config info.
+ * @param grayName gray name
+ * @param grayRule gray rule
+ * @param srcIp remote ip.
+ * @param srcUser user.
+ * @return config operation result.
+ */
+ ConfigOperateResult insertOrUpdateGrayCas(final ConfigInfo configInfo, final String grayName, final String grayRule,
+ final String srcIp, final String srcUser);
+ //------------------------------------------delete---------------------------------------------//
+
+ /**
+ * Delete configuration; database atomic operation, minimum SQL action, no business encapsulation.
+ *
+ * @param dataId dataId
+ * @param group group
+ * @param tenant tenant
+ * @param grayName gray name
+ * @param srcIp remote ip
+ * @param srcUser user
+ */
+ void removeConfigInfoGray(final String dataId, final String group, final String tenant, final String grayName,
+ final String srcIp, final String srcUser);
+ //------------------------------------------update---------------------------------------------//
+
+ /**
+ * Update gray configuration information.
+ *
+ * @param configInfo config info
+ * @param grayName gray name
+ * @param grayRule gray rule
+ * @param srcIp remote ip
+ * @param srcUser user
+ * @return config operation result.
+ */
+ ConfigOperateResult updateConfigInfo4Gray(ConfigInfo configInfo, String grayName, String grayRule,
+ String srcIp, String srcUser);
+
+ /**
+ * Update gray configuration information.
+ *
+ * @param configInfo config info
+ * @param grayName gray name
+ * @param grayRule gray rule
+ * @param srcIp remote ip
+ * @param srcUser user
+ * @return success or not.
+ */
+ ConfigOperateResult updateConfigInfo4GrayCas(ConfigInfo configInfo, String grayName, String grayRule,
+ String srcIp, String srcUser);
+ //------------------------------------------select---------------------------------------------//
+
+ /**
+ * Query gray configuration information based on dataId and group.
+ *
+ * @param dataId data id
+ * @param group group
+ * @param tenant tenant
+ * @param grayName gray name
+ * @return ConfigInfoGrayWrapper gray model instance.
+ */
+ ConfigInfoGrayWrapper findConfigInfo4Gray(final String dataId, final String group, final String tenant,
+ final String grayName);
+
+ /**
+ * Returns the number of gray configuration items.
+ *
+ * @return number of configuration items.
+ */
+ int configInfoGrayCount();
+
+ /**
+ * Query all gray config info for dump task.
+ *
+ * @param pageNo page numbser
+ * @param pageSize page sizxe
+ * @return {@link Page} with {@link ConfigInfoGrayWrapper} generation
+ */
+ Page findAllConfigInfoGrayForDumpAll(final int pageNo, final int pageSize);
+
+ /**
+ * Query all gray config info for dump task.
+ *
+ * @param startTime startTime
+ * @param lastMaxId lastMaxId
+ * @param pageSize pageSize
+ * @return {@link Page} with {@link ConfigInfoGrayWrapper} generation
+ */
+ List findChangeConfig(final Timestamp startTime, long lastMaxId, final int pageSize);
+
+ /**
+ * found all config grays.
+ *
+ * @param dataId dataId.
+ * @param group group.
+ * @param tenant tenant.
+ * @return
+ */
+ List findConfigInfoGrays(final String dataId, final String group, final String tenant);
+}
diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/ConfigInfoPersistService.java b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/ConfigInfoPersistService.java
index afb006529e0..d182900fa2a 100644
--- a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/ConfigInfoPersistService.java
+++ b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/ConfigInfoPersistService.java
@@ -169,10 +169,10 @@ void removeConfigInfo(final String dataId, final String group, final String tena
* @param ids id list
* @param srcIp remote ip
* @param srcUser user
- * @return {@link ConfigInfo} list
+ * @return {@link ConfigAllInfo} list
* @author klw
*/
- List removeConfigInfoByIds(final List ids, final String srcIp, final String srcUser);
+ List removeConfigInfoByIds(final List ids, final String srcIp, final String srcUser);
/**
* Delete tag.
diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/ConfigInfoTagPersistService.java b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/ConfigInfoTagPersistService.java
index 06306b22662..a864977b2b8 100644
--- a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/ConfigInfoTagPersistService.java
+++ b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/ConfigInfoTagPersistService.java
@@ -29,9 +29,10 @@
/**
* Database service, providing access to config_info_tag in the database.
- *
+ * Deprecated since 2.5.0,only support on compatibility,replaced with ConfigInfoGray model, will be soon removed on further version.
* @author lixiaoshuang
*/
+@Deprecated
public interface ConfigInfoTagPersistService {
/**
diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/ConfigRowMapperInjector.java b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/ConfigRowMapperInjector.java
index 8b45b37905e..927d84a1a12 100644
--- a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/ConfigRowMapperInjector.java
+++ b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/ConfigRowMapperInjector.java
@@ -22,10 +22,10 @@
import com.alibaba.nacos.config.server.model.ConfigInfo;
import com.alibaba.nacos.config.server.model.ConfigInfo4Beta;
import com.alibaba.nacos.config.server.model.ConfigInfo4Tag;
-import com.alibaba.nacos.config.server.model.ConfigInfoAggr;
import com.alibaba.nacos.config.server.model.ConfigInfoBase;
import com.alibaba.nacos.config.server.model.ConfigInfoBetaWrapper;
import com.alibaba.nacos.config.server.model.ConfigInfoChanged;
+import com.alibaba.nacos.config.server.model.ConfigInfoGrayWrapper;
import com.alibaba.nacos.config.server.model.ConfigInfoStateWrapper;
import com.alibaba.nacos.config.server.model.ConfigInfoTagWrapper;
import com.alibaba.nacos.config.server.model.ConfigInfoWrapper;
@@ -55,6 +55,8 @@ public class ConfigRowMapperInjector {
public static final ConfigInfoTagWrapperRowMapper CONFIG_INFO_TAG_WRAPPER_ROW_MAPPER = new ConfigInfoTagWrapperRowMapper();
+ public static final ConfigInfoGrayWrapperRowMapper CONFIG_INFO_GRAY_WRAPPER_ROW_MAPPER = new ConfigInfoGrayWrapperRowMapper();
+
public static final ConfigInfoRowMapper CONFIG_INFO_ROW_MAPPER = new ConfigInfoRowMapper();
public static final ConfigAdvanceInfoRowMapper CONFIG_ADVANCE_INFO_ROW_MAPPER = new ConfigAdvanceInfoRowMapper();
@@ -67,8 +69,6 @@ public class ConfigRowMapperInjector {
public static final ConfigInfoBaseRowMapper CONFIG_INFO_BASE_ROW_MAPPER = new ConfigInfoBaseRowMapper();
- public static final ConfigInfoAggrRowMapper CONFIG_INFO_AGGR_ROW_MAPPER = new ConfigInfoAggrRowMapper();
-
public static final ConfigInfoChangedRowMapper CONFIG_INFO_CHANGED_ROW_MAPPER = new ConfigInfoChangedRowMapper();
public static final ConfigHistoryRowMapper HISTORY_LIST_ROW_MAPPER = new ConfigHistoryRowMapper();
@@ -146,12 +146,6 @@ private static void injectConfigRowMapper() {
ConfigRowMapperInjector.CONFIG_INFO_BASE_ROW_MAPPER.getClass().getCanonicalName(),
ConfigRowMapperInjector.CONFIG_INFO_BASE_ROW_MAPPER);
- // CONFIG_INFO_AGGR_ROW_MAPPER
-
- RowMapperManager.registerRowMapper(
- ConfigRowMapperInjector.CONFIG_INFO_AGGR_ROW_MAPPER.getClass().getCanonicalName(),
- ConfigRowMapperInjector.CONFIG_INFO_AGGR_ROW_MAPPER);
-
// CONFIG_INFO_CHANGED_ROW_MAPPER
RowMapperManager.registerRowMapper(
@@ -181,7 +175,7 @@ public ConfigInfoWrapper mapRow(ResultSet rs, int rowNum) throws SQLException {
info.setGroup(rs.getString("group_id"));
info.setTenant(rs.getString("tenant_id"));
info.setAppName(rs.getString("app_name"));
-
+
try {
info.setType(rs.getString("type"));
} catch (SQLException ignore) {
@@ -305,6 +299,48 @@ public ConfigInfoTagWrapper mapRow(ResultSet rs, int rowNum) throws SQLException
}
}
+ public static final class ConfigInfoGrayWrapperRowMapper implements RowMapper {
+
+ @Override
+ public ConfigInfoGrayWrapper mapRow(ResultSet rs, int rowNum) throws SQLException {
+ ConfigInfoGrayWrapper info = new ConfigInfoGrayWrapper();
+
+ info.setDataId(rs.getString("data_id"));
+ info.setGroup(rs.getString("group_id"));
+ info.setTenant(rs.getString("tenant_id"));
+ info.setGrayName(rs.getString("gray_name"));
+ info.setGrayRule(rs.getString("gray_rule"));
+ info.setAppName(rs.getString("app_name"));
+
+ try {
+ info.setContent(rs.getString("content"));
+ } catch (SQLException ignore) {
+ }
+ try {
+ info.setId(rs.getLong("id"));
+ } catch (SQLException ignore) {
+ }
+ try {
+ info.setLastModified(rs.getTimestamp("gmt_modified").getTime());
+ } catch (SQLException ignore) {
+ }
+ try {
+ info.setMd5(rs.getString("md5"));
+ } catch (SQLException ignore) {
+ }
+ try {
+ info.setEncryptedDataKey(rs.getString("encrypted_data_key"));
+ } catch (SQLException ignore) {
+ }
+
+ try {
+ info.setSrcUser(rs.getString("src_user"));
+ } catch (SQLException ignore) {
+ }
+ return info;
+ }
+ }
+
public static final class ConfigInfoRowMapper implements RowMapper {
@Override
@@ -488,21 +524,6 @@ public ConfigInfoBase mapRow(ResultSet rs, int rowNum) throws SQLException {
}
}
- public static final class ConfigInfoAggrRowMapper implements RowMapper {
-
- @Override
- public ConfigInfoAggr mapRow(ResultSet rs, int rowNum) throws SQLException {
- ConfigInfoAggr info = new ConfigInfoAggr();
- info.setDataId(rs.getString("data_id"));
- info.setGroup(rs.getString("group_id"));
- info.setDatumId(rs.getString("datum_id"));
- info.setTenant(rs.getString("tenant_id"));
- info.setAppName(rs.getString("app_name"));
- info.setContent(rs.getString("content"));
- return info;
- }
- }
-
public static final class ConfigInfoChangedRowMapper implements RowMapper {
@Override
@@ -528,6 +549,8 @@ public ConfigHistoryInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
configHistoryInfo.setSrcIp(rs.getString("src_ip"));
configHistoryInfo.setSrcUser(rs.getString("src_user"));
configHistoryInfo.setOpType(rs.getString("op_type"));
+ configHistoryInfo.setPublishType(rs.getString("publish_type"));
+ configHistoryInfo.setExtInfo(rs.getString("ext_info"));
configHistoryInfo.setCreatedTime(rs.getTimestamp("gmt_create"));
configHistoryInfo.setLastModifiedTime(rs.getTimestamp("gmt_modified"));
return configHistoryInfo;
@@ -549,6 +572,8 @@ public ConfigHistoryInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
configHistoryInfo.setSrcUser(rs.getString("src_user"));
configHistoryInfo.setSrcIp(rs.getString("src_ip"));
configHistoryInfo.setOpType(rs.getString("op_type"));
+ configHistoryInfo.setPublishType(rs.getString("publish_type"));
+ configHistoryInfo.setExtInfo(rs.getString("ext_info"));
configHistoryInfo.setCreatedTime(rs.getTimestamp("gmt_create"));
configHistoryInfo.setLastModifiedTime(rs.getTimestamp("gmt_modified"));
try {
diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/HistoryConfigInfoPersistService.java b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/HistoryConfigInfoPersistService.java
index e0e14b71568..3b64db45064 100644
--- a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/HistoryConfigInfoPersistService.java
+++ b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/HistoryConfigInfoPersistService.java
@@ -45,15 +45,17 @@ public interface HistoryConfigInfoPersistService {
/**
* Update change records; database atomic operations, minimal sql actions, no business encapsulation.
*
- * @param id id
- * @param configInfo config info
- * @param srcIp ip
- * @param srcUser user
- * @param time time
- * @param ops ops type
+ * @param id id
+ * @param configInfo config info
+ * @param srcIp ip
+ * @param srcUser user
+ * @param time time
+ * @param ops ops type
+ * @param publishType publish type
+ * @param extInfo extra config info
*/
void insertConfigHistoryAtomic(long id, ConfigInfo configInfo, String srcIp, String srcUser, final Timestamp time,
- String ops);
+ String ops, String publishType, String extInfo);
//------------------------------------------delete---------------------------------------------//
/**
@@ -69,12 +71,13 @@ void insertConfigHistoryAtomic(long id, ConfigInfo configInfo, String srcIp, Str
/**
* Query deleted config.
*
- * @param startTime start time
- * @param startId last max id
- * @param size page size
+ * @param startTime start time
+ * @param startId last max id
+ * @param size page size
+ * @param publishType publish type
* @return {@link ConfigInfoStateWrapper} list
*/
- List findDeletedConfig(final Timestamp startTime, final long startId, int size);
+ List findDeletedConfig(final Timestamp startTime, final long startId, int size, String publishType);
/**
* List configuration history change record.
diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/embedded/EmbeddedConfigInfoAggrPersistServiceImpl.java b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/embedded/EmbeddedConfigInfoAggrPersistServiceImpl.java
deleted file mode 100644
index dab8c013af8..00000000000
--- a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/embedded/EmbeddedConfigInfoAggrPersistServiceImpl.java
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * Copyright 1999-2022 Alibaba Group Holding Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.alibaba.nacos.config.server.service.repository.embedded;
-
-import com.alibaba.nacos.common.notify.NotifyCenter;
-import com.alibaba.nacos.common.utils.StringUtils;
-import com.alibaba.nacos.config.server.exception.NacosConfigException;
-import com.alibaba.nacos.config.server.model.ConfigInfoAggr;
-import com.alibaba.nacos.config.server.model.ConfigInfoChanged;
-import com.alibaba.nacos.config.server.service.repository.ConfigInfoAggrPersistService;
-import com.alibaba.nacos.persistence.configuration.condition.ConditionOnEmbeddedStorage;
-import com.alibaba.nacos.persistence.datasource.DataSourceService;
-import com.alibaba.nacos.persistence.datasource.DynamicDataSource;
-import com.alibaba.nacos.persistence.model.Page;
-import com.alibaba.nacos.persistence.model.event.DerbyImportEvent;
-import com.alibaba.nacos.persistence.repository.PaginationHelper;
-import com.alibaba.nacos.persistence.repository.embedded.EmbeddedPaginationHelperImpl;
-import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
-import com.alibaba.nacos.persistence.repository.embedded.operate.DatabaseOperate;
-import com.alibaba.nacos.plugin.datasource.MapperManager;
-import com.alibaba.nacos.plugin.datasource.constants.CommonConstant;
-import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
-import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
-import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoAggrMapper;
-import com.alibaba.nacos.plugin.datasource.model.MapperContext;
-import com.alibaba.nacos.plugin.datasource.model.MapperResult;
-import com.alibaba.nacos.sys.env.EnvUtil;
-import org.springframework.context.annotation.Conditional;
-import org.springframework.stereotype.Service;
-
-import java.sql.Timestamp;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-
-import static com.alibaba.nacos.config.server.service.repository.ConfigRowMapperInjector.CONFIG_INFO_AGGR_ROW_MAPPER;
-import static com.alibaba.nacos.config.server.service.repository.ConfigRowMapperInjector.CONFIG_INFO_CHANGED_ROW_MAPPER;
-
-/**
- * EmbeddedConfigInfoAggrPersistServiceImpl.
- *
- * @author lixiaoshuang
- */
-@SuppressWarnings({"PMD.MethodReturnWrapperTypeRule", "checkstyle:linelength"})
-@Conditional(value = ConditionOnEmbeddedStorage.class)
-@Service("embeddedConfigInfoAggrPersistServiceImpl")
-public class EmbeddedConfigInfoAggrPersistServiceImpl implements ConfigInfoAggrPersistService {
-
- private DataSourceService dataSourceService;
-
- private final DatabaseOperate databaseOperate;
-
- private MapperManager mapperManager;
-
- /**
- * The constructor sets the dependency injection order.
- *
- * @param databaseOperate databaseOperate.
- */
- public EmbeddedConfigInfoAggrPersistServiceImpl(DatabaseOperate databaseOperate) {
- this.databaseOperate = databaseOperate;
- this.dataSourceService = DynamicDataSource.getInstance().getDataSource();
- Boolean isDataSourceLogEnable = EnvUtil.getProperty(CommonConstant.NACOS_PLUGIN_DATASOURCE_LOG, Boolean.class,
- false);
- this.mapperManager = MapperManager.instance(isDataSourceLogEnable);
- NotifyCenter.registerToSharePublisher(DerbyImportEvent.class);
- }
-
- @Override
- public PaginationHelper createPaginationHelper() {
- return new EmbeddedPaginationHelperImpl<>(databaseOperate);
- }
-
- @Override
- public boolean addAggrConfigInfo(final String dataId, final String group, String tenant, final String datumId,
- String appName, final String content) {
- String appNameTmp = StringUtils.isBlank(appName) ? StringUtils.EMPTY : appName;
- String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
- String contentTmp = StringUtils.isBlank(content) ? StringUtils.EMPTY : content;
- final Timestamp now = new Timestamp(System.currentTimeMillis());
-
- ConfigInfoAggrMapper configInfoAggrMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
- TableConstant.CONFIG_INFO_AGGR);
- final String select = configInfoAggrMapper.select(Collections.singletonList("content"),
- Arrays.asList("data_id", "group_id", "tenant_id", "datum_id"));
- final String insert = configInfoAggrMapper.insert(
- Arrays.asList("data_id", "group_id", "tenant_id", "datum_id", "app_name", "content", "gmt_modified"));
- final String update = configInfoAggrMapper.update(Arrays.asList("content", "gmt_modified"),
- Arrays.asList("data_id", "group_id", "tenant_id", "datum_id"));
-
- String dbContent = databaseOperate.queryOne(select, new Object[] {dataId, group, tenantTmp, datumId},
- String.class);
-
- if (Objects.isNull(dbContent)) {
- final Object[] args = new Object[] {dataId, group, tenantTmp, datumId, appNameTmp, contentTmp, now};
- EmbeddedStorageContextHolder.addSqlContext(insert, args);
- } else if (!dbContent.equals(content)) {
- final Object[] args = new Object[] {contentTmp, now, dataId, group, tenantTmp, datumId};
- EmbeddedStorageContextHolder.addSqlContext(update, args);
- }
-
- try {
- boolean result = databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
- if (!result) {
- throw new NacosConfigException("[Merge] Configuration release failed");
- }
- return true;
- } finally {
- EmbeddedStorageContextHolder.cleanAllContext();
- }
- }
-
- @Override
- public boolean batchPublishAggr(final String dataId, final String group, final String tenant,
- final Map datumMap, final String appName) {
- try {
- Boolean isPublishOk = false;
- for (Map.Entry entry : datumMap.entrySet()) {
- addAggrConfigInfo(dataId, group, tenant, entry.getKey(), appName, entry.getValue());
- }
-
- isPublishOk = databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
-
- if (isPublishOk == null) {
- return false;
- }
- return isPublishOk;
- } finally {
- EmbeddedStorageContextHolder.cleanAllContext();
- }
- }
-
- @Override
- public int aggrConfigInfoCount(String dataId, String group, String tenant) {
- String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
- ConfigInfoAggrMapper configInfoAggrMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
- TableConstant.CONFIG_INFO_AGGR);
- String sql = configInfoAggrMapper.count(Arrays.asList("data_id", "group_id", "tenant_id"));
- Integer result = databaseOperate.queryOne(sql, new Object[] {dataId, group, tenantTmp}, Integer.class);
- if (result == null) {
- throw new IllegalArgumentException("aggrConfigInfoCount error");
- }
- return result;
- }
-
- @Override
- public Page findConfigInfoAggrByPage(String dataId, String group, String tenant, final int pageNo,
- final int pageSize) {
- String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
- ConfigInfoAggrMapper configInfoAggrMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
- TableConstant.CONFIG_INFO_AGGR);
- final int startRow = (pageNo - 1) * pageSize;
- final String sqlCountRows = configInfoAggrMapper.select(Collections.singletonList("count(*)"),
- Arrays.asList("data_id", "group_id", "tenant_id"));
-
- MapperContext context = new MapperContext();
- context.putWhereParameter(FieldConstant.DATA_ID, dataId);
- context.putWhereParameter(FieldConstant.GROUP_ID, group);
- context.putWhereParameter(FieldConstant.TENANT_ID, tenantTmp);
- context.setStartRow(startRow);
- context.setPageSize(pageSize);
- MapperResult mapperResult = configInfoAggrMapper.findConfigInfoAggrByPageFetchRows(context);
- String sqlFetchRows = mapperResult.getSql();
- Object[] sqlFetchArgs = mapperResult.getParamList().toArray();
-
- PaginationHelper helper = createPaginationHelper();
- return helper.fetchPageLimit(sqlCountRows, new Object[] {dataId, group, tenantTmp}, sqlFetchRows, sqlFetchArgs,
- pageNo, pageSize, CONFIG_INFO_AGGR_ROW_MAPPER);
- }
-
- @Override
- public List findAllAggrGroup() {
- ConfigInfoAggrMapper configInfoAggrMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
- TableConstant.CONFIG_INFO_AGGR);
- MapperResult mapperResult = configInfoAggrMapper.findAllAggrGroupByDistinct(null);
-
- return databaseOperate.queryMany(mapperResult.getSql(), EMPTY_ARRAY, CONFIG_INFO_CHANGED_ROW_MAPPER);
-
- }
-
-}
diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/embedded/EmbeddedConfigInfoGrayPersistServiceImpl.java b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/embedded/EmbeddedConfigInfoGrayPersistServiceImpl.java
new file mode 100644
index 00000000000..f5f9e378d6b
--- /dev/null
+++ b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/embedded/EmbeddedConfigInfoGrayPersistServiceImpl.java
@@ -0,0 +1,426 @@
+/*
+ * Copyright 1999-2022 Alibaba Group Holding Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.alibaba.nacos.config.server.service.repository.embedded;
+
+import com.alibaba.nacos.common.notify.NotifyCenter;
+import com.alibaba.nacos.common.utils.MD5Utils;
+import com.alibaba.nacos.common.utils.StringUtils;
+import com.alibaba.nacos.config.server.constant.Constants;
+import com.alibaba.nacos.config.server.model.ConfigInfo;
+import com.alibaba.nacos.config.server.model.ConfigInfoGrayWrapper;
+import com.alibaba.nacos.config.server.model.ConfigInfoStateWrapper;
+import com.alibaba.nacos.config.server.model.ConfigOperateResult;
+import com.alibaba.nacos.config.server.service.repository.ConfigInfoGrayPersistService;
+import com.alibaba.nacos.config.server.service.repository.HistoryConfigInfoPersistService;
+import com.alibaba.nacos.config.server.service.sql.EmbeddedStorageContextUtils;
+import com.alibaba.nacos.config.server.utils.ConfigExtInfoUtil;
+import com.alibaba.nacos.config.server.utils.LogUtil;
+import com.alibaba.nacos.core.distributed.id.IdGeneratorManager;
+import com.alibaba.nacos.persistence.configuration.condition.ConditionOnEmbeddedStorage;
+import com.alibaba.nacos.persistence.datasource.DataSourceService;
+import com.alibaba.nacos.persistence.datasource.DynamicDataSource;
+import com.alibaba.nacos.persistence.model.Page;
+import com.alibaba.nacos.persistence.model.event.DerbyImportEvent;
+import com.alibaba.nacos.persistence.repository.PaginationHelper;
+import com.alibaba.nacos.persistence.repository.embedded.EmbeddedPaginationHelperImpl;
+import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
+import com.alibaba.nacos.persistence.repository.embedded.operate.DatabaseOperate;
+import com.alibaba.nacos.plugin.datasource.MapperManager;
+import com.alibaba.nacos.plugin.datasource.constants.CommonConstant;
+import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
+import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
+import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoGrayMapper;
+import com.alibaba.nacos.plugin.datasource.model.MapperContext;
+import com.alibaba.nacos.plugin.datasource.model.MapperResult;
+import com.alibaba.nacos.sys.env.EnvUtil;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.dao.DataAccessException;
+import org.springframework.stereotype.Service;
+
+import java.sql.Timestamp;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static com.alibaba.nacos.config.server.service.repository.ConfigRowMapperInjector.CONFIG_INFO_GRAY_WRAPPER_ROW_MAPPER;
+import static com.alibaba.nacos.config.server.service.repository.ConfigRowMapperInjector.CONFIG_INFO_STATE_WRAPPER_ROW_MAPPER;
+
+/**
+ * EmbeddedConfigInfoGrayPersistServiceImpl.
+ *
+ * @author rong
+ */
+@SuppressWarnings({"PMD.MethodReturnWrapperTypeRule", "checkstyle:linelength"})
+@Conditional(value = ConditionOnEmbeddedStorage.class)
+@Service("embeddedConfigInfoGrayPersistServiceImpl")
+public class EmbeddedConfigInfoGrayPersistServiceImpl implements ConfigInfoGrayPersistService {
+
+ private static final String RESOURCE_CONFIG_HISTORY_ID = "config-history-id";
+
+ private static final String RESOURCE_CONFIG_HISTORY_GRAY_ID = "config-history-gray-id";
+
+ private DataSourceService dataSourceService;
+
+ private final DatabaseOperate databaseOperate;
+
+ private MapperManager mapperManager;
+
+ private final IdGeneratorManager idGeneratorManager;
+
+ private final HistoryConfigInfoPersistService historyConfigInfoPersistService;
+
+ /**
+ * The constructor sets the dependency injection order.
+ *
+ * @param databaseOperate databaseOperate.
+ */
+ public EmbeddedConfigInfoGrayPersistServiceImpl(DatabaseOperate databaseOperate,
+ IdGeneratorManager idGeneratorManager,
+ @Qualifier("embeddedHistoryConfigInfoPersistServiceImpl") HistoryConfigInfoPersistService historyConfigInfoPersistService) {
+ this.databaseOperate = databaseOperate;
+ this.idGeneratorManager = idGeneratorManager;
+ this.historyConfigInfoPersistService = historyConfigInfoPersistService;
+ idGeneratorManager.register(RESOURCE_CONFIG_HISTORY_GRAY_ID, RESOURCE_CONFIG_HISTORY_ID);
+ this.dataSourceService = DynamicDataSource.getInstance().getDataSource();
+ Boolean isDataSourceLogEnable = EnvUtil.getProperty(CommonConstant.NACOS_PLUGIN_DATASOURCE_LOG, Boolean.class,
+ false);
+ this.mapperManager = MapperManager.instance(isDataSourceLogEnable);
+ NotifyCenter.registerToSharePublisher(DerbyImportEvent.class);
+ }
+
+ @Override
+ public PaginationHelper createPaginationHelper() {
+ return new EmbeddedPaginationHelperImpl<>(databaseOperate);
+ }
+
+ @Override
+ public ConfigInfoStateWrapper findConfigInfo4GrayState(final String dataId, final String group, final String tenant,
+ String grayName) {
+ ConfigInfoGrayMapper configInfoGrayMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
+ TableConstant.CONFIG_INFO_GRAY);
+ String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
+ String grayNameTmp = StringUtils.isBlank(grayName) ? StringUtils.EMPTY : grayName.trim();
+
+ String sql = configInfoGrayMapper.select(
+ Arrays.asList("id", "data_id", "group_id", "tenant_id", "gmt_modified"),
+ Arrays.asList("data_id", "group_id", "tenant_id", "gray_name"));
+ return databaseOperate.queryOne(sql, new Object[] {dataId, group, tenantTmp, grayNameTmp},
+ CONFIG_INFO_STATE_WRAPPER_ROW_MAPPER);
+ }
+
+ private ConfigOperateResult getGrayOperateResult(String dataId, String group, String tenant, String grayName) {
+ String tenantTmp = StringUtils.defaultEmptyIfBlank(tenant);
+ ConfigInfoStateWrapper configInfo4Gray = this.findConfigInfo4GrayState(dataId, group, tenantTmp, grayName);
+ if (configInfo4Gray == null) {
+ return new ConfigOperateResult(false);
+ }
+ return new ConfigOperateResult(configInfo4Gray.getId(), configInfo4Gray.getLastModified());
+
+ }
+
+ @Override
+ public ConfigOperateResult addConfigInfo4Gray(ConfigInfo configInfo, String grayName, String grayRule, String srcIp,
+ String srcUser) {
+ String tenantTmp = StringUtils.defaultEmptyIfBlank(configInfo.getTenant());
+ String grayNameTmp = StringUtils.isBlank(grayName) ? StringUtils.EMPTY : grayName.trim();
+ String grayRuleTmp = StringUtils.isBlank(grayRule) ? StringUtils.EMPTY : grayRule.trim();
+
+ configInfo.setTenant(tenantTmp);
+
+ try {
+ long configGrayId = idGeneratorManager.nextId(RESOURCE_CONFIG_HISTORY_GRAY_ID);
+ long hisId = idGeneratorManager.nextId(RESOURCE_CONFIG_HISTORY_ID);
+
+ addConfigInfoGrayAtomic(configGrayId, configInfo, grayNameTmp, grayRuleTmp, srcIp, srcUser);
+
+ Timestamp now = new Timestamp(System.currentTimeMillis());
+ historyConfigInfoPersistService.insertConfigHistoryAtomic(hisId, configInfo, srcIp, srcUser, now, "I",
+ Constants.GRAY, ConfigExtInfoUtil.getExtInfoFromGrayInfo(grayNameTmp, grayRuleTmp, srcUser));
+
+ EmbeddedStorageContextUtils.onModifyConfigGrayInfo(configInfo, grayNameTmp, grayRuleTmp, srcIp, now);
+ databaseOperate.blockUpdate();
+
+ return getGrayOperateResult(configInfo.getDataId(), configInfo.getGroup(), tenantTmp, grayNameTmp);
+ } finally {
+ EmbeddedStorageContextHolder.cleanAllContext();
+ }
+ }
+
+ @Override
+ public void addConfigInfoGrayAtomic(long configGrayId, ConfigInfo configInfo, String grayName, String grayRule,
+ String srcIp, String srcUser) {
+ String appNameTmp = StringUtils.defaultEmptyIfBlank(configInfo.getAppName());
+ String tenantTmp = StringUtils.defaultEmptyIfBlank(configInfo.getTenant());
+ String grayNameTmp = StringUtils.isBlank(grayName) ? StringUtils.EMPTY : grayName.trim();
+ String grayRuleTmp = StringUtils.isBlank(grayRule) ? StringUtils.EMPTY : grayRule.trim();
+ String md5 = MD5Utils.md5Hex(configInfo.getContent(), Constants.ENCODE);
+
+ ConfigInfoGrayMapper configInfoGrayMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
+ TableConstant.CONFIG_INFO_GRAY);
+
+ final String sql = configInfoGrayMapper.insert(
+ Arrays.asList("id", "data_id", "group_id", "tenant_id", "gray_name", "gray_rule", "app_name", "content",
+ "md5", "src_ip", "src_user", "gmt_create", "gmt_modified"));
+
+ Timestamp time = new Timestamp(System.currentTimeMillis());
+ final Object[] args = new Object[] {configGrayId, configInfo.getDataId(), configInfo.getGroup(), tenantTmp,
+ grayNameTmp, grayRuleTmp, appNameTmp, configInfo.getContent(), md5, srcIp, srcUser, time, time};
+ EmbeddedStorageContextHolder.addSqlContext(sql, args);
+ }
+
+ @Override
+ public ConfigOperateResult insertOrUpdateGray(final ConfigInfo configInfo, final String grayName,
+ final String grayRule, final String srcIp, final String srcUser) {
+ if (findConfigInfo4GrayState(configInfo.getDataId(), configInfo.getGroup(), configInfo.getTenant(), grayName)
+ == null) {
+ return addConfigInfo4Gray(configInfo, grayName, grayRule, srcIp, srcUser);
+ } else {
+ return updateConfigInfo4Gray(configInfo, grayName, grayRule, srcIp, srcUser);
+ }
+ }
+
+ @Override
+ public ConfigOperateResult insertOrUpdateGrayCas(final ConfigInfo configInfo, final String grayName,
+ final String grayRule, final String srcIp, final String srcUser) {
+ if (findConfigInfo4GrayState(configInfo.getDataId(), configInfo.getGroup(), configInfo.getTenant(), grayName)
+ == null) {
+ return addConfigInfo4Gray(configInfo, grayName, grayRule, srcIp, srcUser);
+ } else {
+ return updateConfigInfo4GrayCas(configInfo, grayName, grayRule, srcIp, srcUser);
+ }
+ }
+
+ @Override
+ public void removeConfigInfoGray(final String dataId, final String group, final String tenant,
+ final String grayName, final String srcIp, final String srcUser) {
+ String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
+ String grayNameTmp = StringUtils.isBlank(grayName) ? StringUtils.EMPTY : grayName;
+
+ ConfigInfoGrayWrapper oldConfigAllInfo4Gray = findConfigInfo4Gray(dataId, group, tenantTmp, grayNameTmp);
+ if (oldConfigAllInfo4Gray == null) {
+ if (LogUtil.FATAL_LOG.isErrorEnabled()) {
+ LogUtil.FATAL_LOG.error("expected config info[dataid:{}, group:{}, tenent:{}] but not found.", dataId,
+ group, tenant);
+ }
+ }
+
+ ConfigInfoGrayMapper configInfoGrayMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
+ TableConstant.CONFIG_INFO_GRAY);
+ final String sql = configInfoGrayMapper.delete(Arrays.asList("data_id", "group_id", "tenant_id", "gray_name"));
+ final Object[] args = new Object[] {dataId, group, tenantTmp, grayNameTmp};
+
+ Timestamp now = new Timestamp(System.currentTimeMillis());
+ historyConfigInfoPersistService.insertConfigHistoryAtomic(oldConfigAllInfo4Gray.getId(), oldConfigAllInfo4Gray,
+ srcIp, srcUser, now, "D", Constants.GRAY,
+ ConfigExtInfoUtil.getExtInfoFromGrayInfo(oldConfigAllInfo4Gray.getGrayName(),
+ oldConfigAllInfo4Gray.getGrayRule(), oldConfigAllInfo4Gray.getSrcUser()));
+
+ EmbeddedStorageContextUtils.onDeleteConfigGrayInfo(tenantTmp, group, dataId, grayNameTmp, srcIp);
+ EmbeddedStorageContextHolder.addSqlContext(sql, args);
+ try {
+ databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
+ } finally {
+ EmbeddedStorageContextHolder.cleanAllContext();
+ }
+ }
+
+ @Override
+ public ConfigOperateResult updateConfigInfo4Gray(ConfigInfo configInfo, String grayName, String grayRule,
+ String srcIp, String srcUser) {
+ String appNameTmp = StringUtils.defaultEmptyIfBlank(configInfo.getAppName());
+ String tenantTmp = StringUtils.defaultEmptyIfBlank(configInfo.getTenant());
+ String grayNameTmp = StringUtils.isBlank(grayName) ? StringUtils.EMPTY : grayName.trim();
+ String grayRuleTmp = StringUtils.isBlank(grayRule) ? StringUtils.EMPTY : grayRule.trim();
+
+ configInfo.setTenant(tenantTmp);
+
+ try {
+ ConfigInfoGrayWrapper oldConfigAllInfo4Gray = findConfigInfo4Gray(configInfo.getDataId(),
+ configInfo.getGroup(), tenantTmp, grayNameTmp);
+ if (oldConfigAllInfo4Gray == null) {
+ if (LogUtil.FATAL_LOG.isErrorEnabled()) {
+ LogUtil.FATAL_LOG.error("expected config info[dataid:{}, group:{}, tenent:{}] but not found.",
+ configInfo.getDataId(), configInfo.getGroup(), configInfo.getTenant());
+ }
+ }
+
+ String md5 = MD5Utils.md5Hex(configInfo.getContent(), Constants.ENCODE);
+ ConfigInfoGrayMapper configInfoGrayMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
+ TableConstant.CONFIG_INFO_GRAY);
+ Timestamp time = new Timestamp(System.currentTimeMillis());
+
+ final String sql = configInfoGrayMapper.update(
+ Arrays.asList("content", "md5", "src_ip", "src_user", "gmt_modified", "app_name", "gray_rule"),
+ Arrays.asList("data_id", "group_id", "tenant_id", "gray_name"));
+ final Object[] args = new Object[] {configInfo.getContent(), md5, srcIp, srcUser, time, appNameTmp,
+ grayRuleTmp, configInfo.getDataId(), configInfo.getGroup(), tenantTmp, grayNameTmp};
+
+ Timestamp now = new Timestamp(System.currentTimeMillis());
+ historyConfigInfoPersistService.insertConfigHistoryAtomic(oldConfigAllInfo4Gray.getId(),
+ oldConfigAllInfo4Gray, srcIp, srcUser, now, "U", Constants.GRAY,
+ ConfigExtInfoUtil.getExtInfoFromGrayInfo(oldConfigAllInfo4Gray.getGrayName(),
+ oldConfigAllInfo4Gray.getGrayRule(), oldConfigAllInfo4Gray.getSrcUser()));
+
+ EmbeddedStorageContextUtils.onModifyConfigGrayInfo(configInfo, grayNameTmp, grayRuleTmp, srcIp, time);
+ EmbeddedStorageContextHolder.addSqlContext(sql, args);
+
+ databaseOperate.blockUpdate();
+ return getGrayOperateResult(configInfo.getDataId(), configInfo.getGroup(), tenantTmp, grayNameTmp);
+
+ } finally {
+ EmbeddedStorageContextHolder.cleanAllContext();
+ }
+ }
+
+ @Override
+ public ConfigOperateResult updateConfigInfo4GrayCas(ConfigInfo configInfo, String grayName, String grayRule,
+ String srcIp, String srcUser) {
+ String appNameTmp = StringUtils.defaultEmptyIfBlank(configInfo.getAppName());
+ String tenantTmp = StringUtils.defaultEmptyIfBlank(configInfo.getTenant());
+ String grayNameTmp = StringUtils.isBlank(grayName) ? StringUtils.EMPTY : grayName.trim();
+ String grayRuleTmp = StringUtils.isBlank(grayRule) ? StringUtils.EMPTY : grayRule.trim();
+
+ configInfo.setTenant(tenantTmp);
+
+ try {
+ final ConfigInfoGrayWrapper oldConfigAllInfo4Gray = findConfigInfo4Gray(configInfo.getDataId(),
+ configInfo.getGroup(), tenantTmp, grayNameTmp);
+ if (oldConfigAllInfo4Gray == null) {
+ if (LogUtil.FATAL_LOG.isErrorEnabled()) {
+ LogUtil.FATAL_LOG.error("expected config info[dataid:{}, group:{}, tenent:{}] but not found.",
+ configInfo.getDataId(), configInfo.getGroup(), configInfo.getTenant());
+ }
+ }
+
+ String md5 = MD5Utils.md5Hex(configInfo.getContent(), Constants.ENCODE);
+ ConfigInfoGrayMapper configInfoGrayMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
+ TableConstant.CONFIG_INFO_GRAY);
+ Timestamp time = new Timestamp(System.currentTimeMillis());
+
+ MapperContext context = new MapperContext();
+ context.putUpdateParameter(FieldConstant.CONTENT, configInfo.getContent());
+ context.putUpdateParameter(FieldConstant.MD5, md5);
+ context.putUpdateParameter(FieldConstant.SRC_IP, srcIp);
+ context.putUpdateParameter(FieldConstant.SRC_USER, srcUser);
+ context.putUpdateParameter(FieldConstant.GMT_MODIFIED, time);
+ context.putUpdateParameter(FieldConstant.APP_NAME, appNameTmp);
+
+ context.putWhereParameter(FieldConstant.DATA_ID, configInfo.getDataId());
+ context.putWhereParameter(FieldConstant.GROUP_ID, configInfo.getGroup());
+ context.putWhereParameter(FieldConstant.TENANT_ID, tenantTmp);
+ context.putWhereParameter(FieldConstant.GRAY_NAME, grayNameTmp);
+ context.putWhereParameter(FieldConstant.GRAY_RULE, grayRuleTmp);
+ context.putWhereParameter(FieldConstant.MD5, configInfo.getMd5());
+
+ final MapperResult mapperResult = configInfoGrayMapper.updateConfigInfo4GrayCas(context);
+
+ Timestamp now = new Timestamp(System.currentTimeMillis());
+ historyConfigInfoPersistService.insertConfigHistoryAtomic(oldConfigAllInfo4Gray.getId(),
+ oldConfigAllInfo4Gray, srcIp, srcUser, now, "U", Constants.GRAY,
+ ConfigExtInfoUtil.getExtInfoFromGrayInfo(oldConfigAllInfo4Gray.getGrayName(),
+ oldConfigAllInfo4Gray.getGrayRule(), oldConfigAllInfo4Gray.getSrcUser()));
+
+ EmbeddedStorageContextUtils.onModifyConfigGrayInfo(configInfo, grayNameTmp, grayRuleTmp, srcIp, time);
+ EmbeddedStorageContextHolder.addSqlContext(mapperResult.getSql(), mapperResult.getParamList().toArray());
+
+ Boolean success = databaseOperate.blockUpdate();
+ if (success) {
+ return getGrayOperateResult(configInfo.getDataId(), configInfo.getGroup(), tenantTmp, grayNameTmp);
+ } else {
+ return new ConfigOperateResult(false);
+ }
+
+ } finally {
+ EmbeddedStorageContextHolder.cleanAllContext();
+ }
+ }
+
+ @Override
+ public ConfigInfoGrayWrapper findConfigInfo4Gray(final String dataId, final String group, final String tenant,
+ final String grayName) {
+ String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
+ String grayNameTmp = StringUtils.isBlank(grayName) ? StringUtils.EMPTY : grayName.trim();
+ ConfigInfoGrayMapper configInfoGrayMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
+ TableConstant.CONFIG_INFO_GRAY);
+ final String sql = configInfoGrayMapper.select(
+ Arrays.asList("id", "data_id", "group_id", "tenant_id", "gray_name", "gray_rule", "app_name", "content",
+ "md5", "gmt_modified", "src_user", "encrypted_data_key"),
+ Arrays.asList("data_id", "group_id", "tenant_id", "gray_name"));
+
+ return databaseOperate.queryOne(sql, new Object[] {dataId, group, tenantTmp, grayNameTmp},
+ CONFIG_INFO_GRAY_WRAPPER_ROW_MAPPER);
+ }
+
+ @Override
+ public int configInfoGrayCount() {
+ ConfigInfoGrayMapper configInfoGrayMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
+ TableConstant.CONFIG_INFO_GRAY);
+ String sql = configInfoGrayMapper.count(null);
+ Integer result = databaseOperate.queryOne(sql, Integer.class);
+ if (result == null) {
+ throw new IllegalArgumentException("configInfoBetaCount error");
+ }
+ return result;
+ }
+
+ @Override
+ public Page findAllConfigInfoGrayForDumpAll(final int pageNo, final int pageSize) {
+ final int startRow = (pageNo - 1) * pageSize;
+ ConfigInfoGrayMapper configInfoGrayMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
+ TableConstant.CONFIG_INFO_GRAY);
+ String sqlCountRows = configInfoGrayMapper.count(null);
+ MapperResult sqlFetchRows = configInfoGrayMapper.findAllConfigInfoGrayForDumpAllFetchRows(
+ new MapperContext(startRow, pageSize));
+
+ PaginationHelper helper = createPaginationHelper();
+ return helper.fetchPageLimit(sqlCountRows, sqlFetchRows.getSql(), sqlFetchRows.getParamList().toArray(), pageNo,
+ pageSize, CONFIG_INFO_GRAY_WRAPPER_ROW_MAPPER);
+
+ }
+
+ @Override
+ public List findConfigInfoGrays(String dataId, String group, String tenant) {
+ String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
+ ConfigInfoGrayMapper configInfoGrayMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
+ TableConstant.CONFIG_INFO_GRAY);
+ final String sql = configInfoGrayMapper.select(Collections.singletonList("gray_name"),
+ Arrays.asList("data_id", "group_id", "tenant_id"));
+
+ return databaseOperate.queryMany(sql, new Object[] {dataId, group, tenantTmp}, String.class);
+ }
+
+ @Override
+ public List findChangeConfig(final Timestamp startTime, long lastMaxId, final int pageSize) {
+ try {
+ ConfigInfoGrayMapper configInfoMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
+ TableConstant.CONFIG_INFO_GRAY);
+
+ MapperContext context = new MapperContext();
+ context.putWhereParameter(FieldConstant.START_TIME, startTime);
+ context.putWhereParameter(FieldConstant.PAGE_SIZE, pageSize);
+ context.putWhereParameter(FieldConstant.LAST_MAX_ID, lastMaxId);
+
+ MapperResult mapperResult = configInfoMapper.findChangeConfig(context);
+ return databaseOperate.queryMany(mapperResult.getSql(), mapperResult.getParamList().toArray(),
+ CONFIG_INFO_GRAY_WRAPPER_ROW_MAPPER);
+ } catch (DataAccessException e) {
+ LogUtil.FATAL_LOG.error("[db-error] " + e, e);
+ throw e;
+ }
+ }
+}
diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/embedded/EmbeddedConfigInfoPersistServiceImpl.java b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/embedded/EmbeddedConfigInfoPersistServiceImpl.java
index d547771721d..046bbb25fa6 100644
--- a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/embedded/EmbeddedConfigInfoPersistServiceImpl.java
+++ b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/embedded/EmbeddedConfigInfoPersistServiceImpl.java
@@ -37,6 +37,8 @@
import com.alibaba.nacos.config.server.service.repository.ConfigInfoPersistService;
import com.alibaba.nacos.config.server.service.repository.HistoryConfigInfoPersistService;
import com.alibaba.nacos.config.server.service.sql.EmbeddedStorageContextUtils;
+import com.alibaba.nacos.config.server.utils.ConfigExtInfoUtil;
+import com.alibaba.nacos.config.server.utils.LogUtil;
import com.alibaba.nacos.config.server.utils.ParamUtils;
import com.alibaba.nacos.core.distributed.id.IdGeneratorManager;
import com.alibaba.nacos.persistence.configuration.condition.ConditionOnEmbeddedStorage;
@@ -219,7 +221,9 @@ private ConfigOperateResult addConfigInfo(final String srcIp, final String srcUs
configInfo.getTenant());
Timestamp now = new Timestamp(System.currentTimeMillis());
- historyConfigInfoPersistService.insertConfigHistoryAtomic(hisId, configInfo, srcIp, srcUser, now, "I");
+ historyConfigInfoPersistService.insertConfigHistoryAtomic(hisId, configInfo, srcIp, srcUser, now, "I",
+ Constants.FORMAL, ConfigExtInfoUtil.getExtraInfoFromAdvanceInfoMap(configAdvanceInfo, srcUser));
+
EmbeddedStorageContextUtils.onModifyConfigInfo(configInfo, srcIp, now);
databaseOperate.blockUpdate(consumer);
return getConfigInfoOperateResult(configInfo.getDataId(), configInfo.getGroup(), tenantTmp);
@@ -266,7 +270,7 @@ public long addConfigInfoAtomic(final long id, final String srcIp, final String
configInfo.getEncryptedDataKey() == null ? StringUtils.EMPTY : configInfo.getEncryptedDataKey();
ConfigInfoMapper configInfoMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
TableConstant.CONFIG_INFO);
-
+
final String sql = configInfoMapper.insert(
Arrays.asList("id", "data_id", "group_id", "tenant_id", "app_name", "content", "md5", "src_ip",
"src_user", "gmt_create@NOW()", "gmt_modified@NOW()", "c_desc", "c_use", "effect",
@@ -400,15 +404,15 @@ public Map batchInsertOrUpdate(List configInfoLis
public void removeConfigInfo(final String dataId, final String group, final String tenant, final String srcIp,
final String srcUser) {
final Timestamp time = new Timestamp(System.currentTimeMillis());
- ConfigInfo configInfo = findConfigInfo(dataId, group, tenant);
- if (Objects.nonNull(configInfo)) {
+ ConfigAllInfo oldConfigAllInfo = findConfigAllInfo(dataId, group, tenant);
+ if (Objects.nonNull(oldConfigAllInfo)) {
try {
String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
removeConfigInfoAtomic(dataId, group, tenantTmp, srcIp, srcUser);
- removeTagByIdAtomic(configInfo.getId());
- historyConfigInfoPersistService.insertConfigHistoryAtomic(configInfo.getId(), configInfo, srcIp,
- srcUser, time, "D");
+ removeTagByIdAtomic(oldConfigAllInfo.getId());
+ historyConfigInfoPersistService.insertConfigHistoryAtomic(oldConfigAllInfo.getId(), oldConfigAllInfo, srcIp,
+ srcUser, time, "D", Constants.FORMAL, ConfigExtInfoUtil.getExtInfoFromAllInfo(oldConfigAllInfo));
EmbeddedStorageContextUtils.onDeleteConfigInfo(tenantTmp, group, dataId, srcIp, time);
@@ -423,7 +427,7 @@ public void removeConfigInfo(final String dataId, final String group, final Stri
}
@Override
- public List removeConfigInfoByIds(final List ids, final String srcIp, final String srcUser) {
+ public List removeConfigInfoByIds(final List ids, final String srcIp, final String srcUser) {
if (CollectionUtils.isEmpty(ids)) {
return null;
}
@@ -431,23 +435,24 @@ public List removeConfigInfoByIds(final List ids, final String
final Timestamp time = new Timestamp(System.currentTimeMillis());
try {
String idsStr = StringUtils.join(ids, StringUtils.COMMA);
- List configInfoList = findConfigInfosByIds(idsStr);
- if (CollectionUtils.isNotEmpty(configInfoList)) {
+ List oldConfigAllInfoList = findAllConfigInfo4Export(null, null, null, null, ids);
+ if (CollectionUtils.isNotEmpty(oldConfigAllInfoList)) {
removeConfigInfoByIdsAtomic(idsStr);
- for (ConfigInfo configInfo : configInfoList) {
- removeTagByIdAtomic(configInfo.getId());
- historyConfigInfoPersistService.insertConfigHistoryAtomic(configInfo.getId(), configInfo, srcIp,
- srcUser, time, "D");
+ for (ConfigAllInfo configAllInfo : oldConfigAllInfoList) {
+ removeTagByIdAtomic(configAllInfo.getId());
+ historyConfigInfoPersistService.insertConfigHistoryAtomic(configAllInfo.getId(), configAllInfo,
+ srcIp, srcUser, time, "D", Constants.FORMAL,
+ ConfigExtInfoUtil.getExtInfoFromAllInfo(configAllInfo));
}
}
- EmbeddedStorageContextUtils.onBatchDeleteConfigInfo(configInfoList);
+ EmbeddedStorageContextUtils.onBatchDeleteConfigInfo(oldConfigAllInfoList);
boolean result = databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
if (!result) {
throw new NacosConfigException("Failed to config batch deletion");
}
- return configInfoList;
+ return oldConfigAllInfoList;
} finally {
EmbeddedStorageContextHolder.cleanAllContext();
}
@@ -496,15 +501,22 @@ public void removeConfigInfoByIdsAtomic(final String ids) {
public ConfigOperateResult updateConfigInfo(final ConfigInfo configInfo, final String srcIp, final String srcUser,
final Map configAdvanceInfo) {
try {
- ConfigInfo oldConfigInfo = findConfigInfo(configInfo.getDataId(), configInfo.getGroup(),
+ ConfigAllInfo oldConfigAllInfo = findConfigAllInfo(configInfo.getDataId(), configInfo.getGroup(),
configInfo.getTenant());
+ if (oldConfigAllInfo == null) {
+ if (LogUtil.FATAL_LOG.isErrorEnabled()) {
+ LogUtil.FATAL_LOG.error("expected config info[dataid:{}, group:{}, tenent:{}] but not found.",
+ configInfo.getDataId(), configInfo.getGroup(), configInfo.getTenant());
+ }
+ return new ConfigOperateResult(false);
+ }
final String tenantTmp =
StringUtils.isBlank(configInfo.getTenant()) ? StringUtils.EMPTY : configInfo.getTenant();
- oldConfigInfo.setTenant(tenantTmp);
+ oldConfigAllInfo.setTenant(tenantTmp);
- String appNameTmp = oldConfigInfo.getAppName();
+ String appNameTmp = oldConfigAllInfo.getAppName();
// If the appName passed by the user is not empty, the appName of the user is persisted;
// otherwise, the appName of db is used. Empty string is required to clear appName
if (configInfo.getAppName() == null) {
@@ -516,14 +528,14 @@ public ConfigOperateResult updateConfigInfo(final ConfigInfo configInfo, final S
String configTags = configAdvanceInfo == null ? null : (String) configAdvanceInfo.get("config_tags");
if (configTags != null) {
// Delete all tags and recreate them
- removeTagByIdAtomic(oldConfigInfo.getId());
- addConfigTagsRelation(oldConfigInfo.getId(), configTags, configInfo.getDataId(), configInfo.getGroup(),
+ removeTagByIdAtomic(oldConfigAllInfo.getId());
+ addConfigTagsRelation(oldConfigAllInfo.getId(), configTags, configInfo.getDataId(), configInfo.getGroup(),
configInfo.getTenant());
}
Timestamp time = new Timestamp(System.currentTimeMillis());
- historyConfigInfoPersistService.insertConfigHistoryAtomic(oldConfigInfo.getId(), oldConfigInfo, srcIp,
- srcUser, time, "U");
+ historyConfigInfoPersistService.insertConfigHistoryAtomic(oldConfigAllInfo.getId(), oldConfigAllInfo, srcIp,
+ srcUser, time, "U", Constants.FORMAL, ConfigExtInfoUtil.getExtInfoFromAllInfo(oldConfigAllInfo));
EmbeddedStorageContextUtils.onModifyConfigInfo(configInfo, srcIp, time);
databaseOperate.blockUpdate();
return getConfigInfoOperateResult(configInfo.getDataId(), configInfo.getGroup(), tenantTmp);
@@ -536,15 +548,21 @@ public ConfigOperateResult updateConfigInfo(final ConfigInfo configInfo, final S
public ConfigOperateResult updateConfigInfoCas(final ConfigInfo configInfo, final String srcIp,
final String srcUser, final Map configAdvanceInfo) {
try {
- ConfigInfo oldConfigInfo = findConfigInfo(configInfo.getDataId(), configInfo.getGroup(),
+ ConfigAllInfo oldConfigAllInfo = findConfigAllInfo(configInfo.getDataId(), configInfo.getGroup(),
configInfo.getTenant());
-
+ if (oldConfigAllInfo == null) {
+ if (LogUtil.FATAL_LOG.isErrorEnabled()) {
+ LogUtil.FATAL_LOG.error("expected config info[dataid:{}, group:{}, tenent:{}] but not found.",
+ configInfo.getDataId(), configInfo.getGroup(), configInfo.getTenant());
+ }
+ return new ConfigOperateResult(false);
+ }
final String tenantTmp =
StringUtils.isBlank(configInfo.getTenant()) ? StringUtils.EMPTY : configInfo.getTenant();
- oldConfigInfo.setTenant(tenantTmp);
+ oldConfigAllInfo.setTenant(tenantTmp);
- String appNameTmp = oldConfigInfo.getAppName();
+ String appNameTmp = oldConfigAllInfo.getAppName();
// If the appName passed by the user is not empty, the appName of the user is persisted;
// otherwise, the appName of db is used. Empty string is required to clear appName
if (configInfo.getAppName() == null) {
@@ -556,14 +574,14 @@ public ConfigOperateResult updateConfigInfoCas(final ConfigInfo configInfo, fina
String configTags = configAdvanceInfo == null ? null : (String) configAdvanceInfo.get("config_tags");
if (configTags != null) {
// Delete all tags and recreate them
- removeTagByIdAtomic(oldConfigInfo.getId());
- addConfigTagsRelation(oldConfigInfo.getId(), configTags, configInfo.getDataId(), configInfo.getGroup(),
+ removeTagByIdAtomic(oldConfigAllInfo.getId());
+ addConfigTagsRelation(oldConfigAllInfo.getId(), configTags, configInfo.getDataId(), configInfo.getGroup(),
configInfo.getTenant());
}
-
+
Timestamp time = new Timestamp(System.currentTimeMillis());
- historyConfigInfoPersistService.insertConfigHistoryAtomic(oldConfigInfo.getId(), oldConfigInfo, srcIp,
- srcUser, time, "U");
+ historyConfigInfoPersistService.insertConfigHistoryAtomic(oldConfigAllInfo.getId(), oldConfigAllInfo, srcIp,
+ srcUser, time, "U", Constants.FORMAL, ConfigExtInfoUtil.getExtInfoFromAllInfo(oldConfigAllInfo));
EmbeddedStorageContextUtils.onModifyConfigInfo(configInfo, srcIp, time);
boolean success = databaseOperate.blockUpdate();
if (success) {
@@ -626,7 +644,7 @@ public void updateConfigInfoAtomic(final ConfigInfo configInfo, final String src
final String schema = configAdvanceInfo == null ? null : (String) configAdvanceInfo.get("schema");
final String encryptedDataKey =
configInfo.getEncryptedDataKey() == null ? StringUtils.EMPTY : configInfo.getEncryptedDataKey();
-
+
ConfigInfoMapper configInfoMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
TableConstant.CONFIG_INFO);
final String sql = configInfoMapper.update(
diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/embedded/EmbeddedHistoryConfigInfoPersistServiceImpl.java b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/embedded/EmbeddedHistoryConfigInfoPersistServiceImpl.java
index 4bfdf8ec65b..8be147fc0b0 100644
--- a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/embedded/EmbeddedHistoryConfigInfoPersistServiceImpl.java
+++ b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/embedded/EmbeddedHistoryConfigInfoPersistServiceImpl.java
@@ -24,6 +24,7 @@
import com.alibaba.nacos.config.server.model.ConfigInfo;
import com.alibaba.nacos.config.server.model.ConfigInfoStateWrapper;
import com.alibaba.nacos.config.server.service.repository.HistoryConfigInfoPersistService;
+import com.alibaba.nacos.config.server.utils.ConfigExtInfoUtil;
import com.alibaba.nacos.persistence.configuration.condition.ConditionOnEmbeddedStorage;
import com.alibaba.nacos.persistence.datasource.DataSourceService;
import com.alibaba.nacos.persistence.datasource.DynamicDataSource;
@@ -45,11 +46,11 @@
import org.springframework.stereotype.Service;
import java.sql.Timestamp;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-import static com.alibaba.nacos.config.server.service.repository.ConfigRowMapperInjector.CONFIG_INFO_STATE_WRAPPER_ROW_MAPPER;
import static com.alibaba.nacos.config.server.service.repository.ConfigRowMapperInjector.HISTORY_DETAIL_ROW_MAPPER;
import static com.alibaba.nacos.config.server.service.repository.ConfigRowMapperInjector.HISTORY_LIST_ROW_MAPPER;
@@ -90,19 +91,20 @@ public PaginationHelper createPaginationHelper() {
@Override
public void insertConfigHistoryAtomic(long configHistoryId, ConfigInfo configInfo, String srcIp, String srcUser,
- final Timestamp time, String ops) {
+ final Timestamp time, String ops, String publishType, String extInfo) {
String appNameTmp = StringUtils.defaultEmptyIfBlank(configInfo.getAppName());
String tenantTmp = StringUtils.defaultEmptyIfBlank(configInfo.getTenant());
final String md5Tmp = MD5Utils.md5Hex(configInfo.getContent(), Constants.ENCODE);
+ String publishTypeTmp = StringUtils.defaultEmptyIfBlank(publishType);
String encryptedDataKey = StringUtils.defaultEmptyIfBlank(configInfo.getEncryptedDataKey());
HistoryConfigInfoMapper historyConfigInfoMapper = mapperManager.findMapper(
dataSourceService.getDataSourceType(), TableConstant.HIS_CONFIG_INFO);
final String sql = historyConfigInfoMapper.insert(
Arrays.asList("id", "data_id", "group_id", "tenant_id", "app_name", "content", "md5", "src_ip",
- "src_user", "gmt_modified", "op_type", "encrypted_data_key"));
+ "src_user", "gmt_modified", "op_type", "publish_type", "ext_info", "encrypted_data_key"));
final Object[] args = new Object[] {configHistoryId, configInfo.getDataId(), configInfo.getGroup(), tenantTmp,
- appNameTmp, configInfo.getContent(), md5Tmp, srcIp, srcUser, time, ops, encryptedDataKey};
+ appNameTmp, configInfo.getContent(), md5Tmp, srcIp, srcUser, time, ops, publishTypeTmp, extInfo, encryptedDataKey};
EmbeddedStorageContextHolder.addSqlContext(sql, args);
}
@@ -121,17 +123,32 @@ public void removeConfigHistory(final Timestamp startTime, final int limitSize)
@Override
public List findDeletedConfig(final Timestamp startTime, long lastMaxId,
- final int pageSize) {
+ final int pageSize, String publishType) {
HistoryConfigInfoMapper historyConfigInfoMapper = mapperManager.findMapper(
dataSourceService.getDataSourceType(), TableConstant.HIS_CONFIG_INFO);
MapperContext context = new MapperContext();
context.putWhereParameter(FieldConstant.START_TIME, startTime);
context.putWhereParameter(FieldConstant.PAGE_SIZE, pageSize);
context.putWhereParameter(FieldConstant.LAST_MAX_ID, lastMaxId);
+ context.putWhereParameter(FieldConstant.PUBLISH_TYPE, publishType);
MapperResult mapperResult = historyConfigInfoMapper.findDeletedConfig(context);
- return databaseOperate.queryMany(mapperResult.getSql(), mapperResult.getParamList().toArray(),
- CONFIG_INFO_STATE_WRAPPER_ROW_MAPPER);
+ List configHistoryInfos = databaseOperate.queryMany(mapperResult.getSql(),
+ mapperResult.getParamList().toArray(), HISTORY_DETAIL_ROW_MAPPER);
+
+ List configInfoStateWrappers = new ArrayList<>();
+ for (ConfigHistoryInfo configHistoryInfo : configHistoryInfos) {
+ ConfigInfoStateWrapper configInfoStateWrapper = new ConfigInfoStateWrapper();
+ configInfoStateWrapper.setId(configHistoryInfo.getId());
+ configInfoStateWrapper.setDataId(configHistoryInfo.getDataId());
+ configInfoStateWrapper.setGroup(configHistoryInfo.getGroup());
+ configInfoStateWrapper.setTenant(configHistoryInfo.getTenant());
+ configInfoStateWrapper.setMd5(configHistoryInfo.getMd5());
+ configInfoStateWrapper.setLastModified(configHistoryInfo.getLastModifiedTime().getTime());
+ configInfoStateWrapper.setGrayName(ConfigExtInfoUtil.extractGrayName(configHistoryInfo.getExtInfo()));
+ configInfoStateWrappers.add(configInfoStateWrapper);
+ }
+ return configInfoStateWrappers;
}
@Override
@@ -161,7 +178,7 @@ public ConfigHistoryInfo detailConfigHistory(Long nid) {
dataSourceService.getDataSourceType(), TableConstant.HIS_CONFIG_INFO);
String sqlFetchRows = historyConfigInfoMapper.select(
Arrays.asList("nid", "data_id", "group_id", "tenant_id", "app_name", "content", "md5", "src_user",
- "src_ip", "op_type", "gmt_create", "gmt_modified", "encrypted_data_key"),
+ "src_ip", "op_type", "publish_type", "ext_info", "gmt_create", "gmt_modified", "encrypted_data_key"),
Collections.singletonList("nid"));
return databaseOperate.queryOne(sqlFetchRows, new Object[] {nid}, HISTORY_DETAIL_ROW_MAPPER);
}
diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/extrnal/ExternalConfigInfoAggrPersistServiceImpl.java b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/extrnal/ExternalConfigInfoAggrPersistServiceImpl.java
deleted file mode 100644
index 03c7d093e1c..00000000000
--- a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/extrnal/ExternalConfigInfoAggrPersistServiceImpl.java
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
- * Copyright 1999-2022 Alibaba Group Holding Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.alibaba.nacos.config.server.service.repository.extrnal;
-
-import com.alibaba.nacos.common.utils.StringUtils;
-import com.alibaba.nacos.config.server.model.ConfigInfoAggr;
-import com.alibaba.nacos.config.server.model.ConfigInfoChanged;
-import com.alibaba.nacos.config.server.service.repository.ConfigInfoAggrPersistService;
-import com.alibaba.nacos.config.server.utils.LogUtil;
-import com.alibaba.nacos.persistence.configuration.condition.ConditionOnExternalStorage;
-import com.alibaba.nacos.persistence.datasource.DataSourceService;
-import com.alibaba.nacos.persistence.datasource.DynamicDataSource;
-import com.alibaba.nacos.persistence.model.Page;
-import com.alibaba.nacos.persistence.repository.PaginationHelper;
-import com.alibaba.nacos.persistence.repository.extrnal.ExternalStoragePaginationHelperImpl;
-import com.alibaba.nacos.plugin.datasource.MapperManager;
-import com.alibaba.nacos.plugin.datasource.constants.CommonConstant;
-import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
-import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
-import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoAggrMapper;
-import com.alibaba.nacos.plugin.datasource.model.MapperContext;
-import com.alibaba.nacos.plugin.datasource.model.MapperResult;
-import com.alibaba.nacos.sys.env.EnvUtil;
-import org.springframework.context.annotation.Conditional;
-import org.springframework.dao.DataAccessException;
-import org.springframework.dao.EmptyResultDataAccessException;
-import org.springframework.jdbc.CannotGetJdbcConnectionException;
-import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.TransactionException;
-import org.springframework.transaction.TransactionSystemException;
-import org.springframework.transaction.support.TransactionTemplate;
-
-import java.sql.Timestamp;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import static com.alibaba.nacos.config.server.service.repository.ConfigRowMapperInjector.CONFIG_INFO_AGGR_ROW_MAPPER;
-import static com.alibaba.nacos.config.server.service.repository.ConfigRowMapperInjector.CONFIG_INFO_CHANGED_ROW_MAPPER;
-
-/**
- * ExternalConfigInfoAggrPersistServiceImpl.
- *
- * @author lixiaoshuang
- */
-@SuppressWarnings(value = {"PMD.MethodReturnWrapperTypeRule", "checkstyle:linelength"})
-@Conditional(value = ConditionOnExternalStorage.class)
-@Service("externalConfigInfoAggrPersistServiceImpl")
-public class ExternalConfigInfoAggrPersistServiceImpl implements ConfigInfoAggrPersistService {
-
- private DataSourceService dataSourceService;
-
- protected JdbcTemplate jt;
-
- protected TransactionTemplate tjt;
-
- private MapperManager mapperManager;
-
- public ExternalConfigInfoAggrPersistServiceImpl() {
- this.dataSourceService = DynamicDataSource.getInstance().getDataSource();
- this.jt = dataSourceService.getJdbcTemplate();
- this.tjt = dataSourceService.getTransactionTemplate();
- Boolean isDataSourceLogEnable = EnvUtil.getProperty(CommonConstant.NACOS_PLUGIN_DATASOURCE_LOG, Boolean.class,
- false);
- this.mapperManager = MapperManager.instance(isDataSourceLogEnable);
- }
-
- @Override
- public PaginationHelper createPaginationHelper() {
- return new ExternalStoragePaginationHelperImpl<>(jt);
- }
-
- @Override
- public boolean addAggrConfigInfo(final String dataId, final String group, String tenant, final String datumId,
- String appName, final String content) {
- String appNameTmp = StringUtils.isBlank(appName) ? StringUtils.EMPTY : appName;
- String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
- final Timestamp now = new Timestamp(System.currentTimeMillis());
- ConfigInfoAggrMapper configInfoAggrMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
- TableConstant.CONFIG_INFO_AGGR);
- String select = configInfoAggrMapper.select(Collections.singletonList("content"),
- Arrays.asList("data_id", "group_id", "tenant_id", "datum_id"));
- String insert = configInfoAggrMapper.insert(
- Arrays.asList("data_id", "group_id", "tenant_id", "datum_id", "app_name", "content", "gmt_modified"));
- String update = configInfoAggrMapper.update(Arrays.asList("content", "gmt_modified"),
- Arrays.asList("data_id", "group_id", "tenant_id", "datum_id"));
-
- try {
- try {
- String dbContent = jt.queryForObject(select, new Object[] {dataId, group, tenantTmp, datumId},
- String.class);
-
- if (dbContent != null && dbContent.equals(content)) {
- return true;
- } else {
- return jt.update(update, content, now, dataId, group, tenantTmp, datumId) > 0;
- }
- } catch (EmptyResultDataAccessException ex) { // no data, insert
- return jt.update(insert, dataId, group, tenantTmp, datumId, appNameTmp, content, now) > 0;
- }
- } catch (DataAccessException e) {
- LogUtil.FATAL_LOG.error("[db-error] " + e, e);
- throw e;
- }
- }
-
- @Override
- public boolean batchPublishAggr(final String dataId, final String group, final String tenant,
- final Map datumMap, final String appName) {
- try {
- Boolean isPublishOk = tjt.execute(status -> {
- for (Map.Entry entry : datumMap.entrySet()) {
- try {
- if (!addAggrConfigInfo(dataId, group, tenant, entry.getKey(), appName, entry.getValue())) {
- throw new TransactionSystemException("error in batchPublishAggr");
- }
- } catch (Throwable e) {
- throw new TransactionSystemException("error in batchPublishAggr");
- }
- }
- return Boolean.TRUE;
- });
- if (isPublishOk == null) {
- return false;
- }
- return isPublishOk;
- } catch (TransactionException e) {
- LogUtil.FATAL_LOG.error("[db-error] " + e, e);
- return false;
- }
- }
-
- @Override
- public int aggrConfigInfoCount(String dataId, String group, String tenant) {
- String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
- ConfigInfoAggrMapper configInfoAggrMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
- TableConstant.CONFIG_INFO_AGGR);
- String sql = configInfoAggrMapper.count(Arrays.asList("data_id", "group_id", "tenant_id"));
- Integer result = jt.queryForObject(sql, Integer.class, new Object[] {dataId, group, tenantTmp});
- return result.intValue();
- }
-
- @Override
- public Page findConfigInfoAggrByPage(String dataId, String group, String tenant, final int pageNo,
- final int pageSize) {
- String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
- ConfigInfoAggrMapper configInfoAggrMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
- TableConstant.CONFIG_INFO_AGGR);
- final int startRow = (pageNo - 1) * pageSize;
- String sqlCountRows = configInfoAggrMapper.select(Arrays.asList("count(*)"),
- Arrays.asList("data_id", "group_id", "tenant_id"));
-
- MapperContext context = new MapperContext();
- context.putWhereParameter(FieldConstant.DATA_ID, dataId);
- context.putWhereParameter(FieldConstant.GROUP_ID, group);
- context.putWhereParameter(FieldConstant.TENANT_ID, tenantTmp);
- context.setStartRow(startRow);
- context.setPageSize(pageSize);
-
- MapperResult mapperResult = configInfoAggrMapper.findConfigInfoAggrByPageFetchRows(context);
- String sqlFetchRows = mapperResult.getSql();
- Object[] sqlFetchArgs = mapperResult.getParamList().toArray();
-
- PaginationHelper helper = this.createPaginationHelper();
- try {
- return helper.fetchPageLimit(sqlCountRows, new Object[] {dataId, group, tenantTmp}, sqlFetchRows,
- sqlFetchArgs, pageNo, pageSize, CONFIG_INFO_AGGR_ROW_MAPPER);
-
- } catch (CannotGetJdbcConnectionException e) {
- LogUtil.FATAL_LOG.error("[db-error] " + e, e);
- throw e;
- }
- }
-
- @Override
- public List findAllAggrGroup() {
- ConfigInfoAggrMapper configInfoAggrMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
- TableConstant.CONFIG_INFO_AGGR);
- MapperResult mapperResult = configInfoAggrMapper.findAllAggrGroupByDistinct(null);
-
- try {
- return jt.query(mapperResult.getSql(), mapperResult.getParamList().toArray(),
- CONFIG_INFO_CHANGED_ROW_MAPPER);
- } catch (CannotGetJdbcConnectionException e) {
- LogUtil.FATAL_LOG.error("[db-error] " + e, e);
- throw e;
- } catch (EmptyResultDataAccessException e) {
- return null;
- } catch (Exception e) {
- LogUtil.FATAL_LOG.error("[db-other-error]" + e.getMessage(), e);
- throw new RuntimeException(e);
- }
- }
-
-}
diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/extrnal/ExternalConfigInfoGrayPersistServiceImpl.java b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/extrnal/ExternalConfigInfoGrayPersistServiceImpl.java
new file mode 100644
index 00000000000..a19bc2e840f
--- /dev/null
+++ b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/extrnal/ExternalConfigInfoGrayPersistServiceImpl.java
@@ -0,0 +1,408 @@
+/*
+ * Copyright 1999-2022 Alibaba Group Holding Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.alibaba.nacos.config.server.service.repository.extrnal;
+
+import com.alibaba.nacos.common.utils.MD5Utils;
+import com.alibaba.nacos.common.utils.StringUtils;
+import com.alibaba.nacos.config.server.constant.Constants;
+import com.alibaba.nacos.config.server.model.ConfigInfo;
+import com.alibaba.nacos.config.server.model.ConfigInfoGrayWrapper;
+import com.alibaba.nacos.config.server.model.ConfigInfoStateWrapper;
+import com.alibaba.nacos.config.server.model.ConfigOperateResult;
+import com.alibaba.nacos.config.server.service.repository.ConfigInfoGrayPersistService;
+import com.alibaba.nacos.config.server.service.repository.HistoryConfigInfoPersistService;
+import com.alibaba.nacos.config.server.utils.ConfigExtInfoUtil;
+import com.alibaba.nacos.config.server.utils.LogUtil;
+import com.alibaba.nacos.persistence.configuration.condition.ConditionOnExternalStorage;
+import com.alibaba.nacos.persistence.datasource.DataSourceService;
+import com.alibaba.nacos.persistence.datasource.DynamicDataSource;
+import com.alibaba.nacos.persistence.model.Page;
+import com.alibaba.nacos.persistence.repository.PaginationHelper;
+import com.alibaba.nacos.persistence.repository.extrnal.ExternalStoragePaginationHelperImpl;
+import com.alibaba.nacos.plugin.datasource.MapperManager;
+import com.alibaba.nacos.plugin.datasource.constants.CommonConstant;
+import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
+import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
+import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoGrayMapper;
+import com.alibaba.nacos.plugin.datasource.model.MapperContext;
+import com.alibaba.nacos.plugin.datasource.model.MapperResult;
+import com.alibaba.nacos.sys.env.EnvUtil;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.dao.DataAccessException;
+import org.springframework.dao.EmptyResultDataAccessException;
+import org.springframework.jdbc.CannotGetJdbcConnectionException;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.TransactionStatus;
+import org.springframework.transaction.support.TransactionCallbackWithoutResult;
+import org.springframework.transaction.support.TransactionTemplate;
+
+import java.sql.Timestamp;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static com.alibaba.nacos.config.server.service.repository.ConfigRowMapperInjector.CONFIG_INFO_GRAY_WRAPPER_ROW_MAPPER;
+import static com.alibaba.nacos.config.server.service.repository.ConfigRowMapperInjector.CONFIG_INFO_STATE_WRAPPER_ROW_MAPPER;
+
+
+/**
+ * ExternalConfigInfoGrayPersistServiceImpl.
+ *
+ * @author rong
+ */
+@SuppressWarnings(value = {"PMD.MethodReturnWrapperTypeRule", "checkstyle:linelength"})
+@Conditional(value = ConditionOnExternalStorage.class)
+@Service("externalConfigInfoGrayPersistServiceImpl")
+public class ExternalConfigInfoGrayPersistServiceImpl implements ConfigInfoGrayPersistService {
+
+ private DataSourceService dataSourceService;
+
+ protected JdbcTemplate jt;
+
+ protected TransactionTemplate tjt;
+
+ private MapperManager mapperManager;
+
+ private HistoryConfigInfoPersistService historyConfigInfoPersistService;
+
+ public ExternalConfigInfoGrayPersistServiceImpl(
+ @Qualifier("externalHistoryConfigInfoPersistServiceImpl") HistoryConfigInfoPersistService historyConfigInfoPersistService) {
+ this.historyConfigInfoPersistService = historyConfigInfoPersistService;
+ this.dataSourceService = DynamicDataSource.getInstance().getDataSource();
+ this.jt = dataSourceService.getJdbcTemplate();
+ this.tjt = dataSourceService.getTransactionTemplate();
+ Boolean isDataSourceLogEnable = EnvUtil.getProperty(CommonConstant.NACOS_PLUGIN_DATASOURCE_LOG, Boolean.class,
+ false);
+ this.mapperManager = MapperManager.instance(isDataSourceLogEnable);
+ }
+
+ @Override
+ public PaginationHelper createPaginationHelper() {
+ return new ExternalStoragePaginationHelperImpl<>(jt);
+ }
+
+ @Override
+ public ConfigInfoStateWrapper findConfigInfo4GrayState(final String dataId, final String group, final String tenant,
+ String grayName) {
+ ConfigInfoGrayMapper configInfoGrayMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
+ TableConstant.CONFIG_INFO_GRAY);
+ String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
+ String grayNameTmp = StringUtils.isBlank(grayName) ? StringUtils.EMPTY : grayName.trim();
+ try {
+ return this.jt.queryForObject(configInfoGrayMapper.select(
+ Arrays.asList("id", "data_id", "group_id", "tenant_id", "gray_rule", "gmt_modified"),
+ Arrays.asList("data_id", "group_id", "tenant_id", "gray_name")),
+ new Object[] {dataId, group, tenantTmp, grayNameTmp}, CONFIG_INFO_STATE_WRAPPER_ROW_MAPPER);
+ } catch (EmptyResultDataAccessException e) {
+ return null;
+ }
+ }
+
+ private ConfigOperateResult getGrayOperateResult(String dataId, String group, String tenant, String grayName) {
+ String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
+
+ ConfigInfoStateWrapper configInfo4Gray = this.findConfigInfo4GrayState(dataId, group, tenantTmp, grayName);
+ if (configInfo4Gray == null) {
+ return new ConfigOperateResult(false);
+ }
+ return new ConfigOperateResult(configInfo4Gray.getId(), configInfo4Gray.getLastModified());
+
+ }
+
+ @Override
+ public ConfigOperateResult addConfigInfo4Gray(ConfigInfo configInfo, String grayName, String grayRule, String srcIp,
+ String srcUser) {
+ return tjt.execute(status -> {
+ String tenantTmp =
+ StringUtils.isBlank(configInfo.getTenant()) ? StringUtils.EMPTY : configInfo.getTenant().trim();
+ String grayNameTmp = StringUtils.isBlank(grayName) ? StringUtils.EMPTY : grayName.trim();
+ String grayRuleTmp = StringUtils.isBlank(grayRule) ? StringUtils.EMPTY : grayRule.trim();
+ try {
+ addConfigInfoGrayAtomic(-1, configInfo, grayNameTmp, grayRuleTmp, srcIp, srcUser);
+
+ Timestamp now = new Timestamp(System.currentTimeMillis());
+ historyConfigInfoPersistService.insertConfigHistoryAtomic(0, configInfo, srcIp, srcUser, now, "I",
+ Constants.GRAY, ConfigExtInfoUtil.getExtInfoFromGrayInfo(grayNameTmp, grayRuleTmp, srcUser));
+
+ return getGrayOperateResult(configInfo.getDataId(), configInfo.getGroup(), tenantTmp, grayNameTmp);
+ } catch (Exception e) {
+ LogUtil.FATAL_LOG.error("[db-error] " + e, e);
+ throw e;
+ }
+ });
+ }
+
+ @Override
+ public void addConfigInfoGrayAtomic(long configGrayId, ConfigInfo configInfo, String grayName, String grayRule,
+ String srcIp, String srcUser) {
+ String appNameTmp = StringUtils.defaultEmptyIfBlank(configInfo.getAppName());
+ String tenantTmp = StringUtils.defaultEmptyIfBlank(configInfo.getTenant());
+ String md5 = MD5Utils.md5Hex(configInfo.getContent(), Constants.ENCODE);
+ final String encryptedDataKey =
+ configInfo.getEncryptedDataKey() == null ? StringUtils.EMPTY : configInfo.getEncryptedDataKey();
+ ConfigInfoGrayMapper configInfoGrayMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
+ TableConstant.CONFIG_INFO_GRAY);
+ jt.update(configInfoGrayMapper.insert(
+ Arrays.asList("data_id", "group_id", "tenant_id", "gray_name", "gray_rule", "app_name", "content",
+ "encrypted_data_key", "md5", "src_ip", "src_user", "gmt_create@NOW()", "gmt_modified@NOW()")),
+ configInfo.getDataId(), configInfo.getGroup(), tenantTmp, grayName, grayRule, appNameTmp,
+ configInfo.getContent(), encryptedDataKey, md5, srcIp, srcUser);
+ }
+
+ @Override
+ public ConfigOperateResult insertOrUpdateGray(final ConfigInfo configInfo, final String grayName,
+ final String grayRule, final String srcIp, final String srcUser) {
+ if (findConfigInfo4GrayState(configInfo.getDataId(), configInfo.getGroup(), configInfo.getTenant(), grayName)
+ == null) {
+ return addConfigInfo4Gray(configInfo, grayName, grayRule, srcIp, srcUser);
+ } else {
+ return updateConfigInfo4Gray(configInfo, grayName, grayRule, srcIp, srcUser);
+ }
+ }
+
+ @Override
+ public ConfigOperateResult insertOrUpdateGrayCas(final ConfigInfo configInfo, final String grayName,
+ final String grayRule, final String srcIp, final String srcUser) {
+ if (findConfigInfo4GrayState(configInfo.getDataId(), configInfo.getGroup(), configInfo.getTenant(), grayName)
+ == null) {
+ return addConfigInfo4Gray(configInfo, grayName, grayRule, srcIp, srcUser);
+ } else {
+ return updateConfigInfo4GrayCas(configInfo, grayName, grayRule, srcIp, srcUser);
+ }
+ }
+
+ @Override
+ public void removeConfigInfoGray(final String dataId, final String group, final String tenant,
+ final String grayName, final String srcIp, final String srcUser) {
+ tjt.execute(new TransactionCallbackWithoutResult() {
+ @Override
+ protected void doInTransactionWithoutResult(TransactionStatus status) {
+ String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
+ String grayNameTmp = StringUtils.isBlank(grayName) ? StringUtils.EMPTY : grayName;
+ try {
+ ConfigInfoGrayWrapper oldConfigAllInfo4Gray = findConfigInfo4Gray(dataId, group, tenantTmp,
+ grayNameTmp);
+ if (oldConfigAllInfo4Gray == null) {
+ return;
+ }
+
+ ConfigInfoGrayMapper configInfoGrayMapper = mapperManager.findMapper(
+ dataSourceService.getDataSourceType(), TableConstant.CONFIG_INFO_GRAY);
+ jt.update(
+ configInfoGrayMapper.delete(Arrays.asList("data_id", "group_id", "tenant_id", "gray_name")),
+ dataId, group, tenantTmp, grayNameTmp);
+
+ Timestamp now = new Timestamp(System.currentTimeMillis());
+ historyConfigInfoPersistService.insertConfigHistoryAtomic(oldConfigAllInfo4Gray.getId(),
+ oldConfigAllInfo4Gray, srcIp, srcUser, now, "D", Constants.GRAY,
+ ConfigExtInfoUtil.getExtInfoFromGrayInfo(oldConfigAllInfo4Gray.getGrayName(),
+ oldConfigAllInfo4Gray.getGrayRule(), oldConfigAllInfo4Gray.getSrcUser()));
+ } catch (CannotGetJdbcConnectionException e) {
+ LogUtil.FATAL_LOG.error("[db-error] " + e, e);
+ throw e;
+ }
+ }
+ });
+ }
+
+ @Override
+ public ConfigOperateResult updateConfigInfo4Gray(ConfigInfo configInfo, String grayName, String grayRule,
+ String srcIp, String srcUser) {
+ return tjt.execute(status -> {
+ String appNameTmp = StringUtils.defaultEmptyIfBlank(configInfo.getAppName());
+ String tenantTmp = StringUtils.defaultEmptyIfBlank(configInfo.getTenant());
+ String grayNameTmp = StringUtils.isBlank(grayName) ? StringUtils.EMPTY : grayName.trim();
+ String grayRuleTmp = StringUtils.isBlank(grayRule) ? StringUtils.EMPTY : grayRule.trim();
+ try {
+ ConfigInfoGrayWrapper oldConfigAllInfo4Gray = findConfigInfo4Gray(configInfo.getDataId(),
+ configInfo.getGroup(), tenantTmp, grayNameTmp);
+ if (oldConfigAllInfo4Gray == null) {
+ if (LogUtil.FATAL_LOG.isErrorEnabled()) {
+ LogUtil.FATAL_LOG.error("expected config info[dataid:{}, group:{}, tenent:{}] but not found.",
+ configInfo.getDataId(), configInfo.getGroup(), configInfo.getTenant());
+ }
+ }
+
+ String md5 = MD5Utils.md5Hex(configInfo.getContent(), Constants.ENCODE);
+ ConfigInfoGrayMapper configInfoGrayMapper = mapperManager.findMapper(
+ dataSourceService.getDataSourceType(), TableConstant.CONFIG_INFO_GRAY);
+ jt.update(configInfoGrayMapper.update(
+ Arrays.asList("content", "encrypted_data_key", "md5", "src_ip", "src_user",
+ "gmt_modified@NOW()", "app_name", "gray_rule"),
+ Arrays.asList("data_id", "group_id", "tenant_id", "gray_name")), configInfo.getContent(),
+ configInfo.getEncryptedDataKey(), md5, srcIp, srcUser, appNameTmp, grayRuleTmp,
+ configInfo.getDataId(), configInfo.getGroup(), tenantTmp, grayNameTmp);
+
+ Timestamp now = new Timestamp(System.currentTimeMillis());
+ historyConfigInfoPersistService.insertConfigHistoryAtomic(oldConfigAllInfo4Gray.getId(),
+ oldConfigAllInfo4Gray, srcIp, srcUser, now, "U", Constants.GRAY,
+ ConfigExtInfoUtil.getExtInfoFromGrayInfo(oldConfigAllInfo4Gray.getGrayName(),
+ oldConfigAllInfo4Gray.getGrayRule(), oldConfigAllInfo4Gray.getSrcUser()));
+
+ return getGrayOperateResult(configInfo.getDataId(), configInfo.getGroup(), tenantTmp, grayNameTmp);
+ } catch (CannotGetJdbcConnectionException e) {
+ LogUtil.FATAL_LOG.error("[db-error] " + e, e);
+ throw e;
+ }
+ });
+ }
+
+ @Override
+ public ConfigOperateResult updateConfigInfo4GrayCas(ConfigInfo configInfo, String grayName, String grayRule,
+ String srcIp, String srcUser) {
+ return tjt.execute(status -> {
+ String appNameTmp = StringUtils.defaultEmptyIfBlank(configInfo.getAppName());
+ String tenantTmp = StringUtils.defaultEmptyIfBlank(configInfo.getTenant());
+ String grayNameTmp = StringUtils.isBlank(grayName) ? StringUtils.EMPTY : grayName.trim();
+ String grayRuleTmp = StringUtils.isBlank(grayRule) ? StringUtils.EMPTY : grayRule.trim();
+ try {
+ String md5 = MD5Utils.md5Hex(configInfo.getContent(), Constants.ENCODE);
+ ConfigInfoGrayMapper configInfoGrayMapper = mapperManager.findMapper(
+ dataSourceService.getDataSourceType(), TableConstant.CONFIG_INFO_GRAY);
+ Timestamp time = new Timestamp(System.currentTimeMillis());
+
+ MapperContext context = new MapperContext();
+ context.putUpdateParameter(FieldConstant.CONTENT, configInfo.getContent());
+ context.putUpdateParameter(FieldConstant.MD5, md5);
+ context.putUpdateParameter(FieldConstant.SRC_IP, srcIp);
+ context.putUpdateParameter(FieldConstant.SRC_USER, srcUser);
+ context.putUpdateParameter(FieldConstant.APP_NAME, appNameTmp);
+
+ context.putWhereParameter(FieldConstant.DATA_ID, configInfo.getDataId());
+ context.putWhereParameter(FieldConstant.GROUP_ID, configInfo.getGroup());
+ context.putWhereParameter(FieldConstant.TENANT_ID, tenantTmp);
+ context.putWhereParameter(FieldConstant.GRAY_NAME, grayNameTmp);
+ context.putWhereParameter(FieldConstant.GRAY_RULE, grayRuleTmp);
+ context.putWhereParameter(FieldConstant.MD5, configInfo.getMd5());
+
+ final MapperResult mapperResult = configInfoGrayMapper.updateConfigInfo4GrayCas(context);
+ boolean success = jt.update(mapperResult.getSql(), mapperResult.getParamList().toArray()) > 0;
+
+ ConfigInfoGrayWrapper oldConfigAllInfo4Gray = findConfigInfo4Gray(configInfo.getDataId(),
+ configInfo.getGroup(), tenantTmp, grayNameTmp);
+ if (oldConfigAllInfo4Gray == null) {
+ if (LogUtil.FATAL_LOG.isErrorEnabled()) {
+ LogUtil.FATAL_LOG.error("expected config info[dataid:{}, group:{}, tenent:{}] but not found.",
+ configInfo.getDataId(), configInfo.getGroup(), configInfo.getTenant());
+ }
+ }
+
+ Timestamp now = new Timestamp(System.currentTimeMillis());
+ historyConfigInfoPersistService.insertConfigHistoryAtomic(oldConfigAllInfo4Gray.getId(),
+ oldConfigAllInfo4Gray, srcIp, srcUser, now, "U", Constants.GRAY,
+ ConfigExtInfoUtil.getExtInfoFromGrayInfo(oldConfigAllInfo4Gray.getGrayName(),
+ oldConfigAllInfo4Gray.getGrayRule(), oldConfigAllInfo4Gray.getSrcUser()));
+
+ if (success) {
+ return getGrayOperateResult(configInfo.getDataId(), configInfo.getGroup(), tenantTmp, grayNameTmp);
+ } else {
+ return new ConfigOperateResult(false);
+ }
+ } catch (CannotGetJdbcConnectionException e) {
+ LogUtil.FATAL_LOG.error("[db-error] " + e, e);
+ throw e;
+ }
+ });
+ }
+
+ @Override
+ public ConfigInfoGrayWrapper findConfigInfo4Gray(final String dataId, final String group, final String tenant,
+ final String grayName) {
+ String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
+ String grayNameTmp = StringUtils.isBlank(grayName) ? StringUtils.EMPTY : grayName.trim();
+ try {
+ ConfigInfoGrayMapper configInfoGrayMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
+ TableConstant.CONFIG_INFO_GRAY);
+ return this.jt.queryForObject(configInfoGrayMapper.select(
+ Arrays.asList("id", "data_id", "group_id", "tenant_id", "gray_name", "gray_rule", "app_name",
+ "content", "md5", "encrypted_data_key", "gmt_modified", "src_user"),
+ Arrays.asList("data_id", "group_id", "tenant_id", "gray_name")),
+ new Object[] {dataId, group, tenantTmp, grayNameTmp}, CONFIG_INFO_GRAY_WRAPPER_ROW_MAPPER);
+ } catch (EmptyResultDataAccessException e) { // Indicates that the data does not exist, returns null.
+ return null;
+ } catch (CannotGetJdbcConnectionException e) {
+ LogUtil.FATAL_LOG.error("[db-error] " + e, e);
+ throw e;
+ }
+ }
+
+ @Override
+ public int configInfoGrayCount() {
+ ConfigInfoGrayMapper configInfoGrayMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
+ TableConstant.CONFIG_INFO_GRAY);
+ String sql = configInfoGrayMapper.count(null);
+ Integer result = jt.queryForObject(sql, Integer.class);
+ if (result == null) {
+ throw new IllegalArgumentException("configInfoGrayCount error");
+ }
+ return result;
+ }
+
+ @Override
+ public Page findAllConfigInfoGrayForDumpAll(final int pageNo, final int pageSize) {
+ final int startRow = (pageNo - 1) * pageSize;
+ ConfigInfoGrayMapper configInfoGrayMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
+ TableConstant.CONFIG_INFO_GRAY);
+ String sqlCountRows = configInfoGrayMapper.count(null);
+ MapperResult sqlFetchRows = configInfoGrayMapper.findAllConfigInfoGrayForDumpAllFetchRows(
+ new MapperContext(startRow, pageSize));
+
+ PaginationHelper helper = createPaginationHelper();
+
+ try {
+ return helper.fetchPageLimit(sqlCountRows, sqlFetchRows.getSql(), sqlFetchRows.getParamList().toArray(),
+ pageNo, pageSize, CONFIG_INFO_GRAY_WRAPPER_ROW_MAPPER);
+
+ } catch (CannotGetJdbcConnectionException e) {
+ LogUtil.FATAL_LOG.error("[db-error] " + e, e);
+ throw e;
+ }
+ }
+
+ @Override
+ public List findChangeConfig(final Timestamp startTime, long lastMaxId, final int pageSize) {
+ try {
+ ConfigInfoGrayMapper configInfoMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
+ TableConstant.CONFIG_INFO_GRAY);
+
+ MapperContext context = new MapperContext();
+ context.putWhereParameter(FieldConstant.START_TIME, startTime);
+ context.putWhereParameter(FieldConstant.PAGE_SIZE, pageSize);
+ context.putWhereParameter(FieldConstant.LAST_MAX_ID, lastMaxId);
+
+ MapperResult mapperResult = configInfoMapper.findChangeConfig(context);
+ return jt.query(mapperResult.getSql(), mapperResult.getParamList().toArray(),
+ CONFIG_INFO_GRAY_WRAPPER_ROW_MAPPER);
+ } catch (DataAccessException e) {
+ LogUtil.FATAL_LOG.error("[db-error] " + e, e);
+ throw e;
+ }
+ }
+
+ @Override
+ public List findConfigInfoGrays(final String dataId, final String group, final String tenant) {
+ String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
+ ConfigInfoGrayMapper configInfoGrayMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
+ TableConstant.CONFIG_INFO_GRAY);
+ String selectSql = configInfoGrayMapper.select(Collections.singletonList("gray_name"),
+ Arrays.asList("data_id", "group_id", "tenant_id"));
+ return jt.queryForList(selectSql, new Object[] {dataId, group, tenantTmp}, String.class);
+ }
+
+}
diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/extrnal/ExternalConfigInfoPersistServiceImpl.java b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/extrnal/ExternalConfigInfoPersistServiceImpl.java
index b768c83c8c3..1f04f57a4c3 100644
--- a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/extrnal/ExternalConfigInfoPersistServiceImpl.java
+++ b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/extrnal/ExternalConfigInfoPersistServiceImpl.java
@@ -34,6 +34,7 @@
import com.alibaba.nacos.config.server.service.repository.ConfigInfoPersistService;
import com.alibaba.nacos.config.server.service.repository.HistoryConfigInfoPersistService;
import com.alibaba.nacos.config.server.service.sql.ExternalStorageUtils;
+import com.alibaba.nacos.config.server.utils.ConfigExtInfoUtil;
import com.alibaba.nacos.config.server.utils.LogUtil;
import com.alibaba.nacos.config.server.utils.ParamUtils;
import com.alibaba.nacos.persistence.configuration.condition.ConditionOnExternalStorage;
@@ -150,7 +151,8 @@ public ConfigOperateResult addConfigInfo(final String srcIp, final String srcUse
configInfo.getTenant());
Timestamp now = new Timestamp(System.currentTimeMillis());
- historyConfigInfoPersistService.insertConfigHistoryAtomic(0, configInfo, srcIp, srcUser, now, "I");
+ historyConfigInfoPersistService.insertConfigHistoryAtomic(0, configInfo, srcIp, srcUser, now, "I",
+ Constants.FORMAL, ConfigExtInfoUtil.getExtraInfoFromAdvanceInfoMap(configAdvanceInfo, srcUser));
ConfigInfoStateWrapper configInfoCurrent = this.findConfigInfoState(configInfo.getDataId(),
configInfo.getGroup(), configInfo.getTenant());
if (configInfoCurrent == null) {
@@ -397,12 +399,12 @@ public void removeConfigInfo(final String dataId, final String group, final Stri
@Override
public Boolean doInTransaction(TransactionStatus status) {
try {
- ConfigInfo configInfo = findConfigInfo(dataId, group, tenant);
- if (configInfo != null) {
+ ConfigAllInfo oldConfigAllInfo = findConfigAllInfo(dataId, group, tenant);
+ if (oldConfigAllInfo != null) {
removeConfigInfoAtomic(dataId, group, tenant, srcIp, srcUser);
- removeTagByIdAtomic(configInfo.getId());
- historyConfigInfoPersistService.insertConfigHistoryAtomic(configInfo.getId(), configInfo, srcIp,
- srcUser, time, "D");
+ removeTagByIdAtomic(oldConfigAllInfo.getId());
+ historyConfigInfoPersistService.insertConfigHistoryAtomic(oldConfigAllInfo.getId(), oldConfigAllInfo,
+ srcIp, srcUser, time, "D", Constants.FORMAL, ConfigExtInfoUtil.getExtInfoFromAllInfo(oldConfigAllInfo));
}
} catch (CannotGetJdbcConnectionException e) {
LogUtil.FATAL_LOG.error("[db-error] " + e, e);
@@ -414,28 +416,29 @@ public Boolean doInTransaction(TransactionStatus status) {
}
@Override
- public List removeConfigInfoByIds(final List ids, final String srcIp, final String srcUser) {
+ public List removeConfigInfoByIds(final List ids, final String srcIp, final String srcUser) {
if (CollectionUtils.isEmpty(ids)) {
return null;
}
ids.removeAll(Collections.singleton(null));
- return tjt.execute(new TransactionCallback>() {
+ return tjt.execute(new TransactionCallback>() {
final Timestamp time = new Timestamp(System.currentTimeMillis());
@Override
- public List doInTransaction(TransactionStatus status) {
+ public List doInTransaction(TransactionStatus status) {
try {
String idsStr = StringUtils.join(ids, StringUtils.COMMA);
- List configInfoList = findConfigInfosByIds(idsStr);
- if (!CollectionUtils.isEmpty(configInfoList)) {
+ List oldConfigAllInfoList = findAllConfigInfo4Export(null, null, null, null, ids);
+ if (!CollectionUtils.isEmpty(oldConfigAllInfoList)) {
removeConfigInfoByIdsAtomic(idsStr);
- for (ConfigInfo configInfo : configInfoList) {
- removeTagByIdAtomic(configInfo.getId());
- historyConfigInfoPersistService.insertConfigHistoryAtomic(configInfo.getId(), configInfo,
- srcIp, srcUser, time, "D");
+ for (ConfigAllInfo configAllInfo : oldConfigAllInfoList) {
+ removeTagByIdAtomic(configAllInfo.getId());
+ historyConfigInfoPersistService.insertConfigHistoryAtomic(configAllInfo.getId(),
+ configAllInfo, srcIp, srcUser, time, "D", Constants.FORMAL,
+ ConfigExtInfoUtil.getExtInfoFromAllInfo(configAllInfo));
}
}
- return configInfoList;
+ return oldConfigAllInfoList;
} catch (CannotGetJdbcConnectionException e) {
LogUtil.FATAL_LOG.error("[db-error] " + e, e);
throw e;
@@ -499,9 +502,9 @@ public ConfigOperateResult updateConfigInfo(final ConfigInfo configInfo, final S
final Map configAdvanceInfo) {
return tjt.execute(status -> {
try {
- ConfigInfo oldConfigInfo = findConfigInfo(configInfo.getDataId(), configInfo.getGroup(),
+ ConfigAllInfo oldConfigAllInfo = findConfigAllInfo(configInfo.getDataId(), configInfo.getGroup(),
configInfo.getTenant());
- if (oldConfigInfo == null) {
+ if (oldConfigAllInfo == null) {
if (LogUtil.FATAL_LOG.isErrorEnabled()) {
LogUtil.FATAL_LOG.error("expected config info[dataid:{}, group:{}, tenent:{}] but not found.",
configInfo.getDataId(), configInfo.getGroup(), configInfo.getTenant());
@@ -509,7 +512,7 @@ public ConfigOperateResult updateConfigInfo(final ConfigInfo configInfo, final S
return new ConfigOperateResult(false);
}
- String appNameTmp = oldConfigInfo.getAppName();
+ String appNameTmp = oldConfigAllInfo.getAppName();
/*
If the appName passed by the user is not empty, use the persistent user's appName,
otherwise use db; when emptying appName, you need to pass an empty string
@@ -521,14 +524,14 @@ public ConfigOperateResult updateConfigInfo(final ConfigInfo configInfo, final S
String configTags = configAdvanceInfo == null ? null : (String) configAdvanceInfo.get("config_tags");
if (configTags != null) {
// delete all tags and then recreate
- removeTagByIdAtomic(oldConfigInfo.getId());
- addConfigTagsRelation(oldConfigInfo.getId(), configTags, configInfo.getDataId(),
+ removeTagByIdAtomic(oldConfigAllInfo.getId());
+ addConfigTagsRelation(oldConfigAllInfo.getId(), configTags, configInfo.getDataId(),
configInfo.getGroup(), configInfo.getTenant());
}
-
+
Timestamp now = new Timestamp(System.currentTimeMillis());
- historyConfigInfoPersistService.insertConfigHistoryAtomic(oldConfigInfo.getId(), oldConfigInfo, srcIp,
- srcUser, now, "U");
+ historyConfigInfoPersistService.insertConfigHistoryAtomic(oldConfigAllInfo.getId(), oldConfigAllInfo, srcIp, srcUser,
+ now, "U", Constants.FORMAL, ConfigExtInfoUtil.getExtInfoFromAllInfo(oldConfigAllInfo));
return getConfigInfoOperateResult(configInfo.getDataId(), configInfo.getGroup(),
configInfo.getTenant());
} catch (CannotGetJdbcConnectionException e) {
@@ -552,16 +555,16 @@ public ConfigOperateResult updateConfigInfoCas(final ConfigInfo configInfo, fina
final String srcUser, final Map configAdvanceInfo) {
return tjt.execute(status -> {
try {
- ConfigInfo oldConfigInfo = findConfigInfo(configInfo.getDataId(), configInfo.getGroup(),
+ ConfigAllInfo oldAllConfigInfo = findConfigAllInfo(configInfo.getDataId(), configInfo.getGroup(),
configInfo.getTenant());
- if (oldConfigInfo == null) {
+ if (oldAllConfigInfo == null) {
if (LogUtil.FATAL_LOG.isErrorEnabled()) {
LogUtil.FATAL_LOG.error("expected config info[dataid:{}, group:{}, tenent:{}] but not found.",
configInfo.getDataId(), configInfo.getGroup(), configInfo.getTenant());
}
return new ConfigOperateResult(false);
}
- String appNameTmp = oldConfigInfo.getAppName();
+ String appNameTmp = oldAllConfigInfo.getAppName();
/*
If the appName passed by the user is not empty, use the persistent user's appName,
otherwise use db; when emptying appName, you need to pass an empty string
@@ -576,14 +579,14 @@ public ConfigOperateResult updateConfigInfoCas(final ConfigInfo configInfo, fina
String configTags = configAdvanceInfo == null ? null : (String) configAdvanceInfo.get("config_tags");
if (configTags != null) {
// delete all tags and then recreate
- removeTagByIdAtomic(oldConfigInfo.getId());
- addConfigTagsRelation(oldConfigInfo.getId(), configTags, configInfo.getDataId(),
+ removeTagByIdAtomic(oldAllConfigInfo.getId());
+ addConfigTagsRelation(oldAllConfigInfo.getId(), configTags, configInfo.getDataId(),
configInfo.getGroup(), configInfo.getTenant());
}
Timestamp now = new Timestamp(System.currentTimeMillis());
- historyConfigInfoPersistService.insertConfigHistoryAtomic(oldConfigInfo.getId(), oldConfigInfo, srcIp,
- srcUser, now, "U");
+ historyConfigInfoPersistService.insertConfigHistoryAtomic(oldAllConfigInfo.getId(), oldAllConfigInfo, srcIp, srcUser, now,
+ "U", Constants.FORMAL, ConfigExtInfoUtil.getExtInfoFromAllInfo(oldAllConfigInfo));
ConfigInfoStateWrapper configInfoLast = this.findConfigInfoState(configInfo.getDataId(),
configInfo.getGroup(), configInfo.getTenant());
if (configInfoLast == null) {
@@ -612,7 +615,7 @@ private int updateConfigInfoAtomicCas(final ConfigInfo configInfo, final String
try {
ConfigInfoMapper configInfoMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
TableConstant.CONFIG_INFO);
-
+
MapperContext context = new MapperContext();
context.putUpdateParameter(FieldConstant.CONTENT, configInfo.getContent());
context.putUpdateParameter(FieldConstant.MD5, md5Tmp);
diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/extrnal/ExternalHistoryConfigInfoPersistServiceImpl.java b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/extrnal/ExternalHistoryConfigInfoPersistServiceImpl.java
index eeec61d6130..00df35b8667 100644
--- a/config/src/main/java/com/alibaba/nacos/config/server/service/repository/extrnal/ExternalHistoryConfigInfoPersistServiceImpl.java
+++ b/config/src/main/java/com/alibaba/nacos/config/server/service/repository/extrnal/ExternalHistoryConfigInfoPersistServiceImpl.java
@@ -23,6 +23,7 @@
import com.alibaba.nacos.config.server.model.ConfigInfo;
import com.alibaba.nacos.config.server.model.ConfigInfoStateWrapper;
import com.alibaba.nacos.config.server.service.repository.HistoryConfigInfoPersistService;
+import com.alibaba.nacos.config.server.utils.ConfigExtInfoUtil;
import com.alibaba.nacos.config.server.utils.LogUtil;
import com.alibaba.nacos.persistence.configuration.condition.ConditionOnExternalStorage;
import com.alibaba.nacos.persistence.datasource.DataSourceService;
@@ -46,11 +47,11 @@
import org.springframework.transaction.support.TransactionTemplate;
import java.sql.Timestamp;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-import static com.alibaba.nacos.config.server.service.repository.ConfigRowMapperInjector.CONFIG_INFO_STATE_WRAPPER_ROW_MAPPER;
import static com.alibaba.nacos.config.server.service.repository.ConfigRowMapperInjector.HISTORY_DETAIL_ROW_MAPPER;
import static com.alibaba.nacos.config.server.service.repository.ConfigRowMapperInjector.HISTORY_LIST_ROW_MAPPER;
@@ -88,20 +89,21 @@ public PaginationHelper createPaginationHelper() {
@Override
public void insertConfigHistoryAtomic(long id, ConfigInfo configInfo, String srcIp, String srcUser,
- final Timestamp time, String ops) {
+ final Timestamp time, String ops, String publishType, String extInfo) {
String appNameTmp = StringUtils.defaultEmptyIfBlank(configInfo.getAppName());
String tenantTmp = StringUtils.defaultEmptyIfBlank(configInfo.getTenant());
final String md5Tmp = MD5Utils.md5Hex(configInfo.getContent(), Constants.ENCODE);
String encryptedDataKey = StringUtils.defaultEmptyIfBlank(configInfo.getEncryptedDataKey());
+ String publishTypeTmp = StringUtils.defaultEmptyIfBlank(publishType);
try {
HistoryConfigInfoMapper historyConfigInfoMapper = mapperManager.findMapper(
dataSourceService.getDataSourceType(), TableConstant.HIS_CONFIG_INFO);
jt.update(historyConfigInfoMapper.insert(
Arrays.asList("id", "data_id", "group_id", "tenant_id", "app_name", "content", "md5", "src_ip",
- "src_user", "gmt_modified", "op_type", "encrypted_data_key")), id, configInfo.getDataId(),
- configInfo.getGroup(), tenantTmp, appNameTmp, configInfo.getContent(), md5Tmp, srcIp, srcUser, time,
- ops, encryptedDataKey);
+ "src_user", "gmt_modified", "op_type", "publish_type", "ext_info", "encrypted_data_key")),
+ id, configInfo.getDataId(), configInfo.getGroup(), tenantTmp, appNameTmp, configInfo.getContent(),
+ md5Tmp, srcIp, srcUser, time, ops, publishTypeTmp, extInfo, encryptedDataKey);
} catch (DataAccessException e) {
LogUtil.FATAL_LOG.error("[db-error] " + e, e);
throw e;
@@ -121,7 +123,8 @@ public void removeConfigHistory(final Timestamp startTime, final int limitSize)
}
@Override
- public List findDeletedConfig(final Timestamp startTime, long startId, int pageSize) {
+ public List findDeletedConfig(final Timestamp startTime, long startId, int pageSize,
+ String publishType) {
try {
HistoryConfigInfoMapper historyConfigInfoMapper = mapperManager.findMapper(
dataSourceService.getDataSourceType(), TableConstant.HIS_CONFIG_INFO);
@@ -129,10 +132,25 @@ public List findDeletedConfig(final Timestamp startTime,
context.putWhereParameter(FieldConstant.START_TIME, startTime);
context.putWhereParameter(FieldConstant.PAGE_SIZE, pageSize);
context.putWhereParameter(FieldConstant.LAST_MAX_ID, startId);
+ context.putWhereParameter(FieldConstant.PUBLISH_TYPE, publishType);
MapperResult mapperResult = historyConfigInfoMapper.findDeletedConfig(context);
- return jt.query(mapperResult.getSql(), mapperResult.getParamList().toArray(),
- CONFIG_INFO_STATE_WRAPPER_ROW_MAPPER);
+ List configHistoryInfos = jt.query(mapperResult.getSql(), mapperResult.getParamList().toArray(),
+ HISTORY_DETAIL_ROW_MAPPER);
+
+ List configInfoStateWrappers = new ArrayList<>();
+ for (ConfigHistoryInfo configHistoryInfo : configHistoryInfos) {
+ ConfigInfoStateWrapper configInfoStateWrapper = new ConfigInfoStateWrapper();
+ configInfoStateWrapper.setId(configHistoryInfo.getId());
+ configInfoStateWrapper.setDataId(configHistoryInfo.getDataId());
+ configInfoStateWrapper.setGroup(configHistoryInfo.getGroup());
+ configInfoStateWrapper.setTenant(configHistoryInfo.getTenant());
+ configInfoStateWrapper.setMd5(configHistoryInfo.getMd5());
+ configInfoStateWrapper.setLastModified(configHistoryInfo.getLastModifiedTime().getTime());
+ configInfoStateWrapper.setGrayName(ConfigExtInfoUtil.extractGrayName(configHistoryInfo.getExtInfo()));
+ configInfoStateWrappers.add(configInfoStateWrapper);
+ }
+ return configInfoStateWrappers;
} catch (DataAccessException e) {
LogUtil.FATAL_LOG.error("[db-error] " + e, e);
throw e;
@@ -174,7 +192,7 @@ public ConfigHistoryInfo detailConfigHistory(Long nid) {
dataSourceService.getDataSourceType(), TableConstant.HIS_CONFIG_INFO);
String sqlFetchRows = historyConfigInfoMapper.select(
Arrays.asList("nid", "data_id", "group_id", "tenant_id", "app_name", "content", "md5", "src_user",
- "src_ip", "op_type", "gmt_create", "gmt_modified", "encrypted_data_key"),
+ "src_ip", "op_type", "gmt_create", "gmt_modified", "publish_type", "ext_info", "encrypted_data_key"),
Collections.singletonList("nid"));
try {
ConfigHistoryInfo historyInfo = jt.queryForObject(sqlFetchRows, new Object[] {nid},
diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/sql/EmbeddedStorageContextUtils.java b/config/src/main/java/com/alibaba/nacos/config/server/service/sql/EmbeddedStorageContextUtils.java
index dac6777617f..ecd06f734f7 100644
--- a/config/src/main/java/com/alibaba/nacos/config/server/service/sql/EmbeddedStorageContextUtils.java
+++ b/config/src/main/java/com/alibaba/nacos/config/server/service/sql/EmbeddedStorageContextUtils.java
@@ -19,6 +19,7 @@
import com.alibaba.nacos.common.utils.JacksonUtils;
import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.config.server.constant.Constants;
+import com.alibaba.nacos.config.server.model.ConfigAllInfo;
import com.alibaba.nacos.config.server.model.ConfigInfo;
import com.alibaba.nacos.config.server.model.event.ConfigDumpEvent;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
@@ -102,6 +103,29 @@ public static void onModifyConfigTagInfo(ConfigInfo configInfo, String tag, Stri
}
}
+ /**
+ * In the case of the in-cluster storage mode, the logic of horizontal notification is implemented asynchronously
+ * via the raft state machine, along with the information.
+ *
+ * @param configInfo {@link ConfigInfo}
+ * @param grayName gray name
+ * @param grayRule gray rule
+ * @param srcIp The IP of the operator
+ * @param time Operating time
+ */
+ public static void onModifyConfigGrayInfo(ConfigInfo configInfo, String grayName, String grayRule, String srcIp, Timestamp time) {
+ if (!EnvUtil.getStandaloneMode()) {
+ ConfigDumpEvent event = ConfigDumpEvent.builder().remove(false).namespaceId(configInfo.getTenant())
+ .dataId(configInfo.getDataId()).group(configInfo.getGroup()).isBeta(false).grayName(grayName)
+ .grayRule(grayRule).content(configInfo.getContent()).type(configInfo.getType()).handleIp(srcIp)
+ .lastModifiedTs(time.getTime()).build();
+
+ Map extendInfo = new HashMap<>(2);
+ extendInfo.put(Constants.EXTEND_INFO_CONFIG_DUMP_EVENT, JacksonUtils.toJson(event));
+ EmbeddedStorageContextHolder.putAllExtendInfo(extendInfo);
+ }
+ }
+
/**
* In the case of the in-cluster storage mode, the logic of horizontal notification is implemented asynchronously
* via the raft state machine, along with the information.
@@ -128,12 +152,12 @@ public static void onDeleteConfigInfo(String namespaceId, String group, String d
* In the case of the in-cluster storage mode, the logic of horizontal notification is implemented asynchronously
* via the raft state machine, along with the information.
*
- * @param configInfos {@link ConfigInfo} list
+ * @param configInfos {@link ConfigAllInfo} list
*/
- public static void onBatchDeleteConfigInfo(List configInfos) {
+ public static void onBatchDeleteConfigInfo(List configInfos) {
if (!EnvUtil.getStandaloneMode()) {
List events = new ArrayList<>();
- for (ConfigInfo configInfo : configInfos) {
+ for (ConfigAllInfo configInfo : configInfos) {
String namespaceId =
StringUtils.isBlank(configInfo.getTenant()) ? StringUtils.EMPTY : configInfo.getTenant();
ConfigDumpEvent event = ConfigDumpEvent.builder().remove(true).namespaceId(namespaceId)
@@ -190,4 +214,25 @@ public static void onDeleteConfigTagInfo(String namespaceId, String group, Strin
}
}
+ /**
+ * In the case of the in-cluster storage mode, the logic of horizontal notification is implemented asynchronously
+ * via the raft state machine, along with the information.
+ *
+ * @param namespaceId namespaceId
+ * @param group group
+ * @param dataId dataId
+ * @param grayName gray name
+ * @param srcIp The IP of the operator
+ */
+ public static void onDeleteConfigGrayInfo(String namespaceId, String group, String dataId, String grayName,
+ String srcIp) {
+ if (!EnvUtil.getStandaloneMode()) {
+ ConfigDumpEvent event = ConfigDumpEvent.builder().remove(true).namespaceId(namespaceId).group(group)
+ .dataId(dataId).isBeta(true).grayName(grayName).handleIp(srcIp).build();
+
+ Map extendInfo = new HashMap<>(2);
+ extendInfo.put(Constants.EXTEND_INFO_CONFIG_DUMP_EVENT, JacksonUtils.toJson(event));
+ EmbeddedStorageContextHolder.putAllExtendInfo(extendInfo);
+ }
+ }
}
diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/trace/ConfigTraceService.java b/config/src/main/java/com/alibaba/nacos/config/server/service/trace/ConfigTraceService.java
index ec9b4a58fcc..5133e14c478 100644
--- a/config/src/main/java/com/alibaba/nacos/config/server/service/trace/ConfigTraceService.java
+++ b/config/src/main/java/com/alibaba/nacos/config/server/service/trace/ConfigTraceService.java
@@ -41,8 +41,6 @@ public class ConfigTraceService {
public static final String PERSISTENCE_EVENT_BETA = "persist-beta";
- public static final String PERSISTENCE_EVENT_BATCH = "persist-batch";
-
public static final String PERSISTENCE_EVENT_TAG = "persist-tag";
/**
@@ -101,12 +99,6 @@ public class ConfigTraceService {
*/
public static final String PULL_EVENT = "pull";
- public static final String PULL_EVENT_BETA = "pull-beta";
-
- public static final String PULL_EVENT_BATCH = "pull-batch";
-
- public static final String PULL_EVENT_TAG = "pull-tag";
-
/**
* pull type.
*/
@@ -197,22 +189,10 @@ public static void logDumpEvent(String dataId, String group, String tenant, Stri
delayed, length);
}
- public static void logDumpBetaEvent(String dataId, String group, String tenant, String requestIpAppName, long ts,
- String handleIp, String type, long delayed, long length) {
- logDumpEventInner(dataId, group, tenant, requestIpAppName, ts, handleIp, ConfigTraceService.DUMP_EVENT_BETA,
- type, delayed, length);
- }
-
- public static void logDumpBatchEvent(String dataId, String group, String tenant, String requestIpAppName, long ts,
- String handleIp, String type, long delayed, long length) {
- logDumpEventInner(dataId, group, tenant, requestIpAppName, ts, handleIp, ConfigTraceService.DUMP_EVENT_BATCH,
- type, delayed, length);
- }
-
- public static void logDumpTagEvent(String dataId, String group, String tenant, String tag, String requestIpAppName,
- long ts, String handleIp, String type, long delayed, long length) {
+ public static void logDumpGrayNameEvent(String dataId, String group, String tenant, String grayName,
+ String requestIpAppName, long ts, String handleIp, String type, long delayed, long length) {
logDumpEventInner(dataId, group, tenant, requestIpAppName, ts, handleIp,
- ConfigTraceService.DUMP_EVENT_TAG + "-" + tag, type, delayed, length);
+ ConfigTraceService.DUMP_EVENT + "-" + grayName, type, delayed, length);
}
private static void logDumpEventInner(String dataId, String group, String tenant, String requestIpAppName, long ts,
diff --git a/config/src/main/java/com/alibaba/nacos/config/server/utils/ConfigExtInfoUtil.java b/config/src/main/java/com/alibaba/nacos/config/server/utils/ConfigExtInfoUtil.java
new file mode 100644
index 00000000000..1e7c49e87a3
--- /dev/null
+++ b/config/src/main/java/com/alibaba/nacos/config/server/utils/ConfigExtInfoUtil.java
@@ -0,0 +1,190 @@
+/*
+ * Copyright 1999-$toady.year Alibaba Group Holding Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.alibaba.nacos.config.server.utils;
+
+import com.alibaba.nacos.common.utils.StringUtils;
+import com.alibaba.nacos.config.server.constant.Constants;
+import com.alibaba.nacos.config.server.model.ConfigAllInfo;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Extra info util.
+ *
+ * @author Nacos
+ */
+public class ConfigExtInfoUtil {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ConfigExtInfoUtil.class);
+
+ private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+
+ private static final Map EXTRA_INFO_KEYS_MAPPING = new HashMap<>();
+
+ static {
+ EXTRA_INFO_KEYS_MAPPING.put("type", "type");
+ EXTRA_INFO_KEYS_MAPPING.put("config_tags", "config_tags");
+ EXTRA_INFO_KEYS_MAPPING.put("src_user", "src_user");
+ EXTRA_INFO_KEYS_MAPPING.put("desc", "c_desc");
+ EXTRA_INFO_KEYS_MAPPING.put("use", "c_use");
+ EXTRA_INFO_KEYS_MAPPING.put("effect", "effect");
+ EXTRA_INFO_KEYS_MAPPING.put("schema", "c_schema");
+ }
+
+ private ConfigExtInfoUtil() {
+ }
+
+ /**
+ * Extract the extInfo from advance config info.
+ */
+ public static String getExtraInfoFromAdvanceInfoMap(Map advanceConfigInfoMap, String srcUser) {
+ try {
+ if (advanceConfigInfoMap == null || advanceConfigInfoMap.isEmpty()) {
+ return null;
+ }
+
+ ObjectNode node = OBJECT_MAPPER.createObjectNode();
+
+ if (StringUtils.isNotBlank(srcUser)) {
+ node.put("src_user", srcUser);
+ }
+
+ for (Map.Entry entry : EXTRA_INFO_KEYS_MAPPING.entrySet()) {
+ String key = entry.getKey();
+ String mappedKey = entry.getValue();
+ Object advanceConfigInfoValue = advanceConfigInfoMap.get(key);
+ if (advanceConfigInfoValue instanceof String && StringUtils.isNotBlank(
+ (String) advanceConfigInfoValue)) {
+ node.put(mappedKey, ((String) advanceConfigInfoValue).trim());
+ }
+ }
+
+ return OBJECT_MAPPER.writeValueAsString(node);
+ } catch (Exception ex) {
+ LOGGER.error("Failed to get extra info from advance info map", ex);
+ return null;
+ }
+ }
+
+ /**
+ * Extract the extInfo from all config info.
+ */
+ public static String getExtInfoFromAllInfo(ConfigAllInfo configAllInfo) {
+ ObjectNode node = OBJECT_MAPPER.createObjectNode();
+
+ if (StringUtils.isNotBlank(configAllInfo.getType())) {
+ node.put("type", configAllInfo.getType());
+ }
+ if (StringUtils.isNotBlank(configAllInfo.getConfigTags())) {
+ node.put("config_tags", configAllInfo.getConfigTags());
+ }
+ if (StringUtils.isNotBlank(configAllInfo.getEffect())) {
+ node.put("effect", configAllInfo.getEffect());
+ }
+ if (StringUtils.isNotBlank(configAllInfo.getCreateUser())) {
+ node.put("src_user", configAllInfo.getCreateUser());
+ }
+ if (StringUtils.isNotBlank(configAllInfo.getDesc())) {
+ node.put("c_desc", configAllInfo.getDesc());
+ }
+ if (StringUtils.isNotBlank(configAllInfo.getUse())) {
+ node.put("c_use", configAllInfo.getUse());
+ }
+ if (StringUtils.isNotBlank(configAllInfo.getSchema())) {
+ node.put("c_schema", configAllInfo.getSchema());
+ }
+
+ try {
+ return OBJECT_MAPPER.writeValueAsString(node);
+ } catch (Exception ex) {
+ LOGGER.error("Failed to get extra info from all config info", ex);
+ return null;
+ }
+ }
+
+ /**
+ * Extract the extInfo from gray config info.
+ */
+ public static String getExtInfoFromGrayInfo(String grayName, String grayRuleTmp, String oldSrcUser) {
+ ObjectNode node = OBJECT_MAPPER.createObjectNode();
+ ObjectNode grayRuleNode = OBJECT_MAPPER.createObjectNode();
+
+ if (StringUtils.isNotBlank(grayName)) {
+ node.put("gray_name", grayName);
+ }
+
+ if (StringUtils.isNotBlank(oldSrcUser)) {
+ node.put("src_user", oldSrcUser);
+ }
+
+ if (StringUtils.isNotBlank(grayRuleTmp)) {
+ try {
+ JsonNode parsedGrayRuleNode = OBJECT_MAPPER.readTree(grayRuleTmp);
+ if (parsedGrayRuleNode.has(Constants.GRAY_RULE_TYPE)) {
+ grayRuleNode.put(Constants.GRAY_RULE_TYPE,
+ parsedGrayRuleNode.get(Constants.GRAY_RULE_TYPE).asText());
+ }
+ if (parsedGrayRuleNode.has(Constants.GRAY_RULE_EXPR)) {
+ grayRuleNode.put(Constants.GRAY_RULE_EXPR,
+ parsedGrayRuleNode.get(Constants.GRAY_RULE_EXPR).asText());
+ }
+ if (parsedGrayRuleNode.has(Constants.GRAY_RULE_VERSION)) {
+ grayRuleNode.put(Constants.GRAY_RULE_VERSION,
+ parsedGrayRuleNode.get(Constants.GRAY_RULE_VERSION).asText());
+ }
+ if (parsedGrayRuleNode.has(Constants.GRAY_RULE_PRIORITY)) {
+ grayRuleNode.put(Constants.GRAY_RULE_PRIORITY,
+ parsedGrayRuleNode.get(Constants.GRAY_RULE_PRIORITY).asText());
+ }
+ node.put("gray_rule", grayRuleNode.toString());
+ } catch (Exception ex) {
+ LOGGER.error("Failed to parse gray rule as json", ex);
+ return null;
+ }
+ }
+
+ try {
+ return OBJECT_MAPPER.writeValueAsString(node);
+ } catch (Exception ex) {
+ LOGGER.error("Failed to serialize extra info from gray info", ex);
+ return null;
+ }
+ }
+
+ /**
+ * Extract grayName from extInfo.
+ */
+ public static String extractGrayName(String extraInfo) {
+ try {
+ ObjectMapper objectMapper = new ObjectMapper();
+ Map dataMap = objectMapper.readValue(extraInfo, new TypeReference