Move some methods from EmbeddedStorageContextUtils to EmbeddedStorageContextHolder

This commit is contained in:
KomachiSion 2023-04-23 17:37:14 +08:00
parent 11fc4792c4
commit 6acabeca67
25 changed files with 328 additions and 293 deletions

View File

@ -28,13 +28,13 @@ import com.alibaba.nacos.config.server.service.repository.ConfigInfoBetaPersistS
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;
import com.alibaba.nacos.consistency.cp.MetadataKey;
import com.alibaba.nacos.core.cluster.ServerMemberManager;
import com.alibaba.nacos.core.distributed.ProtocolManager;
import com.alibaba.nacos.core.utils.GlobalExecutor;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
import com.alibaba.nacos.sys.env.EnvUtil;
import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Component;
@ -110,7 +110,7 @@ public class EmbeddedDumpService extends DumpService {
return;
}
// Identify without a timeout mechanism
EmbeddedStorageContextUtils.putExtendInfo(Constants.EXTEND_NEED_READ_UNTIL_HAVE_DATA, "true");
EmbeddedStorageContextHolder.putExtendInfo(Constants.EXTEND_NEED_READ_UNTIL_HAVE_DATA, "true");
// Remove your own listening to avoid task accumulation
boolean canEnd = false;
for (; ; ) {
@ -131,7 +131,7 @@ public class EmbeddedDumpService extends DumpService {
}
ThreadUtils.sleep(500L);
}
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
});
}
};

View File

@ -18,7 +18,7 @@ package com.alibaba.nacos.config.server.service.repository.embedded;
import com.alibaba.nacos.common.utils.ExceptionUtil;
import com.alibaba.nacos.common.utils.LoggerUtils;
import com.alibaba.nacos.config.server.service.sql.ModifyRequest;
import com.alibaba.nacos.persistence.repository.embedded.ModifyRequest;
import com.alibaba.nacos.config.server.utils.DerbyUtils;
import com.alibaba.nacos.config.server.utils.LogUtil;
import org.springframework.dao.DataAccessException;

View File

