Skip to content

Commit

Permalink
fix(alibaba#12231): When inserting and updating configurations in the…
Browse files Browse the repository at this point in the history
… database, the time-related field values need to be set using the time obtained from the database's built-in time function.
  • Loading branch information
Bo-Qiu committed Jun 18, 2024
1 parent 5d87196 commit 665cd2f
Show file tree
Hide file tree
Showing 43 changed files with 514 additions and 259 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,20 @@ public ConfigOperateResult addConfigInfo4Beta(ConfigInfo configInfo, String beta
String md5 = MD5Utils.md5Hex(configInfo.getContent(), Constants.ENCODE);
ConfigInfoBetaMapper configInfoBetaMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
TableConstant.CONFIG_INFO_BETA);
Timestamp time = new Timestamp(System.currentTimeMillis());


final String sql = configInfoBetaMapper.insert(
Arrays.asList("data_id", "group_id", "tenant_id", "app_name", "content", "md5", "beta_ips",
"src_ip", "src_user", "gmt_create", "gmt_modified", "encrypted_data_key"));
final Object[] args = new Object[] {configInfo.getDataId(), configInfo.getGroup(), tenantTmp, appNameTmp,
configInfo.getContent(), md5, betaIps, srcIp, srcUser, time, time, encryptedDataKey};

"src_ip", "src_user", "gmt_create@NOW()", "gmt_modified@NOW()", "encrypted_data_key"));
final Object[] args = new Object[]{configInfo.getDataId(), configInfo.getGroup(), tenantTmp, appNameTmp,
configInfo.getContent(), md5, betaIps, srcIp, srcUser, encryptedDataKey};

Timestamp time = new Timestamp(System.currentTimeMillis());
EmbeddedStorageContextUtils.onModifyConfigBetaInfo(configInfo, betaIps, srcIp, time);
EmbeddedStorageContextHolder.addSqlContext(sql, args);

databaseOperate.blockUpdate();
return getBetaOperateResult(configInfo.getDataId(), configInfo.getGroup(), tenantTmp);

} finally {
EmbeddedStorageContextHolder.cleanAllContext();
}
Expand Down Expand Up @@ -203,20 +203,20 @@ public ConfigOperateResult updateConfigInfo4Beta(ConfigInfo configInfo, String b
String md5 = MD5Utils.md5Hex(configInfo.getContent(), Constants.ENCODE);
ConfigInfoBetaMapper configInfoBetaMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
TableConstant.CONFIG_INFO_BETA);
Timestamp time = new Timestamp(System.currentTimeMillis());
final String sql = configInfoBetaMapper.update(
Arrays.asList("content", "md5", "beta_ips", "src_ip", "src_user", "gmt_modified", "app_name",
"encrypted_data_key"), Arrays.asList("data_id", "group_id", "tenant_id"));
final Object[] args = new Object[] {configInfo.getContent(), md5, betaIps, srcIp, srcUser, time, appNameTmp,
Arrays.asList("content", "md5", "beta_ips", "src_ip", "src_user", "gmt_modified@NOW()",
"app_name", "encrypted_data_key"), Arrays.asList("data_id", "group_id", "tenant_id"));

final Object[] args = new Object[]{configInfo.getContent(), md5, betaIps, srcIp, srcUser, appNameTmp,
encryptedDataKey, configInfo.getDataId(), configInfo.getGroup(), tenantTmp};


Timestamp time = new Timestamp(System.currentTimeMillis());
EmbeddedStorageContextUtils.onModifyConfigBetaInfo(configInfo, betaIps, srcIp, time);
EmbeddedStorageContextHolder.addSqlContext(sql, args);

databaseOperate.blockUpdate();
return getBetaOperateResult(configInfo.getDataId(), configInfo.getGroup(), tenantTmp);

} finally {
EmbeddedStorageContextHolder.cleanAllContext();
}
Expand All @@ -234,29 +234,28 @@ public ConfigOperateResult updateConfigInfo4BetaCas(ConfigInfo configInfo, Strin

ConfigInfoBetaMapper configInfoBetaMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
TableConstant.CONFIG_INFO_BETA);
Timestamp time = new Timestamp(System.currentTimeMillis());
MapperContext context = new MapperContext();
context.putUpdateParameter(FieldConstant.CONTENT, configInfo.getContent());
context.putUpdateParameter(FieldConstant.MD5, md5);
context.putUpdateParameter(FieldConstant.BETA_IPS, betaIps);
context.putUpdateParameter(FieldConstant.SRC_IP, srcIp);
context.putUpdateParameter(FieldConstant.SRC_USER, srcUser);
context.putUpdateParameter(FieldConstant.GMT_MODIFIED, time);
context.putUpdateParameter(FieldConstant.APP_NAME, appNameTmp);

context.putWhereParameter(FieldConstant.DATA_ID, configInfo.getDataId());
context.putWhereParameter(FieldConstant.GROUP_ID, configInfo.getGroup());
context.putWhereParameter(FieldConstant.TENANT_ID, tenantTmp);
context.putWhereParameter(FieldConstant.MD5, configInfo.getMd5());
MapperResult mapperResult = configInfoBetaMapper.updateConfigInfo4BetaCas(context);

