Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#12231): When inserting and updating configurations in the database, the time-related field values need to be set using the time obtained from the database's built-in time function. #12243

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.alibaba.nacos.config.server.model.capacity.GroupCapacity;
import com.alibaba.nacos.persistence.datasource.DataSourceService;
import com.alibaba.nacos.persistence.datasource.DynamicDataSource;
import com.alibaba.nacos.config.server.utils.TimeUtils;
import com.alibaba.nacos.plugin.datasource.MapperManager;
import com.alibaba.nacos.plugin.datasource.constants.CommonConstant;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
Expand Down Expand Up @@ -274,8 +273,7 @@ public boolean updateGroupCapacity(String group, Integer quota, Integer maxSize,
columnList.add("max_aggr_size");
argList.add(maxAggrSize);
}
columnList.add("gmt_modified");
argList.add(TimeUtils.getCurrentTime());
columnList.add("gmt_modified@NOW()");

List<String> whereList = CollectionUtils.list();
whereList.add("group_id");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.alibaba.nacos.config.server.model.capacity.TenantCapacity;
import com.alibaba.nacos.persistence.datasource.DataSourceService;
import com.alibaba.nacos.persistence.datasource.DynamicDataSource;
import com.alibaba.nacos.config.server.utils.TimeUtils;
import com.alibaba.nacos.plugin.datasource.MapperManager;
import com.alibaba.nacos.plugin.datasource.constants.CommonConstant;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;
Expand Down Expand Up @@ -256,9 +255,8 @@ public boolean updateTenantCapacity(String tenant, Integer quota, Integer maxSiz
columns.add("max_aggr_size");
argList.add(maxAggrSize);
}
columns.add("gmt_modified");
argList.add(TimeUtils.getCurrentTime());

columns.add("gmt_modified@NOW()");

List<String> where = new ArrayList<>();
where.add("tenant_id");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -93,28 +92,27 @@ public boolean addAggrConfigInfo(final String dataId, final String group, String
String appNameTmp = StringUtils.isBlank(appName) ? StringUtils.EMPTY : appName;
String tenantTmp = StringUtils.isBlank(tenant) ? StringUtils.EMPTY : tenant;
String contentTmp = StringUtils.isBlank(content) ? StringUtils.EMPTY : content;
final Timestamp now = new Timestamp(System.currentTimeMillis());


ConfigInfoAggrMapper configInfoAggrMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
TableConstant.CONFIG_INFO_AGGR);
final String select = configInfoAggrMapper.select(Collections.singletonList("content"),
Arrays.asList("data_id", "group_id", "tenant_id", "datum_id"));
final String insert = configInfoAggrMapper.insert(
Arrays.asList("data_id", "group_id", "tenant_id", "datum_id", "app_name", "content", "gmt_modified"));
final String update = configInfoAggrMapper.update(Arrays.asList("content", "gmt_modified"),
Arrays.asList("data_id", "group_id", "tenant_id", "datum_id", "app_name", "content", "gmt_modified@NOW()"));
final String update = configInfoAggrMapper.update(Arrays.asList("content", "gmt_modified@NOW()"),
Arrays.asList("data_id", "group_id", "tenant_id", "datum_id"));
String dbContent = databaseOperate.queryOne(select, new Object[] {dataId, group, tenantTmp, datumId},

String dbContent = databaseOperate.queryOne(select, new Object[]{dataId, group, tenantTmp, datumId},
String.class);

if (Objects.isNull(dbContent)) {
final Object[] args = new Object[] {dataId, group, tenantTmp, datumId, appNameTmp, contentTmp, now};
final Object[] args = new Object[]{dataId, group, tenantTmp, datumId, appNameTmp, contentTmp};
EmbeddedStorageContextHolder.addSqlContext(insert, args);
} else if (!dbContent.equals(content)) {
final Object[] args = new Object[] {contentTmp, now, dataId, group, tenantTmp, datumId};
final Object[] args = new Object[]{contentTmp, dataId, group, tenantTmp, datumId};
EmbeddedStorageContextHolder.addSqlContext(update, args);
}

try {
boolean result = databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext());
if (!result) {
Expand Down
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 Down
Original file line number Diff line number Diff line change
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 @@ -632,18 +630,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 @@ -127,18 +127,18 @@ public ConfigOperateResult addConfigInfo4Tag(ConfigInfo configInfo, String tag,
TableConstant.CONFIG_INFO_TAG);
final String sql = configInfoTagMapper.insert(
Arrays.asList("data_id", "group_id", "tenant_id", "tag_id", "app_name", "content", "md5", "src_ip",
"src_user", "gmt_create", "gmt_modified"));
"src_user", "gmt_create@NOW()", "gmt_modified@NOW()"));

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

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

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