@ -17,8 +17,8 @@
package com.alibaba.nacos.config.server.service.repository.embedded;
import com.alibaba.nacos.common.model.RestResult;
import com.alibaba.nacos.config.server.service.sql.EmbeddedStorageContextUtils;
import com.alibaba.nacos.config.server.service.sql.ModifyRequest;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
import com.alibaba.nacos.persistence.repository.embedded.ModifyRequest;
import org.springframework.jdbc.core.RowMapper;
import java.io.File;
@ -146,9 +146,9 @@ public interface DatabaseOperate {
*/
default Boolean blockUpdate(BiConsumer<Boolean, Throwable> consumer) {
try {
return update(EmbeddedStorageContextUtils.getCurrentSqlContext(), consumer);
return update(EmbeddedStorageContextHolder.getCurrentSqlContext(), consumer);
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -161,7 +161,7 @@ public interface DatabaseOperate {
default CompletableFuture<Boolean> futureUpdate() {
try {
CompletableFuture<Boolean> future = new CompletableFuture<>();
update(EmbeddedStorageContextUtils.getCurrentSqlContext(), (o, throwable) -> {
update(EmbeddedStorageContextHolder.getCurrentSqlContext(), (o, throwable) -> {
if (Objects.nonNull(throwable)) {
future.completeExceptionally(throwable);
return;
@ -170,7 +170,7 @@ public interface DatabaseOperate {
});
return future;
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}

View File

@ -40,10 +40,10 @@ import com.alibaba.nacos.persistence.datasource.DynamicDataSource;
import com.alibaba.nacos.persistence.datasource.LocalDataSourceServiceImpl;
import com.alibaba.nacos.config.server.service.dump.DumpConfigHandler;
import com.alibaba.nacos.config.server.service.repository.RowMapperManager;
import com.alibaba.nacos.config.server.service.sql.EmbeddedStorageContextUtils;
import com.alibaba.nacos.config.server.service.sql.ModifyRequest;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
import com.alibaba.nacos.persistence.repository.embedded.ModifyRequest;
import com.alibaba.nacos.config.server.service.sql.QueryType;
import com.alibaba.nacos.config.server.service.sql.SelectRequest;
import com.alibaba.nacos.persistence.repository.embedded.SelectRequest;
import com.alibaba.nacos.config.server.utils.ConfigExecutor;
import com.alibaba.nacos.config.server.utils.LogUtil;
import com.alibaba.nacos.consistency.SerializeFactory;
@ -223,7 +223,7 @@ public class DistributedDatabaseOperateImpl extends RequestProcessor4CP implemen
SelectRequest.builder().queryType(QueryType.QUERY_ONE_NO_MAPPER_NO_ARGS).sql(sql)
.className(cls.getCanonicalName()).build());
final boolean blockRead = EmbeddedStorageContextUtils
final boolean blockRead = EmbeddedStorageContextHolder
.containsExtendInfo(Constants.EXTEND_NEED_READ_UNTIL_HAVE_DATA);
Response response = innerRead(
@ -247,7 +247,7 @@ public class DistributedDatabaseOperateImpl extends RequestProcessor4CP implemen
SelectRequest.builder().queryType(QueryType.QUERY_ONE_NO_MAPPER_WITH_ARGS).sql(sql).args(args)
.className(cls.getCanonicalName()).build());
final boolean blockRead = EmbeddedStorageContextUtils
final boolean blockRead = EmbeddedStorageContextHolder
.containsExtendInfo(Constants.EXTEND_NEED_READ_UNTIL_HAVE_DATA);
Response response = innerRead(
@ -271,7 +271,7 @@ public class DistributedDatabaseOperateImpl extends RequestProcessor4CP implemen
SelectRequest.builder().queryType(QueryType.QUERY_ONE_WITH_MAPPER_WITH_ARGS).sql(sql).args(args)
.className(mapper.getClass().getCanonicalName()).build());
final boolean blockRead = EmbeddedStorageContextUtils
final boolean blockRead = EmbeddedStorageContextHolder
.containsExtendInfo(Constants.EXTEND_NEED_READ_UNTIL_HAVE_DATA);
Response response = innerRead(
@ -296,7 +296,7 @@ public class DistributedDatabaseOperateImpl extends RequestProcessor4CP implemen
SelectRequest.builder().queryType(QueryType.QUERY_MANY_WITH_MAPPER_WITH_ARGS).sql(sql).args(args)
.className(mapper.getClass().getCanonicalName()).build());
final boolean blockRead = EmbeddedStorageContextUtils
final boolean blockRead = EmbeddedStorageContextHolder
.containsExtendInfo(Constants.EXTEND_NEED_READ_UNTIL_HAVE_DATA);
Response response = innerRead(
@ -320,7 +320,7 @@ public class DistributedDatabaseOperateImpl extends RequestProcessor4CP implemen
SelectRequest.builder().queryType(QueryType.QUERY_MANY_NO_MAPPER_WITH_ARGS).sql(sql).args(args)
.className(rClass.getCanonicalName()).build());
final boolean blockRead = EmbeddedStorageContextUtils
final boolean blockRead = EmbeddedStorageContextHolder
.containsExtendInfo(Constants.EXTEND_NEED_READ_UNTIL_HAVE_DATA);
Response response = innerRead(
@ -344,7 +344,7 @@ public class DistributedDatabaseOperateImpl extends RequestProcessor4CP implemen
SelectRequest.builder().queryType(QueryType.QUERY_MANY_WITH_LIST_WITH_ARGS).sql(sql).args(args)
.build());
final boolean blockRead = EmbeddedStorageContextUtils
final boolean blockRead = EmbeddedStorageContextHolder
.containsExtendInfo(Constants.EXTEND_NEED_READ_UNTIL_HAVE_DATA);
Response response = innerRead(
@ -429,7 +429,7 @@ public class DistributedDatabaseOperateImpl extends RequestProcessor4CP implemen
+ MD5Utils.md5Hex(sqlContext.toString(), Constants.ENCODE);
WriteRequest request = WriteRequest.newBuilder().setGroup(group()).setKey(key)
.setData(ByteString.copyFrom(serializer.serialize(sqlContext)))
.putAllExtendInfo(EmbeddedStorageContextUtils.getCurrentExtendInfo())
.putAllExtendInfo(EmbeddedStorageContextHolder.getCurrentExtendInfo())
.setType(sqlContext.getClass().getCanonicalName()).build();
if (Objects.isNull(consumer)) {
Response response = this.protocol.write(request);

View File

@ -25,7 +25,7 @@ import com.alibaba.nacos.config.server.model.event.DerbyImportEvent;
import com.alibaba.nacos.persistence.datasource.DataSourceService;
import com.alibaba.nacos.persistence.datasource.DynamicDataSource;
import com.alibaba.nacos.config.server.service.repository.CommonPersistService;
import com.alibaba.nacos.config.server.service.sql.EmbeddedStorageContextUtils;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
import com.alibaba.nacos.plugin.datasource.MapperManager;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.TenantInfoMapper;
@ -81,15 +81,15 @@ public class EmbeddedCommonPersistServiceImpl implements CommonPersistService {
"gmt_modified"));
final Object[] args = new Object[] {kp, tenantId, tenantName, tenantDesc, createResoure, time, time};
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
try {
boolean result = databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
boolean result = databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
if (!result) {
throw new NacosConfigException("Namespace creation failed");
}
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -98,12 +98,12 @@ public class EmbeddedCommonPersistServiceImpl implements CommonPersistService {
TenantInfoMapper tenantInfoMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
TableConstant.TENANT_INFO);
EmbeddedStorageContextUtils.addSqlContext(tenantInfoMapper.delete(Arrays.asList("kp", "tenant_id")), kp,
EmbeddedStorageContextHolder.addSqlContext(tenantInfoMapper.delete(Arrays.asList("kp", "tenant_id")), kp,
tenantId);
try {
databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -116,15 +116,15 @@ public class EmbeddedCommonPersistServiceImpl implements CommonPersistService {
Arrays.asList("kp", "tenant_id"));
final Object[] args = new Object[] {tenantName, tenantDesc, System.currentTimeMillis(), kp, tenantId};
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
try {
boolean result = databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
boolean result = databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
if (!result) {
throw new NacosConfigException("Namespace update failed");
}
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}

View File

@ -30,7 +30,7 @@ import com.alibaba.nacos.persistence.datasource.DataSourceService;
import com.alibaba.nacos.persistence.datasource.DynamicDataSource;
import com.alibaba.nacos.config.server.service.repository.ConfigInfoAggrPersistService;
import com.alibaba.nacos.persistence.repository.PaginationHelper;
import com.alibaba.nacos.config.server.service.sql.EmbeddedStorageContextUtils;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
import com.alibaba.nacos.plugin.datasource.MapperManager;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
@ -120,20 +120,20 @@ public class EmbeddedConfigInfoAggrPersistServiceImpl implements ConfigInfoAggrP
if (Objects.isNull(dbContent)) {
final Object[] args = new Object[] {dataId, group, tenantTmp, datumId, appNameTmp, contentTmp, now};
EmbeddedStorageContextUtils.addSqlContext(insert, args);
EmbeddedStorageContextHolder.addSqlContext(insert, args);
} else if (!dbContent.equals(content)) {
final Object[] args = new Object[] {contentTmp, now, dataId, group, tenantTmp, datumId};
EmbeddedStorageContextUtils.addSqlContext(update, args);
EmbeddedStorageContextHolder.addSqlContext(update, args);
}
try {
boolean result = databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
boolean result = databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
if (!result) {
throw new NacosConfigException("[Merge] Configuration release failed");
}
return true;
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -146,14 +146,14 @@ public class EmbeddedConfigInfoAggrPersistServiceImpl implements ConfigInfoAggrP
addAggrConfigInfo(dataId, group, tenant, entry.getKey(), appName, entry.getValue());
}
isPublishOk = databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
isPublishOk = databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
if (isPublishOk == null) {
return false;
}
return isPublishOk;
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -173,17 +173,17 @@ public class EmbeddedConfigInfoAggrPersistServiceImpl implements ConfigInfoAggrP
for (Map.Entry<String, String> datumEntry : datumMap.entrySet()) {
final Object[] args = new Object[] {dataId, group, tenantTmp, datumEntry.getKey(), appNameTmp,
datumEntry.getValue(), new Timestamp(System.currentTimeMillis())};
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
}
try {
isReplaceOk = databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
isReplaceOk = databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
if (isReplaceOk == null) {
return false;
}
return isReplaceOk;
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -197,15 +197,15 @@ public class EmbeddedConfigInfoAggrPersistServiceImpl implements ConfigInfoAggrP
TableConstant.CONFIG_INFO_AGGR);
final String sql = configInfoAggrMapper.delete(Arrays.asList("data_id", "group_id", "tenant_id", "datum_id"));
final Object[] args = new Object[] {dataId, group, tenantTmp, datumId};
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
try {
boolean result = databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
boolean result = databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
if (!result) {
throw new NacosConfigException("[aggregation with single] Configuration deletion failed");
}
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -217,15 +217,15 @@ public class EmbeddedConfigInfoAggrPersistServiceImpl implements ConfigInfoAggrP
TableConstant.CONFIG_INFO_AGGR);
final String sql = configInfoAggrMapper.delete(Arrays.asList("data_id", "group_id", "tenant_id"));
final Object[] args = new Object[] {dataId, group, tenantTmp};
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
try {
boolean result = databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
boolean result = databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
if (!result) {
throw new NacosConfigException("[aggregation with all] Configuration deletion failed");
}
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -246,16 +246,16 @@ public class EmbeddedConfigInfoAggrPersistServiceImpl implements ConfigInfoAggrP
final String sql = mapperResult.getSql();
final Object[] args = mapperResult.getParamList().toArray();
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
try {
boolean result = databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
boolean result = databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
if (!result) {
throw new NacosConfigException("[aggregation] Failed to configure batch deletion");
}
return true;
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}

View File

@ -31,6 +31,7 @@ import com.alibaba.nacos.persistence.datasource.DynamicDataSource;
import com.alibaba.nacos.config.server.service.repository.ConfigInfoBetaPersistService;
import com.alibaba.nacos.persistence.repository.PaginationHelper;
import com.alibaba.nacos.config.server.service.sql.EmbeddedStorageContextUtils;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
import com.alibaba.nacos.plugin.datasource.MapperManager;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
@ -102,11 +103,11 @@ public class EmbeddedConfigInfoBetaPersistServiceImpl implements ConfigInfoBetaP
configInfo.getContent(), md5, betaIps, srcIp, srcUser, time, time, encryptedDataKey};
EmbeddedStorageContextUtils.onModifyConfigBetaInfo(configInfo, betaIps, srcIp, time);
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
databaseOperate.blockUpdate();
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -145,14 +146,14 @@ public class EmbeddedConfigInfoBetaPersistServiceImpl implements ConfigInfoBetaP
EmbeddedStorageContextUtils.onDeleteConfigBetaInfo(tenantTmp, group, dataId,
System.currentTimeMillis());
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
boolean result = databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
boolean result = databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
if (!result) {
throw new NacosConfigException("[Tag] Configuration deletion failed");
}
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -179,11 +180,11 @@ public class EmbeddedConfigInfoBetaPersistServiceImpl implements ConfigInfoBetaP
encryptedDataKey, configInfo.getDataId(), configInfo.getGroup(), tenantTmp};
EmbeddedStorageContextUtils.onModifyConfigBetaInfo(configInfo, betaIps, srcIp, time);
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
databaseOperate.blockUpdate();
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -220,11 +221,11 @@ public class EmbeddedConfigInfoBetaPersistServiceImpl implements ConfigInfoBetaP
final Object[] args = paramList.toArray();
EmbeddedStorageContextUtils.onModifyConfigBetaInfo(configInfo, betaIps, srcIp, time);
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
return databaseOperate.blockUpdate();
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}

View File

@ -43,6 +43,7 @@ import com.alibaba.nacos.persistence.repository.PaginationHelper;
import com.alibaba.nacos.config.server.service.sql.EmbeddedStorageContextUtils;
import com.alibaba.nacos.config.server.utils.ParamUtils;
import com.alibaba.nacos.core.distributed.id.IdGeneratorManager;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
import com.alibaba.nacos.plugin.datasource.MapperManager;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
@ -194,7 +195,7 @@ public class EmbeddedConfigInfoPersistServiceImpl implements ConfigInfoPersistSe
EmbeddedStorageContextUtils.onModifyConfigInfo(configInfo, srcIp, time);
databaseOperate.blockUpdate(consumer);
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -255,7 +256,7 @@ public class EmbeddedConfigInfoPersistServiceImpl implements ConfigInfoPersistSe
final Object[] args = new Object[] {id, configInfo.getDataId(), configInfo.getGroup(), tenantTmp, appNameTmp,
configInfo.getContent(), md5Tmp, srcIp, srcUser, time, time, desc, use, effect, type, schema,
encryptedDataKey};
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
return id;
}
@ -266,7 +267,7 @@ public class EmbeddedConfigInfoPersistServiceImpl implements ConfigInfoPersistSe
final String sql = configTagsRelationMapper.insert(
Arrays.asList("id", "tag_name", "tag_type", "data_id", "group_id", "tenant_id"));
final Object[] args = new Object[] {configId, tagName, StringUtils.EMPTY, dataId, group, tenant};
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
}
@Override
@ -394,12 +395,12 @@ public class EmbeddedConfigInfoPersistServiceImpl implements ConfigInfoPersistSe
EmbeddedStorageContextUtils.onDeleteConfigInfo(tenantTmp, group, dataId, srcIp, time);
boolean result = databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
boolean result = databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
if (!result) {
throw new NacosConfigException("config deletion failed");
}
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
}
@ -424,14 +425,14 @@ public class EmbeddedConfigInfoPersistServiceImpl implements ConfigInfoPersistSe
}
EmbeddedStorageContextUtils.onBatchDeleteConfigInfo(configInfoList);
boolean result = databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
boolean result = databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
if (!result) {
throw new NacosConfigException("Failed to config batch deletion");
}
return configInfoList;
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -441,7 +442,7 @@ public class EmbeddedConfigInfoPersistServiceImpl implements ConfigInfoPersistSe
dataSourceService.getDataSourceType(), TableConstant.CONFIG_TAGS_RELATION);
final String sql = configTagsRelationMapper.delete(Arrays.asList("id"));
final Object[] args = new Object[] {id};
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
}
@Override
@ -453,7 +454,7 @@ public class EmbeddedConfigInfoPersistServiceImpl implements ConfigInfoPersistSe
final String sql = configInfoMapper.delete(Arrays.asList("data_id", "group_id", "tenant_id"));
final Object[] args = new Object[] {dataId, group, tenantTmp};
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
}
@Override
@ -471,7 +472,7 @@ public class EmbeddedConfigInfoPersistServiceImpl implements ConfigInfoPersistSe
MapperContext context = new MapperContext();
context.putWhereParameter(FieldConstant.IDS, paramList);
MapperResult result = configInfoMapper.removeConfigInfoByIdsAtomic(context);
EmbeddedStorageContextUtils.addSqlContext(result.getSql(), result.getParamList());
EmbeddedStorageContextHolder.addSqlContext(result.getSql(), result.getParamList());
}
@Override
@ -509,7 +510,7 @@ public class EmbeddedConfigInfoPersistServiceImpl implements ConfigInfoPersistSe
EmbeddedStorageContextUtils.onModifyConfigInfo(configInfo, srcIp, time);
databaseOperate.blockUpdate();
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -548,7 +549,7 @@ public class EmbeddedConfigInfoPersistServiceImpl implements ConfigInfoPersistSe
EmbeddedStorageContextUtils.onModifyConfigInfo(configInfo, srcIp, time);
return databaseOperate.blockUpdate();
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -586,7 +587,7 @@ public class EmbeddedConfigInfoPersistServiceImpl implements ConfigInfoPersistSe
context.putWhereParameter(FieldConstant.MD5, configInfo.getMd5());
MapperResult mapperResult = configInfoMapper.updateConfigInfoAtomicCas(context);
EmbeddedStorageContextUtils.addSqlContext(mapperResult.getSql(), mapperResult.getParamList().toArray());
EmbeddedStorageContextHolder.addSqlContext(mapperResult.getSql(), mapperResult.getParamList().toArray());
}
@Override
@ -614,7 +615,7 @@ public class EmbeddedConfigInfoPersistServiceImpl implements ConfigInfoPersistSe
final Object[] args = new Object[] {configInfo.getContent(), md5Tmp, srcIp, srcUser, time, appNameTmp, desc,
use, effect, type, schema, encryptedDataKey, configInfo.getDataId(), configInfo.getGroup(), tenantTmp};
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
}
@Override
@ -627,14 +628,14 @@ public class EmbeddedConfigInfoPersistServiceImpl implements ConfigInfoPersistSe
Arrays.asList("data_id", "group_id", "tenant_id", "gmt_modified"));
final Object[] args = new Object[] {md5, dataId, group, tenantTmp, lastTime};
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
boolean result = databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
boolean result = databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
if (!result) {
throw new NacosConfigException("Failed to config the MD5 modification");
}
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}