final String sql = mapperResult.getSql();
List<Object> paramList = mapperResult.getParamList();
final Object[] args = paramList.toArray();


Timestamp time = new Timestamp(System.currentTimeMillis());
EmbeddedStorageContextUtils.onModifyConfigBetaInfo(configInfo, betaIps, srcIp, time);
EmbeddedStorageContextHolder.addSqlContext(sql, args);

boolean success = databaseOperate.blockUpdate();
if (success) {
return getBetaOperateResult(configInfo.getDataId(), configInfo.getGroup(), tenantTmp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ private ConfigOperateResult addConfigInfo(final String srcIp, final String srcUs

addConfigTagsRelation(configId, configTags, configInfo.getDataId(), configInfo.getGroup(),
configInfo.getTenant());

Timestamp now = new Timestamp(System.currentTimeMillis());

historyConfigInfoPersistService.insertConfigHistoryAtomic(hisId, configInfo, srcIp, srcUser, now, "I");
EmbeddedStorageContextUtils.onModifyConfigInfo(configInfo, srcIp, now);
databaseOperate.blockUpdate(consumer);
Expand Down Expand Up @@ -264,15 +264,13 @@ public long addConfigInfoAtomic(final long id, final String srcIp, final String
configInfo.getEncryptedDataKey() == null ? StringUtils.EMPTY : configInfo.getEncryptedDataKey();
ConfigInfoMapper configInfoMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
TableConstant.CONFIG_INFO);
Timestamp time = new Timestamp(System.currentTimeMillis());


final String sql = configInfoMapper.insert(
Arrays.asList("id", "data_id", "group_id", "tenant_id", "app_name", "content", "md5", "src_ip",
"src_user", "gmt_create", "gmt_modified", "c_desc", "c_use", "effect", "type", "c_schema",
"encrypted_data_key"));
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};
"src_user", "gmt_create@NOW()", "gmt_modified@NOW()", "c_desc", "c_use", "effect",
"type", "c_schema", "encrypted_data_key"));
final Object[] args = new Object[]{id, configInfo.getDataId(), configInfo.getGroup(), tenantTmp, appNameTmp,
configInfo.getContent(), md5Tmp, srcIp, srcUser, desc, use, effect, type, schema, encryptedDataKey};
EmbeddedStorageContextHolder.addSqlContext(sql, args);
return id;
}
Expand Down Expand Up @@ -522,14 +520,11 @@ public ConfigOperateResult updateConfigInfo(final ConfigInfo configInfo, final S
}

Timestamp time = new Timestamp(System.currentTimeMillis());

historyConfigInfoPersistService.insertConfigHistoryAtomic(oldConfigInfo.getId(), oldConfigInfo, srcIp,
srcUser, time, "U");

EmbeddedStorageContextUtils.onModifyConfigInfo(configInfo, srcIp, time);
databaseOperate.blockUpdate();
return getConfigInfoOperateResult(configInfo.getDataId(), configInfo.getGroup(), tenantTmp);

} finally {
EmbeddedStorageContextHolder.cleanAllContext();
}
Expand Down Expand Up @@ -563,11 +558,10 @@ public ConfigOperateResult updateConfigInfoCas(final ConfigInfo configInfo, fina
addConfigTagsRelation(oldConfigInfo.getId(), configTags, configInfo.getDataId(), configInfo.getGroup(),
configInfo.getTenant());
}

Timestamp time = new Timestamp(System.currentTimeMillis());

historyConfigInfoPersistService.insertConfigHistoryAtomic(oldConfigInfo.getId(), oldConfigInfo, srcIp,
srcUser, time, "U");

