in config/src/main/java/com/alibaba/nacos/config/server/service/repository/extrnal/ExternalConfigInfoPersistServiceImpl.java [305:382]
public Map<String, Object> batchInsertOrUpdate(List<ConfigAllInfo> configInfoList, String srcUser, String srcIp,
Map<String, Object> configAdvanceInfo, SameConfigPolicy policy) throws NacosException {
int succCount = 0;
int skipCount = 0;
List<Map<String, String>> failData = null;
List<Map<String, String>> skipData = null;
for (int i = 0; i < configInfoList.size(); i++) {
ConfigAllInfo configInfo = configInfoList.get(i);
try {
ParamUtils.checkParam(configInfo.getDataId(), configInfo.getGroup(), "datumId",
configInfo.getContent());
} catch (NacosException e) {
LogUtil.DEFAULT_LOG.error("data verification failed", e);
throw e;
}
ConfigInfo configInfo2Save = new ConfigInfo(configInfo.getDataId(), configInfo.getGroup(),
configInfo.getTenant(), configInfo.getAppName(), configInfo.getContent());
configInfo2Save.setEncryptedDataKey(
configInfo.getEncryptedDataKey() == null ? StringUtils.EMPTY : configInfo.getEncryptedDataKey());
String type = determineConfigType(configInfo);
if (configAdvanceInfo == null) {
configAdvanceInfo = new HashMap<>(16);
}
configAdvanceInfo.put("type", type);
configAdvanceInfo.put("desc", configInfo.getDesc());
boolean success;
try {
ConfigOperateResult configOperateResult = addConfigInfo(srcIp, srcUser, configInfo2Save,
configAdvanceInfo);
success = configOperateResult.isSuccess();
} catch (DataIntegrityViolationException ive) {
success = false;
}
if (success) {
succCount++;
} else {
if (SameConfigPolicy.ABORT.equals(policy)) {
failData = new ArrayList<>();
skipData = new ArrayList<>();
Map<String, String> failedItem = new HashMap<>(2);
failedItem.put("dataId", configInfo2Save.getDataId());
failedItem.put("group", configInfo2Save.getGroup());
failData.add(failedItem);
for (int j = (i + 1); j < configInfoList.size(); j++) {
ConfigInfo skipConfigInfo = configInfoList.get(j);
Map<String, String> skipItem = new HashMap<>(2);
skipItem.put("dataId", skipConfigInfo.getDataId());
skipItem.put("group", skipConfigInfo.getGroup());
skipData.add(skipItem);
skipCount++;
}
break;
} else if (SameConfigPolicy.SKIP.equals(policy)) {
skipCount++;
if (skipData == null) {
skipData = new ArrayList<>();
}
Map<String, String> skipItem = new HashMap<>(2);
skipItem.put("dataId", configInfo2Save.getDataId());
skipItem.put("group", configInfo2Save.getGroup());
skipData.add(skipItem);
} else if (SameConfigPolicy.OVERWRITE.equals(policy)) {
succCount++;
updateConfigInfo(configInfo2Save, srcIp, srcUser, configAdvanceInfo);
}
}
}
Map<String, Object> result = new HashMap<>(4);
result.put("succCount", succCount);
result.put("skipCount", skipCount);
if (failData != null && !failData.isEmpty()) {
result.put("failData", failData);
}
if (skipData != null && !skipData.isEmpty()) {
result.put("skipData", skipData);
}
return result;
}