View File

@ -30,6 +30,7 @@ import com.alibaba.nacos.persistence.datasource.DynamicDataSource;
import com.alibaba.nacos.config.server.service.repository.ConfigInfoTagPersistService;
import com.alibaba.nacos.persistence.repository.PaginationHelper;
import com.alibaba.nacos.config.server.service.sql.EmbeddedStorageContextUtils;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
import com.alibaba.nacos.plugin.datasource.MapperManager;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
@ -100,11 +101,11 @@ public class EmbeddedConfigInfoTagPersistServiceImpl implements ConfigInfoTagPer
appNameTmp, configInfo.getContent(), md5, srcIp, srcUser, time, time};
EmbeddedStorageContextUtils.onModifyConfigTagInfo(configInfo, tagTmp, srcIp, time);
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
databaseOperate.blockUpdate();
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -141,11 +142,11 @@ public class EmbeddedConfigInfoTagPersistServiceImpl implements ConfigInfoTagPer
final Object[] args = new Object[] {dataId, group, tenantTmp, tagTmp};
EmbeddedStorageContextUtils.onDeleteConfigTagInfo(tenantTmp, group, dataId, tagTmp, srcIp);
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
try {
databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -170,11 +171,11 @@ public class EmbeddedConfigInfoTagPersistServiceImpl implements ConfigInfoTagPer
configInfo.getDataId(), configInfo.getGroup(), tenantTmp, tagTmp};
EmbeddedStorageContextUtils.onModifyConfigTagInfo(configInfo, tagTmp, srcIp, time);
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
databaseOperate.blockUpdate();
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -208,11 +209,11 @@ public class EmbeddedConfigInfoTagPersistServiceImpl implements ConfigInfoTagPer
final MapperResult mapperResult = configInfoTagMapper.updateConfigInfo4TagCas(context);
EmbeddedStorageContextUtils.onModifyConfigTagInfo(configInfo, tagTmp, srcIp, time);
EmbeddedStorageContextUtils.addSqlContext(mapperResult.getSql(), mapperResult.getParamList());
EmbeddedStorageContextHolder.addSqlContext(mapperResult.getSql(), mapperResult.getParamList());
return databaseOperate.blockUpdate();
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}