EmbeddedStorageContextUtils.onModifyConfigInfo(configInfo, srcIp, time);
boolean success = databaseOperate.blockUpdate();
if (success) {
Expand All @@ -594,13 +588,11 @@ private ConfigOperateResult updateConfigInfoAtomicCas(final ConfigInfo configInf
configInfo.getEncryptedDataKey() == null ? StringUtils.EMPTY : configInfo.getEncryptedDataKey();
ConfigInfoMapper configInfoMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
TableConstant.CONFIG_INFO);
Timestamp time = new Timestamp(System.currentTimeMillis());
MapperContext context = new MapperContext();
context.putUpdateParameter(FieldConstant.CONTENT, configInfo.getContent());
context.putUpdateParameter(FieldConstant.MD5, md5Tmp);
context.putUpdateParameter(FieldConstant.SRC_IP, srcIp);
context.putUpdateParameter(FieldConstant.SRC_USER, srcUser);
context.putUpdateParameter(FieldConstant.GMT_MODIFIED, time);
context.putUpdateParameter(FieldConstant.APP_NAME, appNameTmp);
context.putUpdateParameter(FieldConstant.C_DESC, desc);
context.putUpdateParameter(FieldConstant.C_USE, use);
Expand Down Expand Up @@ -632,18 +624,17 @@ public void updateConfigInfoAtomic(final ConfigInfo configInfo, final String src
final String schema = configAdvanceInfo == null ? null : (String) configAdvanceInfo.get("schema");
final String encryptedDataKey =
configInfo.getEncryptedDataKey() == null ? StringUtils.EMPTY : configInfo.getEncryptedDataKey();

ConfigInfoMapper configInfoMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
TableConstant.CONFIG_INFO);
final String sql = configInfoMapper.update(
Arrays.asList("content", "md5", "src_ip", "src_user", "gmt_modified", "app_name", "c_desc", "c_use",
"effect", "type", "c_schema", "encrypted_data_key"),
Arrays.asList("content", "md5", "src_ip", "src_user", "gmt_modified@NOW()", "app_name",
"c_desc", "c_use", "effect", "type", "c_schema", "encrypted_data_key"),
Arrays.asList("data_id", "group_id", "tenant_id"));
Timestamp time = new Timestamp(System.currentTimeMillis());

final Object[] args = new Object[] {configInfo.getContent(), md5Tmp, srcIp, srcUser, time, appNameTmp, desc,

final Object[] args = new Object[]{configInfo.getContent(), md5Tmp, srcIp, srcUser, appNameTmp, desc,
use, effect, type, schema, encryptedDataKey, configInfo.getDataId(), configInfo.getGroup(), tenantTmp};

EmbeddedStorageContextHolder.addSqlContext(sql, args);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.support.TransactionTemplate;

import java.sql.Timestamp;
import java.util.Arrays;
import java.util.List;

Expand Down Expand Up @@ -94,13 +93,12 @@ public ConfigOperateResult addConfigInfo4Beta(ConfigInfo configInfo, String beta
try {
ConfigInfoBetaMapper configInfoBetaMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
TableConstant.CONFIG_INFO_BETA);
Timestamp time = new Timestamp(System.currentTimeMillis());

jt.update(configInfoBetaMapper.insert(
Arrays.asList("data_id", "group_id", "tenant_id", "app_name", "content", "md5", "beta_ips",
"src_ip", "src_user", "gmt_create", "gmt_modified", "encrypted_data_key")),
"src_ip", "src_user", "gmt_create@NOW()", "gmt_modified@NOW()", "encrypted_data_key")),
configInfo.getDataId(), configInfo.getGroup(), tenantTmp, appNameTmp, configInfo.getContent(), md5,
betaIps, srcIp, srcUser, time, time, encryptedDataKey);
betaIps, srcIp, srcUser, encryptedDataKey);
return getBetaOperateResult(configInfo.getDataId(), configInfo.getGroup(), tenantTmp);

} catch (CannotGetJdbcConnectionException e) {
Expand Down Expand Up @@ -165,12 +163,11 @@ public ConfigOperateResult updateConfigInfo4Beta(ConfigInfo configInfo, String b
try {
ConfigInfoBetaMapper configInfoBetaMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
TableConstant.CONFIG_INFO_BETA);
Timestamp time = new Timestamp(System.currentTimeMillis());


jt.update(configInfoBetaMapper.update(
Arrays.asList("content", "md5", "beta_ips", "src_ip", "src_user", "gmt_modified", "app_name",
"encrypted_data_key"), Arrays.asList("data_id", "group_id", "tenant_id")),
configInfo.getContent(), md5, betaIps, srcIp, srcUser, time, appNameTmp, encryptedDataKey,
Arrays.asList("content", "md5", "beta_ips", "src_ip", "src_user", "gmt_modified@NOW()",
"app_name", "encrypted_data_key"), Arrays.asList("data_id", "group_id", "tenant_id")),
configInfo.getContent(), md5, betaIps, srcIp, srcUser, appNameTmp, encryptedDataKey,
configInfo.getDataId(), configInfo.getGroup(), tenantTmp);
return getBetaOperateResult(configInfo.getDataId(), configInfo.getGroup(), tenantTmp);

Expand Down Expand Up @@ -214,15 +211,13 @@ public ConfigOperateResult updateConfigInfo4BetaCas(ConfigInfo configInfo, Strin
try {
ConfigInfoBetaMapper configInfoBetaMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
TableConstant.CONFIG_INFO_BETA);
Timestamp time = new Timestamp(System.currentTimeMillis());


MapperContext context = new MapperContext();
context.putUpdateParameter(FieldConstant.CONTENT, configInfo.getContent());
context.putUpdateParameter(FieldConstant.MD5, md5);
context.putUpdateParameter(FieldConstant.BETA_IPS, betaIps);
context.putUpdateParameter(FieldConstant.SRC_IP, srcIp);
context.putUpdateParameter(FieldConstant.SRC_USER, srcUser);
context.putUpdateParameter(FieldConstant.GMT_MODIFIED, time);
context.putUpdateParameter(FieldConstant.APP_NAME, appNameTmp);

context.putWhereParameter(FieldConstant.DATA_ID, configInfo.getDataId());
Expand Down
Loading

0 comments on commit 665cd2f

Please sign in to comment.