EmbeddedStorageContextUtils.onModifyConfigTagInfo(configInfo, tagTmp, srcIp, time);
EmbeddedStorageContextHolder.addSqlContext(sql, args);

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

} finally {
EmbeddedStorageContextHolder.cleanAllContext();
}
Expand Down Expand Up @@ -189,28 +189,25 @@ public ConfigOperateResult updateConfigInfo4Tag(ConfigInfo configInfo, String ta
String appNameTmp = StringUtils.defaultEmptyIfBlank(configInfo.getAppName());
String tenantTmp = StringUtils.defaultEmptyIfBlank(configInfo.getTenant());
String tagTmp = StringUtils.isBlank(tag) ? StringUtils.EMPTY : tag.trim();

configInfo.setTenant(tenantTmp);

try {
String md5 = MD5Utils.md5Hex(configInfo.getContent(), Constants.ENCODE);

ConfigInfoTagMapper configInfoTagMapper = mapperManager.findMapper(dataSourceService.getDataSourceType(),
TableConstant.CONFIG_INFO_TAG);
Timestamp time = new Timestamp(System.currentTimeMillis());


final String sql = configInfoTagMapper.update(
Arrays.asList("content", "md5", "src_ip", "src_user", "gmt_modified", "app_name"),
Arrays.asList("content", "md5", "src_ip", "src_user", "gmt_modified@NOW()", "app_name"),
Arrays.asList("data_id", "group_id", "tenant_id", "tag_id"));
final Object[] args = new Object[] {configInfo.getContent(), md5, srcIp, srcUser, time, appNameTmp,
final Object[] args = new Object[]{configInfo.getContent(), md5, srcIp, srcUser, appNameTmp,
configInfo.getDataId(), configInfo.getGroup(), tenantTmp, tagTmp};


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

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

} finally {
EmbeddedStorageContextHolder.cleanAllContext();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,22 @@ public boolean addAggrConfigInfo(final String dataId, final String group, String
String select = configInfoAggrMapper.select(Collections.singletonList("content"),
Arrays.asList("data_id", "group_id", "tenant_id", "datum_id"));
String insert = configInfoAggrMapper.insert(
Arrays.asList("data_id", "group_id", "tenant_id", "datum_id", "app_name", "content", "gmt_modified"));
String update = configInfoAggrMapper.update(Arrays.asList("content", "gmt_modified"),
Arrays.asList("data_id", "group_id", "tenant_id", "datum_id", "app_name", "content", "gmt_modified@NOW()"));
String update = configInfoAggrMapper.update(Arrays.asList("content", "gmt_modified@NOW()"),
Arrays.asList("data_id", "group_id", "tenant_id", "datum_id"));

try {
try {
String dbContent = jt.queryForObject(select, new Object[] {dataId, group, tenantTmp, datumId},
String dbContent = jt.queryForObject(select, new Object[]{dataId, group, tenantTmp, datumId},
String.class);

if (dbContent != null && dbContent.equals(content)) {
return true;
} else {
return jt.update(update, content, now, dataId, group, tenantTmp, datumId) > 0;
return jt.update(update, content, dataId, group, tenantTmp, datumId) > 0;
}
} catch (EmptyResultDataAccessException ex) { // no data, insert
return jt.update(insert, dataId, group, tenantTmp, datumId, appNameTmp, content, now) > 0;
return jt.update(insert, dataId, group, tenantTmp, datumId, appNameTmp, content) > 0;
}
} catch (DataAccessException e) {
LogUtil.FATAL_LOG.error("[db-error] " + e, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,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 +164,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
Loading
Loading