View File

@ -29,7 +29,7 @@ import com.alibaba.nacos.persistence.datasource.DataSourceService;
import com.alibaba.nacos.persistence.datasource.DynamicDataSource;
import com.alibaba.nacos.config.server.service.repository.HistoryConfigInfoPersistService;
import com.alibaba.nacos.persistence.repository.PaginationHelper;
import com.alibaba.nacos.config.server.service.sql.EmbeddedStorageContextUtils;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
import com.alibaba.nacos.plugin.datasource.MapperManager;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
@ -118,7 +118,7 @@ public class EmbeddedHistoryConfigInfoPersistServiceImpl implements HistoryConfi
final Object[] args = new Object[] {configHistoryId, configInfo.getDataId(), configInfo.getGroup(), tenantTmp,
appNameTmp, configInfo.getContent(), md5Tmp, srcIp, srcUser, time, ops, encryptedDataKey};
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
}
@Override

View File

@ -18,7 +18,7 @@ package com.alibaba.nacos.config.server.service.repository.embedded;
import com.alibaba.nacos.persistence.model.Page;
import com.alibaba.nacos.persistence.repository.PaginationHelper;
import com.alibaba.nacos.config.server.service.sql.EmbeddedStorageContextUtils;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;
import org.springframework.jdbc.core.RowMapper;
@ -187,11 +187,11 @@ class EmbeddedPaginationHelperImpl<E> implements PaginationHelper {
@Override
public void updateLimit(final String sql, final Object[] args) {
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
try {
databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}

View File

@ -49,6 +49,7 @@ import com.alibaba.nacos.config.server.service.repository.PersistService;
import com.alibaba.nacos.config.server.service.sql.EmbeddedStorageContextUtils;
import com.alibaba.nacos.config.server.utils.ParamUtils;
import com.alibaba.nacos.core.distributed.id.IdGeneratorManager;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
import com.alibaba.nacos.plugin.datasource.MapperManager;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
@ -239,7 +240,7 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
EmbeddedStorageContextUtils.onModifyConfigInfo(configInfo, srcIp, time);
databaseOperate.blockUpdate(consumer);
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -263,11 +264,11 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
configInfo.getContent(), md5, betaIps, srcIp, srcUser, time, time, encryptedDataKey};
EmbeddedStorageContextUtils.onModifyConfigBetaInfo(configInfo, betaIps, srcIp, time);
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
databaseOperate.blockUpdate();
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -291,11 +292,11 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
appNameTmp, configInfo.getContent(), md5, srcIp, srcUser, time, time};
EmbeddedStorageContextUtils.onModifyConfigTagInfo(configInfo, tagTmp, srcIp, time);
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
databaseOperate.blockUpdate();
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -333,7 +334,7 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
EmbeddedStorageContextUtils.onModifyConfigInfo(configInfo, srcIp, time);
databaseOperate.blockUpdate();
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -371,7 +372,7 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
EmbeddedStorageContextUtils.onModifyConfigInfo(configInfo, srcIp, time);
return databaseOperate.blockUpdate();
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -396,11 +397,11 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
encryptedDataKey, configInfo.getDataId(), configInfo.getGroup(), tenantTmp};
EmbeddedStorageContextUtils.onModifyConfigBetaInfo(configInfo, betaIps, srcIp, time);
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
databaseOperate.blockUpdate();
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -438,11 +439,11 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
final Object[] args = paramList.toArray();
EmbeddedStorageContextUtils.onModifyConfigBetaInfo(configInfo, betaIps, srcIp, time);
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
return databaseOperate.blockUpdate();
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -467,11 +468,11 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
configInfo.getDataId(), configInfo.getGroup(), tenantTmp, tagTmp};
EmbeddedStorageContextUtils.onModifyConfigTagInfo(configInfo, tagTmp, srcIp, time);
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
databaseOperate.blockUpdate();
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -505,11 +506,11 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
final MapperResult mapperResult = configInfoTagMapper.updateConfigInfo4TagCas(context);
EmbeddedStorageContextUtils.onModifyConfigTagInfo(configInfo, tagTmp, srcIp, time);
EmbeddedStorageContextUtils.addSqlContext(mapperResult.getSql(), mapperResult.getParamList());
EmbeddedStorageContextHolder.addSqlContext(mapperResult.getSql(), mapperResult.getParamList());
return databaseOperate.blockUpdate();
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -566,14 +567,14 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
Arrays.asList("data_id", "group_id", "tenant_id", "gmt_modified"));
final Object[] args = new Object[] {md5, dataId, group, tenantTmp, lastTime};
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
boolean result = databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
boolean result = databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
if (!result) {
throw new NacosConfigException("Failed to config the MD5 modification");
}
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -632,12 +633,12 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
EmbeddedStorageContextUtils.onDeleteConfigInfo(tenantTmp, group, dataId, srcIp, time);
boolean result = databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
boolean result = databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
if (!result) {
throw new NacosConfigException("config deletion failed");
}
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
}
@ -661,14 +662,14 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
}
EmbeddedStorageContextUtils.onBatchDeleteConfigInfo(configInfoList);
boolean result = databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
boolean result = databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
if (!result) {
throw new NacosConfigException("Failed to config batch deletion");
}
return configInfoList;
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -685,14 +686,14 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
EmbeddedStorageContextUtils.onDeleteConfigBetaInfo(tenantTmp, group, dataId,
System.currentTimeMillis());
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
boolean result = databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
boolean result = databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
if (!result) {
throw new NacosConfigException("[Tag] Configuration deletion failed");
}
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -720,20 +721,20 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
if (Objects.isNull(dbContent)) {
final Object[] args = new Object[] {dataId, group, tenantTmp, datumId, appNameTmp, contentTmp, now};
EmbeddedStorageContextUtils.addSqlContext(insert, args);
EmbeddedStorageContextHolder.addSqlContext(insert, args);
} else if (!dbContent.equals(content)) {
final Object[] args = new Object[] {contentTmp, now, dataId, group, tenantTmp, datumId};
EmbeddedStorageContextUtils.addSqlContext(update, args);
EmbeddedStorageContextHolder.addSqlContext(update, args);
}
try {
boolean result = databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
boolean result = databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
if (!result) {
throw new NacosConfigException("[Merge] Configuration release failed");
}
return true;
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -746,15 +747,15 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
TableConstant.CONFIG_INFO_AGGR);
final String sql = configInfoAggrMapper.delete(Arrays.asList("data_id", "group_id", "tenant_id", "datum_id"));
final Object[] args = new Object[] {dataId, group, tenantTmp, datumId};
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
try {
boolean result = databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
boolean result = databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
if (!result) {
throw new NacosConfigException("[aggregation with single] Configuration deletion failed");
}
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -766,15 +767,15 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
TableConstant.CONFIG_INFO_AGGR);
final String sql = configInfoAggrMapper.delete(Arrays.asList("data_id", "group_id", "tenant_id"));
final Object[] args = new Object[] {dataId, group, tenantTmp};
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
try {
boolean result = databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
boolean result = databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
if (!result) {
throw new NacosConfigException("[aggregation with all] Configuration deletion failed");
}
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -796,16 +797,16 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
List<Object> paramList = mapperResult.getParamList();
Object[] args = paramList.toArray();
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
try {
boolean result = databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
boolean result = databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
if (!result) {
throw new NacosConfigException("[aggregation] Failed to configure batch deletion");
}
return true;
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -853,14 +854,14 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
addAggrConfigInfo(dataId, group, tenant, entry.getKey(), appName, entry.getValue());
}
isPublishOk = databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
isPublishOk = databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
if (isPublishOk == null) {
return false;
}
return isPublishOk;
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -880,17 +881,17 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
for (Entry<String, String> datumEntry : datumMap.entrySet()) {
final Object[] args = new Object[] {dataId, group, tenantTmp, datumEntry.getKey(), appNameTmp,
datumEntry.getValue(), new Timestamp(System.currentTimeMillis())};
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
}
try {
isReplaceOk = databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
isReplaceOk = databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
if (isReplaceOk == null) {
return false;
}
return isReplaceOk;
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -1721,7 +1722,7 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
final Object[] args = new Object[] {id, configInfo.getDataId(), configInfo.getGroup(), tenantTmp, appNameTmp,
configInfo.getContent(), md5Tmp, srcIp, srcUser, time, time, desc, use, effect, type, schema,
encryptedDataKey};
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
return id;
}
@ -1732,7 +1733,7 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
final String sql = configTagsRelationMapper.insert(
Arrays.asList("id", "tag_name", "tag_type", "data_id", "group_id", "tenant_id"));
final Object[] args = new Object[] {configId, tagName, StringUtils.EMPTY, dataId, group, tenant};
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
}
@Override
@ -1751,7 +1752,7 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
dataSourceService.getDataSourceType(), TableConstant.CONFIG_TAGS_RELATION);
final String sql = configTagsRelationMapper.delete(Arrays.asList("id"));
final Object[] args = new Object[] {id};
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
}
@Override
@ -1772,7 +1773,7 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
final String sql = configInfoMapper.delete(Arrays.asList("data_id", "group_id", "tenant_id"));
final Object[] args = new Object[] {dataId, group, tenantTmp};
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
}
@Override
@ -1790,7 +1791,7 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
MapperContext context = new MapperContext();
context.putWhereParameter(FieldConstant.IDS, paramList);
MapperResult result = configInfoMapper.removeConfigInfoByIdsAtomic(context);
EmbeddedStorageContextUtils.addSqlContext(result.getSql(), result.getParamList());
EmbeddedStorageContextHolder.addSqlContext(result.getSql(), result.getParamList());
}
@Override
@ -1805,11 +1806,11 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
final Object[] args = new Object[] {dataId, group, tenantTmp, tagTmp};
EmbeddedStorageContextUtils.onDeleteConfigTagInfo(tenantTmp, group, dataId, tagTmp, srcIp);
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
try {
databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -1838,7 +1839,7 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
final Object[] args = new Object[] {configInfo.getContent(), md5Tmp, srcIp, srcUser, time, appNameTmp, desc,
use, effect, type, schema, encryptedDataKey, configInfo.getDataId(), configInfo.getGroup(), tenantTmp};
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
}
private void updateConfigInfoAtomicCas(final ConfigInfo configInfo, final String srcIp, final String srcUser,
@ -1875,7 +1876,7 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
context.putWhereParameter(FieldConstant.MD5, configInfo.getMd5());
final MapperResult mapperResult = configInfoMapper.updateConfigInfoAtomicCas(context);
EmbeddedStorageContextUtils.addSqlContext(true, mapperResult.getSql(), mapperResult.getParamList().toArray());
EmbeddedStorageContextHolder.addSqlContext(true, mapperResult.getSql(), mapperResult.getParamList().toArray());
}
@Override
@ -1971,7 +1972,7 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
final Object[] args = new Object[] {configHistoryId, configInfo.getDataId(), configInfo.getGroup(), tenantTmp,
appNameTmp, configInfo.getContent(), md5Tmp, srcIp, srcUser, time, ops, encryptedDataKey};
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
}
@Override
@ -2027,15 +2028,15 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
"gmt_modified"));
final Object[] args = new Object[] {kp, tenantId, tenantName, tenantDesc, createResoure, time, time};
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
try {
boolean result = databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
boolean result = databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
if (!result) {
throw new NacosConfigException("Namespace creation failed");
}
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -2048,15 +2049,15 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
Arrays.asList("kp", "tenant_id"));
final Object[] args = new Object[] {tenantName, tenantDesc, System.currentTimeMillis(), kp, tenantId};
EmbeddedStorageContextUtils.addSqlContext(sql, args);
EmbeddedStorageContextHolder.addSqlContext(sql, args);
try {
boolean result = databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
boolean result = databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
if (!result) {
throw new NacosConfigException("Namespace update failed");
}
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -2085,12 +2086,12 @@ public class EmbeddedStoragePersistServiceImpl implements PersistService {
TenantInfoMapper tenantInfoMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
TableConstant.TENANT_INFO);
EmbeddedStorageContextUtils.addSqlContext(tenantInfoMapper.delete(Arrays.asList("kp", "tenant_id")), kp,
EmbeddedStorageContextHolder.addSqlContext(tenantInfoMapper.delete(Arrays.asList("kp", "tenant_id")), kp,
tenantId);
try {
databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}

View File

@ -23,7 +23,7 @@ import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.config.server.configuration.ConditionStandaloneEmbedStorage;
import com.alibaba.nacos.persistence.datasource.DataSourceService;
import com.alibaba.nacos.persistence.datasource.DynamicDataSource;
import com.alibaba.nacos.config.server.service.sql.ModifyRequest;
import com.alibaba.nacos.persistence.repository.embedded.ModifyRequest;
import com.alibaba.nacos.config.server.utils.LogUtil;
import com.alibaba.nacos.sys.utils.DiskUtils;
import org.springframework.context.annotation.Conditional;

View File

@ -18,7 +18,7 @@ package com.alibaba.nacos.config.server.service.repository.extrnal;
import com.alibaba.nacos.persistence.model.Page;
import com.alibaba.nacos.persistence.repository.PaginationHelper;
import com.alibaba.nacos.config.server.service.sql.EmbeddedStorageContextUtils;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
@ -188,7 +188,7 @@ class ExternalStoragePaginationHelperImpl<E> implements PaginationHelper {
try {
jdbcTemplate.update(sql, args);
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -198,7 +198,7 @@ class ExternalStoragePaginationHelperImpl<E> implements PaginationHelper {
try {
return jdbcTemplate.update(sqlUpdate, args);
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}

View File

@ -21,6 +21,7 @@ import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.config.server.constant.Constants;
import com.alibaba.nacos.config.server.model.ConfigInfo;
import com.alibaba.nacos.config.server.model.event.ConfigDumpEvent;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
import com.alibaba.nacos.sys.env.EnvUtil;
import java.sql.Timestamp;
@ -36,67 +37,6 @@ import java.util.Map;
*/
public class EmbeddedStorageContextUtils {
private static final ThreadLocal<ArrayList<ModifyRequest>> SQL_CONTEXT = ThreadLocal.withInitial(ArrayList::new);
private static final ThreadLocal<Map<String, String>> EXTEND_INFO_CONTEXT = ThreadLocal.withInitial(HashMap::new);
/**
* Add sql context.
*
* @param sql sql
* @param args argument list
*/
public static void addSqlContext(String sql, Object... args) {
ArrayList<ModifyRequest> requests = SQL_CONTEXT.get();
ModifyRequest context = new ModifyRequest();
context.setExecuteNo(requests.size());
context.setSql(sql);
context.setArgs(args);
requests.add(context);
SQL_CONTEXT.set(requests);
}
/**
* Add sql context.
*
* @param rollbackOnUpdateFail roll back when update fail
* @param sql sql
* @param args argument list
*/
public static void addSqlContext(boolean rollbackOnUpdateFail, String sql, Object... args) {
ArrayList<ModifyRequest> requests = SQL_CONTEXT.get();
ModifyRequest context = new ModifyRequest();
context.setExecuteNo(requests.size());
context.setSql(sql);
context.setArgs(args);
context.setRollBackOnUpdateFail(rollbackOnUpdateFail);
requests.add(context);
SQL_CONTEXT.set(requests);
}
/**
* Put extend info.
*
* @param key key
* @param value value
*/
public static void putExtendInfo(String key, String value) {
Map<String, String> old = EXTEND_INFO_CONTEXT.get();
old.put(key, value);
EXTEND_INFO_CONTEXT.set(old);
}
/**
* Put all extend info.
*
* @param map all extend info
*/
public static void putAllExtendInfo(Map<String, String> map) {
Map<String, String> old = EXTEND_INFO_CONTEXT.get();
old.putAll(map);
EXTEND_INFO_CONTEXT.set(old);
}
/**
* In the case of the in-cluster storage mode, the logic of horizontal notification is implemented asynchronously
* via the raft state machine, along with the information.
@ -114,7 +54,7 @@ public class EmbeddedStorageContextUtils {
Map<String, String> extendInfo = new HashMap<>(2);
extendInfo.put(Constants.EXTEND_INFO_CONFIG_DUMP_EVENT, JacksonUtils.toJson(event));
EmbeddedStorageContextUtils.putAllExtendInfo(extendInfo);
EmbeddedStorageContextHolder.putAllExtendInfo(extendInfo);
}
}
@ -136,7 +76,7 @@ public class EmbeddedStorageContextUtils {
Map<String, String> extendInfo = new HashMap<>(2);
extendInfo.put(Constants.EXTEND_INFO_CONFIG_DUMP_EVENT, JacksonUtils.toJson(event));
EmbeddedStorageContextUtils.putAllExtendInfo(extendInfo);
EmbeddedStorageContextHolder.putAllExtendInfo(extendInfo);
}
}
@ -158,7 +98,7 @@ public class EmbeddedStorageContextUtils {
Map<String, String> extendInfo = new HashMap<>(2);
extendInfo.put(Constants.EXTEND_INFO_CONFIG_DUMP_EVENT, JacksonUtils.toJson(event));
EmbeddedStorageContextUtils.putAllExtendInfo(extendInfo);
EmbeddedStorageContextHolder.putAllExtendInfo(extendInfo);
}
}
@ -180,7 +120,7 @@ public class EmbeddedStorageContextUtils {
Map<String, String> extendInfo = new HashMap<>(2);
extendInfo.put(Constants.EXTEND_INFO_CONFIG_DUMP_EVENT, JacksonUtils.toJson(event));
EmbeddedStorageContextUtils.putAllExtendInfo(extendInfo);
EmbeddedStorageContextHolder.putAllExtendInfo(extendInfo);
}
}
@ -204,7 +144,7 @@ public class EmbeddedStorageContextUtils {
Map<String, String> extendInfo = new HashMap<>(2);
extendInfo.put(Constants.EXTEND_INFOS_CONFIG_DUMP_EVENT, JacksonUtils.toJson(events));
EmbeddedStorageContextUtils.putAllExtendInfo(extendInfo);
EmbeddedStorageContextHolder.putAllExtendInfo(extendInfo);
}
}
@ -224,7 +164,7 @@ public class EmbeddedStorageContextUtils {
Map<String, String> extendInfo = new HashMap<>(2);
extendInfo.put(Constants.EXTEND_INFO_CONFIG_DUMP_EVENT, JacksonUtils.toJson(event));
EmbeddedStorageContextUtils.putAllExtendInfo(extendInfo);
EmbeddedStorageContextHolder.putAllExtendInfo(extendInfo);
}
}
@ -246,34 +186,8 @@ public class EmbeddedStorageContextUtils {
Map<String, String> extendInfo = new HashMap<>(2);
extendInfo.put(Constants.EXTEND_INFO_CONFIG_DUMP_EVENT, JacksonUtils.toJson(event));
EmbeddedStorageContextUtils.putAllExtendInfo(extendInfo);
EmbeddedStorageContextHolder.putAllExtendInfo(extendInfo);
}
}
/**
* Determine if key is included.
*
* @param key key
* @return {@code true} if contains key
*/
public static boolean containsExtendInfo(String key) {
Map<String, String> extendInfo = EXTEND_INFO_CONTEXT.get();
boolean exist = extendInfo.containsKey(key);
EXTEND_INFO_CONTEXT.set(extendInfo);
return exist;
}
public static List<ModifyRequest> getCurrentSqlContext() {
return SQL_CONTEXT.get();
}
public static Map<String, String> getCurrentExtendInfo() {
return EXTEND_INFO_CONTEXT.get();
}
public static void cleanAllContext() {
SQL_CONTEXT.remove();
EXTEND_INFO_CONTEXT.remove();
}
}

View File

@ -18,8 +18,8 @@ package com.alibaba.nacos.config.server.service.repository.embedded;
import com.alibaba.nacos.common.model.RestResult;
import com.alibaba.nacos.config.server.model.ConfigInfo;
import com.alibaba.nacos.config.server.service.sql.EmbeddedStorageContextUtils;
import com.alibaba.nacos.config.server.service.sql.ModifyRequest;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
import com.alibaba.nacos.persistence.repository.embedded.ModifyRequest;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@ -314,7 +314,7 @@ public class StandaloneDatabaseOperateImplTest {
@Test
public void testBlockUpdate1() {
String sql = "UPDATE config_info SET data_id = 'test' WHERE id = 1;";
EmbeddedStorageContextUtils.addSqlContext(sql);
EmbeddedStorageContextHolder.addSqlContext(sql);
when(transactionTemplate.execute(any(TransactionCallback.class))).thenReturn(true);
Assert.assertTrue(operate.blockUpdate());
}
@ -322,7 +322,7 @@ public class StandaloneDatabaseOperateImplTest {
@Test
public void testBlockUpdate2() {
String sql = "UPDATE config_info SET data_id = 'test' WHERE id = 1;";
EmbeddedStorageContextUtils.addSqlContext(sql);
EmbeddedStorageContextHolder.addSqlContext(sql);
when(transactionTemplate.execute(any(TransactionCallback.class))).thenReturn(true);
Assert.assertTrue(operate.blockUpdate(biConsumer));
}
@ -343,7 +343,7 @@ public class StandaloneDatabaseOperateImplTest {
@Test
public void testFutureUpdate() throws ExecutionException, InterruptedException {
String sql = "SELECT 1";
EmbeddedStorageContextUtils.addSqlContext(sql);
EmbeddedStorageContextHolder.addSqlContext(sql);
CompletableFuture<Boolean> future = new CompletableFuture<>();
future.complete(true);
doAnswer((invocationOnMock) -> null).when(operate).futureUpdate();

View File

@ -0,0 +1,117 @@
/*
* Copyright 1999-2023 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.persistence.repository.embedded;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Embedded storae context holder.
*
* @author xiweng.yy
*/
public class EmbeddedStorageContextHolder {
private static final ThreadLocal<ArrayList<ModifyRequest>> SQL_CONTEXT = ThreadLocal.withInitial(ArrayList::new);
private static final ThreadLocal<Map<String, String>> EXTEND_INFO_CONTEXT = ThreadLocal.withInitial(HashMap::new);
/**
* Add sql context.
*
* @param sql sql
* @param args argument list
*/
public static void addSqlContext(String sql, Object... args) {
ArrayList<ModifyRequest> requests = SQL_CONTEXT.get();
ModifyRequest context = new ModifyRequest();
context.setExecuteNo(requests.size());
context.setSql(sql);
context.setArgs(args);
requests.add(context);
SQL_CONTEXT.set(requests);
}
/**
* Add sql context.
*
* @param rollbackOnUpdateFail roll back when update fail
* @param sql sql
* @param args argument list
*/
public static void addSqlContext(boolean rollbackOnUpdateFail, String sql, Object... args) {
ArrayList<ModifyRequest> requests = SQL_CONTEXT.get();
ModifyRequest context = new ModifyRequest();
context.setExecuteNo(requests.size());
context.setSql(sql);
context.setArgs(args);
context.setRollBackOnUpdateFail(rollbackOnUpdateFail);
requests.add(context);
SQL_CONTEXT.set(requests);
}
/**
* Put extend info.
*
* @param key key
* @param value value
*/
public static void putExtendInfo(String key, String value) {
Map<String, String> old = EXTEND_INFO_CONTEXT.get();
old.put(key, value);
EXTEND_INFO_CONTEXT.set(old);
}
/**
* Put all extend info.
*
* @param map all extend info
*/
public static void putAllExtendInfo(Map<String, String> map) {
Map<String, String> old = EXTEND_INFO_CONTEXT.get();
old.putAll(map);
EXTEND_INFO_CONTEXT.set(old);
}
/**
* Determine if key is included.
*
* @param key key
* @return {@code true} if contains key
*/
public static boolean containsExtendInfo(String key) {
Map<String, String> extendInfo = EXTEND_INFO_CONTEXT.get();
boolean exist = extendInfo.containsKey(key);
EXTEND_INFO_CONTEXT.set(extendInfo);
return exist;
}
public static List<ModifyRequest> getCurrentSqlContext() {
return SQL_CONTEXT.get();
}
public static Map<String, String> getCurrentExtendInfo() {
return EXTEND_INFO_CONTEXT.get();
}
public static void cleanAllContext() {
SQL_CONTEXT.remove();
EXTEND_INFO_CONTEXT.remove();
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
* Copyright 1999-2023 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.alibaba.nacos.config.server.service.sql;
package com.alibaba.nacos.persistence.repository.embedded;
import java.io.Serializable;
import java.util.Arrays;

View File

@ -1,5 +1,5 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
* Copyright 1999-2023 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.alibaba.nacos.config.server.service.sql;
package com.alibaba.nacos.persistence.repository.embedded;
import java.io.Serializable;
import java.util.Arrays;

View File

@ -22,7 +22,7 @@ import com.alibaba.nacos.persistence.model.Page;
import com.alibaba.nacos.persistence.repository.PaginationHelper;
import com.alibaba.nacos.config.server.service.repository.embedded.DatabaseOperate;
import com.alibaba.nacos.config.server.service.repository.embedded.EmbeddedStoragePersistServiceImpl;
import com.alibaba.nacos.config.server.service.sql.EmbeddedStorageContextUtils;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Component;
@ -90,7 +90,7 @@ public class EmbeddedPermissionPersistServiceImpl implements PermissionPersistSe
@Override
public void addPermission(String role, String resource, String action) {
String sql = "INSERT INTO permissions (role, resource, action) VALUES (?, ?, ?)";
EmbeddedStorageContextUtils.addSqlContext(sql, role, resource, action);
EmbeddedStorageContextHolder.addSqlContext(sql, role, resource, action);
databaseOperate.blockUpdate();
}
@ -104,7 +104,7 @@ public class EmbeddedPermissionPersistServiceImpl implements PermissionPersistSe
@Override
public void deletePermission(String role, String resource, String action) {
String sql = "DELETE FROM permissions WHERE role=? AND resource=? AND action=?";
EmbeddedStorageContextUtils.addSqlContext(sql, role, resource, action);
EmbeddedStorageContextHolder.addSqlContext(sql, role, resource, action);
databaseOperate.blockUpdate();
}

View File

@ -26,8 +26,8 @@ import com.alibaba.nacos.persistence.model.Page;
import com.alibaba.nacos.persistence.repository.PaginationHelper;
import com.alibaba.nacos.config.server.service.repository.embedded.DatabaseOperate;
import com.alibaba.nacos.config.server.service.repository.embedded.EmbeddedStoragePersistServiceImpl;
import com.alibaba.nacos.config.server.service.sql.EmbeddedStorageContextUtils;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Component;
@ -113,10 +113,10 @@ public class EmbeddedRolePersistServiceImpl implements RolePersistService {
String sql = "INSERT INTO roles (role, username) VALUES (?, ?)";
try {
EmbeddedStorageContextUtils.addSqlContext(sql, role, userName);
databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
EmbeddedStorageContextHolder.addSqlContext(sql, role, userName);
databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -129,10 +129,10 @@ public class EmbeddedRolePersistServiceImpl implements RolePersistService {
public void deleteRole(String role) {
String sql = "DELETE FROM roles WHERE role=?";
try {
EmbeddedStorageContextUtils.addSqlContext(sql, role);
databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
EmbeddedStorageContextHolder.addSqlContext(sql, role);
databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -146,10 +146,10 @@ public class EmbeddedRolePersistServiceImpl implements RolePersistService {
public void deleteRole(String role, String username) {
String sql = "DELETE FROM roles WHERE role=? AND username=?";
try {
EmbeddedStorageContextUtils.addSqlContext(sql, role, username);
databaseOperate.update(EmbeddedStorageContextUtils.getCurrentSqlContext());
EmbeddedStorageContextHolder.addSqlContext(sql, role, username);
databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}

View File

@ -22,8 +22,8 @@ import com.alibaba.nacos.persistence.model.Page;
import com.alibaba.nacos.persistence.repository.PaginationHelper;
import com.alibaba.nacos.config.server.service.repository.embedded.DatabaseOperate;
import com.alibaba.nacos.config.server.service.repository.embedded.EmbeddedStoragePersistServiceImpl;
import com.alibaba.nacos.config.server.service.sql.EmbeddedStorageContextUtils;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Component;
@ -63,10 +63,10 @@ public class EmbeddedUserPersistServiceImpl implements UserPersistService {
String sql = "INSERT INTO users (username, password, enabled) VALUES (?, ?, ?)";
try {
EmbeddedStorageContextUtils.addSqlContext(sql, username, password, true);
EmbeddedStorageContextHolder.addSqlContext(sql, username, password, true);
databaseOperate.blockUpdate();
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -79,10 +79,10 @@ public class EmbeddedUserPersistServiceImpl implements UserPersistService {
public void deleteUser(String username) {
String sql = "DELETE FROM users WHERE username=?";
try {
EmbeddedStorageContextUtils.addSqlContext(sql, username);
EmbeddedStorageContextHolder.addSqlContext(sql, username);
databaseOperate.blockUpdate();
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}
@ -95,11 +95,11 @@ public class EmbeddedUserPersistServiceImpl implements UserPersistService {
@Override
public void updateUserPassword(String username, String password) {
try {
EmbeddedStorageContextUtils
EmbeddedStorageContextHolder
.addSqlContext("UPDATE users SET password = ? WHERE username=?", password, username);
databaseOperate.blockUpdate();
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
EmbeddedStorageContextHolder.cleanAllContext();
}
}

View File

@ -20,8 +20,8 @@ import com.alibaba.nacos.persistence.model.Page;
import com.alibaba.nacos.persistence.repository.PaginationHelper;
import com.alibaba.nacos.config.server.service.repository.embedded.DatabaseOperate;
import com.alibaba.nacos.config.server.service.repository.embedded.EmbeddedStoragePersistServiceImpl;
import com.alibaba.nacos.config.server.service.sql.EmbeddedStorageContextUtils;
import com.alibaba.nacos.config.server.service.sql.ModifyRequest;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
import com.alibaba.nacos.persistence.repository.embedded.ModifyRequest;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@ -72,7 +72,7 @@ public class EmbeddedPermissionPersistServiceImplTest {
@Test
public void testAddPermission() {
embeddedPermissionPersistService.addPermission("role", "resource", "action");
List<ModifyRequest> currentSqlContext = EmbeddedStorageContextUtils.getCurrentSqlContext();
List<ModifyRequest> currentSqlContext = EmbeddedStorageContextHolder.getCurrentSqlContext();
Mockito.verify(databaseOperate).blockUpdate();
}
@ -80,7 +80,7 @@ public class EmbeddedPermissionPersistServiceImplTest {
@Test
public void testDeletePermission() {
embeddedPermissionPersistService.deletePermission("role", "resource", "action");
List<ModifyRequest> currentSqlContext = EmbeddedStorageContextUtils.getCurrentSqlContext();
List<ModifyRequest> currentSqlContext = EmbeddedStorageContextHolder.getCurrentSqlContext();
Mockito.verify(databaseOperate).blockUpdate();
}

View File

@ -20,8 +20,8 @@ import com.alibaba.nacos.persistence.model.Page;
import com.alibaba.nacos.persistence.repository.PaginationHelper;
import com.alibaba.nacos.config.server.service.repository.embedded.DatabaseOperate;
import com.alibaba.nacos.config.server.service.repository.embedded.EmbeddedStoragePersistServiceImpl;
import com.alibaba.nacos.config.server.service.sql.EmbeddedStorageContextUtils;
import com.alibaba.nacos.config.server.service.sql.ModifyRequest;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
import com.alibaba.nacos.persistence.repository.embedded.ModifyRequest;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@ -79,7 +79,7 @@ public class EmbeddedRolePersistServiceImplTest {
@Test
public void testAddRole() {
embeddedRolePersistService.addRole("role", "userName");
List<ModifyRequest> currentSqlContext = EmbeddedStorageContextUtils.getCurrentSqlContext();
List<ModifyRequest> currentSqlContext = EmbeddedStorageContextHolder.getCurrentSqlContext();
Assert.assertEquals(currentSqlContext.size(), 0);
}
@ -89,7 +89,7 @@ public class EmbeddedRolePersistServiceImplTest {
embeddedRolePersistService.deleteRole("role");
embeddedRolePersistService.deleteRole("role", "userName");
List<ModifyRequest> currentSqlContext = EmbeddedStorageContextUtils.getCurrentSqlContext();
List<ModifyRequest> currentSqlContext = EmbeddedStorageContextHolder.getCurrentSqlContext();
Assert.assertEquals(currentSqlContext.size(), 0);
}

View File

@ -16,8 +16,8 @@
package com.alibaba.nacos.test.config;
import com.alibaba.nacos.config.server.service.sql.EmbeddedStorageContextUtils;
import com.alibaba.nacos.config.server.service.sql.ModifyRequest;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
import com.alibaba.nacos.persistence.repository.embedded.ModifyRequest;
import com.alibaba.nacos.test.base.ConfigCleanUtils;
import org.junit.AfterClass;
import org.junit.Assert;
@ -50,10 +50,10 @@ public class EmbeddedStorageContextUtils_CITCase {
final int j = i;
service.submit(() -> {
try {
EmbeddedStorageContextUtils.addSqlContext("test_" + j, j);
EmbeddedStorageContextUtils.addSqlContext("test_" + j * 10, j);
EmbeddedStorageContextHolder.addSqlContext("test_" + j, j);
EmbeddedStorageContextHolder.addSqlContext("test_" + j * 10, j);
List<ModifyRequest> list = EmbeddedStorageContextUtils.getCurrentSqlContext();
List<ModifyRequest> list = EmbeddedStorageContextHolder.getCurrentSqlContext();
System.out.println(list);
Assert.assertEquals("test_" + j, list.get(0).getSql());
Assert.assertEquals("test_" + j * 10, list.get(0).getSql());