From ba37d63ad46e4d48eeca67a5c0515c271a0b528b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=99=93=E5=8F=8C=20Li=20Xiao=20Shuang?= <644968328@qq.com> Date: Fri, 18 Nov 2022 11:08:18 +0800 Subject: [PATCH] [ISSUE #9571] Replace PersistService (#9583) * replace PersistService * replace PersistService * fix test --- .../aspect/CapacityManagementAspect.java | 8 +-- .../server/controller/ConfigController.java | 47 +++++++------ .../controller/ConfigOpsController.java | 6 +- .../server/controller/ConfigServletInner.java | 26 ++++--- .../remote/ConfigPublishRequestHandler.java | 30 ++++++--- .../remote/ConfigQueryRequestHandler.java | 26 ++++--- .../remote/ConfigRemoveRequestHandler.java | 17 +++-- .../server/service/ConfigCacheService.java | 10 +-- .../service/ConfigOperationService.java | 35 ++++++---- .../config/server/service/HistoryService.java | 21 +++--- .../service/capacity/CapacityService.java | 8 +-- .../server/service/dump/DumpService.java | 67 ++++++++++++++----- .../service/dump/EmbeddedDumpService.java | 17 +++-- .../service/dump/ExternalDumpService.java | 19 ++++-- .../dump/processor/DumpAllBetaProcessor.java | 10 +-- .../dump/processor/DumpAllProcessor.java | 10 +-- .../dump/processor/DumpAllTagProcessor.java | 10 +-- .../dump/processor/DumpChangeProcessor.java | 18 +++-- .../service/dump/processor/DumpProcessor.java | 20 ++++-- .../service/merge/MergeDatumService.java | 31 ++++++--- .../service/merge/MergeTaskProcessor.java | 32 ++++++--- .../ConfigPublishRequestHandlerTest.java | 15 ++++- .../ConfigRemoveRequestHandlerTest.java | 11 ++- .../service/ConfigOperationServiceTest.java | 15 ++++- .../server/service/HistoryServiceTest.java | 26 ++++--- .../console/controller/HealthController.java | 10 +-- .../controller/NamespaceController.java | 6 +- .../service/NamespaceOperationService.java | 35 +++++----- .../controller/HealthControllerTest.java | 12 ++-- .../controller/NamespaceControllerTest.java | 8 +-- .../NamespaceOperationServiceTest.java | 28 ++++---- 31 files changed, 407 insertions(+), 227 deletions(-) diff --git a/config/src/main/java/com/alibaba/nacos/config/server/aspect/CapacityManagementAspect.java b/config/src/main/java/com/alibaba/nacos/config/server/aspect/CapacityManagementAspect.java index d158fa744..8159d3737 100644 --- a/config/src/main/java/com/alibaba/nacos/config/server/aspect/CapacityManagementAspect.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/aspect/CapacityManagementAspect.java @@ -21,7 +21,7 @@ import com.alibaba.nacos.config.server.constant.CounterMode; import com.alibaba.nacos.config.server.model.ConfigInfo; import com.alibaba.nacos.config.server.model.capacity.Capacity; import com.alibaba.nacos.config.server.service.capacity.CapacityService; -import com.alibaba.nacos.config.server.service.repository.PersistService; +import com.alibaba.nacos.config.server.service.repository.ConfigInfoPersistService; import com.alibaba.nacos.config.server.utils.PropertyUtil; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; @@ -59,7 +59,7 @@ public class CapacityManagementAspect { private CapacityService capacityService; @Autowired - private PersistService persistService; + private ConfigInfoPersistService configInfoPersistService; /** * Need to judge the size of content whether to exceed the limitation. @@ -76,7 +76,7 @@ public class CapacityManagementAspect { if (StringUtils.isBlank(betaIps)) { if (StringUtils.isBlank(tag)) { // do capacity management limitation check for writing or updating config_info table. - if (persistService.findConfigInfo(dataId, group, tenant) == null) { + if (configInfoPersistService.findConfigInfo(dataId, group, tenant) == null) { // Write operation. return do4Insert(pjp, request, response, group, tenant, content); } @@ -153,7 +153,7 @@ public class CapacityManagementAspect { return pjp.proceed(); } LOGGER.info("[capacityManagement] aroundDeleteConfig"); - ConfigInfo configInfo = persistService.findConfigInfo(dataId, group, tenant); + ConfigInfo configInfo = configInfoPersistService.findConfigInfo(dataId, group, tenant); if (configInfo == null) { return pjp.proceed(); } diff --git a/config/src/main/java/com/alibaba/nacos/config/server/controller/ConfigController.java b/config/src/main/java/com/alibaba/nacos/config/server/controller/ConfigController.java index 2d011584f..1cbec2c24 100644 --- a/config/src/main/java/com/alibaba/nacos/config/server/controller/ConfigController.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/controller/ConfigController.java @@ -44,7 +44,9 @@ import com.alibaba.nacos.config.server.result.code.ResultCodeEnum; import com.alibaba.nacos.config.server.service.ConfigChangePublisher; import com.alibaba.nacos.config.server.service.ConfigOperationService; import com.alibaba.nacos.config.server.service.ConfigSubService; -import com.alibaba.nacos.config.server.service.repository.PersistService; +import com.alibaba.nacos.config.server.service.repository.CommonPersistService; +import com.alibaba.nacos.config.server.service.repository.ConfigInfoBetaPersistService; +import com.alibaba.nacos.config.server.service.repository.ConfigInfoPersistService; import com.alibaba.nacos.config.server.service.trace.ConfigTraceService; import com.alibaba.nacos.config.server.utils.GroupKey; import com.alibaba.nacos.config.server.utils.MD5Util; @@ -107,18 +109,25 @@ public class ConfigController { private final ConfigServletInner inner; - private final PersistService persistService; + private ConfigInfoPersistService configInfoPersistService; + + private ConfigInfoBetaPersistService configInfoBetaPersistService; + + private CommonPersistService commonPersistService; private final ConfigOperationService configOperationService; private final ConfigSubService configSubService; - public ConfigController(ConfigServletInner inner, PersistService persistService, ConfigOperationService configOperationService, - ConfigSubService configSubService) { + public ConfigController(ConfigServletInner inner, ConfigOperationService configOperationService, + ConfigSubService configSubService, ConfigInfoPersistService configInfoPersistService, + CommonPersistService commonPersistService, ConfigInfoBetaPersistService configInfoBetaPersistService) { this.inner = inner; - this.persistService = persistService; this.configOperationService = configOperationService; this.configSubService = configSubService; + this.configInfoPersistService = configInfoPersistService; + this.commonPersistService = commonPersistService; + this.configInfoBetaPersistService = configInfoBetaPersistService; } /** @@ -227,7 +236,7 @@ public class ConfigController { ParamUtils.checkTenant(tenant); // check params ParamUtils.checkParam(dataId, group, "datumId", "content"); - ConfigAllInfo configAllInfo = persistService.findConfigAllInfo(dataId, group, tenant); + ConfigAllInfo configAllInfo = configInfoPersistService.findConfigAllInfo(dataId, group, tenant); // decrypted if (Objects.nonNull(configAllInfo)) { @@ -281,7 +290,7 @@ public class ConfigController { public RestResult deleteConfigs(HttpServletRequest request, @RequestParam(value = "ids") List ids) { String clientIp = RequestUtil.getRemoteIp(request); final Timestamp time = TimeUtils.getCurrentTime(); - List configInfoList = persistService.removeConfigInfoByIds(ids, clientIp, null); + List configInfoList = configInfoPersistService.removeConfigInfoByIds(ids, clientIp, null); if (CollectionUtils.isEmpty(configInfoList)) { return RestResultUtils.success(true); } @@ -302,7 +311,7 @@ public class ConfigController { public RestResult getConfigAdvanceInfo(@RequestParam("dataId") String dataId, @RequestParam("group") String group, @RequestParam(value = "tenant", required = false, defaultValue = StringUtils.EMPTY) String tenant) { - ConfigAdvanceInfo configInfo = persistService.findConfigAdvanceInfo(dataId, group, tenant); + ConfigAdvanceInfo configInfo = configInfoPersistService.findConfigAdvanceInfo(dataId, group, tenant); return RestResultUtils.success(configInfo); } @@ -370,7 +379,7 @@ public class ConfigController { configAdvanceInfo.put("config_tags", configTags); } try { - return persistService.findConfigInfo4Page(pageNo, pageSize, dataId, group, tenant, configAdvanceInfo); + return configInfoPersistService.findConfigInfo4Page(pageNo, pageSize, dataId, group, tenant, configAdvanceInfo); } catch (Exception e) { String errorMsg = "serialize page error, dataId=" + dataId + ", group=" + group; LOGGER.error(errorMsg, e); @@ -398,7 +407,7 @@ public class ConfigController { configAdvanceInfo.put("config_tags", configTags); } try { - return persistService.findConfigInfoLike4Page(pageNo, pageSize, dataId, group, tenant, configAdvanceInfo); + return configInfoPersistService.findConfigInfoLike4Page(pageNo, pageSize, dataId, group, tenant, configAdvanceInfo); } catch (Exception e) { String errorMsg = "serialize page error, dataId=" + dataId + ", group=" + group; LOGGER.error(errorMsg, e); @@ -420,7 +429,7 @@ public class ConfigController { @RequestParam(value = "group") String group, @RequestParam(value = "tenant", required = false, defaultValue = StringUtils.EMPTY) String tenant) { try { - persistService.removeConfigInfo4Beta(dataId, group, tenant); + configInfoBetaPersistService.removeConfigInfo4Beta(dataId, group, tenant); } catch (Throwable e) { LOGGER.error("remove beta data error", e); return RestResultUtils.failed(500, false, "remove beta data error"); @@ -444,7 +453,7 @@ public class ConfigController { @RequestParam(value = "group") String group, @RequestParam(value = "tenant", required = false, defaultValue = StringUtils.EMPTY) String tenant) { try { - ConfigInfo4Beta ci = persistService.findConfigInfo4Beta(dataId, group, tenant); + ConfigInfo4Beta ci = configInfoBetaPersistService.findConfigInfo4Beta(dataId, group, tenant); if (Objects.nonNull(ci)) { String encryptedDataKey = ci.getEncryptedDataKey(); @@ -477,7 +486,7 @@ public class ConfigController { @RequestParam(value = "ids", required = false) List ids) { ids.removeAll(Collections.singleton(null)); tenant = NamespaceUtil.processNamespaceParameter(tenant); - List dataList = persistService.findAllConfigInfo4Export(dataId, group, tenant, appName, ids); + List dataList = configInfoPersistService.findAllConfigInfo4Export(dataId, group, tenant, appName, ids); List zipItemList = new ArrayList<>(); StringBuilder metaData = null; for (ConfigInfo ci : dataList) { @@ -531,7 +540,7 @@ public class ConfigController { @RequestParam(value = "ids", required = false) List ids) { ids.removeAll(Collections.singleton(null)); tenant = NamespaceUtil.processNamespaceParameter(tenant); - List dataList = persistService.findAllConfigInfo4Export(dataId, group, tenant, appName, ids); + List dataList = configInfoPersistService.findAllConfigInfo4Export(dataId, group, tenant, appName, ids); List zipItemList = new ArrayList<>(); List configMetadataItems = new ArrayList<>(); for (ConfigAllInfo ci : dataList) { @@ -584,7 +593,7 @@ public class ConfigController { } namespace = NamespaceUtil.processNamespaceParameter(namespace); - if (StringUtils.isNotBlank(namespace) && persistService.tenantInfoCountByTenantId(namespace) <= 0) { + if (StringUtils.isNotBlank(namespace) && commonPersistService.tenantInfoCountByTenantId(namespace) <= 0) { failedData.put("succCount", 0); return RestResultUtils.buildResult(ResultCodeEnum.NAMESPACE_NOT_EXIST, failedData); } @@ -616,7 +625,7 @@ public class ConfigController { final String srcIp = RequestUtil.getRemoteIp(request); String requestIpApp = RequestUtil.getAppName(request); final Timestamp time = TimeUtils.getCurrentTime(); - Map saveResult = persistService.batchInsertOrUpdate(configInfoList, srcUser, srcIp, null, time, + Map saveResult = configInfoPersistService.batchInsertOrUpdate(configInfoList, srcUser, srcIp, null, time, false, policy); for (ConfigInfo configInfo : configInfoList) { ConfigChangePublisher.notifyConfigChange( @@ -818,7 +827,7 @@ public class ConfigController { configBeansList.removeAll(Collections.singleton(null)); namespace = NamespaceUtil.processNamespaceParameter(namespace); - if (StringUtils.isNotBlank(namespace) && persistService.tenantInfoCountByTenantId(namespace) <= 0) { + if (StringUtils.isNotBlank(namespace) && commonPersistService.tenantInfoCountByTenantId(namespace) <= 0) { failedData.put("succCount", 0); return RestResultUtils.buildResult(ResultCodeEnum.NAMESPACE_NOT_EXIST, failedData); } @@ -830,7 +839,7 @@ public class ConfigController { return cfg; }, (k1, k2) -> k1)); - List queryedDataList = persistService.findAllConfigInfo4Export(null, null, null, null, idList); + List queryedDataList = configInfoPersistService.findAllConfigInfo4Export(null, null, null, null, idList); if (queryedDataList == null || queryedDataList.isEmpty()) { failedData.put("succCount", 0); @@ -861,7 +870,7 @@ public class ConfigController { final String srcIp = RequestUtil.getRemoteIp(request); String requestIpApp = RequestUtil.getAppName(request); final Timestamp time = TimeUtils.getCurrentTime(); - Map saveResult = persistService.batchInsertOrUpdate(configInfoList4Clone, srcUser, srcIp, null, + Map saveResult = configInfoPersistService.batchInsertOrUpdate(configInfoList4Clone, srcUser, srcIp, null, time, false, policy); for (ConfigInfo configInfo : configInfoList4Clone) { ConfigChangePublisher.notifyConfigChange( diff --git a/config/src/main/java/com/alibaba/nacos/config/server/controller/ConfigOpsController.java b/config/src/main/java/com/alibaba/nacos/config/server/controller/ConfigOpsController.java index bb68152c4..9ed73805c 100755 --- a/config/src/main/java/com/alibaba/nacos/config/server/controller/ConfigOpsController.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/controller/ConfigOpsController.java @@ -26,7 +26,6 @@ import com.alibaba.nacos.config.server.model.event.DerbyImportEvent; import com.alibaba.nacos.config.server.service.datasource.DynamicDataSource; import com.alibaba.nacos.config.server.service.datasource.LocalDataSourceServiceImpl; import com.alibaba.nacos.config.server.service.dump.DumpService; -import com.alibaba.nacos.config.server.service.repository.PersistService; import com.alibaba.nacos.config.server.service.repository.embedded.DatabaseOperate; import com.alibaba.nacos.config.server.utils.LogUtil; import com.alibaba.nacos.config.server.utils.PropertyUtil; @@ -61,12 +60,9 @@ public class ConfigOpsController { private static final Logger LOGGER = LoggerFactory.getLogger(ConfigOpsController.class); - protected final PersistService persistService; - private final DumpService dumpService; - public ConfigOpsController(PersistService persistService, DumpService dumpService) { - this.persistService = persistService; + public ConfigOpsController(DumpService dumpService) { this.dumpService = dumpService; } diff --git a/config/src/main/java/com/alibaba/nacos/config/server/controller/ConfigServletInner.java b/config/src/main/java/com/alibaba/nacos/config/server/controller/ConfigServletInner.java index 7150e208a..67856f98c 100755 --- a/config/src/main/java/com/alibaba/nacos/config/server/controller/ConfigServletInner.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/controller/ConfigServletInner.java @@ -30,7 +30,9 @@ import com.alibaba.nacos.config.server.model.CacheItem; import com.alibaba.nacos.config.server.model.ConfigInfoBase; import com.alibaba.nacos.config.server.service.ConfigCacheService; import com.alibaba.nacos.config.server.service.LongPollingService; -import com.alibaba.nacos.config.server.service.repository.PersistService; +import com.alibaba.nacos.config.server.service.repository.ConfigInfoBetaPersistService; +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.DiskUtil; import com.alibaba.nacos.config.server.utils.GroupKey2; @@ -75,11 +77,19 @@ public class ConfigServletInner { private final LongPollingService longPollingService; - private final PersistService persistService; + private ConfigInfoPersistService configInfoPersistService; - public ConfigServletInner(LongPollingService longPollingService, PersistService persistService) { + private ConfigInfoBetaPersistService configInfoBetaPersistService; + + private ConfigInfoTagPersistService configInfoTagPersistService; + + public ConfigServletInner(LongPollingService longPollingService, ConfigInfoPersistService configInfoPersistService, + ConfigInfoBetaPersistService configInfoBetaPersistService, + ConfigInfoTagPersistService configInfoTagPersistService) { this.longPollingService = longPollingService; - this.persistService = persistService; + this.configInfoPersistService = configInfoPersistService; + this.configInfoBetaPersistService = configInfoBetaPersistService; + this.configInfoTagPersistService = configInfoTagPersistService; } /** @@ -185,7 +195,7 @@ public class ConfigServletInner { md5 = cacheItem.getMd54Beta(); lastModified = cacheItem.getLastModifiedTs4Beta(); if (PropertyUtil.isDirectRead()) { - configInfoBase = persistService.findConfigInfo4Beta(dataId, group, tenant); + configInfoBase = configInfoBetaPersistService.findConfigInfo4Beta(dataId, group, tenant); } else { file = DiskUtil.targetBetaFile(dataId, group, tenant); } @@ -200,7 +210,7 @@ public class ConfigServletInner { lastModified = cacheItem.tagLastModifiedTs.get(autoTag); } if (PropertyUtil.isDirectRead()) { - configInfoBase = persistService.findConfigInfo4Tag(dataId, group, tenant, autoTag); + configInfoBase = configInfoTagPersistService.findConfigInfo4Tag(dataId, group, tenant, autoTag); } else { file = DiskUtil.targetTagFile(dataId, group, tenant, autoTag); } @@ -211,7 +221,7 @@ public class ConfigServletInner { md5 = cacheItem.getMd5(); lastModified = cacheItem.getLastModifiedTs(); if (PropertyUtil.isDirectRead()) { - configInfoBase = persistService.findConfigInfo(dataId, group, tenant); + configInfoBase = configInfoPersistService.findConfigInfo(dataId, group, tenant); } else { file = DiskUtil.targetFile(dataId, group, tenant); } @@ -240,7 +250,7 @@ public class ConfigServletInner { } } if (PropertyUtil.isDirectRead()) { - configInfoBase = persistService.findConfigInfo4Tag(dataId, group, tenant, tag); + configInfoBase = configInfoTagPersistService.findConfigInfo4Tag(dataId, group, tenant, tag); } else { file = DiskUtil.targetTagFile(dataId, group, tenant, tag); } diff --git a/config/src/main/java/com/alibaba/nacos/config/server/remote/ConfigPublishRequestHandler.java b/config/src/main/java/com/alibaba/nacos/config/server/remote/ConfigPublishRequestHandler.java index 1cd4851c7..085773eb2 100644 --- a/config/src/main/java/com/alibaba/nacos/config/server/remote/ConfigPublishRequestHandler.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/remote/ConfigPublishRequestHandler.java @@ -28,7 +28,9 @@ import com.alibaba.nacos.config.server.model.ConfigInfo; import com.alibaba.nacos.config.server.model.event.ConfigDataChangeEvent; import com.alibaba.nacos.config.server.service.AggrWhitelist; import com.alibaba.nacos.config.server.service.ConfigChangePublisher; -import com.alibaba.nacos.config.server.service.repository.PersistService; +import com.alibaba.nacos.config.server.service.repository.ConfigInfoBetaPersistService; +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.ParamUtils; import com.alibaba.nacos.config.server.utils.TimeUtils; @@ -53,10 +55,18 @@ import java.util.Map; @Component public class ConfigPublishRequestHandler extends RequestHandler { - private final PersistService persistService; + private final ConfigInfoPersistService configInfoPersistService; - public ConfigPublishRequestHandler(PersistService persistService) { - this.persistService = persistService; + private final ConfigInfoTagPersistService configInfoTagPersistService; + + private final ConfigInfoBetaPersistService configInfoBetaPersistService; + + public ConfigPublishRequestHandler(ConfigInfoPersistService configInfoPersistService, + ConfigInfoTagPersistService configInfoTagPersistService, + ConfigInfoBetaPersistService configInfoBetaPersistService) { + this.configInfoPersistService = configInfoPersistService; + this.configInfoTagPersistService = configInfoTagPersistService; + this.configInfoBetaPersistService = configInfoBetaPersistService; } @Override @@ -106,27 +116,27 @@ public class ConfigPublishRequestHandler extends RequestHandler { - private final PersistService persistService; + private final ConfigInfoPersistService configInfoPersistService; - public ConfigRemoveRequestHandler(PersistService persistService) { - this.persistService = persistService; + private final ConfigInfoTagPersistService configInfoTagPersistService; + + public ConfigRemoveRequestHandler(ConfigInfoPersistService configInfoPersistService, + ConfigInfoTagPersistService configInfoTagPersistService) { + this.configInfoPersistService = configInfoPersistService; + this.configInfoTagPersistService = configInfoTagPersistService; } @Override @@ -70,9 +75,9 @@ public class ConfigRemoveRequestHandler extends RequestHandler CACHE = new ConcurrentHashMap<>(); @Autowired - private static PersistService persistService; + private static ConfigInfoPersistService configInfoPersistService; public static int groupCount() { return CACHE.size(); @@ -296,7 +296,7 @@ public class ConfigCacheService { String aggreds = null; try { if (PropertyUtil.isEmbeddedStorage()) { - ConfigInfoBase config = persistService + ConfigInfoBase config = configInfoPersistService .findConfigInfoBase(AggrWhitelist.AGGRIDS_METADATA, "DEFAULT_GROUP"); if (config != null) { aggreds = config.getContent(); @@ -314,7 +314,7 @@ public class ConfigCacheService { String clientIpWhitelist = null; try { if (PropertyUtil.isEmbeddedStorage()) { - ConfigInfoBase config = persistService + ConfigInfoBase config = configInfoPersistService .findConfigInfoBase(ClientIpWhiteList.CLIENT_IP_WHITELIST_METADATA, "DEFAULT_GROUP"); if (config != null) { clientIpWhitelist = config.getContent(); @@ -333,7 +333,7 @@ public class ConfigCacheService { String switchContent = null; try { if (PropertyUtil.isEmbeddedStorage()) { - ConfigInfoBase config = persistService + ConfigInfoBase config = configInfoPersistService .findConfigInfoBase(SwitchService.SWITCH_META_DATAID, "DEFAULT_GROUP"); if (config != null) { switchContent = config.getContent(); diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/ConfigOperationService.java b/config/src/main/java/com/alibaba/nacos/config/server/service/ConfigOperationService.java index 246757cc0..45c645e38 100644 --- a/config/src/main/java/com/alibaba/nacos/config/server/service/ConfigOperationService.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/service/ConfigOperationService.java @@ -25,7 +25,9 @@ import com.alibaba.nacos.config.server.model.ConfigInfo; import com.alibaba.nacos.config.server.model.event.ConfigDataChangeEvent; import com.alibaba.nacos.config.server.model.ConfigRequestInfo; import com.alibaba.nacos.config.server.model.form.ConfigForm; -import com.alibaba.nacos.config.server.service.repository.PersistService; +import com.alibaba.nacos.config.server.service.repository.ConfigInfoBetaPersistService; +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.ParamUtils; import com.alibaba.nacos.config.server.utils.TimeUtils; @@ -49,12 +51,20 @@ import java.util.Map; @Service public class ConfigOperationService { - private PersistService persistService; + private ConfigInfoPersistService configInfoPersistService; + + private ConfigInfoTagPersistService configInfoTagPersistService; + + private ConfigInfoBetaPersistService configInfoBetaPersistService; private static final Logger LOGGER = LoggerFactory.getLogger(ConfigOperationService.class); - public ConfigOperationService(PersistService persistService) { - this.persistService = persistService; + public ConfigOperationService(ConfigInfoPersistService configInfoPersistService, + ConfigInfoTagPersistService configInfoTagPersistService, + ConfigInfoBetaPersistService configInfoBetaPersistService) { + this.configInfoPersistService = configInfoPersistService; + this.configInfoTagPersistService = configInfoTagPersistService; + this.configInfoBetaPersistService = configInfoBetaPersistService; } /** @@ -84,23 +94,22 @@ public class ConfigOperationService { if (StringUtils.isBlank(configRequestInfo.getBetaIps())) { if (StringUtils.isBlank(configForm.getTag())) { - persistService.insertOrUpdate(configRequestInfo.getSrcIp(), configForm.getSrcUser(), configInfo, time, - configAdvanceInfo, false); + configInfoPersistService.insertOrUpdate(configRequestInfo.getSrcIp(), configForm.getSrcUser(), + configInfo, time, configAdvanceInfo, false); ConfigChangePublisher.notifyConfigChange( new ConfigDataChangeEvent(false, configForm.getDataId(), configForm.getGroup(), configForm.getNamespaceId(), time.getTime())); } else { - persistService.insertOrUpdateTag(configInfo, configForm.getTag(), configRequestInfo.getSrcIp(), - configForm.getSrcUser(), time, false); + configInfoTagPersistService.insertOrUpdateTag(configInfo, configForm.getTag(), + configRequestInfo.getSrcIp(), configForm.getSrcUser(), time, false); ConfigChangePublisher.notifyConfigChange( new ConfigDataChangeEvent(false, configForm.getDataId(), configForm.getGroup(), configForm.getNamespaceId(), configForm.getTag(), time.getTime())); } } else { // beta publish - persistService - .insertOrUpdateBeta(configInfo, configRequestInfo.getBetaIps(), configRequestInfo.getSrcIp(), - configForm.getSrcUser(), time, false); + configInfoBetaPersistService.insertOrUpdateBeta(configInfo, configRequestInfo.getBetaIps(), + configRequestInfo.getSrcIp(), configForm.getSrcUser(), time, false); ConfigChangePublisher.notifyConfigChange( new ConfigDataChangeEvent(true, configForm.getDataId(), configForm.getGroup(), configForm.getNamespaceId(), time.getTime())); @@ -118,9 +127,9 @@ public class ConfigOperationService { public Boolean deleteConfig(String dataId, String group, String namespaceId, String tag, String clientIp, String srcUser) { if (StringUtils.isBlank(tag)) { - persistService.removeConfigInfo(dataId, group, namespaceId, clientIp, srcUser); + configInfoPersistService.removeConfigInfo(dataId, group, namespaceId, clientIp, srcUser); } else { - persistService.removeConfigInfoTag(dataId, group, namespaceId, tag, clientIp, srcUser); + configInfoTagPersistService.removeConfigInfoTag(dataId, group, namespaceId, tag, clientIp, srcUser); } final Timestamp time = TimeUtils.getCurrentTime(); ConfigTraceService.logPersistenceEvent(dataId, group, namespaceId, null, time.getTime(), clientIp, diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/HistoryService.java b/config/src/main/java/com/alibaba/nacos/config/server/service/HistoryService.java index c2de73ea0..11d700657 100644 --- a/config/src/main/java/com/alibaba/nacos/config/server/service/HistoryService.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/service/HistoryService.java @@ -20,7 +20,8 @@ import com.alibaba.nacos.common.utils.Pair; import com.alibaba.nacos.config.server.model.ConfigHistoryInfo; import com.alibaba.nacos.config.server.model.ConfigInfoWrapper; import com.alibaba.nacos.config.server.model.Page; -import com.alibaba.nacos.config.server.service.repository.PersistService; +import com.alibaba.nacos.config.server.service.repository.ConfigInfoPersistService; +import com.alibaba.nacos.config.server.service.repository.HistoryConfigInfoPersistService; import com.alibaba.nacos.plugin.auth.exception.AccessException; import com.alibaba.nacos.plugin.encryption.handler.EncryptionHandler; import org.springframework.stereotype.Service; @@ -37,10 +38,14 @@ import java.util.Objects; @Service public class HistoryService { - private final PersistService persistService; + private final HistoryConfigInfoPersistService historyConfigInfoPersistService; - public HistoryService(PersistService persistService) { - this.persistService = persistService; + private final ConfigInfoPersistService configInfoPersistService; + + public HistoryService(HistoryConfigInfoPersistService historyConfigInfoPersistService, + ConfigInfoPersistService configInfoPersistService) { + this.historyConfigInfoPersistService = historyConfigInfoPersistService; + this.configInfoPersistService = configInfoPersistService; } /** @@ -48,7 +53,7 @@ public class HistoryService { */ public Page listConfigHistory(String dataId, String group, String namespaceId, Integer pageNo, Integer pageSize) { - return persistService.findConfigHistory(dataId, group, namespaceId, pageNo, pageSize); + return historyConfigInfoPersistService.findConfigHistory(dataId, group, namespaceId, pageNo, pageSize); } /** @@ -56,7 +61,7 @@ public class HistoryService { */ public ConfigHistoryInfo getConfigHistoryInfo(String dataId, String group, String namespaceId, Long nid) throws AccessException { - ConfigHistoryInfo configHistoryInfo = persistService.detailConfigHistory(nid); + ConfigHistoryInfo configHistoryInfo = historyConfigInfoPersistService.detailConfigHistory(nid); if (Objects.isNull(configHistoryInfo)) { return null; } @@ -76,7 +81,7 @@ public class HistoryService { */ public ConfigHistoryInfo getPreviousConfigHistoryInfo(String dataId, String group, String namespaceId, Long id) throws AccessException { - ConfigHistoryInfo configHistoryInfo = persistService.detailPreviousConfigHistory(id); + ConfigHistoryInfo configHistoryInfo = historyConfigInfoPersistService.detailPreviousConfigHistory(id); if (Objects.isNull(configHistoryInfo)) { return null; } @@ -89,7 +94,7 @@ public class HistoryService { * Query configs list by namespace. */ public List getConfigListByNamespace(String namespaceId) { - return persistService.queryConfigInfoByNamespace(namespaceId); + return configInfoPersistService.queryConfigInfoByNamespace(namespaceId); } /** diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/capacity/CapacityService.java b/config/src/main/java/com/alibaba/nacos/config/server/service/capacity/CapacityService.java index 7b433e972..7905c606b 100644 --- a/config/src/main/java/com/alibaba/nacos/config/server/service/capacity/CapacityService.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/service/capacity/CapacityService.java @@ -20,7 +20,7 @@ import com.alibaba.nacos.config.server.constant.CounterMode; import com.alibaba.nacos.config.server.model.capacity.Capacity; import com.alibaba.nacos.config.server.model.capacity.GroupCapacity; import com.alibaba.nacos.config.server.model.capacity.TenantCapacity; -import com.alibaba.nacos.config.server.service.repository.PersistService; +import com.alibaba.nacos.config.server.service.repository.ConfigInfoPersistService; import com.alibaba.nacos.config.server.utils.ConfigExecutor; import com.alibaba.nacos.config.server.utils.LogUtil; import com.alibaba.nacos.config.server.utils.PropertyUtil; @@ -60,7 +60,7 @@ public class CapacityService { private TenantCapacityPersistService tenantCapacityPersistService; @Autowired - private PersistService persistService; + private ConfigInfoPersistService configInfoPersistService; /** * Init. @@ -154,9 +154,9 @@ public class CapacityService { while (true) { List list; if (isTenant) { - list = persistService.getTenantIdList(page, INIT_PAGE_SIZE); + list = configInfoPersistService.getTenantIdList(page, INIT_PAGE_SIZE); } else { - list = persistService.getGroupIdList(page, INIT_PAGE_SIZE); + list = configInfoPersistService.getGroupIdList(page, INIT_PAGE_SIZE); } for (String targetId : list) { if (isTenant) { diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/dump/DumpService.java b/config/src/main/java/com/alibaba/nacos/config/server/service/dump/DumpService.java index e1afda70f..2c374a6cb 100755 --- a/config/src/main/java/com/alibaba/nacos/config/server/service/dump/DumpService.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/service/dump/DumpService.java @@ -40,7 +40,12 @@ import com.alibaba.nacos.config.server.service.dump.task.DumpAllTask; import com.alibaba.nacos.config.server.service.dump.task.DumpChangeTask; import com.alibaba.nacos.config.server.service.dump.task.DumpTask; import com.alibaba.nacos.config.server.service.merge.MergeTaskProcessor; -import com.alibaba.nacos.config.server.service.repository.PersistService; +import com.alibaba.nacos.config.server.service.repository.CommonPersistService; +import com.alibaba.nacos.config.server.service.repository.ConfigInfoAggrPersistService; +import com.alibaba.nacos.config.server.service.repository.ConfigInfoBetaPersistService; +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.repository.HistoryConfigInfoPersistService; import com.alibaba.nacos.config.server.utils.ConfigExecutor; import com.alibaba.nacos.config.server.utils.ContentUtils; import com.alibaba.nacos.config.server.utils.DiskUtil; @@ -88,7 +93,17 @@ public abstract class DumpService { protected DumpAllTagProcessor dumpAllTagProcessor; - protected final PersistService persistService; + protected ConfigInfoPersistService configInfoPersistService; + + protected CommonPersistService commonPersistService; + + protected HistoryConfigInfoPersistService historyConfigInfoPersistService; + + protected ConfigInfoAggrPersistService configInfoAggrPersistService; + + protected ConfigInfoBetaPersistService configInfoBetaPersistService; + + protected ConfigInfoTagPersistService configInfoTagPersistService; protected final ServerMemberManager memberManager; @@ -126,11 +141,19 @@ public abstract class DumpService { * Here you inject the dependent objects constructively, ensuring that some of the dependent functionality is * initialized ahead of time. * - * @param persistService {@link PersistService} * @param memberManager {@link ServerMemberManager} */ - public DumpService(PersistService persistService, ServerMemberManager memberManager) { - this.persistService = persistService; + public DumpService(ConfigInfoPersistService configInfoPersistService, CommonPersistService commonPersistService, + HistoryConfigInfoPersistService historyConfigInfoPersistService, + ConfigInfoAggrPersistService configInfoAggrPersistService, + ConfigInfoBetaPersistService configInfoBetaPersistService, + ConfigInfoTagPersistService configInfoTagPersistService, ServerMemberManager memberManager) { + this.configInfoPersistService = configInfoPersistService; + this.commonPersistService = commonPersistService; + this.historyConfigInfoPersistService = historyConfigInfoPersistService; + this.configInfoAggrPersistService = configInfoAggrPersistService; + this.configInfoBetaPersistService = configInfoBetaPersistService; + this.configInfoTagPersistService = configInfoTagPersistService; this.memberManager = memberManager; this.processor = new DumpProcessor(this); this.dumpAllProcessor = new DumpAllProcessor(this); @@ -149,8 +172,20 @@ public abstract class DumpService { DynamicDataSource.getInstance().getDataSource(); } - public PersistService getPersistService() { - return persistService; + public ConfigInfoPersistService getConfigInfoPersistService() { + return configInfoPersistService; + } + + public ConfigInfoBetaPersistService getConfigInfoBetaPersistService() { + return configInfoBetaPersistService; + } + + public ConfigInfoTagPersistService getConfigInfoTagPersistService() { + return configInfoTagPersistService; + } + + public HistoryConfigInfoPersistService getHistoryConfigInfoPersistService() { + return historyConfigInfoPersistService; } public ServerMemberManager getMemberManager() { @@ -184,7 +219,7 @@ public abstract class DumpService { Timestamp startTime = getBeforeStamp(TimeUtils.getCurrentTime(), 24 * getRetentionDays()); int pageSize = 1000; LOGGER.warn("clearConfigHistory, getBeforeStamp:{}, pageSize:{}", startTime, pageSize); - persistService.removeConfigHistory(startTime, pageSize); + historyConfigInfoPersistService.removeConfigHistory(startTime, pageSize); } catch (Throwable e) { LOGGER.error("clearConfigHistory error : {}", e.toString()); } @@ -197,18 +232,18 @@ public abstract class DumpService { // update Beta cache LogUtil.DEFAULT_LOG.info("start clear all config-info-beta."); DiskUtil.clearAllBeta(); - if (persistService.isExistTable(BETA_TABLE_NAME)) { + if (commonPersistService.isExistTable(BETA_TABLE_NAME)) { dumpAllBetaProcessor.process(new DumpAllBetaTask()); } // update Tag cache LogUtil.DEFAULT_LOG.info("start clear all config-info-tag."); DiskUtil.clearAllTag(); - if (persistService.isExistTable(TAG_TABLE_NAME)) { + if (commonPersistService.isExistTable(TAG_TABLE_NAME)) { dumpAllTagProcessor.process(new DumpAllTagTask()); } // add to dump aggr - List configList = persistService.findAllAggrGroup(); + List configList = configInfoAggrPersistService.findAllAggrGroup(); if (configList != null && !configList.isEmpty()) { total = configList.size(); List> splitList = splitList(configList, INIT_THREAD_COUNT); @@ -293,7 +328,7 @@ public abstract class DumpService { String dataId = dg[0]; String group = dg[1]; String tenant = dg[2]; - ConfigInfoWrapper configInfo = persistService.queryConfigInfo(dataId, group, tenant); + ConfigInfoWrapper configInfo = configInfoPersistService.queryConfigInfo(dataId, group, tenant); ConfigCacheService.dumpChange(dataId, group, tenant, configInfo.getContent(), configInfo.getLastModified(), configInfo.getEncryptedDataKey()); } @@ -424,10 +459,10 @@ public abstract class DumpService { String tenant = configInfo.getTenant(); try { List datumList = new ArrayList<>(); - int rowCount = persistService.aggrConfigInfoCount(dataId, group, tenant); + 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 = persistService + Page page = configInfoAggrPersistService .findConfigInfoAggrByPage(dataId, group, tenant, pageNo, PAGE_SIZE); if (page != null) { datumList.addAll(page.getPageItems()); @@ -445,14 +480,14 @@ public abstract class DumpService { String aggrConetentMD5 = MD5Utils.md5Hex(aggrContent, Constants.ENCODE); if (!StringUtils.equals(localContentMD5, aggrConetentMD5)) { - persistService.insertOrUpdate(null, null, cf, time, null, false); + configInfoPersistService.insertOrUpdate(null, null, cf, time, null, false); 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 - persistService.removeConfigInfo(dataId, group, tenant, InetUtils.getSelfIP(), null); + configInfoPersistService.removeConfigInfo(dataId, group, tenant, InetUtils.getSelfIP(), null); LOGGER.warn( "[merge-delete] delete config info because no datum. dataId=" + dataId + ", groupId=" + group); diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/dump/EmbeddedDumpService.java b/config/src/main/java/com/alibaba/nacos/config/server/service/dump/EmbeddedDumpService.java index 0205943d0..5ba0b8c57 100644 --- a/config/src/main/java/com/alibaba/nacos/config/server/service/dump/EmbeddedDumpService.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/service/dump/EmbeddedDumpService.java @@ -22,7 +22,12 @@ import com.alibaba.nacos.common.utils.StringUtils; import com.alibaba.nacos.common.utils.ThreadUtils; import com.alibaba.nacos.config.server.configuration.ConditionOnEmbeddedStorage; import com.alibaba.nacos.config.server.constant.Constants; -import com.alibaba.nacos.config.server.service.repository.PersistService; +import com.alibaba.nacos.config.server.service.repository.CommonPersistService; +import com.alibaba.nacos.config.server.service.repository.ConfigInfoAggrPersistService; +import com.alibaba.nacos.config.server.service.repository.ConfigInfoBetaPersistService; +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.repository.HistoryConfigInfoPersistService; import com.alibaba.nacos.config.server.service.sql.EmbeddedStorageContextUtils; import com.alibaba.nacos.consistency.ProtocolMetaData; import com.alibaba.nacos.consistency.cp.CPProtocol; @@ -64,13 +69,17 @@ public class EmbeddedDumpService extends DumpService { * Here you inject the dependent objects constructively, ensuring that some of the dependent functionality is * initialized ahead of time. * - * @param persistService {@link PersistService} * @param memberManager {@link ServerMemberManager} * @param protocolManager {@link ProtocolManager} */ - public EmbeddedDumpService(PersistService persistService, ServerMemberManager memberManager, + public EmbeddedDumpService(ConfigInfoPersistService configInfoPersistService, + CommonPersistService commonPersistService, HistoryConfigInfoPersistService historyConfigInfoPersistService, + ConfigInfoAggrPersistService configInfoAggrPersistService, + ConfigInfoBetaPersistService configInfoBetaPersistService, + ConfigInfoTagPersistService configInfoTagPersistService, ServerMemberManager memberManager, ProtocolManager protocolManager) { - super(persistService, memberManager); + super(configInfoPersistService, commonPersistService, historyConfigInfoPersistService, + configInfoAggrPersistService, configInfoBetaPersistService, configInfoTagPersistService, memberManager); this.protocolManager = protocolManager; } diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/dump/ExternalDumpService.java b/config/src/main/java/com/alibaba/nacos/config/server/service/dump/ExternalDumpService.java index 64b84982f..2c163f147 100644 --- a/config/src/main/java/com/alibaba/nacos/config/server/service/dump/ExternalDumpService.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/service/dump/ExternalDumpService.java @@ -17,7 +17,12 @@ package com.alibaba.nacos.config.server.service.dump; import com.alibaba.nacos.config.server.configuration.ConditionOnExternalStorage; -import com.alibaba.nacos.config.server.service.repository.PersistService; +import com.alibaba.nacos.config.server.service.repository.CommonPersistService; +import com.alibaba.nacos.config.server.service.repository.ConfigInfoAggrPersistService; +import com.alibaba.nacos.config.server.service.repository.ConfigInfoBetaPersistService; +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.repository.HistoryConfigInfoPersistService; import com.alibaba.nacos.core.cluster.ServerMemberManager; import org.springframework.context.annotation.Conditional; import org.springframework.context.annotation.DependsOn; @@ -39,11 +44,15 @@ public class ExternalDumpService extends DumpService { * Here you inject the dependent objects constructively, ensuring that some of the dependent functionality is * initialized ahead of time. * - * @param persistService {@link PersistService} - * @param memberManager {@link ServerMemberManager} + * @param memberManager {@link ServerMemberManager} */ - public ExternalDumpService(PersistService persistService, ServerMemberManager memberManager) { - super(persistService, memberManager); + public ExternalDumpService(ConfigInfoPersistService configInfoPersistService, + CommonPersistService commonPersistService, HistoryConfigInfoPersistService historyConfigInfoPersistService, + ConfigInfoAggrPersistService configInfoAggrPersistService, + ConfigInfoBetaPersistService configInfoBetaPersistService, + ConfigInfoTagPersistService configInfoTagPersistService, ServerMemberManager memberManager) { + super(configInfoPersistService, commonPersistService, historyConfigInfoPersistService, + configInfoAggrPersistService, configInfoBetaPersistService, configInfoTagPersistService, memberManager); } @PostConstruct diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/dump/processor/DumpAllBetaProcessor.java b/config/src/main/java/com/alibaba/nacos/config/server/service/dump/processor/DumpAllBetaProcessor.java index 86de8dd6e..c2eadb26b 100644 --- a/config/src/main/java/com/alibaba/nacos/config/server/service/dump/processor/DumpAllBetaProcessor.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/service/dump/processor/DumpAllBetaProcessor.java @@ -22,7 +22,7 @@ import com.alibaba.nacos.config.server.model.ConfigInfoBetaWrapper; import com.alibaba.nacos.config.server.model.Page; import com.alibaba.nacos.config.server.service.ConfigCacheService; import com.alibaba.nacos.config.server.service.dump.DumpService; -import com.alibaba.nacos.config.server.service.repository.PersistService; +import com.alibaba.nacos.config.server.service.repository.ConfigInfoBetaPersistService; import com.alibaba.nacos.config.server.utils.GroupKey2; import com.alibaba.nacos.config.server.utils.LogUtil; @@ -39,17 +39,17 @@ public class DumpAllBetaProcessor implements NacosTaskProcessor { public DumpAllBetaProcessor(DumpService dumpService) { this.dumpService = dumpService; - this.persistService = dumpService.getPersistService(); + this.configInfoBetaPersistService = dumpService.getConfigInfoBetaPersistService(); } @Override public boolean process(NacosTask task) { - int rowCount = persistService.configInfoBetaCount(); + int rowCount = configInfoBetaPersistService.configInfoBetaCount(); int pageCount = (int) Math.ceil(rowCount * 1.0 / PAGE_SIZE); int actualRowCount = 0; for (int pageNo = 1; pageNo <= pageCount; pageNo++) { - Page page = persistService.findAllConfigInfoBetaForDumpAll(pageNo, PAGE_SIZE); + Page page = configInfoBetaPersistService.findAllConfigInfoBetaForDumpAll(pageNo, PAGE_SIZE); if (page != null) { for (ConfigInfoBetaWrapper cf : page.getPageItems()) { boolean result = ConfigCacheService @@ -71,5 +71,5 @@ public class DumpAllBetaProcessor implements NacosTaskProcessor { final DumpService dumpService; - final PersistService persistService; + final ConfigInfoBetaPersistService configInfoBetaPersistService; } 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 277a88c87..86ca2bda7 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 @@ -27,7 +27,7 @@ import com.alibaba.nacos.config.server.service.ClientIpWhiteList; import com.alibaba.nacos.config.server.service.ConfigCacheService; import com.alibaba.nacos.config.server.service.SwitchService; import com.alibaba.nacos.config.server.service.dump.DumpService; -import com.alibaba.nacos.config.server.service.repository.PersistService; +import com.alibaba.nacos.config.server.service.repository.ConfigInfoPersistService; import com.alibaba.nacos.config.server.utils.GroupKey2; import com.alibaba.nacos.config.server.utils.LogUtil; @@ -43,15 +43,15 @@ public class DumpAllProcessor implements NacosTaskProcessor { public DumpAllProcessor(DumpService dumpService) { this.dumpService = dumpService; - this.persistService = dumpService.getPersistService(); + this.configInfoPersistService = dumpService.getConfigInfoPersistService(); } @Override public boolean process(NacosTask task) { - long currentMaxId = persistService.findConfigMaxId(); + long currentMaxId = configInfoPersistService.findConfigMaxId(); long lastMaxId = 0; while (lastMaxId < currentMaxId) { - Page page = persistService.findAllConfigInfoFragment(lastMaxId, PAGE_SIZE); + Page page = configInfoPersistService.findAllConfigInfoFragment(lastMaxId, PAGE_SIZE); if (page != null && page.getPageItems() != null && !page.getPageItems().isEmpty()) { for (ConfigInfoWrapper cf : page.getPageItems()) { long id = cf.getId(); @@ -89,5 +89,5 @@ public class DumpAllProcessor implements NacosTaskProcessor { final DumpService dumpService; - final PersistService persistService; + final ConfigInfoPersistService configInfoPersistService; } diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/dump/processor/DumpAllTagProcessor.java b/config/src/main/java/com/alibaba/nacos/config/server/service/dump/processor/DumpAllTagProcessor.java index 9768a0637..e3125180a 100644 --- a/config/src/main/java/com/alibaba/nacos/config/server/service/dump/processor/DumpAllTagProcessor.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/service/dump/processor/DumpAllTagProcessor.java @@ -22,7 +22,7 @@ import com.alibaba.nacos.config.server.model.ConfigInfoTagWrapper; import com.alibaba.nacos.config.server.model.Page; import com.alibaba.nacos.config.server.service.ConfigCacheService; import com.alibaba.nacos.config.server.service.dump.DumpService; -import com.alibaba.nacos.config.server.service.repository.PersistService; +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; @@ -38,17 +38,17 @@ public class DumpAllTagProcessor implements NacosTaskProcessor { public DumpAllTagProcessor(DumpService dumpService) { this.dumpService = dumpService; - this.persistService = dumpService.getPersistService(); + this.configInfoTagPersistService = dumpService.getConfigInfoTagPersistService(); } @Override public boolean process(NacosTask task) { - int rowCount = persistService.configInfoTagCount(); + int rowCount = configInfoTagPersistService.configInfoTagCount(); int pageCount = (int) Math.ceil(rowCount * 1.0 / PAGE_SIZE); int actualRowCount = 0; for (int pageNo = 1; pageNo <= pageCount; pageNo++) { - Page page = persistService.findAllConfigInfoTagForDumpAll(pageNo, PAGE_SIZE); + Page page = configInfoTagPersistService.findAllConfigInfoTagForDumpAll(pageNo, PAGE_SIZE); if (page != null) { for (ConfigInfoTagWrapper cf : page.getPageItems()) { boolean result = ConfigCacheService @@ -70,5 +70,5 @@ public class DumpAllTagProcessor implements NacosTaskProcessor { final DumpService dumpService; - final PersistService persistService; + final ConfigInfoTagPersistService configInfoTagPersistService; } diff --git a/config/src/main/java/com/alibaba/nacos/config/server/service/dump/processor/DumpChangeProcessor.java b/config/src/main/java/com/alibaba/nacos/config/server/service/dump/processor/DumpChangeProcessor.java index d0f1f4e2d..0de63f03b 100644 --- a/config/src/main/java/com/alibaba/nacos/config/server/service/dump/processor/DumpChangeProcessor.java +++ b/config/src/main/java/com/alibaba/nacos/config/server/service/dump/processor/DumpChangeProcessor.java @@ -24,7 +24,8 @@ import com.alibaba.nacos.config.server.model.ConfigInfo; import com.alibaba.nacos.config.server.model.ConfigInfoWrapper; import com.alibaba.nacos.config.server.service.ConfigCacheService; import com.alibaba.nacos.config.server.service.dump.DumpService; -import com.alibaba.nacos.config.server.service.repository.PersistService; +import com.alibaba.nacos.config.server.service.repository.ConfigInfoPersistService; +import com.alibaba.nacos.config.server.service.repository.HistoryConfigInfoPersistService; import com.alibaba.nacos.config.server.utils.GroupKey2; import com.alibaba.nacos.config.server.utils.LogUtil; @@ -41,7 +42,9 @@ public class DumpChangeProcessor implements NacosTaskProcessor { final DumpService dumpService; - final PersistService persistService; + final ConfigInfoPersistService configInfoPersistService; + + final HistoryConfigInfoPersistService historyConfigInfoPersistService; final Timestamp startTime; @@ -49,7 +52,8 @@ public class DumpChangeProcessor implements NacosTaskProcessor { public DumpChangeProcessor(DumpService dumpService, Timestamp startTime, Timestamp endTime) { this.dumpService = dumpService; - this.persistService = dumpService.getPersistService(); + this.configInfoPersistService = dumpService.getConfigInfoPersistService(); + this.historyConfigInfoPersistService = dumpService.getHistoryConfigInfoPersistService(); this.startTime = startTime; this.endTime = endTime; } @@ -59,7 +63,7 @@ public class DumpChangeProcessor implements NacosTaskProcessor { LogUtil.DEFAULT_LOG.warn("quick start; startTime:{},endTime:{}", startTime, endTime); LogUtil.DEFAULT_LOG.warn("updateMd5 start"); long startUpdateMd5 = System.currentTimeMillis(); - List updateMd5List = persistService.listAllGroupKeyMd5(); + List updateMd5List = configInfoPersistService.listAllGroupKeyMd5(); LogUtil.DEFAULT_LOG.warn("updateMd5 count:{}", updateMd5List.size()); for (ConfigInfoWrapper config : updateMd5List) { final String groupKey = GroupKey2.getKey(config.getDataId(), config.getGroup()); @@ -71,10 +75,10 @@ public class DumpChangeProcessor implements NacosTaskProcessor { LogUtil.DEFAULT_LOG.warn("deletedConfig start"); long startDeletedConfigTime = System.currentTimeMillis(); - List configDeleted = persistService.findDeletedConfig(startTime, endTime); + List configDeleted = historyConfigInfoPersistService.findDeletedConfig(startTime, endTime); LogUtil.DEFAULT_LOG.warn("deletedConfig count:{}", configDeleted.size()); for (ConfigInfo configInfo : configDeleted) { - if (persistService.findConfigInfo(configInfo.getDataId(), configInfo.getGroup(), configInfo.getTenant()) + if (configInfoPersistService.findConfigInfo(configInfo.getDataId(), configInfo.getGroup(), configInfo.getTenant()) == null) { ConfigCacheService.remove(configInfo.getDataId(), configInfo.getGroup(), configInfo.getTenant()); } @@ -84,7 +88,7 @@ public class DumpChangeProcessor implements NacosTaskProcessor { LogUtil.DEFAULT_LOG.warn("changeConfig start"); final long startChangeConfigTime = System.currentTimeMillis(); - List changeConfigs = persistService.findChangeConfig(startTime, endTime); + List changeConfigs = configInfoPersistService.findChangeConfig(startTime, endTime); LogUtil.DEFAULT_LOG.warn("changeConfig count:{}", changeConfigs.size()); for (ConfigInfoWrapper cf : changeConfigs) { 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 1f351c5d1..d0640e927 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 @@ -25,7 +25,9 @@ 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.DumpService; import com.alibaba.nacos.config.server.service.dump.task.DumpTask; -import com.alibaba.nacos.config.server.service.repository.PersistService; +import com.alibaba.nacos.config.server.service.repository.ConfigInfoBetaPersistService; +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.common.utils.StringUtils; @@ -41,13 +43,21 @@ public class DumpProcessor implements NacosTaskProcessor { final DumpService dumpService; + final ConfigInfoPersistService configInfoPersistService; + + final ConfigInfoBetaPersistService configInfoBetaPersistService; + + final ConfigInfoTagPersistService configInfoTagPersistService; + public DumpProcessor(DumpService dumpService) { this.dumpService = dumpService; + this.configInfoPersistService = dumpService.getConfigInfoPersistService(); + this.configInfoBetaPersistService = dumpService.getConfigInfoBetaPersistService(); + this.configInfoTagPersistService = dumpService.getConfigInfoTagPersistService(); } @Override public boolean process(NacosTask task) { - final PersistService persistService = dumpService.getPersistService(); DumpTask dumpTask = (DumpTask) task; String[] pair = GroupKey2.parseKey(dumpTask.getGroupKey()); String dataId = pair[0]; @@ -63,7 +73,7 @@ public class DumpProcessor implements NacosTaskProcessor { if (isBeta) { // if publish beta, then dump config, update beta cache - ConfigInfo4Beta cf = persistService.findConfigInfo4Beta(dataId, group, tenant); + ConfigInfo4Beta cf = configInfoBetaPersistService.findConfigInfo4Beta(dataId, group, tenant); build.remove(Objects.isNull(cf)); build.betaIps(Objects.isNull(cf) ? null : cf.getBetaIps()); @@ -73,14 +83,14 @@ public class DumpProcessor implements NacosTaskProcessor { return DumpConfigHandler.configDump(build.build()); } if (StringUtils.isBlank(tag)) { - ConfigInfo cf = persistService.findConfigInfo(dataId, group, tenant); + ConfigInfo cf = configInfoPersistService.findConfigInfo(dataId, group, tenant); 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()); } else { - ConfigInfo4Tag cf = persistService.findConfigInfo4Tag(dataId, group, tenant, tag); + ConfigInfo4Tag cf = configInfoTagPersistService.findConfigInfo4Tag(dataId, group, tenant, tag); build.remove(Objects.isNull(cf)); build.content(Objects.isNull(cf) ? null : cf.getContent()); 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 index c14abb43e..4731a95b1 100644 --- 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 @@ -22,7 +22,9 @@ 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.model.Page; -import com.alibaba.nacos.config.server.service.repository.PersistService; +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.PropertyUtil; import com.alibaba.nacos.config.server.utils.TimeUtils; @@ -54,19 +56,26 @@ public class MergeDatumService { final TaskManager mergeTasks; - private PersistService persistService; - 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(PersistService persistService) { - this.persistService = persistService; + 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(persistService, this)); + mergeTasks.setDefaultTaskProcessor( + new MergeTaskProcessor(configInfoPersistService, configInfoAggrPersistService, + configInfoTagPersistService, this)); } static List> splitList(List list, int count) { @@ -110,7 +119,7 @@ public class MergeDatumService { if (!canExecute()) { return; } - for (ConfigInfoChanged item : persistService.findAllAggrGroup()) { + for (ConfigInfoChanged item : configInfoAggrPersistService.findAllAggrGroup()) { addMergeTask(item.getDataId(), item.getGroup(), item.getTenant(), InetUtils.getSelfIP()); } } @@ -145,10 +154,10 @@ public class MergeDatumService { String tenant = configInfo.getTenant(); try { List datumList = new ArrayList<>(); - int rowCount = persistService.aggrConfigInfoCount(dataId, group, tenant); + 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 = persistService + Page page = configInfoAggrPersistService .findConfigInfoAggrByPage(dataId, group, tenant, pageNo, PAGE_SIZE); if (page != null) { datumList.addAll(page.getPageItems()); @@ -162,13 +171,13 @@ public class MergeDatumService { if (datumList.size() > 0) { // merge ConfigInfo cf = MergeTaskProcessor.merge(dataId, group, tenant, datumList); - persistService.insertOrUpdate(null, null, cf, time, null, false); + configInfoPersistService.insertOrUpdate(null, null, cf, time, null, false); LOGGER.info("[merge-ok] {}, {}, size={}, length={}, md5={}, content={}", dataId, group, datumList.size(), cf.getContent().length(), cf.getMd5(), ContentUtils.truncateContent(cf.getContent())); } else { // remove - persistService.removeConfigInfo(dataId, group, tenant, InetUtils.getSelfIP(), null); + configInfoPersistService.removeConfigInfo(dataId, group, tenant, InetUtils.getSelfIP(), null); LOGGER.warn("[merge-delete] delete config info because no datum. dataId=" + dataId + ", groupId=" + group); } 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 index 07a00ab0e..b4e24e6e1 100755 --- 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 @@ -24,7 +24,9 @@ import com.alibaba.nacos.config.server.model.ConfigInfo; import com.alibaba.nacos.config.server.model.ConfigInfoAggr; import com.alibaba.nacos.config.server.model.Page; import com.alibaba.nacos.config.server.model.event.ConfigDataChangeEvent; -import com.alibaba.nacos.config.server.service.repository.PersistService; +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; @@ -47,13 +49,21 @@ public class MergeTaskProcessor implements NacosTaskProcessor { private static final Logger LOGGER = LoggerFactory.getLogger(MergeTaskProcessor.class); private static final int PAGE_SIZE = 10000; - - private PersistService persistService; + + private ConfigInfoPersistService configInfoPersistService; + + private ConfigInfoAggrPersistService configInfoAggrPersistService; + + private ConfigInfoTagPersistService configInfoTagPersistService; private MergeDatumService mergeService; - MergeTaskProcessor(PersistService persistService, MergeDatumService mergeService) { - this.persistService = persistService; + MergeTaskProcessor(ConfigInfoPersistService configInfoPersistService, + ConfigInfoAggrPersistService configInfoAggrPersistService, + ConfigInfoTagPersistService configInfoTagPersistService, MergeDatumService mergeService) { + this.configInfoPersistService = configInfoPersistService; + this.configInfoAggrPersistService = configInfoAggrPersistService; + this.configInfoTagPersistService = configInfoTagPersistService; this.mergeService = mergeService; } @@ -67,10 +77,10 @@ public class MergeTaskProcessor implements NacosTaskProcessor { final String clientIp = mergeTask.getClientIp(); try { List datumList = new ArrayList<>(); - int rowCount = persistService.aggrConfigInfoCount(dataId, group, tenant); + 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 = persistService + Page page = configInfoAggrPersistService .findConfigInfoAggrByPage(dataId, group, tenant, pageNo, PAGE_SIZE); if (page != null) { datumList.addAll(page.getPageItems()); @@ -82,8 +92,8 @@ public class MergeTaskProcessor implements NacosTaskProcessor { if (datumList.size() > 0) { // merge ConfigInfo cf = merge(dataId, group, tenant, datumList); - - persistService.insertOrUpdate(null, null, cf, time, null); + + configInfoPersistService.insertOrUpdate(null, null, cf, time, null); LOGGER.info("[merge-ok] {}, {}, size={}, length={}, md5={}, content={}", dataId, group, datumList.size(), cf.getContent().length(), cf.getMd5(), @@ -95,9 +105,9 @@ public class MergeTaskProcessor implements NacosTaskProcessor { } else { // remove if (StringUtils.isBlank(tag)) { - persistService.removeConfigInfo(dataId, group, tenant, clientIp, null); + configInfoPersistService.removeConfigInfo(dataId, group, tenant, clientIp, null); } else { - persistService.removeConfigInfoTag(dataId, group, tenant, tag, clientIp, null); + configInfoTagPersistService.removeConfigInfoTag(dataId, group, tenant, tag, clientIp, null); } LOGGER.warn( diff --git a/config/src/test/java/com/alibaba/nacos/config/server/remote/ConfigPublishRequestHandlerTest.java b/config/src/test/java/com/alibaba/nacos/config/server/remote/ConfigPublishRequestHandlerTest.java index 07662e931..d738eba28 100644 --- a/config/src/test/java/com/alibaba/nacos/config/server/remote/ConfigPublishRequestHandlerTest.java +++ b/config/src/test/java/com/alibaba/nacos/config/server/remote/ConfigPublishRequestHandlerTest.java @@ -21,7 +21,9 @@ import com.alibaba.nacos.api.config.remote.response.ConfigPublishResponse; import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.api.remote.request.RequestMeta; import com.alibaba.nacos.api.remote.response.ResponseCode; -import com.alibaba.nacos.config.server.service.repository.PersistService; +import com.alibaba.nacos.config.server.service.repository.ConfigInfoBetaPersistService; +import com.alibaba.nacos.config.server.service.repository.ConfigInfoPersistService; +import com.alibaba.nacos.config.server.service.repository.ConfigInfoTagPersistService; import com.alibaba.nacos.sys.env.EnvUtil; import org.junit.Assert; import org.junit.Before; @@ -37,11 +39,18 @@ public class ConfigPublishRequestHandlerTest { private ConfigPublishRequestHandler configPublishRequestHandler; @Mock - private PersistService persistService; + private ConfigInfoPersistService configInfoPersistService; + + @Mock + private ConfigInfoTagPersistService configInfoTagPersistService; + + @Mock + private ConfigInfoBetaPersistService configInfoBetaPersistService; @Before public void setUp() { - configPublishRequestHandler = new ConfigPublishRequestHandler(persistService); + configPublishRequestHandler = new ConfigPublishRequestHandler(configInfoPersistService, + configInfoTagPersistService, configInfoBetaPersistService); EnvUtil.setEnvironment(new StandardEnvironment()); } diff --git a/config/src/test/java/com/alibaba/nacos/config/server/remote/ConfigRemoveRequestHandlerTest.java b/config/src/test/java/com/alibaba/nacos/config/server/remote/ConfigRemoveRequestHandlerTest.java index 7be0d7bda..1e68f6448 100644 --- a/config/src/test/java/com/alibaba/nacos/config/server/remote/ConfigRemoveRequestHandlerTest.java +++ b/config/src/test/java/com/alibaba/nacos/config/server/remote/ConfigRemoveRequestHandlerTest.java @@ -21,7 +21,8 @@ import com.alibaba.nacos.api.config.remote.response.ConfigRemoveResponse; import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.api.remote.request.RequestMeta; import com.alibaba.nacos.api.remote.response.ResponseCode; -import com.alibaba.nacos.config.server.service.repository.PersistService; +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 org.junit.Assert; import org.junit.Before; @@ -37,11 +38,15 @@ public class ConfigRemoveRequestHandlerTest { private ConfigRemoveRequestHandler configRemoveRequestHandler; @Mock - private PersistService persistService; + private ConfigInfoPersistService configInfoPersistService; + + @Mock + private ConfigInfoTagPersistService configInfoTagPersistService; @Before public void setUp() throws Exception { - configRemoveRequestHandler = new ConfigRemoveRequestHandler(persistService); + configRemoveRequestHandler = new ConfigRemoveRequestHandler(configInfoPersistService, + configInfoTagPersistService); Mockito.mockStatic(ConfigTraceService.class); } diff --git a/config/src/test/java/com/alibaba/nacos/config/server/service/ConfigOperationServiceTest.java b/config/src/test/java/com/alibaba/nacos/config/server/service/ConfigOperationServiceTest.java index 8449e1128..31bbbcce7 100644 --- a/config/src/test/java/com/alibaba/nacos/config/server/service/ConfigOperationServiceTest.java +++ b/config/src/test/java/com/alibaba/nacos/config/server/service/ConfigOperationServiceTest.java @@ -20,6 +20,9 @@ import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.config.server.model.ConfigInfo; import com.alibaba.nacos.config.server.model.ConfigRequestInfo; import com.alibaba.nacos.config.server.model.form.ConfigForm; +import com.alibaba.nacos.config.server.service.repository.ConfigInfoBetaPersistService; +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.repository.PersistService; import com.alibaba.nacos.sys.env.EnvUtil; import org.junit.Assert; @@ -52,10 +55,20 @@ public class ConfigOperationServiceTest { @Mock private PersistService persistService; + @Mock + private ConfigInfoPersistService configInfoPersistService; + + @Mock + private ConfigInfoTagPersistService configInfoTagPersistService; + + @Mock + private ConfigInfoBetaPersistService configInfoBetaPersistService; + @Before public void setUp() throws Exception { EnvUtil.setEnvironment(new StandardEnvironment()); - this.configOperationService = new ConfigOperationService(persistService); + this.configOperationService = new ConfigOperationService(configInfoPersistService, configInfoTagPersistService, + configInfoBetaPersistService); } @Test diff --git a/config/src/test/java/com/alibaba/nacos/config/server/service/HistoryServiceTest.java b/config/src/test/java/com/alibaba/nacos/config/server/service/HistoryServiceTest.java index 6d30aa96e..bf245887e 100644 --- a/config/src/test/java/com/alibaba/nacos/config/server/service/HistoryServiceTest.java +++ b/config/src/test/java/com/alibaba/nacos/config/server/service/HistoryServiceTest.java @@ -19,7 +19,8 @@ package com.alibaba.nacos.config.server.service; import com.alibaba.nacos.config.server.model.ConfigHistoryInfo; import com.alibaba.nacos.config.server.model.ConfigInfoWrapper; import com.alibaba.nacos.config.server.model.Page; -import com.alibaba.nacos.config.server.service.repository.PersistService; +import com.alibaba.nacos.config.server.service.repository.ConfigInfoPersistService; +import com.alibaba.nacos.config.server.service.repository.HistoryConfigInfoPersistService; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -48,7 +49,10 @@ public class HistoryServiceTest { private HistoryService historyService; @Mock - private PersistService persistService; + private HistoryConfigInfoPersistService historyConfigInfoPersistService; + + @Mock + private ConfigInfoPersistService configInfoPersistService; private static final String TEST_DATA_ID = "test"; @@ -60,7 +64,7 @@ public class HistoryServiceTest { @Before public void setUp() throws Exception { - this.historyService = new HistoryService(persistService); + this.historyService = new HistoryService(historyConfigInfoPersistService, configInfoPersistService); } @Test @@ -80,12 +84,12 @@ public class HistoryServiceTest { page.setPagesAvailable(2); page.setPageItems(configHistoryInfoList); - when(persistService.findConfigHistory(TEST_DATA_ID, TEST_GROUP, TEST_TENANT, 1, 10)).thenReturn(page); + when(historyConfigInfoPersistService.findConfigHistory(TEST_DATA_ID, TEST_GROUP, TEST_TENANT, 1, 10)).thenReturn(page); Page pageResult = historyService .listConfigHistory(TEST_DATA_ID, TEST_GROUP, TEST_TENANT, 1, 10); - verify(persistService).findConfigHistory(TEST_DATA_ID, TEST_GROUP, TEST_TENANT, 1, 10); + verify(historyConfigInfoPersistService).findConfigHistory(TEST_DATA_ID, TEST_GROUP, TEST_TENANT, 1, 10); List resultList = pageResult.getPageItems(); ConfigHistoryInfo resConfigHistoryInfo = resultList.get(0); @@ -107,12 +111,12 @@ public class HistoryServiceTest { configHistoryInfo.setCreatedTime(new Timestamp(new Date().getTime())); configHistoryInfo.setLastModifiedTime(new Timestamp(new Date().getTime())); - when(persistService.detailConfigHistory(1L)).thenReturn(configHistoryInfo); + when(historyConfigInfoPersistService.detailConfigHistory(1L)).thenReturn(configHistoryInfo); ConfigHistoryInfo resConfigHistoryInfo = historyService .getConfigHistoryInfo(TEST_DATA_ID, TEST_GROUP, TEST_TENANT, 1L); - verify(persistService).detailConfigHistory(1L); + verify(historyConfigInfoPersistService).detailConfigHistory(1L); assertEquals(configHistoryInfo.getDataId(), resConfigHistoryInfo.getDataId()); assertEquals(configHistoryInfo.getGroup(), resConfigHistoryInfo.getGroup()); @@ -131,12 +135,12 @@ public class HistoryServiceTest { configHistoryInfo.setCreatedTime(new Timestamp(new Date().getTime())); configHistoryInfo.setLastModifiedTime(new Timestamp(new Date().getTime())); - when(persistService.detailPreviousConfigHistory(1L)).thenReturn(configHistoryInfo); + when(historyConfigInfoPersistService.detailPreviousConfigHistory(1L)).thenReturn(configHistoryInfo); ConfigHistoryInfo resConfigHistoryInfo = historyService .getPreviousConfigHistoryInfo(TEST_DATA_ID, TEST_GROUP, TEST_TENANT, 1L); - verify(persistService).detailPreviousConfigHistory(1L); + verify(historyConfigInfoPersistService).detailPreviousConfigHistory(1L); assertEquals(configHistoryInfo.getDataId(), resConfigHistoryInfo.getDataId()); assertEquals(configHistoryInfo.getGroup(), resConfigHistoryInfo.getGroup()); @@ -152,11 +156,11 @@ public class HistoryServiceTest { configInfoWrapper.setContent("test"); List configInfoWrappers = Collections.singletonList(configInfoWrapper); - when(persistService.queryConfigInfoByNamespace("test")).thenReturn(configInfoWrappers); + when(configInfoPersistService.queryConfigInfoByNamespace("test")).thenReturn(configInfoWrappers); List actualList = historyService.getConfigListByNamespace("test"); - verify(persistService).queryConfigInfoByNamespace("test"); + verify(configInfoPersistService).queryConfigInfoByNamespace("test"); assertEquals(configInfoWrappers.size(), actualList.size()); ConfigInfoWrapper actualConfigInfoWrapper = actualList.get(0); diff --git a/console/src/main/java/com/alibaba/nacos/console/controller/HealthController.java b/console/src/main/java/com/alibaba/nacos/console/controller/HealthController.java index f95cba770..f5b0e9813 100644 --- a/console/src/main/java/com/alibaba/nacos/console/controller/HealthController.java +++ b/console/src/main/java/com/alibaba/nacos/console/controller/HealthController.java @@ -16,7 +16,7 @@ package com.alibaba.nacos.console.controller; -import com.alibaba.nacos.config.server.service.repository.PersistService; +import com.alibaba.nacos.config.server.service.repository.ConfigInfoPersistService; import com.alibaba.nacos.naming.controllers.OperatorController; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,13 +40,13 @@ public class HealthController { private static final Logger LOGGER = LoggerFactory.getLogger(HealthController.class); - private final PersistService persistService; + private final ConfigInfoPersistService configInfoPersistService; private final OperatorController apiCommands; @Autowired - public HealthController(PersistService persistService, OperatorController apiCommands) { - this.persistService = persistService; + public HealthController(ConfigInfoPersistService configInfoPersistService, OperatorController apiCommands) { + this.configInfoPersistService = configInfoPersistService; this.apiCommands = apiCommands; } @@ -90,7 +90,7 @@ public class HealthController { private boolean isConfigReadiness() { // check db try { - persistService.configInfoCount(""); + configInfoPersistService.configInfoCount(""); return true; } catch (Exception e) { LOGGER.error("Config health check fail.", e); diff --git a/console/src/main/java/com/alibaba/nacos/console/controller/NamespaceController.java b/console/src/main/java/com/alibaba/nacos/console/controller/NamespaceController.java index 342a9629d..ffe1e31de 100644 --- a/console/src/main/java/com/alibaba/nacos/console/controller/NamespaceController.java +++ b/console/src/main/java/com/alibaba/nacos/console/controller/NamespaceController.java @@ -21,7 +21,7 @@ import com.alibaba.nacos.auth.annotation.Secured; import com.alibaba.nacos.common.model.RestResult; import com.alibaba.nacos.common.model.RestResultUtils; import com.alibaba.nacos.common.utils.StringUtils; -import com.alibaba.nacos.config.server.service.repository.PersistService; +import com.alibaba.nacos.config.server.service.repository.CommonPersistService; import com.alibaba.nacos.console.model.Namespace; import com.alibaba.nacos.console.model.NamespaceAllInfo; import com.alibaba.nacos.console.service.NamespaceOperationService; @@ -50,7 +50,7 @@ import java.util.regex.Pattern; public class NamespaceController { @Autowired - private PersistService persistService; + private CommonPersistService commonPersistService; @Autowired private NamespaceOperationService namespaceOperationService; @@ -121,7 +121,7 @@ public class NamespaceController { if (StringUtils.isBlank(namespaceId)) { return false; } - return (persistService.tenantInfoCountByTenantId(namespaceId) > 0); + return (commonPersistService.tenantInfoCountByTenantId(namespaceId) > 0); } /** diff --git a/console/src/main/java/com/alibaba/nacos/console/service/NamespaceOperationService.java b/console/src/main/java/com/alibaba/nacos/console/service/NamespaceOperationService.java index a4c6ba8ee..f2fd9fdb1 100644 --- a/console/src/main/java/com/alibaba/nacos/console/service/NamespaceOperationService.java +++ b/console/src/main/java/com/alibaba/nacos/console/service/NamespaceOperationService.java @@ -21,7 +21,8 @@ import com.alibaba.nacos.api.exception.api.NacosApiException; import com.alibaba.nacos.api.model.v2.ErrorCode; import com.alibaba.nacos.common.utils.StringUtils; import com.alibaba.nacos.config.server.model.TenantInfo; -import com.alibaba.nacos.config.server.service.repository.PersistService; +import com.alibaba.nacos.config.server.service.repository.CommonPersistService; +import com.alibaba.nacos.config.server.service.repository.ConfigInfoPersistService; import com.alibaba.nacos.console.enums.NamespaceTypeEnum; import com.alibaba.nacos.console.model.Namespace; import com.alibaba.nacos.console.model.NamespaceAllInfo; @@ -41,7 +42,9 @@ import java.util.List; @Service public class NamespaceOperationService { - private final PersistService persistService; + private final ConfigInfoPersistService configInfoPersistService; + + private final CommonPersistService commonPersistService; private static final String DEFAULT_NAMESPACE = "public"; @@ -57,21 +60,23 @@ public class NamespaceOperationService { private static final String DEFAULT_KP = "1"; - public NamespaceOperationService(PersistService persistService) { - this.persistService = persistService; + public NamespaceOperationService(ConfigInfoPersistService configInfoPersistService, + CommonPersistService commonPersistService) { + this.configInfoPersistService = configInfoPersistService; + this.commonPersistService = commonPersistService; } public List getNamespaceList() { // TODO 获取用kp - List tenantInfos = persistService.findTenantByKp(DEFAULT_KP); + List tenantInfos = commonPersistService.findTenantByKp(DEFAULT_KP); Namespace namespace0 = new Namespace("", DEFAULT_NAMESPACE, DEFAULT_QUOTA, - persistService.configInfoCount(DEFAULT_TENANT), NamespaceTypeEnum.GLOBAL.getType()); + configInfoPersistService.configInfoCount(DEFAULT_TENANT), NamespaceTypeEnum.GLOBAL.getType()); List namespaceList = new ArrayList<>(); namespaceList.add(namespace0); for (TenantInfo tenantInfo : tenantInfos) { - int configCount = persistService.configInfoCount(tenantInfo.getTenantId()); + int configCount = configInfoPersistService.configInfoCount(tenantInfo.getTenantId()); Namespace namespaceTmp = new Namespace(tenantInfo.getTenantId(), tenantInfo.getTenantName(), tenantInfo.getTenantDesc(), DEFAULT_QUOTA, configCount, NamespaceTypeEnum.CUSTOM.getType()); namespaceList.add(namespaceTmp); @@ -89,15 +94,15 @@ public class NamespaceOperationService { // TODO 获取用kp if (StringUtils.isBlank(namespaceId)) { return new NamespaceAllInfo(namespaceId, DEFAULT_NAMESPACE_SHOW_NAME, DEFAULT_QUOTA, - persistService.configInfoCount(DEFAULT_TENANT), NamespaceTypeEnum.GLOBAL.getType(), + configInfoPersistService.configInfoCount(DEFAULT_TENANT), NamespaceTypeEnum.GLOBAL.getType(), DEFAULT_NAMESPACE_DESCRIPTION); } else { - TenantInfo tenantInfo = persistService.findTenantByKp(DEFAULT_KP, namespaceId); + TenantInfo tenantInfo = commonPersistService.findTenantByKp(DEFAULT_KP, namespaceId); if (null == tenantInfo) { throw new NacosApiException(HttpStatus.NOT_FOUND.value(), ErrorCode.NAMESPACE_NOT_EXIST, "namespaceId [ " + namespaceId + " ] not exist"); } - int configCount = persistService.configInfoCount(namespaceId); + int configCount = configInfoPersistService.configInfoCount(namespaceId); return new NamespaceAllInfo(namespaceId, tenantInfo.getTenantName(), DEFAULT_QUOTA, configCount, NamespaceTypeEnum.CUSTOM.getType(), tenantInfo.getTenantDesc()); } @@ -114,12 +119,12 @@ public class NamespaceOperationService { public Boolean createNamespace(String namespaceId, String namespaceName, String namespaceDesc) throws NacosException { // TODO 获取用kp - if (persistService.tenantInfoCountByTenantId(namespaceId) > 0) { + if (commonPersistService.tenantInfoCountByTenantId(namespaceId) > 0) { throw new NacosApiException(HttpStatus.INTERNAL_SERVER_ERROR.value(), ErrorCode.NAMESPACE_ALREADY_EXIST, "namespaceId [" + namespaceId + "] already exist"); } - - persistService + + commonPersistService .insertTenantInfoAtomic(DEFAULT_KP, namespaceId, namespaceName, namespaceDesc, DEFAULT_CREATE_SOURCE, System.currentTimeMillis()); return true; @@ -130,7 +135,7 @@ public class NamespaceOperationService { */ public Boolean editNamespace(String namespaceId, String namespaceName, String namespaceDesc) { // TODO 获取用kp - persistService.updateTenantNameAtomic(DEFAULT_KP, namespaceId, namespaceName, namespaceDesc); + commonPersistService.updateTenantNameAtomic(DEFAULT_KP, namespaceId, namespaceName, namespaceDesc); return true; } @@ -138,7 +143,7 @@ public class NamespaceOperationService { * remove namespace. */ public Boolean removeNamespace(String namespaceId) { - persistService.removeTenantInfoAtomic(DEFAULT_KP, namespaceId); + commonPersistService.removeTenantInfoAtomic(DEFAULT_KP, namespaceId); return true; } } diff --git a/console/src/test/java/com/alibaba/nacos/console/controller/HealthControllerTest.java b/console/src/test/java/com/alibaba/nacos/console/controller/HealthControllerTest.java index c9dfbbba1..a0d3126cf 100644 --- a/console/src/test/java/com/alibaba/nacos/console/controller/HealthControllerTest.java +++ b/console/src/test/java/com/alibaba/nacos/console/controller/HealthControllerTest.java @@ -17,7 +17,7 @@ package com.alibaba.nacos.console.controller; import com.alibaba.nacos.common.utils.JacksonUtils; -import com.alibaba.nacos.config.server.service.repository.PersistService; +import com.alibaba.nacos.config.server.service.repository.ConfigInfoPersistService; import com.alibaba.nacos.naming.controllers.OperatorController; import org.junit.Assert; import org.junit.Before; @@ -49,7 +49,7 @@ public class HealthControllerTest { private HealthController healthController; @Mock - private PersistService persistService; + private ConfigInfoPersistService configInfoPersistService; @Mock private OperatorController apiCommands; @@ -72,13 +72,13 @@ public class HealthControllerTest { public void testReadiness() throws Exception { String url = "/v1/console/health/readiness"; - Mockito.when(persistService.configInfoCount(any(String.class))).thenReturn(0); + Mockito.when(configInfoPersistService.configInfoCount(any(String.class))).thenReturn(0); Mockito.when(apiCommands.metrics(any(HttpServletRequest.class))).thenReturn(JacksonUtils.createEmptyJsonNode()); MockHttpServletRequestBuilder builder = MockMvcRequestBuilders.get(url); Assert.assertEquals(200, mockmvc.perform(builder).andReturn().getResponse().getStatus()); // Config and Naming are not in readiness - Mockito.when(persistService.configInfoCount(any(String.class))) + Mockito.when(configInfoPersistService.configInfoCount(any(String.class))) .thenThrow(new RuntimeException("HealthControllerTest.testReadiness")); Mockito.when(apiCommands.metrics(any(HttpServletRequest.class))) .thenThrow(new RuntimeException("HealthControllerTest.testReadiness")); @@ -88,7 +88,7 @@ public class HealthControllerTest { Assert.assertEquals("Config and Naming are not in readiness", response.getContentAsString()); // Config is not in readiness - Mockito.when(persistService.configInfoCount(any(String.class))) + Mockito.when(configInfoPersistService.configInfoCount(any(String.class))) .thenThrow(new RuntimeException("HealthControllerTest.testReadiness")); Mockito.when(apiCommands.metrics(any(HttpServletRequest.class))).thenReturn(JacksonUtils.createEmptyJsonNode()); response = mockmvc.perform(builder).andReturn().getResponse(); @@ -96,7 +96,7 @@ public class HealthControllerTest { Assert.assertEquals("Config is not in readiness", response.getContentAsString()); // Naming is not in readiness - Mockito.when(persistService.configInfoCount(any(String.class))).thenReturn(0); + Mockito.when(configInfoPersistService.configInfoCount(any(String.class))).thenReturn(0); Mockito.when(apiCommands.metrics(any(HttpServletRequest.class))) .thenThrow(new RuntimeException("HealthControllerTest.testReadiness")); builder = MockMvcRequestBuilders.get(url); diff --git a/console/src/test/java/com/alibaba/nacos/console/controller/NamespaceControllerTest.java b/console/src/test/java/com/alibaba/nacos/console/controller/NamespaceControllerTest.java index e8c33dbf8..4dc3c3b03 100644 --- a/console/src/test/java/com/alibaba/nacos/console/controller/NamespaceControllerTest.java +++ b/console/src/test/java/com/alibaba/nacos/console/controller/NamespaceControllerTest.java @@ -18,7 +18,7 @@ package com.alibaba.nacos.console.controller; import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.common.model.RestResult; -import com.alibaba.nacos.config.server.service.repository.PersistService; +import com.alibaba.nacos.config.server.service.repository.CommonPersistService; import com.alibaba.nacos.console.model.Namespace; import com.alibaba.nacos.console.model.NamespaceAllInfo; import com.alibaba.nacos.console.service.NamespaceOperationService; @@ -49,7 +49,7 @@ public class NamespaceControllerTest { private NamespaceController namespaceController; @Mock - private PersistService persistService; + private CommonPersistService commonPersistService; @Mock private NamespaceOperationService namespaceOperationService; @@ -115,8 +115,8 @@ public class NamespaceControllerTest { @Test public void testCheckNamespaceIdExist() throws Exception { - when(persistService.tenantInfoCountByTenantId("public")).thenReturn(1); - when(persistService.tenantInfoCountByTenantId("123")).thenReturn(0); + when(commonPersistService.tenantInfoCountByTenantId("public")).thenReturn(1); + when(commonPersistService.tenantInfoCountByTenantId("123")).thenReturn(0); assertFalse(namespaceController.checkNamespaceIdExist("")); assertTrue(namespaceController.checkNamespaceIdExist("public")); assertFalse(namespaceController.checkNamespaceIdExist("123")); diff --git a/console/src/test/java/com/alibaba/nacos/console/service/NamespaceOperationServiceTest.java b/console/src/test/java/com/alibaba/nacos/console/service/NamespaceOperationServiceTest.java index 4a153310f..6289c8851 100644 --- a/console/src/test/java/com/alibaba/nacos/console/service/NamespaceOperationServiceTest.java +++ b/console/src/test/java/com/alibaba/nacos/console/service/NamespaceOperationServiceTest.java @@ -19,7 +19,8 @@ package com.alibaba.nacos.console.service; import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.api.exception.api.NacosApiException; import com.alibaba.nacos.config.server.model.TenantInfo; -import com.alibaba.nacos.config.server.service.repository.PersistService; +import com.alibaba.nacos.config.server.service.repository.CommonPersistService; +import com.alibaba.nacos.config.server.service.repository.ConfigInfoPersistService; import com.alibaba.nacos.console.enums.NamespaceTypeEnum; import com.alibaba.nacos.console.model.Namespace; import com.alibaba.nacos.console.model.NamespaceAllInfo; @@ -51,7 +52,10 @@ public class NamespaceOperationServiceTest { private NamespaceOperationService namespaceOperationService; @Mock - private PersistService persistService; + private ConfigInfoPersistService configInfoPersistService; + + @Mock + private CommonPersistService commonPersistService; private static final String TEST_NAMESPACE_ID = "testId"; @@ -67,7 +71,7 @@ public class NamespaceOperationServiceTest { @Before public void setUp() throws Exception { - namespaceOperationService = new NamespaceOperationService(persistService); + namespaceOperationService = new NamespaceOperationService(configInfoPersistService, commonPersistService); } @Test @@ -76,8 +80,8 @@ public class NamespaceOperationServiceTest { tenantInfo.setTenantId(TEST_NAMESPACE_ID); tenantInfo.setTenantName(TEST_NAMESPACE_NAME); tenantInfo.setTenantDesc(TEST_NAMESPACE_DESC); - when(persistService.findTenantByKp(DEFAULT_KP)).thenReturn(Collections.singletonList(tenantInfo)); - when(persistService.configInfoCount(anyString())).thenReturn(1); + when(commonPersistService.findTenantByKp(DEFAULT_KP)).thenReturn(Collections.singletonList(tenantInfo)); + when(configInfoPersistService.configInfoCount(anyString())).thenReturn(1); List list = namespaceOperationService.getNamespaceList(); assertEquals(2, list.size()); @@ -100,9 +104,9 @@ public class NamespaceOperationServiceTest { tenantInfo.setTenantId(TEST_NAMESPACE_ID); tenantInfo.setTenantName(TEST_NAMESPACE_NAME); tenantInfo.setTenantDesc(TEST_NAMESPACE_DESC); - when(persistService.findTenantByKp(DEFAULT_KP, TEST_NAMESPACE_ID)).thenReturn(tenantInfo); - when(persistService.findTenantByKp(DEFAULT_KP, "test_not_exist_id")).thenReturn(null); - when(persistService.configInfoCount(anyString())).thenReturn(1); + when(commonPersistService.findTenantByKp(DEFAULT_KP, TEST_NAMESPACE_ID)).thenReturn(tenantInfo); + when(commonPersistService.findTenantByKp(DEFAULT_KP, "test_not_exist_id")).thenReturn(null); + when(configInfoPersistService.configInfoCount(anyString())).thenReturn(1); NamespaceAllInfo namespaceAllInfo = new NamespaceAllInfo(TEST_NAMESPACE_ID, TEST_NAMESPACE_NAME, DEFAULT_QUOTA, 1, NamespaceTypeEnum.GLOBAL.getType(), TEST_NAMESPACE_DESC); NamespaceAllInfo namespace = namespaceOperationService.getNamespace(TEST_NAMESPACE_ID); @@ -118,9 +122,9 @@ public class NamespaceOperationServiceTest { @Test public void testCreateNamespace() throws NacosException { - when(persistService.tenantInfoCountByTenantId(anyString())).thenReturn(0); + when(commonPersistService.tenantInfoCountByTenantId(anyString())).thenReturn(0); namespaceOperationService.createNamespace(TEST_NAMESPACE_ID, TEST_NAMESPACE_NAME, TEST_NAMESPACE_DESC); - verify(persistService) + verify(commonPersistService) .insertTenantInfoAtomic(eq(DEFAULT_KP), eq(TEST_NAMESPACE_ID), eq(TEST_NAMESPACE_NAME), eq(TEST_NAMESPACE_DESC), any(), anyLong()); } @@ -128,12 +132,12 @@ public class NamespaceOperationServiceTest { @Test public void testEditNamespace() { namespaceOperationService.editNamespace(TEST_NAMESPACE_ID, TEST_NAMESPACE_NAME, TEST_NAMESPACE_DESC); - verify(persistService).updateTenantNameAtomic(DEFAULT_KP, TEST_NAMESPACE_ID, TEST_NAMESPACE_NAME, TEST_NAMESPACE_DESC); + verify(commonPersistService).updateTenantNameAtomic(DEFAULT_KP, TEST_NAMESPACE_ID, TEST_NAMESPACE_NAME, TEST_NAMESPACE_DESC); } @Test public void testRemoveNamespace() { namespaceOperationService.removeNamespace(TEST_NAMESPACE_ID); - verify(persistService).removeTenantInfoAtomic(DEFAULT_KP, TEST_NAMESPACE_ID); + verify(commonPersistService).removeTenantInfoAtomic(DEFAULT_KP, TEST_NAMESPACE_ID); } }