resolve conflict
This commit is contained in:
commit
608935d08d
@ -137,7 +137,7 @@ public class ConfigServletInner {
|
||||
if (isBeta) {
|
||||
md5 = cacheItem.getMd54Beta();
|
||||
lastModified = cacheItem.getLastModifiedTs4Beta();
|
||||
if (STANDALONE_MODE) {
|
||||
if (STANDALONE_MODE && !PropertyUtil.isStandaloneUseMysql()) {
|
||||
configInfoBase = persistService.findConfigInfo4Beta(dataId, group, tenant);
|
||||
} else {
|
||||
file = DiskUtil.targetBetaFile(dataId, group, tenant);
|
||||
@ -154,7 +154,7 @@ public class ConfigServletInner {
|
||||
lastModified = cacheItem.tagLastModifiedTs.get(autoTag);
|
||||
}
|
||||
}
|
||||
if (STANDALONE_MODE) {
|
||||
if (STANDALONE_MODE && !PropertyUtil.isStandaloneUseMysql()) {
|
||||
configInfoBase = persistService.findConfigInfo4Tag(dataId, group, tenant, autoTag);
|
||||
} else {
|
||||
file = DiskUtil.targetTagFile(dataId, group, tenant, autoTag);
|
||||
@ -165,7 +165,7 @@ public class ConfigServletInner {
|
||||
} else {
|
||||
md5 = cacheItem.getMd5();
|
||||
lastModified = cacheItem.getLastModifiedTs();
|
||||
if (STANDALONE_MODE) {
|
||||
if (STANDALONE_MODE && !PropertyUtil.isStandaloneUseMysql()) {
|
||||
configInfoBase = persistService.findConfigInfo(dataId, group, tenant);
|
||||
} else {
|
||||
file = DiskUtil.targetFile(dataId, group, tenant);
|
||||
@ -197,7 +197,7 @@ public class ConfigServletInner {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (STANDALONE_MODE) {
|
||||
if (STANDALONE_MODE && !PropertyUtil.isStandaloneUseMysql()) {
|
||||
configInfoBase = persistService.findConfigInfo4Tag(dataId, group, tenant, tag);
|
||||
} else {
|
||||
file = DiskUtil.targetTagFile(dataId, group, tenant, tag);
|
||||
@ -227,14 +227,14 @@ public class ConfigServletInner {
|
||||
response.setHeader("Pragma", "no-cache");
|
||||
response.setDateHeader("Expires", 0);
|
||||
response.setHeader("Cache-Control", "no-cache,no-store");
|
||||
if (STANDALONE_MODE) {
|
||||
if (STANDALONE_MODE && !PropertyUtil.isStandaloneUseMysql()) {
|
||||
response.setDateHeader("Last-Modified", lastModified);
|
||||
} else {
|
||||
fis = new FileInputStream(file);
|
||||
response.setDateHeader("Last-Modified", file.lastModified());
|
||||
}
|
||||
|
||||
if (STANDALONE_MODE) {
|
||||
if (STANDALONE_MODE && !PropertyUtil.isStandaloneUseMysql()) {
|
||||
out = response.getWriter();
|
||||
out.print(configInfoBase.getContent());
|
||||
out.flush();
|
||||
|
@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.service;
|
||||
|
||||
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
||||
import org.apache.commons.dbcp.BasicDataSource;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
@ -50,6 +51,9 @@ import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog;
|
||||
public class BasicDataSourceServiceImpl implements DataSourceService {
|
||||
private static final String JDBC_DRIVER_NAME = "com.mysql.jdbc.Driver";
|
||||
|
||||
@Autowired
|
||||
private PropertyUtil propertyUtil;
|
||||
|
||||
/**
|
||||
* JDBC执行超时时间, 单位秒
|
||||
*/
|
||||
@ -105,7 +109,7 @@ public class BasicDataSourceServiceImpl implements DataSourceService {
|
||||
* 事务的超时时间需要与普通操作区分开
|
||||
*/
|
||||
tjt.setTimeout(TRANSACTION_QUERY_TIMEOUT);
|
||||
if (!STANDALONE_MODE) {
|
||||
if (!STANDALONE_MODE || propertyUtil.isStandaloneUseMysql()) {
|
||||
try {
|
||||
reload();
|
||||
} catch (IOException e) {
|
||||
|
@ -21,6 +21,7 @@ import com.alibaba.nacos.config.server.model.ConfigInfoBase;
|
||||
import com.alibaba.nacos.config.server.utils.GroupKey;
|
||||
import com.alibaba.nacos.config.server.utils.GroupKey2;
|
||||
import com.alibaba.nacos.config.server.utils.MD5;
|
||||
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
||||
import com.alibaba.nacos.config.server.utils.event.EventDispatcher;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
@ -74,7 +75,7 @@ public class ConfigService {
|
||||
"[dump-ignore] ignore to save cache file. groupKey={}, md5={}, lastModifiedOld={}, "
|
||||
+ "lastModifiedNew={}",
|
||||
groupKey, md5, ConfigService.getLastModifiedTs(groupKey), lastModifiedTs);
|
||||
} else if (!STANDALONE_MODE) {
|
||||
} else if (!STANDALONE_MODE || PropertyUtil.isStandaloneUseMysql()) {
|
||||
DiskUtil.saveToDisk(dataId, group, tenant, content);
|
||||
}
|
||||
updateMd5(groupKey, md5, lastModifiedTs);
|
||||
@ -119,7 +120,7 @@ public class ConfigService {
|
||||
"[dump-beta-ignore] ignore to save cache file. groupKey={}, md5={}, lastModifiedOld={}, "
|
||||
+ "lastModifiedNew={}",
|
||||
groupKey, md5, ConfigService.getLastModifiedTs(groupKey), lastModifiedTs);
|
||||
} else if (!STANDALONE_MODE) {
|
||||
} else if (!STANDALONE_MODE || PropertyUtil.isStandaloneUseMysql()) {
|
||||
DiskUtil.saveBetaToDisk(dataId, group, tenant, content);
|
||||
}
|
||||
String[] betaIpsArr = betaIps.split(",");
|
||||
@ -158,7 +159,7 @@ public class ConfigService {
|
||||
"[dump-tag-ignore] ignore to save cache file. groupKey={}, md5={}, lastModifiedOld={}, "
|
||||
+ "lastModifiedNew={}",
|
||||
groupKey, md5, ConfigService.getLastModifiedTs(groupKey), lastModifiedTs);
|
||||
} else if (!STANDALONE_MODE) {
|
||||
} else if (!STANDALONE_MODE || PropertyUtil.isStandaloneUseMysql()) {
|
||||
DiskUtil.saveTagToDisk(dataId, group, tenant, tag, content);
|
||||
}
|
||||
|
||||
@ -190,7 +191,7 @@ public class ConfigService {
|
||||
|
||||
try {
|
||||
final String md5 = MD5.getInstance().getMD5String(content);
|
||||
if (!STANDALONE_MODE) {
|
||||
if (!STANDALONE_MODE || PropertyUtil.isStandaloneUseMysql()) {
|
||||
String loacalMd5 = DiskUtil.getLocalConfigMd5(dataId, group, tenant);
|
||||
if (md5.equals(loacalMd5)) {
|
||||
dumpLog.warn(
|
||||
@ -215,7 +216,7 @@ public class ConfigService {
|
||||
static public void reloadConfig() {
|
||||
String aggreds = null;
|
||||
try {
|
||||
if (STANDALONE_MODE) {
|
||||
if (STANDALONE_MODE && !PropertyUtil.isStandaloneUseMysql()) {
|
||||
ConfigInfoBase config = persistService.findConfigInfoBase(AggrWhitelist.AGGRIDS_METADATA,
|
||||
"DEFAULT_GROUP");
|
||||
if (config != null) {
|
||||
@ -234,7 +235,7 @@ public class ConfigService {
|
||||
|
||||
String clientIpWhitelist = null;
|
||||
try {
|
||||
if (STANDALONE_MODE) {
|
||||
if (STANDALONE_MODE && !PropertyUtil.isStandaloneUseMysql()) {
|
||||
ConfigInfoBase config = persistService.findConfigInfoBase(
|
||||
ClientIpWhiteList.CLIENT_IP_WHITELIST_METADATA, "DEFAULT_GROUP");
|
||||
if (config != null) {
|
||||
@ -254,7 +255,7 @@ public class ConfigService {
|
||||
|
||||
String switchContent = null;
|
||||
try {
|
||||
if (STANDALONE_MODE) {
|
||||
if (STANDALONE_MODE && !PropertyUtil.isStandaloneUseMysql()) {
|
||||
ConfigInfoBase config = persistService.findConfigInfoBase(SwitchService.SWITCH_META_DATAID,
|
||||
"DEFAULT_GROUP");
|
||||
if (config != null) {
|
||||
@ -322,7 +323,7 @@ public class ConfigService {
|
||||
}
|
||||
|
||||
try {
|
||||
if (!STANDALONE_MODE) {
|
||||
if (!STANDALONE_MODE || PropertyUtil.isStandaloneUseMysql()) {
|
||||
DiskUtil.removeConfigInfo(dataId, group, tenant);
|
||||
}
|
||||
CACHE.remove(groupKey);
|
||||
@ -356,7 +357,7 @@ public class ConfigService {
|
||||
}
|
||||
|
||||
try {
|
||||
if (!STANDALONE_MODE) {
|
||||
if (!STANDALONE_MODE || PropertyUtil.isStandaloneUseMysql()) {
|
||||
DiskUtil.removeConfigInfo4Beta(dataId, group, tenant);
|
||||
}
|
||||
EventDispatcher.fireEvent(new LocalDataChangeEvent(groupKey, true, CACHE.get(groupKey).getIps4Beta()));
|
||||
@ -391,7 +392,7 @@ public class ConfigService {
|
||||
}
|
||||
|
||||
try {
|
||||
if (!STANDALONE_MODE) {
|
||||
if (!STANDALONE_MODE || PropertyUtil.isStandaloneUseMysql()) {
|
||||
DiskUtil.removeConfigInfo4Tag(dataId, group, tenant, tag);
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.alibaba.nacos.config.server.service;
|
||||
|
||||
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -28,6 +30,10 @@ import static com.alibaba.nacos.common.util.SystemUtils.STANDALONE_MODE;
|
||||
*/
|
||||
@Component
|
||||
public class DynamicDataSource implements ApplicationContextAware {
|
||||
|
||||
@Autowired
|
||||
private PropertyUtil propertyUtil;
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
public void setApplicationContext(ApplicationContext applicationContext) {
|
||||
@ -41,7 +47,7 @@ public class DynamicDataSource implements ApplicationContextAware {
|
||||
public DataSourceService getDataSource() {
|
||||
DataSourceService dataSourceService = null;
|
||||
|
||||
if (STANDALONE_MODE) {
|
||||
if (STANDALONE_MODE && !propertyUtil.isStandaloneUseMysql()) {
|
||||
dataSourceService = (DataSourceService)applicationContext.getBean("localDataSourceService");
|
||||
} else {
|
||||
dataSourceService = (DataSourceService)applicationContext.getBean("basicDataSourceService");
|
||||
|
@ -17,10 +17,12 @@ package com.alibaba.nacos.config.server.service;
|
||||
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.config.server.utils.LogUtil;
|
||||
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
||||
import com.alibaba.nacos.config.server.utils.StringUtils;
|
||||
import org.apache.commons.dbcp.BasicDataSource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -60,6 +62,9 @@ public class LocalDataSourceServiceImpl implements DataSourceService {
|
||||
private JdbcTemplate jt;
|
||||
private TransactionTemplate tjt;
|
||||
|
||||
@Autowired
|
||||
private PropertyUtil propertyUtil;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
BasicDataSource ds = new BasicDataSource();
|
||||
@ -85,7 +90,7 @@ public class LocalDataSourceServiceImpl implements DataSourceService {
|
||||
tm.setDataSource(ds);
|
||||
tjt.setTimeout(5000);
|
||||
|
||||
if (STANDALONE_MODE) {
|
||||
if (STANDALONE_MODE && !propertyUtil.isStandaloneUseMysql()) {
|
||||
reload();
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import com.alibaba.nacos.config.server.model.capacity.Capacity;
|
||||
import com.alibaba.nacos.config.server.model.capacity.GroupCapacity;
|
||||
import com.alibaba.nacos.config.server.service.DataSourceService;
|
||||
import com.alibaba.nacos.config.server.service.DynamicDataSource;
|
||||
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
||||
import com.alibaba.nacos.config.server.utils.TimeUtils;
|
||||
import com.google.common.collect.Lists;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
@ -281,7 +282,7 @@ public class GroupCapacityPersistService {
|
||||
public List<GroupCapacity> getCapacityList4CorrectUsage(long lastId, int pageSize) {
|
||||
String sql = "SELECT id, group_id FROM group_capacity WHERE id>? LIMIT ?";
|
||||
|
||||
if (STANDALONE_MODE) {
|
||||
if (STANDALONE_MODE && !PropertyUtil.isStandaloneUseMysql()) {
|
||||
sql = "SELECT id, group_id FROM group_capacity WHERE id>? OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY";
|
||||
}
|
||||
try {
|
||||
|
@ -18,6 +18,7 @@ package com.alibaba.nacos.config.server.service.capacity;
|
||||
import com.alibaba.nacos.config.server.model.capacity.TenantCapacity;
|
||||
import com.alibaba.nacos.config.server.service.DataSourceService;
|
||||
import com.alibaba.nacos.config.server.service.DynamicDataSource;
|
||||
import com.alibaba.nacos.config.server.utils.PropertyUtil;
|
||||
import com.alibaba.nacos.config.server.utils.TimeUtils;
|
||||
import com.google.common.collect.Lists;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
@ -231,7 +232,7 @@ public class TenantCapacityPersistService {
|
||||
public List<TenantCapacity> getCapacityList4CorrectUsage(long lastId, int pageSize) {
|
||||
String sql = "SELECT id, tenant_id FROM tenant_capacity WHERE id>? LIMIT ?";
|
||||
|
||||
if (STANDALONE_MODE) {
|
||||
if (STANDALONE_MODE && !PropertyUtil.isStandaloneUseMysql()) {
|
||||
sql = "SELECT id, tenant_id FROM tenant_capacity WHERE id>? OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY";
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,7 @@ public class PaginationHelper<E> {
|
||||
|
||||
final int startRow = (pageNo - 1) * pageSize;
|
||||
String selectSQL = "";
|
||||
if (STANDALONE_MODE) {
|
||||
if (STANDALONE_MODE && !PropertyUtil.isStandaloneUseMysql()) {
|
||||
selectSQL = sqlFetchRows + " OFFSET " + startRow + " ROWS FETCH NEXT " + pageSize + " ROWS ONLY";
|
||||
} else if (lastMaxId != null) {
|
||||
selectSQL = sqlFetchRows + " and id > " + lastMaxId + " order by id asc" + " limit " + 0 + "," + pageSize;
|
||||
@ -127,7 +127,7 @@ public class PaginationHelper<E> {
|
||||
}
|
||||
|
||||
String selectSQL = sqlFetchRows;
|
||||
if (STANDALONE_MODE) {
|
||||
if (STANDALONE_MODE && !PropertyUtil.isStandaloneUseMysql()) {
|
||||
selectSQL = selectSQL.replaceAll("(?i)LIMIT \\?,\\?", "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY");
|
||||
}
|
||||
|
||||
@ -169,7 +169,7 @@ public class PaginationHelper<E> {
|
||||
}
|
||||
|
||||
String selectSQL = sqlFetchRows;
|
||||
if (STANDALONE_MODE) {
|
||||
if (STANDALONE_MODE && !PropertyUtil.isStandaloneUseMysql()) {
|
||||
selectSQL = selectSQL.replaceAll("(?i)LIMIT \\?,\\?", "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY");
|
||||
}
|
||||
|
||||
@ -190,7 +190,7 @@ public class PaginationHelper<E> {
|
||||
final Page<E> page = new Page<E>();
|
||||
|
||||
String selectSQL = sqlFetchRows;
|
||||
if (STANDALONE_MODE) {
|
||||
if (STANDALONE_MODE && !PropertyUtil.isStandaloneUseMysql()) {
|
||||
selectSQL = selectSQL.replaceAll("(?i)LIMIT \\?,\\?", "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY");
|
||||
}
|
||||
|
||||
@ -204,7 +204,7 @@ public class PaginationHelper<E> {
|
||||
public void updateLimit(final JdbcTemplate jt, final String sql, final Object args[]) {
|
||||
String sqlUpdate = sql;
|
||||
|
||||
if (STANDALONE_MODE) {
|
||||
if (STANDALONE_MODE && !PropertyUtil.isStandaloneUseMysql()) {
|
||||
sqlUpdate = sqlUpdate.replaceAll("limit \\?", "OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY");
|
||||
}
|
||||
|
||||
|
@ -80,6 +80,11 @@ public class PropertyUtil {
|
||||
* 修正容量信息表使用量(usage)的时间间隔,单位为秒
|
||||
*/
|
||||
private static int correctUsageDelay = 10 * 60;
|
||||
/**
|
||||
* 单机模式使用db
|
||||
*/
|
||||
private static boolean standaloneUseMysql = false;
|
||||
|
||||
|
||||
@Autowired
|
||||
private Environment env;
|
||||
@ -109,6 +114,7 @@ public class PropertyUtil {
|
||||
setDefaultMaxAggrSize(getInt("defaultMaxAggrSize", defaultMaxAggrSize));
|
||||
setCorrectUsageDelay(getInt("correctUsageDelay", correctUsageDelay));
|
||||
setInitialExpansionPercent(getInt("initialExpansionPercent", initialExpansionPercent));
|
||||
setStandaloneUseMysql(getString("spring.datasource.platform", "").equals("mysql"));
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("read application.properties failed", e);
|
||||
@ -204,6 +210,10 @@ public class PropertyUtil {
|
||||
return STANDALONE_MODE;
|
||||
}
|
||||
|
||||
public static boolean isStandaloneUseMysql() {
|
||||
return standaloneUseMysql;
|
||||
}
|
||||
|
||||
public static void setNotifyConnectTimeout(int notifyConnectTimeout) {
|
||||
PropertyUtil.notifyConnectTimeout = notifyConnectTimeout;
|
||||
}
|
||||
@ -263,5 +273,7 @@ public class PropertyUtil {
|
||||
public static void setCorrectUsageDelay(int correctUsageDelay) {
|
||||
PropertyUtil.correctUsageDelay = correctUsageDelay;
|
||||
}
|
||||
|
||||
public static void setStandaloneUseMysql(boolean standaloneUseMysql) {
|
||||
PropertyUtil.standaloneUseMysql = standaloneUseMysql;
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ import javax.servlet.ServletContext;
|
||||
|
||||
/**
|
||||
* Running config
|
||||
*
|
||||
* @author <a href="mailto:zpf.073@gmail.com">nkorange</a>
|
||||
*/
|
||||
@Component
|
||||
@ -33,18 +32,18 @@ public class RunningConfigUtils implements ApplicationListener<WebServerInitiali
|
||||
private static int serverPort;
|
||||
|
||||
private static String contextPath;
|
||||
|
||||
|
||||
private static String clusterName = "serverlist";
|
||||
|
||||
@Autowired
|
||||
@Autowired
|
||||
private ServletContext servletContext;
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(WebServerInitializedEvent event) {
|
||||
public void onApplicationEvent(WebServerInitializedEvent event) {
|
||||
|
||||
setServerPort(event.getWebServer().getPort());
|
||||
setContextPath(servletContext.getContextPath());
|
||||
}
|
||||
setServerPort(event.getWebServer().getPort());
|
||||
setContextPath(servletContext.getContextPath());
|
||||
}
|
||||
|
||||
public static int getServerPort() {
|
||||
return serverPort;
|
||||
@ -53,17 +52,17 @@ public class RunningConfigUtils implements ApplicationListener<WebServerInitiali
|
||||
public static String getContextPath() {
|
||||
return contextPath;
|
||||
}
|
||||
|
||||
|
||||
public static String getClusterName() {
|
||||
return clusterName;
|
||||
}
|
||||
return clusterName;
|
||||
}
|
||||
|
||||
public static void setServerPort(int serverPort) {
|
||||
RunningConfigUtils.serverPort = serverPort;
|
||||
}
|
||||
|
||||
public static void setContextPath(String contextPath) {
|
||||
RunningConfigUtils.contextPath = contextPath;
|
||||
}
|
||||
public static void setServerPort(int serverPort) {
|
||||
RunningConfigUtils.serverPort = serverPort;
|
||||
}
|
||||
|
||||
public static void setContextPath(String contextPath) {
|
||||
RunningConfigUtils.contextPath = contextPath;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,8 +2,8 @@ function getValue(key) {
|
||||
if (!document.cookie) return null;
|
||||
const list = document.cookie.split(';') || [];
|
||||
for (const item of list) {
|
||||
const [k, v] = item.split('=');
|
||||
if (k === key) return v;
|
||||
const [k = '', v = ''] = item.split('=');
|
||||
if (k.trim() === key) return v;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
@ -4,9 +4,10 @@ server.contextPath=/nacos
|
||||
server.servlet.contextPath=/nacos
|
||||
server.port=8848
|
||||
|
||||
#spring.datasource.platform=mysql
|
||||
|
||||
#db.num=2
|
||||
#db.url.0=jdbc:mysql://11.162.196.16:3306/nacos_devtest?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
|
||||
#db.url.1=jdbc:mysql://11.163.152.9:3306/nacos_devtest?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
|
||||
#db.user=nacos_devtest
|
||||
#db.password=youdontknow
|
||||
#db.password=youdontknow
|
||||
|
Loading…
Reference in New Issue
Block a user