[#3241]Reformat the nacos-config module by new code style. (#3243)

This commit is contained in:
Hu Zongtang 2020-07-03 16:51:08 +08:00 committed by GitHub
parent aa020e0b81
commit 31670f124c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
160 changed files with 6293 additions and 6136 deletions

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server;
import org.springframework.boot.SpringApplication;
@ -25,10 +26,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
* @author Nacos
*/
@EnableScheduling
@SpringBootApplication(scanBasePackages = {
"com.alibaba.nacos.config.server",
"com.alibaba.nacos.core"
})
@SpringBootApplication(scanBasePackages = {"com.alibaba.nacos.config.server", "com.alibaba.nacos.core"})
public class Config {
public static void main(String[] args) {

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.aspect;
import com.alibaba.nacos.config.server.constant.Constants;
@ -42,18 +43,20 @@ import java.nio.charset.Charset;
*/
@Aspect
public class CapacityManagementAspect {
private static final Logger LOGGER = LoggerFactory.getLogger(CapacityManagementAspect.class);
private static final String SYNC_UPDATE_CONFIG_ALL
= "execution(* com.alibaba.nacos.config.server.controller.ConfigController.publishConfig(..)) && args"
private static final String SYNC_UPDATE_CONFIG_ALL =
"execution(* com.alibaba.nacos.config.server.controller.ConfigController.publishConfig(..)) && args"
+ "(request,response,dataId,group,content,appName,srcUser,tenant,tag,..)";
private static final String DELETE_CONFIG
= "execution(* com.alibaba.nacos.config.server.controller.ConfigController.deleteConfig(..)) && args"
private static final String DELETE_CONFIG =
"execution(* com.alibaba.nacos.config.server.controller.ConfigController.deleteConfig(..)) && args"
+ "(request,response,dataId,group,tenant,..)";
@Autowired
private CapacityService capacityService;
@Autowired
private PersistService persistService;
@ -62,9 +65,8 @@ public class CapacityManagementAspect {
*/
@Around(SYNC_UPDATE_CONFIG_ALL)
public Object aroundSyncUpdateConfigAll(ProceedingJoinPoint pjp, HttpServletRequest request,
HttpServletResponse response, String dataId, String group, String content,
String appName, String srcUser, String tenant, String tag)
throws Throwable {
HttpServletResponse response, String dataId, String group, String content, String appName, String srcUser,
String tenant, String tag) throws Throwable {
if (!PropertyUtil.isManageCapacity()) {
return pjp.proceed();
}
@ -111,9 +113,8 @@ public class CapacityManagementAspect {
*
* @throws Throwable "实际操作"抛出的异常
*/
private Object do4Insert(ProceedingJoinPoint pjp, HttpServletRequest request,
HttpServletResponse response, String group, String tenant, String content)
throws Throwable {
private Object do4Insert(ProceedingJoinPoint pjp, HttpServletRequest request, HttpServletResponse response,
String group, String tenant, String content) throws Throwable {
LOGGER.info("[capacityManagement] do4Insert");
CounterMode counterMode = CounterMode.INCREMENT;
boolean hasTenant = hasTenant(tenant);
@ -160,8 +161,7 @@ public class CapacityManagementAspect {
* @throws Throwable "实际操作"抛出的异常
*/
private Object do4Delete(ProceedingJoinPoint pjp, HttpServletResponse response, String group, String tenant,
ConfigInfo configInfo)
throws Throwable {
ConfigInfo configInfo) throws Throwable {
boolean hasTenant = hasTenant(tenant);
if (configInfo == null) {
// "configInfo == null"有2种可能
@ -202,8 +202,8 @@ public class CapacityManagementAspect {
doResult(counterMode, response, group, tenant, result, hasTenant);
return result;
} catch (Throwable throwable) {
LOGGER.warn("[capacityManagement] inner operation throw exception, rollback, group: {}, tenant: {}",
group, tenant, throwable);
LOGGER.warn("[capacityManagement] inner operation throw exception, rollback, group: {}, tenant: {}", group,
tenant, throwable);
rollback(counterMode, group, tenant, hasTenant);
throw throwable;
}
@ -225,8 +225,8 @@ public class CapacityManagementAspect {
}
}
private LimitType getLimitType(CounterMode counterMode, String group, String tenant, String content, boolean
hasTenant) {
private LimitType getLimitType(CounterMode counterMode, String group, String tenant, String content,
boolean hasTenant) {
try {
boolean clusterLimited = !capacityService.insertAndUpdateClusterUsage(counterMode, false);
if (clusterLimited) {
@ -237,8 +237,7 @@ public class CapacityManagementAspect {
return null;
}
int currentSize = getCurrentSize(content);
LimitType limitType = getGroupOrTenantLimitType(counterMode, group, tenant, currentSize,
hasTenant);
LimitType limitType = getGroupOrTenantLimitType(counterMode, group, tenant, currentSize, hasTenant);
if (limitType != null) {
rollbackClusterUsage(counterMode);
return limitType;
@ -261,8 +260,8 @@ public class CapacityManagementAspect {
return 0;
}
private LimitType getGroupOrTenantLimitType(CounterMode counterMode, String group, String tenant,
int currentSize, boolean hasTenant) {
private LimitType getGroupOrTenantLimitType(CounterMode counterMode, String group, String tenant, int currentSize,
boolean hasTenant) {
if (group == null) {
return null;
}
@ -363,8 +362,8 @@ public class CapacityManagementAspect {
return false;
}
private void doResult(CounterMode counterMode, HttpServletResponse response, String group,
String tenant, Object result, boolean hasTenant) {
private void doResult(CounterMode counterMode, HttpServletResponse response, String group, String tenant,
Object result, boolean hasTenant) {
try {
if (!isSuccess(response, result)) {
LOGGER.warn(
@ -382,8 +381,7 @@ public class CapacityManagementAspect {
if (status == HttpServletResponse.SC_OK) {
return true;
}
LOGGER.warn("[capacityManagement] response status is not 200, status: {}, result: {}", status,
result);
LOGGER.warn("[capacityManagement] response status is not 200, status: {}, result: {}", status, result);
return false;
}
@ -423,7 +421,9 @@ public class CapacityManagementAspect {
OVER_GROUP_QUOTA("超过该Group配置个数上限", 429),
OVER_TENANT_QUOTA("超过该租户配置个数上限", 429),
OVER_MAX_SIZE("超过配置的内容大小上限", 429);
public final String description;
public final int status;
LimitType(String description, int status) {

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.aspect;
import com.alibaba.nacos.common.utils.MD5Utils;
@ -38,25 +39,26 @@ import javax.servlet.http.HttpServletResponse;
@Aspect
@Component
public class RequestLogAspect {
/**
* publish config
*/
private static final String CLIENT_INTERFACE_PUBLISH_SINGLE_CONFIG
= "execution(* com.alibaba.nacos.config.server.controller.ConfigController.publishConfig(..)) && args"
private static final String CLIENT_INTERFACE_PUBLISH_SINGLE_CONFIG =
"execution(* com.alibaba.nacos.config.server.controller.ConfigController.publishConfig(..)) && args"
+ "(request,response,dataId,group,tenant,content,..)";
/**
* get config
*/
private static final String CLIENT_INTERFACE_GET_CONFIG
= "execution(* com.alibaba.nacos.config.server.controller.ConfigController.getConfig(..)) && args(request,"
private static final String CLIENT_INTERFACE_GET_CONFIG =
"execution(* com.alibaba.nacos.config.server.controller.ConfigController.getConfig(..)) && args(request,"
+ "response,dataId,group,tenant,..)";
/**
* remove config
*/
private static final String CLIENT_INTERFACE_REMOVE_ALL_CONFIG
= "execution(* com.alibaba.nacos.config.server.controller.ConfigController.deleteConfig(..)) && args(request,"
private static final String CLIENT_INTERFACE_REMOVE_ALL_CONFIG =
"execution(* com.alibaba.nacos.config.server.controller.ConfigController.deleteConfig(..)) && args(request,"
+ "response,dataId,group,tenant,..)";
@ -65,8 +67,7 @@ public class RequestLogAspect {
*/
@Around(CLIENT_INTERFACE_PUBLISH_SINGLE_CONFIG)
public Object interfacePublishSingle(ProceedingJoinPoint pjp, HttpServletRequest request,
HttpServletResponse response, String dataId, String group, String tenant,
String content) throws Throwable {
HttpServletResponse response, String dataId, String group, String tenant, String content) throws Throwable {
final String md5 = content == null ? null : MD5Utils.md5Hex(content, Constants.ENCODE);
MetricsMonitor.getPublishMonitor().incrementAndGet();
return logClientRequest("publish", pjp, request, response, dataId, group, tenant, md5);
@ -97,8 +98,7 @@ public class RequestLogAspect {
* client api request log rt | status | requestIp | opType | dataId | group | datumId | md5
*/
private Object logClientRequest(String requestType, ProceedingJoinPoint pjp, HttpServletRequest request,
HttpServletResponse response, String dataId, String group, String tenant,
String md5) throws Throwable {
HttpServletResponse response, String dataId, String group, String tenant, String md5) throws Throwable {
final String requestIp = RequestUtil.getRemoteIp(request);
String appName = request.getHeader(RequestUtil.CLIENT_APPNAME_HEADER);
final long st = System.currentTimeMillis();
@ -106,8 +106,9 @@ public class RequestLogAspect {
final long rt = System.currentTimeMillis() - st;
// rt | status | requestIp | opType | dataId | group | datumId | md5 |
// appName
LogUtil.clientLog.info("{}|{}|{}|{}|{}|{}|{}|{}|{}", rt, retVal, requestIp, requestType, dataId, group, tenant,
md5, appName);
LogUtil.clientLog
.info("{}|{}|{}|{}|{}|{}|{}|{}|{}", rt, retVal, requestIp, requestType, dataId, group, tenant, md5,
appName);
return retVal;
}

View File

@ -13,11 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.auth;
import com.alibaba.nacos.core.auth.Resource;
import com.alibaba.nacos.core.auth.ResourceParser;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
/**
@ -46,15 +49,9 @@ public class ConfigResourceParser implements ResourceParser {
sb.append(Resource.SPLITTER);
if (StringUtils.isBlank(dataId)) {
sb.append("*")
.append(Resource.SPLITTER)
.append(AUTH_CONFIG_PREFIX)
.append("*");
sb.append("*").append(Resource.SPLITTER).append(AUTH_CONFIG_PREFIX).append("*");
} else {
sb.append(groupName)
.append(Resource.SPLITTER)
.append(AUTH_CONFIG_PREFIX)
.append(dataId);
sb.append(groupName).append(Resource.SPLITTER).append(AUTH_CONFIG_PREFIX).append(dataId);
}
return sb.toString();

View File

@ -50,8 +50,7 @@ public class EmbeddedPermissionPersistServiceImpl implements PermissionPersistSe
PaginationHelper<PermissionInfo> helper = persistService.createPaginationHelper();
String sqlCountRows = "select count(*) from permissions where ";
String sqlFetchRows
= "select role,resource,action from permissions where ";
String sqlFetchRows = "select role,resource,action from permissions where ";
String where = " role='" + role + "' ";
@ -59,8 +58,8 @@ public class EmbeddedPermissionPersistServiceImpl implements PermissionPersistSe
where = " 1=1 ";
}
Page<PermissionInfo> pageInfo = helper.fetchPage(sqlCountRows
+ where, sqlFetchRows + where, new ArrayList<String>().toArray(), pageNo,
Page<PermissionInfo> pageInfo = helper
.fetchPage(sqlCountRows + where, sqlFetchRows + where, new ArrayList<String>().toArray(), pageNo,
pageSize, PERMISSION_ROW_MAPPER);
if (pageInfo == null) {

View File

@ -51,13 +51,12 @@ public class EmbeddedRolePersistServiceImpl implements RolePersistService {
PaginationHelper<RoleInfo> helper = persistService.createPaginationHelper();
String sqlCountRows = "select count(*) from (select distinct role from roles) roles where ";
String sqlFetchRows
= "select role,username from roles where ";
String sqlFetchRows = "select role,username from roles where ";
String where = " 1=1 ";
Page<RoleInfo> pageInfo = helper.fetchPage(sqlCountRows
+ where, sqlFetchRows + where, new ArrayList<String>().toArray(), pageNo,
Page<RoleInfo> pageInfo = helper
.fetchPage(sqlCountRows + where, sqlFetchRows + where, new ArrayList<String>().toArray(), pageNo,
pageSize, ROLE_INFO_ROW_MAPPER);
if (pageInfo == null) {
pageInfo = new Page<>();
@ -73,8 +72,7 @@ public class EmbeddedRolePersistServiceImpl implements RolePersistService {
PaginationHelper<RoleInfo> helper = persistService.createPaginationHelper();
String sqlCountRows = "select count(*) from roles where ";
String sqlFetchRows
= "select role,username from roles where ";
String sqlFetchRows = "select role,username from roles where ";
String where = " username='" + username + "' ";
@ -82,8 +80,7 @@ public class EmbeddedRolePersistServiceImpl implements RolePersistService {
where = " 1=1 ";
}
return helper.fetchPage(sqlCountRows
+ where, sqlFetchRows + where, new ArrayList<String>().toArray(), pageNo,
return helper.fetchPage(sqlCountRows + where, sqlFetchRows + where, new ArrayList<String>().toArray(), pageNo,
pageSize, ROLE_INFO_ROW_MAPPER);
}

View File

@ -69,9 +69,8 @@ public class EmbeddedUserPersistServiceImpl implements UserPersistService {
public void updateUserPassword(String username, String password) {
try {
EmbeddedStorageContextUtils.addSqlContext(
"UPDATE users SET password = ? WHERE username=?",
password, username);
EmbeddedStorageContextUtils
.addSqlContext("UPDATE users SET password = ? WHERE username=?", password, username);
databaseOperate.blockUpdate();
} finally {
EmbeddedStorageContextUtils.cleanAllContext();
@ -88,12 +87,11 @@ public class EmbeddedUserPersistServiceImpl implements UserPersistService {
PaginationHelper<User> helper = persistService.createPaginationHelper();
String sqlCountRows = "select count(*) from users where ";
String sqlFetchRows
= "select username,password from users where ";
String sqlFetchRows = "select username,password from users where ";
String where = " 1=1 ";
Page<User> pageInfo = helper.fetchPage(sqlCountRows
+ where, sqlFetchRows + where, new ArrayList<String>().toArray(), pageNo,
Page<User> pageInfo = helper
.fetchPage(sqlCountRows + where, sqlFetchRows + where, new ArrayList<String>().toArray(), pageNo,
pageSize, USER_ROW_MAPPER);
if (pageInfo == null) {
pageInfo = new Page<>();

View File

@ -54,8 +54,7 @@ public class ExternalPermissionPersistServiceImpl implements PermissionPersistSe
PaginationHelper<PermissionInfo> helper = persistService.createPaginationHelper();
String sqlCountRows = "select count(*) from permissions where ";
String sqlFetchRows
= "select role,resource,action from permissions where ";
String sqlFetchRows = "select role,resource,action from permissions where ";
String where = " role='" + role + "' ";
@ -64,8 +63,8 @@ public class ExternalPermissionPersistServiceImpl implements PermissionPersistSe
}
try {
Page<PermissionInfo> pageInfo = helper.fetchPage(sqlCountRows
+ where, sqlFetchRows + where, new ArrayList<String>().toArray(), pageNo,
Page<PermissionInfo> pageInfo = helper
.fetchPage(sqlCountRows + where, sqlFetchRows + where, new ArrayList<String>().toArray(), pageNo,
pageSize, PERMISSION_ROW_MAPPER);
if (pageInfo == null) {

View File

@ -58,14 +58,13 @@ public class ExternalRolePersistServiceImpl implements RolePersistService {
PaginationHelper<RoleInfo> helper = persistService.createPaginationHelper();
String sqlCountRows = "select count(*) from (select distinct role from roles) roles where ";
String sqlFetchRows
= "select role,username from roles where ";
String sqlFetchRows = "select role,username from roles where ";
String where = " 1=1 ";
try {
Page<RoleInfo> pageInfo = helper.fetchPage(sqlCountRows
+ where, sqlFetchRows + where, new ArrayList<String>().toArray(), pageNo,
Page<RoleInfo> pageInfo = helper
.fetchPage(sqlCountRows + where, sqlFetchRows + where, new ArrayList<String>().toArray(), pageNo,
pageSize, ROLE_INFO_ROW_MAPPER);
if (pageInfo == null) {
pageInfo = new Page<>();
@ -84,8 +83,7 @@ public class ExternalRolePersistServiceImpl implements RolePersistService {
PaginationHelper<RoleInfo> helper = persistService.createPaginationHelper();
String sqlCountRows = "select count(*) from roles where ";
String sqlFetchRows
= "select role,username from roles where ";
String sqlFetchRows = "select role,username from roles where ";
String where = " username='" + username + "' ";
@ -94,8 +92,8 @@ public class ExternalRolePersistServiceImpl implements RolePersistService {
}
try {
return helper.fetchPage(sqlCountRows
+ where, sqlFetchRows + where, new ArrayList<String>().toArray(), pageNo,
return helper
.fetchPage(sqlCountRows + where, sqlFetchRows + where, new ArrayList<String>().toArray(), pageNo,
pageSize, ROLE_INFO_ROW_MAPPER);
} catch (CannotGetJdbcConnectionException e) {
LogUtil.fatalLog.error("[db-error] " + e.toString(), e);
@ -136,9 +134,9 @@ public class ExternalRolePersistServiceImpl implements RolePersistService {
}
private static final class RoleInfoRowMapper implements RowMapper<RoleInfo> {
@Override
public RoleInfo mapRow(ResultSet rs, int rowNum)
throws SQLException {
public RoleInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
RoleInfo roleInfo = new RoleInfo();
roleInfo.setRole(rs.getString("role"));
roleInfo.setUsername(rs.getString("username"));

View File

@ -74,9 +74,7 @@ public class ExternalUserPersistServiceImpl implements UserPersistService {
public void updateUserPassword(String username, String password) {
try {
jt.update(
"UPDATE users SET password = ? WHERE username=?",
password, username);
jt.update("UPDATE users SET password = ? WHERE username=?", password, username);
} catch (CannotGetJdbcConnectionException e) {
LogUtil.fatalLog.error("[db-error] " + e.toString(), e);
throw e;
@ -103,14 +101,13 @@ public class ExternalUserPersistServiceImpl implements UserPersistService {
PaginationHelper<User> helper = persistService.createPaginationHelper();
String sqlCountRows = "select count(*) from users where ";
String sqlFetchRows
= "select username,password from users where ";
String sqlFetchRows = "select username,password from users where ";
String where = " 1=1 ";
try {
Page<User> pageInfo = helper.fetchPage(sqlCountRows
+ where, sqlFetchRows + where, new ArrayList<String>().toArray(), pageNo,
Page<User> pageInfo = helper
.fetchPage(sqlCountRows + where, sqlFetchRows + where, new ArrayList<String>().toArray(), pageNo,
pageSize, USER_ROW_MAPPER);
if (pageInfo == null) {
pageInfo = new Page<>();

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.auth;
import java.io.Serializable;
@ -24,6 +25,7 @@ import java.io.Serializable;
public class PermissionInfo implements Serializable {
private static final long serialVersionUID = 388813573388837395L;
/**
* Role name
*/

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.auth;
import com.alibaba.nacos.config.server.model.Page;

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.auth;
import java.io.Serializable;
@ -49,9 +50,6 @@ public class RoleInfo implements Serializable {
@Override
public String toString() {
return "RoleInfo{" +
"role='" + role + '\'' +
", username='" + username + '\'' +
'}';
return "RoleInfo{" + "role='" + role + '\'' + ", username='" + username + '\'' + '}';
}
}

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.auth;
import com.alibaba.nacos.config.server.model.Page;

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.auth;
import com.alibaba.nacos.config.server.model.Page;

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.configuration;
import com.alibaba.nacos.config.server.filter.NacosWebFilter;

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.constant;
import com.alibaba.nacos.config.server.model.event.ConfigDumpEvent;
@ -27,82 +28,129 @@ public class Constants {
public static final String CLIENT_VERSION_HEADER = "Client-Version";
public static final String CLIENT_VERSION = "3.0.0";
public static final String DEFAULT_GROUP = "DEFAULT_GROUP";
/**
* server端配置文件基目录
*/
public static final String BASE_DIR = "config-data";
/**
* server端配置文件备份目录
*/
public static final String CONFIG_BAK_DIR = System.getProperty("user.home", "/home/admin") + "/nacos/bak_data";
public static final String APPNAME = "AppName";
public static final String UNKNOWN_APP = "UnknownApp";
public static final String DEFAULT_DOMAINNAME = "commonconfig.config-host.taobao.com";
public static final String DAILY_DOMAINNAME = "commonconfig.taobao.net";
public static final String NULL = "";
public static final String DATAID = "dataId";
public static final String GROUP = "group";
public static final String LAST_MODIFIED = "Last-Modified";
public static final String ACCEPT_ENCODING = "Accept-Encoding";
public static final String CONTENT_ENCODING = "Content-Encoding";
public static final String PROBE_MODIFY_REQUEST = "Listening-Configs";
public static final String PROBE_MODIFY_RESPONSE = "Probe-Modify-Response";
public static final String PROBE_MODIFY_RESPONSE_NEW = "Probe-Modify-Response-New";
public static final String USE_ZIP = "true";
public static final String CONTENT_MD5 = "Content-MD5";
public static final String CONFIG_VERSION = "Config-Version";
public static final String IF_MODIFIED_SINCE = "If-Modified-Since";
public static final String SPACING_INTERVAL = "client-spacing-interval";
/**
*
*/
public static final int ASYNC_UPDATE_ADDRESS_INTERVAL = 300;
/**
*
*/
public static final int POLLING_INTERVAL_TIME = 15;
/**
* 毫秒
*/
public static final int ONCE_TIMEOUT = 2000;
/**
* 毫秒
*/
public static final int CONN_TIMEOUT = 2000;
/**
* 毫秒
*/
public static final int SO_TIMEOUT = 60000;
/**
* 毫秒
*/
public static final int RECV_WAIT_TIMEOUT = ONCE_TIMEOUT * 5;
public static final String BASE_PATH = "/v1/cs";
public static final String OPS_CONTROLLER_PATH = BASE_PATH + "/ops";
public static final String CAPACITY_CONTROLLER_PATH = BASE_PATH + "/capacity";
public static final String COMMUNICATION_CONTROLLER_PATH = BASE_PATH + "/communication";
public static final String CONFIG_CONTROLLER_PATH = BASE_PATH + "/configs";
public static final String HEALTH_CONTROLLER_PATH = BASE_PATH + "/health";
public static final String HISTORY_CONTROLLER_PATH = BASE_PATH + "/history";
public static final String LISTENER_CONTROLLER_PATH = BASE_PATH + "/listener";
public static final String NAMESPACE_CONTROLLER_PATH = BASE_PATH + "/namespaces";
public static final String ENCODE = "UTF-8";
public static final String MAP_FILE = "map-file.js";
public static final int FLOW_CONTROL_THRESHOLD = 20;
public static final int FLOW_CONTROL_SLOT = 10;
public static final int FLOW_CONTROL_INTERVAL = 1000;
public static final String LINE_SEPARATOR = Character.toString((char) 1);
public static final String WORD_SEPARATOR = Character.toString((char) 2);
public static final String NACOS_LINE_SEPARATOR = "\r\n";
/**
* 从网络获取数据的总时间, 当超过此时间, 不再从网络获取数据, 单位ms
*/
public static final long TOTALTIME_FROM_SERVER = 10000;
/**
* 从网络获取数据的总时间的失效时间, 单位ms
*/
public static final long TOTALTIME_INVALID_THRESHOLD = 60000;
/**
* 发生异常
*/
@ -112,54 +160,76 @@ public class Constants {
* 批量操作时, 单条数据的状态码
*/
public static final String BATCH_OP_ERROR_IO_MSG = "get config dump error";
public static final String BATCH_OP_ERROR_CONFLICT_MSG = "config get conflicts";
/**
* 查询成功, 数据存在
*/
public static final int BATCH_QUERY_EXISTS = 1;
public static final String BATCH_QUERY_EXISTS_MSG = "config exits";
/**
* 查询成功, 数据不存在
*/
public static final int BATCH_QUERY_NONEXISTS = 2;
public static final String BATCH_QUERY_NONEEXISTS_MSG = "config not exits";
/**
* 新增成功
*/
public static final int BATCH_ADD_SUCCESS = 3;
/**
* 更新成功
*/
public static final int BATCH_UPDATE_SUCCESS = 4;
public static final int MAX_UPDATE_FAIL_COUNT = 5;
public static final int MAX_UPDATEALL_FAIL_COUNT = 5;
public static final int MAX_REMOVE_FAIL_COUNT = 5;
public static final int MAX_REMOVEALL_FAIL_COUNT = 5;
public static final int MAX_NOTIFY_COUNT = 5;
public static final int MAX_ADDACK_COUNT = 5;
/**
* 数据的初始版本号
*/
public static final int FIRST_VERSION = 1;
/**
* 数据被删除的标识版本号
*/
public static final int POISON_VERSION = -1;
/**
* 写磁盘文件时, 临时版本号
*/
public static final int TEMP_VERSION = 0;
/**
* 获取数据的顺序容灾文件-> 服务器 -> 本地缓存
*/
public static final int GETCONFIG_LOCAL_SERVER_SNAPSHOT = 1;
/**
* 获取数据的顺序容灾文件-> 本地缓存 -> 服务器
*/
public static final int GETCONFIG_LOCAL_SNAPSHOT_SERVER = 2;
public static final String CLIENT_APPNAME_HEADER = "Client-AppName";
public static final String CLIENT_REQUEST_TS_HEADER = "Client-RequestTS";
public static final String CLIENT_REQUEST_TOKEN_HEADER = "Client-RequestToken";
/**
* client, sdk请求server服务的身份
*/
@ -174,8 +244,11 @@ public class Constants {
* 鉴权结果信息
*/
public static final String ACL_RESPONSE = "ACL-Response";
public static final int ATOMIC_MAX_SIZE = 1000;
public static final String CONFIG_MODEL_RAFT_GROUP = "nacos_config";
public static int DATA_IN_BODY_VERSION = 204;
/**

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.constant;
/**

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.controller;
import com.alibaba.nacos.common.model.RestResult;
@ -46,8 +47,7 @@ public class CapacityController {
}
@GetMapping
public RestResult<Capacity> getCapacity(HttpServletResponse response,
@RequestParam(required = false) String group,
public RestResult<Capacity> getCapacity(HttpServletResponse response, @RequestParam(required = false) String group,
@RequestParam(required = false) String tenant) {
if (group == null && tenant == null) {
RestResult<Capacity> restResult = new RestResult<Capacity>();
@ -90,12 +90,9 @@ public class CapacityController {
*/
@PostMapping
public RestResult<Boolean> updateCapacity(HttpServletResponse response,
@RequestParam(required = false) String group,
@RequestParam(required = false) String tenant,
@RequestParam(required = false) Integer quota,
@RequestParam(required = false) Integer maxSize,
@RequestParam(required = false) Integer maxAggrCount,
@RequestParam(required = false) Integer maxAggrSize) {
@RequestParam(required = false) String group, @RequestParam(required = false) String tenant,
@RequestParam(required = false) Integer quota, @RequestParam(required = false) Integer maxSize,
@RequestParam(required = false) Integer maxAggrCount, @RequestParam(required = false) Integer maxAggrSize) {
if (StringUtils.isBlank(group) && StringUtils.isBlank(tenant)) {
capacityService.initAllCapacity();
RestResult<Boolean> restResult = new RestResult<Boolean>();
@ -125,8 +122,8 @@ public class CapacityController {
return restResult;
}
try {
boolean insertOrUpdateResult = capacityService.insertOrUpdateCapacity(group, tenant, quota, maxSize,
maxAggrCount, maxAggrSize);
boolean insertOrUpdateResult = capacityService
.insertOrUpdateCapacity(group, tenant, quota, maxSize, maxAggrCount, maxAggrSize);
if (insertOrUpdateResult) {
setSuccessResult(response, restResult);
restResult.setMessage(String.format("成功更新%s为%s的容量信息配置", targetFieldName, targetFieldValue));

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.controller;
import com.alibaba.nacos.config.server.constant.Constants;
@ -57,10 +58,9 @@ public class CommunicationController {
* 通知配置信息改变
*/
@GetMapping("/dataChange")
public Boolean notifyConfigInfo(HttpServletRequest request,
@RequestParam("dataId") String dataId, @RequestParam("group") String group,
@RequestParam(value = "tenant", required = false, defaultValue = StringUtils.EMPTY)
String tenant,
public Boolean notifyConfigInfo(HttpServletRequest request, @RequestParam("dataId") String dataId,
@RequestParam("group") String group,
@RequestParam(value = "tenant", required = false, defaultValue = StringUtils.EMPTY) String tenant,
@RequestParam(value = "tag", required = false) String tag) {
dataId = dataId.trim();
group = group.trim();
@ -80,10 +80,8 @@ public class CommunicationController {
* 在本台机器上获得订阅改配置的客户端信息
*/
@GetMapping("/configWatchers")
public SampleResult getSubClientConfig(@RequestParam("dataId") String dataId,
@RequestParam("group") String group,
@RequestParam(value = "tenant", required = false) String tenant,
ModelMap modelMap) {
public SampleResult getSubClientConfig(@RequestParam("dataId") String dataId, @RequestParam("group") String group,
@RequestParam(value = "tenant", required = false) String tenant, ModelMap modelMap) {
group = StringUtils.isBlank(group) ? Constants.DEFAULT_GROUP : group;
return longPollingService.getCollectSubscribleInfo(dataId, group, tenant);
}
@ -92,9 +90,8 @@ public class CommunicationController {
* 在本台机器上获得客户端监听的配置列表
*/
@GetMapping("/watcherConfigs")
public SampleResult getSubClientConfigByIp(HttpServletRequest request,
HttpServletResponse response, @RequestParam("ip") String ip,
ModelMap modelMap) {
public SampleResult getSubClientConfigByIp(HttpServletRequest request, HttpServletResponse response,
@RequestParam("ip") String ip, ModelMap modelMap) {
return longPollingService.getCollectSubscribleInfoByIp(ip);
}
}

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.controller;
import com.alibaba.nacos.api.exception.NacosException;
@ -104,8 +105,8 @@ public class ConfigController {
private final ConfigSubService configSubService;
@Autowired
public ConfigController(ConfigServletInner configServletInner,
PersistService persistService, ConfigSubService configSubService) {
public ConfigController(ConfigServletInner configServletInner, PersistService persistService,
ConfigSubService configSubService) {
this.inner = configServletInner;
this.persistService = persistService;
this.configSubService = configSubService;
@ -121,8 +122,7 @@ public class ConfigController {
public Boolean publishConfig(HttpServletRequest request, HttpServletResponse response,
@RequestParam(value = "dataId") String dataId, @RequestParam(value = "group") String group,
@RequestParam(value = "tenant", required = false, defaultValue = StringUtils.EMPTY) String tenant,
@RequestParam(value = "content") String content,
@RequestParam(value = "tag", required = false) String tag,
@RequestParam(value = "content") String content, @RequestParam(value = "tag", required = false) String tag,
@RequestParam(value = "appName", required = false) String appName,
@RequestParam(value = "src_user", required = false) String srcUser,
@RequestParam(value = "config_tags", required = false) String configTags,
@ -130,8 +130,7 @@ public class ConfigController {
@RequestParam(value = "use", required = false) String use,
@RequestParam(value = "effect", required = false) String effect,
@RequestParam(value = "type", required = false) String type,
@RequestParam(value = "schema", required = false) String schema)
throws NacosException {
@RequestParam(value = "schema", required = false) String schema) throws NacosException {
final String srcIp = RequestUtil.getRemoteIp(request);
String requestIpApp = RequestUtil.getAppName(request);
@ -149,10 +148,9 @@ public class ConfigController {
ParamUtils.checkParam(configAdvanceInfo);
if (AggrWhitelist.isAggrDataId(dataId)) {
log.warn("[aggr-conflict] {} attemp to publish single data, {}, {}",
RequestUtil.getRemoteIp(request), dataId, group);
throw new NacosException(NacosException.NO_RIGHT,
"dataId:" + dataId + " is aggr");
log.warn("[aggr-conflict] {} attemp to publish single data, {}, {}", RequestUtil.getRemoteIp(request),
dataId, group);
throw new NacosException(NacosException.NO_RIGHT, "dataId:" + dataId + " is aggr");
}
final Timestamp time = TimeUtils.getCurrentTime();
@ -161,24 +159,23 @@ public class ConfigController {
configInfo.setType(type);
if (StringUtils.isBlank(betaIps)) {
if (StringUtils.isBlank(tag)) {
persistService.insertOrUpdate(srcIp, srcUser, configInfo, time,
configAdvanceInfo, true);
ConfigChangePublisher.notifyConfigChange(new ConfigDataChangeEvent(false, dataId, group, tenant, time.getTime()));
persistService.insertOrUpdate(srcIp, srcUser, configInfo, time, configAdvanceInfo, true);
ConfigChangePublisher
.notifyConfigChange(new ConfigDataChangeEvent(false, dataId, group, tenant, time.getTime()));
} else {
persistService.insertOrUpdateTag(configInfo, tag, srcIp, srcUser, time, true);
ConfigChangePublisher.notifyConfigChange(
new ConfigDataChangeEvent(false, dataId, group, tenant, tag, time.getTime()));
}
else {
persistService
.insertOrUpdateTag(configInfo, tag, srcIp, srcUser, time, true);
ConfigChangePublisher.notifyConfigChange(new ConfigDataChangeEvent(false, dataId, group, tenant, tag, time.getTime()));
}
}
else {
} else {
// beta publish
persistService
.insertOrUpdateBeta(configInfo, betaIps, srcIp, srcUser, time, true);
ConfigChangePublisher.notifyConfigChange(new ConfigDataChangeEvent(true, dataId, group, tenant, time.getTime()));
persistService.insertOrUpdateBeta(configInfo, betaIps, srcIp, srcUser, time, true);
ConfigChangePublisher
.notifyConfigChange(new ConfigDataChangeEvent(true, dataId, group, tenant, time.getTime()));
}
ConfigTraceService.logPersistenceEvent(dataId, group, tenant, requestIpApp, time.getTime(),
InetUtils.getSelfIp(), ConfigTraceService.PERSISTENCE_EVENT_PUB, content);
ConfigTraceService
.logPersistenceEvent(dataId, group, tenant, requestIpApp, time.getTime(), InetUtils.getSelfIp(),
ConfigTraceService.PERSISTENCE_EVENT_PUB, content);
return true;
}
@ -214,9 +211,8 @@ public class ConfigController {
*/
@GetMapping(params = "show=all")
@Secured(action = ActionTypes.READ, parser = ConfigResourceParser.class)
public ConfigAllInfo detailConfigInfo(HttpServletRequest request,
HttpServletResponse response, @RequestParam("dataId") String dataId,
@RequestParam("group") String group,
public ConfigAllInfo detailConfigInfo(HttpServletRequest request, HttpServletResponse response,
@RequestParam("dataId") String dataId, @RequestParam("group") String group,
@RequestParam(value = "tenant", required = false, defaultValue = StringUtils.EMPTY) String tenant)
throws NacosException {
// check tenant
@ -237,8 +233,7 @@ public class ConfigController {
@RequestParam("dataId") String dataId, //
@RequestParam("group") String group, //
@RequestParam(value = "tenant", required = false, defaultValue = StringUtils.EMPTY) String tenant,
@RequestParam(value = "tag", required = false) String tag)
throws NacosException {
@RequestParam(value = "tag", required = false) String tag) throws NacosException {
// check tenant
ParamUtils.checkTenant(tenant);
ParamUtils.checkParam(dataId, group, "datumId", "rm");
@ -246,16 +241,14 @@ public class ConfigController {
String clientIp = RequestUtil.getRemoteIp(request);
if (StringUtils.isBlank(tag)) {
persistService.removeConfigInfo(dataId, group, tenant, clientIp, null);
}
else {
persistService
.removeConfigInfoTag(dataId, group, tenant, tag, clientIp, null);
} else {
persistService.removeConfigInfoTag(dataId, group, tenant, tag, clientIp, null);
}
final Timestamp time = TimeUtils.getCurrentTime();
ConfigTraceService
.logPersistenceEvent(dataId, group, tenant, null, time.getTime(),
clientIp, ConfigTraceService.PERSISTENCE_EVENT_REMOVE, null);
ConfigChangePublisher.notifyConfigChange(new ConfigDataChangeEvent(false, dataId, group, tenant, tag, time.getTime()));
ConfigTraceService.logPersistenceEvent(dataId, group, tenant, null, time.getTime(), clientIp,
ConfigTraceService.PERSISTENCE_EVENT_REMOVE, null);
ConfigChangePublisher
.notifyConfigChange(new ConfigDataChangeEvent(false, dataId, group, tenant, tag, time.getTime()));
return true;
}
@ -268,20 +261,19 @@ public class ConfigController {
*/
@DeleteMapping(params = "delType=ids")
@Secured(action = ActionTypes.WRITE, parser = ConfigResourceParser.class)
public RestResult<Boolean> deleteConfigs(HttpServletRequest request,
HttpServletResponse response, @RequestParam(value = "ids") List<Long> ids) {
public RestResult<Boolean> deleteConfigs(HttpServletRequest request, HttpServletResponse response,
@RequestParam(value = "ids") List<Long> ids) {
String clientIp = RequestUtil.getRemoteIp(request);
final Timestamp time = TimeUtils.getCurrentTime();
List<ConfigInfo> configInfoList = persistService
.removeConfigInfoByIds(ids, clientIp, null);
List<ConfigInfo> configInfoList = persistService.removeConfigInfoByIds(ids, clientIp, null);
if (!CollectionUtils.isEmpty(configInfoList)) {
for (ConfigInfo configInfo : configInfoList) {
ConfigChangePublisher.notifyConfigChange(new ConfigDataChangeEvent(false, configInfo.getDataId(),
configInfo.getGroup(), configInfo.getTenant(), time.getTime()));
ConfigTraceService.logPersistenceEvent(configInfo.getDataId(),
configInfo.getGroup(), configInfo.getTenant(), null,
time.getTime(), clientIp,
ConfigTraceService.PERSISTENCE_EVENT_REMOVE, null);
ConfigChangePublisher.notifyConfigChange(
new ConfigDataChangeEvent(false, configInfo.getDataId(), configInfo.getGroup(),
configInfo.getTenant(), time.getTime()));
ConfigTraceService
.logPersistenceEvent(configInfo.getDataId(), configInfo.getGroup(), configInfo.getTenant(),
null, time.getTime(), clientIp, ConfigTraceService.PERSISTENCE_EVENT_REMOVE, null);
}
}
return ResultBuilder.buildSuccessResult(true);
@ -289,12 +281,11 @@ public class ConfigController {
@GetMapping("/catalog")
@Secured(action = ActionTypes.READ, parser = ConfigResourceParser.class)
public RestResult<ConfigAdvanceInfo> getConfigAdvanceInfo(
@RequestParam("dataId") String dataId, @RequestParam("group") String group,
public RestResult<ConfigAdvanceInfo> getConfigAdvanceInfo(@RequestParam("dataId") String dataId,
@RequestParam("group") String group,
@RequestParam(value = "tenant", required = false, defaultValue = StringUtils.EMPTY) String tenant) {
RestResult<ConfigAdvanceInfo> rr = new RestResult<ConfigAdvanceInfo>();
ConfigAdvanceInfo configInfo = persistService
.findConfigAdvanceInfo(dataId, group, tenant);
ConfigAdvanceInfo configInfo = persistService.findConfigAdvanceInfo(dataId, group, tenant);
rr.setCode(200);
rr.setData(configInfo);
return rr;
@ -318,8 +309,7 @@ public class ConfigController {
Map<String, String> clientMd5Map;
try {
clientMd5Map = MD5Util.getClientMd5Map(probeModify);
}
catch (Throwable e) {
} catch (Throwable e) {
throw new IllegalArgumentException("invalid probeModify");
}
@ -333,18 +323,14 @@ public class ConfigController {
@GetMapping("/listener")
@Secured(action = ActionTypes.READ, parser = ConfigResourceParser.class)
public GroupkeyListenserStatus getListeners(@RequestParam("dataId") String dataId,
@RequestParam("group") String group,
@RequestParam(value = "tenant", required = false) String tenant,
@RequestParam(value = "sampleTime", required = false, defaultValue = "1") int sampleTime)
throws Exception {
@RequestParam("group") String group, @RequestParam(value = "tenant", required = false) String tenant,
@RequestParam(value = "sampleTime", required = false, defaultValue = "1") int sampleTime) throws Exception {
group = StringUtils.isBlank(group) ? Constants.DEFAULT_GROUP : group;
SampleResult collectSampleResult = configSubService
.getCollectSampleResult(dataId, group, tenant, sampleTime);
SampleResult collectSampleResult = configSubService.getCollectSampleResult(dataId, group, tenant, sampleTime);
GroupkeyListenserStatus gls = new GroupkeyListenserStatus();
gls.setCollectStatus(200);
if (collectSampleResult.getLisentersGroupkeyStatus() != null) {
gls.setLisentersGroupkeyStatus(
collectSampleResult.getLisentersGroupkeyStatus());
gls.setLisentersGroupkeyStatus(collectSampleResult.getLisentersGroupkeyStatus());
}
return gls;
}
@ -354,8 +340,7 @@ public class ConfigController {
*/
@GetMapping(params = "search=accurate")
@Secured(action = ActionTypes.READ, parser = ConfigResourceParser.class)
public Page<ConfigInfo> searchConfig(@RequestParam("dataId") String dataId,
@RequestParam("group") String group,
public Page<ConfigInfo> searchConfig(@RequestParam("dataId") String dataId, @RequestParam("group") String group,
@RequestParam(value = "appName", required = false) String appName,
@RequestParam(value = "tenant", required = false, defaultValue = StringUtils.EMPTY) String tenant,
@RequestParam(value = "config_tags", required = false) String configTags,
@ -368,27 +353,22 @@ public class ConfigController {
configAdvanceInfo.put("config_tags", configTags);
}
try {
return persistService
.findConfigInfo4Page(pageNo, pageSize, dataId, group, tenant,
configAdvanceInfo);
}
catch (Exception e) {
String errorMsg =
"serialize page error, dataId=" + dataId + ", group=" + group;
return persistService.findConfigInfo4Page(pageNo, pageSize, dataId, group, tenant, configAdvanceInfo);
} catch (Exception e) {
String errorMsg = "serialize page error, dataId=" + dataId + ", group=" + group;
log.error(errorMsg, e);
throw new RuntimeException(errorMsg, e);
}
}
/**
* Fuzzy query configuration information. Fuzzy queries based only on content are not allowed, that is,
* both dataId and group are NULL, but content is not NULL. In this case, all configurations are returned.
* Fuzzy query configuration information. Fuzzy queries based only on content are not allowed, that is, both dataId
* and group are NULL, but content is not NULL. In this case, all configurations are returned.
*/
@GetMapping(params = "search=blur")
@Secured(action = ActionTypes.READ, parser = ConfigResourceParser.class)
public Page<ConfigInfo> fuzzySearchConfig(@RequestParam("dataId") String dataId,
@RequestParam("group") String group,
@RequestParam(value = "appName", required = false) String appName,
@RequestParam("group") String group, @RequestParam(value = "appName", required = false) String appName,
@RequestParam(value = "tenant", required = false, defaultValue = StringUtils.EMPTY) String tenant,
@RequestParam(value = "config_tags", required = false) String configTags,
@RequestParam("pageNo") int pageNo, @RequestParam("pageSize") int pageSize) {
@ -400,13 +380,9 @@ public class ConfigController {
configAdvanceInfo.put("config_tags", configTags);
}
try {
return persistService
.findConfigInfoLike4Page(pageNo, pageSize, dataId, group, tenant,
configAdvanceInfo);
}
catch (Exception e) {
String errorMsg =
"serialize page error, dataId=" + dataId + ", group=" + group;
return persistService.findConfigInfoLike4Page(pageNo, pageSize, dataId, group, tenant, configAdvanceInfo);
} catch (Exception e) {
String errorMsg = "serialize page error, dataId=" + dataId + ", group=" + group;
log.error(errorMsg, e);
throw new RuntimeException(errorMsg, e);
}
@ -420,15 +396,15 @@ public class ConfigController {
RestResult<Boolean> rr = new RestResult<Boolean>();
try {
persistService.removeConfigInfo4Beta(dataId, group, tenant);
}
catch (Exception e) {
} catch (Exception e) {
log.error("remove beta data error", e);
rr.setCode(500);
rr.setData(false);
rr.setMessage("remove beta data error");
return rr;
}
ConfigChangePublisher.notifyConfigChange(new ConfigDataChangeEvent(true, dataId, group, tenant, System.currentTimeMillis()));
ConfigChangePublisher
.notifyConfigChange(new ConfigDataChangeEvent(true, dataId, group, tenant, System.currentTimeMillis()));
rr.setCode(200);
rr.setData(true);
rr.setMessage("stop beta ok");
@ -437,20 +413,17 @@ public class ConfigController {
@GetMapping(params = "beta=true")
@Secured(action = ActionTypes.READ, parser = ConfigResourceParser.class)
public RestResult<ConfigInfo4Beta> queryBeta(
@RequestParam(value = "dataId") String dataId,
public RestResult<ConfigInfo4Beta> queryBeta(@RequestParam(value = "dataId") String dataId,
@RequestParam(value = "group") String group,
@RequestParam(value = "tenant", required = false, defaultValue = StringUtils.EMPTY) String tenant) {
RestResult<ConfigInfo4Beta> rr = new RestResult<ConfigInfo4Beta>();
try {
ConfigInfo4Beta ci = persistService
.findConfigInfo4Beta(dataId, group, tenant);
ConfigInfo4Beta ci = persistService.findConfigInfo4Beta(dataId, group, tenant);
rr.setCode(200);
rr.setData(ci);
rr.setMessage("stop beta ok");
return rr;
}
catch (Exception e) {
} catch (Exception e) {
log.error("remove beta data error", e);
rr.setCode(500);
rr.setMessage("remove beta data error");
@ -460,16 +433,14 @@ public class ConfigController {
@GetMapping(params = "export=true")
@Secured(action = ActionTypes.READ, parser = ConfigResourceParser.class)
public ResponseEntity<byte[]> exportConfig(
@RequestParam(value = "dataId", required = false) String dataId,
public ResponseEntity<byte[]> exportConfig(@RequestParam(value = "dataId", required = false) String dataId,
@RequestParam(value = "group", required = false) String group,
@RequestParam(value = "appName", required = false) String appName,
@RequestParam(value = "tenant", required = false, defaultValue = StringUtils.EMPTY) String tenant,
@RequestParam(value = "ids", required = false) List<Long> ids) {
ids.removeAll(Collections.singleton(null));
tenant = processTenant(tenant);
List<ConfigAllInfo> dataList = persistService
.findAllConfigInfo4Export(dataId, group, tenant, appName, ids);
List<ConfigAllInfo> dataList = persistService.findAllConfigInfo4Export(dataId, group, tenant, appName, ids);
List<ZipUtils.ZipItem> zipItemList = new ArrayList<>();
StringBuilder metaData = null;
for (ConfigInfo ci : dataList) {
@ -480,13 +451,10 @@ public class ConfigController {
}
String metaDataId = ci.getDataId();
if (metaDataId.contains(".")) {
metaDataId =
metaDataId.substring(0, metaDataId.lastIndexOf(".")) + "~"
+ metaDataId
metaDataId = metaDataId.substring(0, metaDataId.lastIndexOf(".")) + "~" + metaDataId
.substring(metaDataId.lastIndexOf(".") + 1);
}
metaData.append(ci.getGroup()).append(".").append(metaDataId)
.append(".app=")
metaData.append(ci.getGroup()).append(".").append(metaDataId).append(".app=")
// Fixed use of "\r\n" here
.append(ci.getAppName()).append("\r\n");
}
@ -498,22 +466,20 @@ public class ConfigController {
}
HttpHeaders headers = new HttpHeaders();
String fileName = EXPORT_CONFIG_FILE_NAME + DateFormatUtils
.format(new Date(), EXPORT_CONFIG_FILE_NAME_DATE_FORMAT)
String fileName =
EXPORT_CONFIG_FILE_NAME + DateFormatUtils.format(new Date(), EXPORT_CONFIG_FILE_NAME_DATE_FORMAT)
+ EXPORT_CONFIG_FILE_NAME_EXT;
headers.add("Content-Disposition", "attachment;filename=" + fileName);
return new ResponseEntity<byte[]>(ZipUtils.zip(zipItemList), headers,
HttpStatus.OK);
return new ResponseEntity<byte[]>(ZipUtils.zip(zipItemList), headers, HttpStatus.OK);
}
@PostMapping(params = "import=true")
@Secured(action = ActionTypes.WRITE, parser = ConfigResourceParser.class)
public RestResult<Map<String, Object>> importAndPublishConfig(
HttpServletRequest request,
public RestResult<Map<String, Object>> importAndPublishConfig(HttpServletRequest request,
@RequestParam(value = "src_user", required = false) String srcUser,
@RequestParam(value = "namespace", required = false) String namespace,
@RequestParam(value = "policy", defaultValue = "ABORT") SameConfigPolicy policy,
MultipartFile file) throws NacosException {
@RequestParam(value = "policy", defaultValue = "ABORT") SameConfigPolicy policy, MultipartFile file)
throws NacosException {
Map<String, Object> failedData = new HashMap<>(4);
if (Objects.isNull(file)) {
@ -523,8 +489,7 @@ public class ConfigController {
if (StringUtils.isNotBlank(namespace)) {
if (persistService.tenantInfoCountByTenantId(namespace) <= 0) {
failedData.put("succCount", 0);
return ResultBuilder
.buildResult(ResultCodeEnum.NAMESPACE_NOT_EXIST, failedData);
return ResultBuilder.buildResult(ResultCodeEnum.NAMESPACE_NOT_EXIST, failedData);
}
}
List<ConfigAllInfo> configInfoList = null;
@ -539,8 +504,7 @@ public class ConfigController {
String[] metaDataItemArr = metaDataItem.split("=");
if (metaDataItemArr.length != 2) {
failedData.put("succCount", 0);
return ResultBuilder
.buildResult(ResultCodeEnum.METADATA_ILLEGAL, failedData);
return ResultBuilder.buildResult(ResultCodeEnum.METADATA_ILLEGAL, failedData);
}
metaDataMap.put(metaDataItemArr[0], metaDataItemArr[1]);
}
@ -552,17 +516,13 @@ public class ConfigController {
String[] groupAdnDataId = item.getItemName().split("/");
if (!item.getItemName().contains("/") || groupAdnDataId.length != 2) {
failedData.put("succCount", 0);
return ResultBuilder
.buildResult(ResultCodeEnum.DATA_VALIDATION_FAILED,
failedData);
return ResultBuilder.buildResult(ResultCodeEnum.DATA_VALIDATION_FAILED, failedData);
}
String group = groupAdnDataId[0];
String dataId = groupAdnDataId[1];
String tempDataId = dataId;
if (tempDataId.contains(".")) {
tempDataId =
tempDataId.substring(0, tempDataId.lastIndexOf(".")) + "~"
+ tempDataId
tempDataId = tempDataId.substring(0, tempDataId.lastIndexOf(".")) + "~" + tempDataId
.substring(tempDataId.lastIndexOf(".") + 1);
}
String metaDataId = group + "." + tempDataId + ".app";
@ -577,12 +537,10 @@ public class ConfigController {
configInfoList.add(ci);
}
}
}
catch (IOException e) {
} catch (IOException e) {
failedData.put("succCount", 0);
log.error("parsing data failed", e);
return ResultBuilder
.buildResult(ResultCodeEnum.PARSING_DATA_FAILED, failedData);
return ResultBuilder.buildResult(ResultCodeEnum.PARSING_DATA_FAILED, failedData);
}
if (configInfoList == null || configInfoList.isEmpty()) {
failedData.put("succCount", 0);
@ -592,18 +550,15 @@ public class ConfigController {
String requestIpApp = RequestUtil.getAppName(request);
final Timestamp time = TimeUtils.getCurrentTime();
Map<String, Object> saveResult = persistService
.batchInsertOrUpdate(configInfoList, srcUser, srcIp, null, time, false,
policy);
.batchInsertOrUpdate(configInfoList, srcUser, srcIp, null, time, false, policy);
for (ConfigInfo configInfo : configInfoList) {
ConfigChangePublisher.notifyConfigChange(
new ConfigDataChangeEvent(false, configInfo.getDataId(),
configInfo.getGroup(), configInfo.getTenant(),
time.getTime()));
new ConfigDataChangeEvent(false, configInfo.getDataId(), configInfo.getGroup(),
configInfo.getTenant(), time.getTime()));
ConfigTraceService
.logPersistenceEvent(configInfo.getDataId(), configInfo.getGroup(),
configInfo.getTenant(), requestIpApp, time.getTime(),
InetUtils.getSelfIp(), ConfigTraceService.PERSISTENCE_EVENT_PUB,
configInfo.getContent());
.logPersistenceEvent(configInfo.getDataId(), configInfo.getGroup(), configInfo.getTenant(),
requestIpApp, time.getTime(), InetUtils.getSelfIp(),
ConfigTraceService.PERSISTENCE_EVENT_PUB, configInfo.getContent());
}
return ResultBuilder.buildSuccessResult("导入成功", saveResult);
}
@ -614,23 +569,19 @@ public class ConfigController {
@RequestParam(value = "src_user", required = false) String srcUser,
@RequestParam(value = "tenant", required = true) String namespace,
@RequestBody(required = true) List<SameNamespaceCloneConfigBean> configBeansList,
@RequestParam(value = "policy", defaultValue = "ABORT") SameConfigPolicy policy)
throws NacosException {
@RequestParam(value = "policy", defaultValue = "ABORT") SameConfigPolicy policy) throws NacosException {
Map<String, Object> failedData = new HashMap<>(4);
if (CollectionUtils.isEmpty(configBeansList)) {
failedData.put("succCount", 0);
return ResultBuilder
.buildResult(ResultCodeEnum.NO_SELECTED_CONFIG, failedData);
return ResultBuilder.buildResult(ResultCodeEnum.NO_SELECTED_CONFIG, failedData);
}
configBeansList.removeAll(Collections.singleton(null));
if (NAMESPACE_PUBLIC_KEY.equalsIgnoreCase(namespace)) {
namespace = "";
}
else if (persistService.tenantInfoCountByTenantId(namespace) <= 0) {
} else if (persistService.tenantInfoCountByTenantId(namespace) <= 0) {
failedData.put("succCount", 0);
return ResultBuilder
.buildResult(ResultCodeEnum.NAMESPACE_NOT_EXIST, failedData);
return ResultBuilder.buildResult(ResultCodeEnum.NAMESPACE_NOT_EXIST, failedData);
}
List<Long> idList = new ArrayList<>(configBeansList.size());
@ -640,30 +591,25 @@ public class ConfigController {
return cfg;
}, (k1, k2) -> k1));
List<ConfigAllInfo> queryedDataList = persistService
.findAllConfigInfo4Export(null, null, null, null, idList);
List<ConfigAllInfo> queryedDataList = persistService.findAllConfigInfo4Export(null, null, null, null, idList);
if (queryedDataList == null || queryedDataList.isEmpty()) {
failedData.put("succCount", 0);
return ResultBuilder.buildResult(ResultCodeEnum.DATA_EMPTY, failedData);
}
List<ConfigAllInfo> configInfoList4Clone = new ArrayList<>(
queryedDataList.size());
List<ConfigAllInfo> configInfoList4Clone = new ArrayList<>(queryedDataList.size());
for (ConfigAllInfo ci : queryedDataList) {
SameNamespaceCloneConfigBean prarmBean = configBeansMap.get(ci.getId());
ConfigAllInfo ci4save = new ConfigAllInfo();
ci4save.setTenant(namespace);
ci4save.setType(ci.getType());
ci4save.setGroup(
(prarmBean != null && StringUtils.isNotBlank(prarmBean.getGroup())) ?
prarmBean.getGroup() :
ci.getGroup());
ci4save.setGroup((prarmBean != null && StringUtils.isNotBlank(prarmBean.getGroup())) ? prarmBean.getGroup()
: ci.getGroup());
ci4save.setDataId(
(prarmBean != null && StringUtils.isNotBlank(prarmBean.getDataId())) ?
prarmBean.getDataId() :
ci.getDataId());
(prarmBean != null && StringUtils.isNotBlank(prarmBean.getDataId())) ? prarmBean.getDataId()
: ci.getDataId());
ci4save.setContent(ci.getContent());
if (StringUtils.isNotBlank(ci.getAppName())) {
ci4save.setAppName(ci.getAppName());
@ -679,25 +625,21 @@ public class ConfigController {
String requestIpApp = RequestUtil.getAppName(request);
final Timestamp time = TimeUtils.getCurrentTime();
Map<String, Object> saveResult = persistService
.batchInsertOrUpdate(configInfoList4Clone, srcUser, srcIp, null, time,
false, policy);
.batchInsertOrUpdate(configInfoList4Clone, srcUser, srcIp, null, time, false, policy);
for (ConfigInfo configInfo : configInfoList4Clone) {
ConfigChangePublisher.notifyConfigChange(
new ConfigDataChangeEvent(false, configInfo.getDataId(),
configInfo.getGroup(), configInfo.getTenant(),
time.getTime()));
new ConfigDataChangeEvent(false, configInfo.getDataId(), configInfo.getGroup(),
configInfo.getTenant(), time.getTime()));
ConfigTraceService
.logPersistenceEvent(configInfo.getDataId(), configInfo.getGroup(),
configInfo.getTenant(), requestIpApp, time.getTime(),
InetUtils.getSelfIp(), ConfigTraceService.PERSISTENCE_EVENT_PUB,
configInfo.getContent());
.logPersistenceEvent(configInfo.getDataId(), configInfo.getGroup(), configInfo.getTenant(),
requestIpApp, time.getTime(), InetUtils.getSelfIp(),
ConfigTraceService.PERSISTENCE_EVENT_PUB, configInfo.getContent());
}
return ResultBuilder.buildSuccessResult("Clone Completed Successfully", saveResult);
}
private String processTenant(String tenant) {
if (StringUtils.isEmpty(tenant) || NAMESPACE_PUBLIC_KEY
.equalsIgnoreCase(tenant)) {
if (StringUtils.isEmpty(tenant) || NAMESPACE_PUBLIC_KEY.equalsIgnoreCase(tenant)) {
return "";
}
return tenant;

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.controller;
import com.alibaba.nacos.config.server.constant.Constants;
@ -66,8 +67,7 @@ public class ConfigServletInner {
* 轮询接口
*/
public String doPollingConfig(HttpServletRequest request, HttpServletResponse response,
Map<String, String> clientMd5Map, int probeRequestSize)
throws IOException {
Map<String, String> clientMd5Map, int probeRequestSize) throws IOException {
// 长轮询
if (LongPollingService.isSupportLongPolling(request)) {
@ -210,8 +210,7 @@ public class ConfigServletInner {
// FIXME CacheItem
// 不存在了无法简单的计算推送delayed这里简单的记做-1
ConfigTraceService.logPullEvent(dataId, group, tenant, requestIpApp, -1,
ConfigTraceService.PULL_EVENT_NOTFOUND,
-1, requestIp);
ConfigTraceService.PULL_EVENT_NOTFOUND, -1, requestIp);
// pullLog.info("[client-get] clientIp={}, {},
// no data",
@ -244,8 +243,8 @@ public class ConfigServletInner {
out.flush();
out.close();
} else {
fis.getChannel().transferTo(0L, fis.getChannel().size(),
Channels.newChannel(response.getOutputStream()));
fis.getChannel()
.transferTo(0L, fis.getChannel().size(), Channels.newChannel(response.getOutputStream()));
}
LogUtil.pullCheckLog.warn("{}|{}|{}|{}", groupKey, requestIp, md5, TimeUtils.getCurrentTimeStr());
@ -255,8 +254,7 @@ public class ConfigServletInner {
// TODO distinguish pull-get && push-get
// 否则无法直接把delayed作为推送延时的依据因为主动get请求的delayed值都很大
ConfigTraceService.logPullEvent(dataId, group, tenant, requestIpApp, lastModified,
ConfigTraceService.PULL_EVENT_OK, delayed,
requestIp);
ConfigTraceService.PULL_EVENT_OK, delayed, requestIp);
} finally {
releaseConfigReadLock(groupKey);
@ -267,8 +265,9 @@ public class ConfigServletInner {
} else if (lockResult == 0) {
// FIXME CacheItem 不存在了无法简单的计算推送delayed这里简单的记做-1
ConfigTraceService.logPullEvent(dataId, group, tenant, requestIpApp, -1,
ConfigTraceService.PULL_EVENT_NOTFOUND, -1, requestIp);
ConfigTraceService
.logPullEvent(dataId, group, tenant, requestIpApp, -1, ConfigTraceService.PULL_EVENT_NOTFOUND, -1,
requestIp);
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
response.getWriter().println("config data not exist");

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.controller;
import com.alibaba.nacos.config.server.constant.Constants;
@ -37,8 +38,11 @@ import javax.annotation.PostConstruct;
public class HealthController {
private DataSourceService dataSourceService;
private String heathUpStr = "UP";
private String heathDownStr = "DOWN";
private String heathWarnStr = "WARN";
@Autowired
@ -56,16 +60,13 @@ public class HealthController {
String dbStatus = dataSourceService.getHealth();
if (dbStatus.contains(heathUpStr) && memberManager.isInIpList()) {
sb.append(heathUpStr);
}
else if (dbStatus.contains(heathWarnStr) && memberManager.isInIpList()) {
} else if (dbStatus.contains(heathWarnStr) && memberManager.isInIpList()) {
sb.append("WARN:");
sb.append("slave db (").append(dbStatus.split(":")[1]).append(") down. ");
}
else {
} else {
sb.append("DOWN:");
if (dbStatus.contains(heathDownStr)) {
sb.append("master db (").append(dbStatus.split(":")[1])
.append(") down. ");
sb.append("master db (").append(dbStatus.split(":")[1]).append(") down. ");
}
if (!memberManager.isInIpList()) {
sb.append("server ip ").append(InetUtils.getSelfIp())

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.controller;
import com.alibaba.nacos.config.server.constant.Constants;
@ -45,13 +46,11 @@ public class HistoryController {
@GetMapping(params = "search=accurate")
public Page<ConfigHistoryInfo> listConfigHistory(@RequestParam("dataId") String dataId, //
@RequestParam("group") String group, //
@RequestParam(value = "tenant", required = false,
defaultValue = StringUtils.EMPTY) String tenant,
@RequestParam(value = "tenant", required = false, defaultValue = StringUtils.EMPTY) String tenant,
@RequestParam(value = "appName", required = false) String appName,
@RequestParam(value = "pageNo", required = false) Integer pageNo,
//
@RequestParam(value = "pageSize", required = false)
Integer pageSize, //
@RequestParam(value = "pageSize", required = false) Integer pageSize, //
ModelMap modelMap) {
pageNo = null == pageNo ? 1 : pageNo;
pageSize = null == pageSize ? 100 : pageSize;

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.controller;
import com.alibaba.nacos.config.server.constant.Constants;
@ -53,10 +54,8 @@ public class ListenerController {
@GetMapping
public GroupkeyListenserStatus getAllSubClientConfigByIp(@RequestParam("ip") String ip,
@RequestParam(value = "all", required = false) boolean all,
@RequestParam(value = "tenant", required = false)
String tenant,
@RequestParam(value = "sampleTime", required = false,
defaultValue = "1") int sampleTime, ModelMap modelMap)
@RequestParam(value = "tenant", required = false) String tenant,
@RequestParam(value = "sampleTime", required = false, defaultValue = "1") int sampleTime, ModelMap modelMap)
throws Exception {
SampleResult collectSampleResult = configSubService.getCollectSampleResultByIp(ip, sampleTime);
GroupkeyListenserStatus gls = new GroupkeyListenserStatus();

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.controller.parameters;
/**

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.enums;
/**

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.exception;
import com.alibaba.nacos.api.exception.NacosException;

View File

@ -36,7 +36,8 @@ public class NacosConfigException extends RuntimeException {
super(cause);
}
public NacosConfigException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
public NacosConfigException(String message, Throwable cause, boolean enableSuppression,
boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}

View File

@ -44,15 +44,15 @@ import java.security.AccessControlException;
import java.util.List;
/**
* If the embedded distributed storage is enabled, all requests are routed to the Leader
* node for processing, and the maximum number of forwards for a single request cannot
* exceed three
* If the embedded distributed storage is enabled, all requests are routed to the Leader node for processing, and the
* maximum number of forwards for a single request cannot exceed three
*
* @author <a href="mailto:liaochuntao@live.com">liaochuntao</a>
*/
public class CurcuitFilter implements Filter {
private volatile boolean isDowngrading = false;
private volatile boolean isOpenService = false;
@Autowired
@ -71,8 +71,8 @@ public class CurcuitFilter implements Filter {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse resp = (HttpServletResponse) response;
@ -93,14 +93,10 @@ public class CurcuitFilter implements Filter {
}
chain.doFilter(req, response);
}
catch (AccessControlException e) {
resp.sendError(HttpServletResponse.SC_FORBIDDEN,
"access denied: " + ExceptionUtil.getAllExceptionMsg(e));
}
catch (Throwable e) {
resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"Server failed," + e.toString());
} catch (AccessControlException e) {
resp.sendError(HttpServletResponse.SC_FORBIDDEN, "access denied: " + ExceptionUtil.getAllExceptionMsg(e));
} catch (Throwable e) {
resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Server failed," + e.toString());
}
}
@ -110,12 +106,12 @@ public class CurcuitFilter implements Filter {
}
private void listenerSelfInCluster() {
protocol.protocolMetaData().subscribe(Constants.CONFIG_MODEL_RAFT_GROUP,
MetadataKey.RAFT_GROUP_MEMBER, (o, arg) -> {
protocol.protocolMetaData()
.subscribe(Constants.CONFIG_MODEL_RAFT_GROUP, MetadataKey.RAFT_GROUP_MEMBER, (o, arg) -> {
final List<String> peers = (List<String>) arg;
final Member self = memberManager.getSelf();
final String raftAddress = self.getIp() + ":" + self
.getExtendVal(MemberMetaDataConstants.RAFT_PORT);
final String raftAddress =
self.getIp() + ":" + self.getExtendVal(MemberMetaDataConstants.RAFT_PORT);
// Only when you are in the cluster and the current Leader is
// elected can you provide external services
isOpenService = peers.contains(raftAddress);
@ -140,8 +136,7 @@ public class CurcuitFilter implements Filter {
@Override
public boolean canNotify(Event event) {
return (event instanceof RaftDBErrorEvent)
|| (event instanceof RaftDBErrorRecoverEvent);
return (event instanceof RaftDBErrorEvent) || (event instanceof RaftDBErrorRecoverEvent);
}
});
}

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.filter;
import com.alibaba.nacos.config.server.constant.Constants;

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.manager;
/**
@ -21,6 +22,7 @@ package com.alibaba.nacos.config.server.manager;
* @author huali
*/
public abstract class AbstractTask {
/**
* 一个任务两次处理的间隔单位是毫秒
*/

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.manager;
import com.alibaba.nacos.config.server.constant.Constants;
@ -41,8 +42,7 @@ public final class TaskManager implements TaskManagerMBean {
private final ConcurrentHashMap<String, AbstractTask> tasks = new ConcurrentHashMap<String, AbstractTask>();
private final ConcurrentHashMap<String, TaskProcessor> taskProcessors =
new ConcurrentHashMap<String, TaskProcessor>();
private final ConcurrentHashMap<String, TaskProcessor> taskProcessors = new ConcurrentHashMap<String, TaskProcessor>();
private TaskProcessor defaultTaskProcessor;

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.manager;
/**

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.manager;
/**
@ -21,6 +22,7 @@ package com.alibaba.nacos.config.server.manager;
* @author Nacos
*/
public interface TaskProcessor {
/**
* process task
*

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model;
import java.io.Serializable;
@ -27,7 +28,9 @@ import java.util.List;
public class ACLInfo implements Serializable {
private static final long serialVersionUID = 1383026926036269457L;
private Boolean isOpen;
private List<String> ips;
public List<String> getIps() {

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model;
/**

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model;
import com.alibaba.nacos.config.server.constant.Constants;
@ -118,19 +119,28 @@ public class CacheItem {
}
final String groupKey;
public volatile String md5 = Constants.NULL;
public volatile long lastModifiedTs;
/**
* use for beta
*/
public volatile boolean isBeta = false;
public volatile String md54Beta = Constants.NULL;
public volatile List<String> ips4Beta;
public volatile long lastModifiedTs4Beta;
public volatile Map<String, String> tagMd5;
public volatile Map<String, Long> tagLastModifiedTs;
public SimpleReadWriteLock rwLock = new SimpleReadWriteLock();
public String type;
}

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model;
import java.io.Serializable;
@ -23,16 +24,27 @@ import java.io.Serializable;
* @author Nacos
*/
public class ConfigAdvanceInfo implements Serializable {
static final long serialVersionUID = -1L;
private long createTime;
private long modifyTime;
private String createUser;
private String createIp;
private String desc;
private String use;
private String effect;
private String type;
private String schema;
private String configTags;
public long getCreateTime() {

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model;
/**
@ -28,14 +29,23 @@ public class ConfigAllInfo extends ConfigInfo {
private static final long serialVersionUID = 296578467953931353L;
private long createTime;
private long modifyTime;
private String createUser;
private String createIp;
private String desc;
private String use;
private String effect;
private String type;
private String schema;
private String configTags;
public ConfigAllInfo() {

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
@ -29,21 +30,27 @@ import java.sql.Timestamp;
public class ConfigHistoryInfo implements Serializable {
private static final long serialVersionUID = -7827521105376245603L;
/**
* id, nid, data_id, group_id, content, md5, gmt_create, gmt_modified, 配置创建时间配置变更时间 src_user, src_ip, (变更操作者)
* op_type变更操作类型
*/
@JsonSerialize(using = ToStringSerializer.class)
private long id;
/**
* 上次改动历史的id
*/
private long lastId = -1;
private String dataId;
private String group;
private String tenant;
private String appName;
private String md5;
public long getId() {
@ -153,12 +160,15 @@ public class ConfigHistoryInfo implements Serializable {
private String content;
private String srcIp;
private String srcUser;
/**
* 操作类型, 包括插入更新删除
*/
private String opType;
private Timestamp createdTime;
private Timestamp lastModifiedTime;
}

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model;
/**
@ -22,6 +23,7 @@ package com.alibaba.nacos.config.server.model;
* @date 2010-5-4
*/
public class ConfigInfo extends ConfigInfoBase {
static final long serialVersionUID = -1L;
private String tenant;

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model;
/**

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model;
/**

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
@ -28,14 +29,20 @@ import java.io.Serializable;
public class ConfigInfoAggr implements Serializable {
private static final long serialVersionUID = -3845825581059306364L;
@JsonSerialize(using = ToStringSerializer.class)
private long id;
private String dataId;
private String group;
private String datumId;
private String tenant;
private String appName;
private String content;
public ConfigInfoAggr(String dataId, String group, String datumId, String content) {
@ -153,8 +160,8 @@ public class ConfigInfoAggr implements Serializable {
@Override
public String toString() {
return "ConfigInfoAggr [dataId=" + dataId + ", group=" + group + ", datumId=" + datumId + ", content="
+ content + "]";
return "ConfigInfoAggr [dataId=" + dataId + ", group=" + group + ", datumId=" + datumId + ", content=" + content
+ "]";
}
public String getAppName() {

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model;
import com.alibaba.nacos.common.utils.MD5Utils;
@ -29,6 +30,7 @@ import java.io.Serializable;
* @author Nacos
*/
public class ConfigInfoBase implements Serializable, Comparable<ConfigInfoBase> {
static final long serialVersionUID = -1L;
/**
@ -36,9 +38,13 @@ public class ConfigInfoBase implements Serializable, Comparable<ConfigInfoBase>
*/
@JsonSerialize(using = ToStringSerializer.class)
private long id;
private String dataId;
private String group;
private String content;
private String md5;
public ConfigInfoBase() {
@ -212,8 +218,7 @@ public class ConfigInfoBase implements Serializable, Comparable<ConfigInfoBase>
@Override
public String toString() {
return "ConfigInfoBase{" + "id=" + id + ", dataId='" + dataId + '\''
+ ", group='" + group + '\'' + ", content='" + content + '\''
+ ", md5='" + md5 + '\'' + '}';
return "ConfigInfoBase{" + "id=" + id + ", dataId='" + dataId + '\'' + ", group='" + group + '\''
+ ", content='" + content + '\'' + ", md5='" + md5 + '\'' + '}';
}
}

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model;
/**
@ -24,10 +25,12 @@ public class ConfigInfoBaseEx extends ConfigInfoBase {
private static final long serialVersionUID = -1L;
//不能增加字段
/**
* 批量查询时, 单条数据的状态码, 具体的状态码在Constants.java中
*/
private int status;
/**
* 批量查询时, 单条数据的信息
*/
@ -41,8 +44,7 @@ public class ConfigInfoBaseEx extends ConfigInfoBase {
super(dataId, group, content);
}
public ConfigInfoBaseEx(String dataId, String group, String content,
int status, String message) {
public ConfigInfoBaseEx(String dataId, String group, String content, int status, String message) {
super(dataId, group, content);
this.status = status;
this.message = message;
@ -71,9 +73,8 @@ public class ConfigInfoBaseEx extends ConfigInfoBase {
@Override
public String toString() {
return "ConfigInfoBaseEx [status=" + status + ", message=" + message
+ ", dataId=" + getDataId() + ", group()=" + getGroup()
+ ", content()=" + getContent() + "]";
return "ConfigInfoBaseEx [status=" + status + ", message=" + message + ", dataId=" + getDataId() + ", group()="
+ getGroup() + ", content()=" + getContent() + "]";
}
@Override

View File

@ -20,6 +20,7 @@ package com.alibaba.nacos.config.server.model;
* @author <a href="mailto:liaochuntao@live.com">liaochuntao</a>
*/
public class ConfigInfoBetaWrapper extends ConfigInfo4Beta {
private static final long serialVersionUID = 4511997359365712505L;
private long lastModified;

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model;
import java.io.Serializable;
@ -25,8 +26,11 @@ import java.io.Serializable;
public class ConfigInfoChanged implements Serializable {
private static final long serialVersionUID = -1819539062100125171L;
private String dataId;
private String group;
private String tenant;
public ConfigInfoChanged(String dataId, String group, String tenant) {

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model;
/**
@ -28,6 +29,7 @@ public class ConfigInfoEx extends ConfigInfo {
* 批量查询时, 单条数据的状态码, 具体的状态码在Constants.java中
*/
private int status;
/**
* 批量查询时, 单条数据的信息
*/
@ -75,10 +77,8 @@ public class ConfigInfoEx extends ConfigInfo {
@Override
public String toString() {
return "ConfigInfoEx [status=" + status + ", message=" + message
+ ", dataId=" + getDataId() + ", group=" + getGroup()
+ ", appName=" + getAppName() + ", content=" + getContent()
+ "]";
return "ConfigInfoEx [status=" + status + ", message=" + message + ", dataId=" + getDataId() + ", group="
+ getGroup() + ", appName=" + getAppName() + ", content=" + getContent() + "]";
}
}

View File

@ -20,6 +20,7 @@ package com.alibaba.nacos.config.server.model;
* @author <a href="mailto:liaochuntao@live.com">liaochuntao</a>
*/
public class ConfigInfoTagWrapper extends ConfigInfo4Tag {
private static final long serialVersionUID = 4511997359365712505L;
private long lastModified;

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model;
/**
@ -21,6 +22,7 @@ package com.alibaba.nacos.config.server.model;
* @author Nacos
*/
public class ConfigInfoWrapper extends ConfigInfo {
private static final long serialVersionUID = 4511997359365712505L;
private long lastModified;

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model;
import java.io.Serializable;
@ -30,7 +31,9 @@ public class ConfigKey implements Serializable {
private static final long serialVersionUID = -1748953484511867580L;
private String appName;
private String dataId;
private String group;
public ConfigKey() {

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
@ -26,12 +27,16 @@ import java.io.Serializable;
* @author Nacos
*/
public class GroupInfo implements Serializable {
static final long serialVersionUID = -1L;
@JsonSerialize(using = ToStringSerializer.class)
private long id;
private String address;
private String group;
private String dataId;
public GroupInfo() {

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model;
import java.io.Serializable;
@ -46,8 +47,7 @@ public class GroupkeyListenserStatus implements Serializable {
return lisentersGroupkeyStatus;
}
public void setLisentersGroupkeyStatus(
Map<String, String> lisentersGroupkeyStatus) {
public void setLisentersGroupkeyStatus(Map<String, String> lisentersGroupkeyStatus) {
this.lisentersGroupkeyStatus = lisentersGroupkeyStatus;
}
}

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model;
import java.io.Serializable;
@ -25,14 +26,23 @@ import java.io.Serializable;
public class HistoryContext implements Serializable {
private static final long serialVersionUID = -8400843549603420766L;
public String serverId;
public String dataId;
public String group;
public String tenant;
private String appName;
public boolean success;
public int statusCode;
public String statusMsg;
public Page<ConfigHistoryInfo> configs;
public HistoryContext(String serverId, String dataId, String group, int statusCode, String statusMsg,

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model;
import java.io.Serializable;
@ -27,19 +28,24 @@ import java.util.List;
* @date 2010-5-6
*/
public class Page<E> implements Serializable {
static final long serialVersionUID = -1L;
/**
* 总记录数
*/
private int totalCount;
/**
* 页数
*/
private int pageNumber;
/**
* 总页数
*/
private int pagesAvailable;
/**
* 该页内容
*/

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model;
import java.io.Serializable;
@ -31,10 +32,15 @@ public class RestPageResult<T> implements Serializable {
private static final long serialVersionUID = -8048577763828650575L;
private int code;
private String message;
private int total;
private int pageSize;
private int currentPage;
private T data;
public int getCode() {

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model;
/**

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model;
import java.io.Serializable;
@ -36,8 +37,7 @@ public class SampleResult implements Serializable {
return lisentersGroupkeyStatus;
}
public void setLisentersGroupkeyStatus(
Map<String, String> lisentersGroupkeyStatus) {
public void setLisentersGroupkeyStatus(Map<String, String> lisentersGroupkeyStatus) {
this.lisentersGroupkeyStatus = lisentersGroupkeyStatus;
}

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model;
import java.io.Serializable;
@ -26,10 +27,15 @@ import java.sql.Timestamp;
public class SubInfo implements Serializable {
private static final long serialVersionUID = -3900485932969066685L;
private String appName;
private String dataId;
private String group;
private String localIp;
private Timestamp date;
public String getAppName() {

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model;
import java.io.Serializable;
@ -25,10 +26,15 @@ import java.io.Serializable;
public class SubscriberStatus implements Serializable {
private static final long serialVersionUID = 1065466896062351086L;
String groupKey;
String md5;
Long lastTime;
Boolean status;
String serverIp;
public SubscriberStatus() {

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model;
import java.io.Serializable;
@ -25,8 +26,11 @@ import java.io.Serializable;
public class TenantInfo implements Serializable {
private static final long serialVersionUID = -1498218072016383809L;
private String tenantId;
private String tenantName;
private String tenantDesc;
public String getTenantId() {

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model;
import java.io.Serializable;
@ -25,7 +26,9 @@ import java.io.Serializable;
public class User implements Serializable {
private static final long serialVersionUID = 3371769277802700069L;
private String username;
private String password;
public String getPassword() {

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model.app;
import com.alibaba.nacos.core.utils.InetUtils;
@ -25,6 +26,7 @@ import com.alibaba.nacos.core.utils.InetUtils;
public class ApplicationInfo {
private static final long LOCK_EXPIRE_DURATION = 30 * 1000L;
private static final long RECENTLY_DURATION = 24 * 60 * 60 * 1000L;
private String appName;
@ -61,8 +63,7 @@ public class ApplicationInfo {
return lastSubscribeInfoCollectedTime;
}
public void setLastSubscribeInfoCollectedTime(
long lastSubscribeInfoCollectedTime) {
public void setLastSubscribeInfoCollectedTime(long lastSubscribeInfoCollectedTime) {
this.lastSubscribeInfoCollectedTime = lastSubscribeInfoCollectedTime;
}
@ -78,8 +79,7 @@ public class ApplicationInfo {
return subInfoCollectLockExpireTime;
}
public void setSubInfoCollectLockExpireTime(
long subInfoCollectLockExpireTime) {
public void setSubInfoCollectLockExpireTime(long subInfoCollectLockExpireTime) {
this.subInfoCollectLockExpireTime = subInfoCollectLockExpireTime;
}
@ -91,8 +91,8 @@ public class ApplicationInfo {
}
public boolean canCurrentServerOwnTheLock() {
boolean currentOwnerIsMe = subInfoCollectLockOwner == null || InetUtils.getSelfIp()
.equals(subInfoCollectLockOwner);
boolean currentOwnerIsMe =
subInfoCollectLockOwner == null || InetUtils.getSelfIp().equals(subInfoCollectLockOwner);
if (currentOwnerIsMe) {
return true;

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model.app;
/**
@ -23,6 +24,7 @@ package com.alibaba.nacos.config.server.model.app;
public class ApplicationPublishRecord {
private String appName;
private GroupKey configInfo;
public ApplicationPublishRecord(String appName, String dataId, String groupId) {

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model.app;
import com.alibaba.nacos.config.server.utils.GroupKey2;
@ -25,6 +26,7 @@ import com.alibaba.nacos.config.server.utils.GroupKey2;
public class GroupKey extends GroupKey2 {
private String dataId;
private String group;
public GroupKey(String dataId, String group) {

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model.app;
/**
@ -21,42 +22,52 @@ package com.alibaba.nacos.config.server.model.app;
* @author Nacos
*/
public class MonitorInfo {
/**
* 可使用内存.
*/
private long totalMemory;
/**
* 剩余内存.
*/
private long freeMemory;
/**
* 最大可使用内存.
*/
private volatile long maxMemory;
/**
* cpu使用率.
*/
private double cpuRatio;
/**
* 系统负载.
*/
private double load;
/**
* ygc次数
*/
private int ygc;
/**
* ygc时间
*/
private double ygct;
/**
* fgc次数
*/
private int fgc;
/**
* fgc时间
*/
private double fgct;
/**
* gc时间
*/
@ -144,18 +155,9 @@ public class MonitorInfo {
@Override
public String toString() {
return "MonitorInfo{" +
"totalMemory=" + totalMemory +
", freeMemory=" + freeMemory +
", maxMemory=" + maxMemory +
", cpuRatio=" + cpuRatio +
", load=" + load +
", ygc=" + ygc +
", ygct=" + ygct +
", fgc=" + fgc +
", fgct=" + fgct +
", gct=" + gct +
'}';
return "MonitorInfo{" + "totalMemory=" + totalMemory + ", freeMemory=" + freeMemory + ", maxMemory=" + maxMemory
+ ", cpuRatio=" + cpuRatio + ", load=" + load + ", ygc=" + ygc + ", ygct=" + ygct + ", fgc=" + fgc
+ ", fgct=" + fgct + ", gct=" + gct + '}';
}
}

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model.capacity;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
@ -33,12 +34,19 @@ public class Capacity implements Serializable {
@JsonSerialize(using = ToStringSerializer.class)
private Long id;
private Integer quota;
private Integer usage;
private Integer maxSize;
private Integer maxAggrCount;
private Integer maxAggrSize;
private Timestamp gmtCreate;
private Timestamp gmtModified;
public Long getId() {

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model.capacity;
/**
@ -24,6 +25,7 @@ package com.alibaba.nacos.config.server.model.capacity;
public class GroupCapacity extends Capacity {
private static final long serialVersionUID = 5888791286289014878L;
private String group;
public String getGroup() {

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model.capacity;
/**
@ -24,6 +25,7 @@ package com.alibaba.nacos.config.server.model.capacity;
public class TenantCapacity extends Capacity {
private static final long serialVersionUID = -1238179608935781384L;
private String tenant;
public String getTenant() {

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model.event;
import com.alibaba.nacos.config.server.utils.event.EventDispatcher.Event;
@ -26,10 +27,15 @@ import org.apache.commons.lang3.StringUtils;
public class ConfigDataChangeEvent implements Event {
final public boolean isBeta;
final public String dataId;
final public String group;
final public String tenant;
final public String tag;
final public long lastModifiedTs;
public ConfigDataChangeEvent(String dataId, String group, long gmtModified) {

View File

@ -26,15 +26,25 @@ public class ConfigDumpEvent implements Event {
private static final long serialVersionUID = -8776888606458370294L;
private boolean remove;
private String namespaceId;
private String dataId;
private String group;
private boolean isBeta;
private String tag;
private String content;
private String betaIps;
private String handleIp;
private String type;
private long lastModifiedTs;
public boolean isRemove() {
@ -130,16 +140,27 @@ public class ConfigDumpEvent implements Event {
}
public static final class ConfigDumpEventBuilder {
private boolean remove;
private String namespaceId;
private String dataId;
private String group;
private boolean isBeta;
private String tag;
private String content;
private String betaIps;
private String handleIp;
private String type;
private long lastModifiedTs;
private ConfigDumpEventBuilder() {

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model.event;
import com.alibaba.nacos.config.server.utils.event.EventDispatcher.Event;
@ -25,9 +26,13 @@ import java.util.List;
* @author Nacos
*/
public class LocalDataChangeEvent implements Event {
final public String groupKey;
final public boolean isBeta;
final public List<String> betaIps;
final public String tag;
public LocalDataChangeEvent(String groupKey) {

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.model.event;
import com.alibaba.nacos.core.notify.SlowEvent;

View File

@ -20,7 +20,6 @@ import com.alibaba.nacos.common.JustForTest;
import com.alibaba.nacos.core.notify.Event;
/**
*
* @author <a href="mailto:liaochuntao@live.com">liaochuntao</a>
*/
@SuppressWarnings("PMD.ClassNamingShouldBeCamelRule")

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.monitor;
import com.alibaba.nacos.config.server.service.ClientTrackService;
@ -39,11 +40,10 @@ public class MemoryMonitor {
@Autowired
public MemoryMonitor(AsyncNotifyService notifySingleService) {
ConfigExecutor.scheduleWithFixedDelay(new PrintMemoryTask(), DELAY_SECONDS,
DELAY_SECONDS, TimeUnit.SECONDS);
ConfigExecutor.scheduleWithFixedDelay(new PrintMemoryTask(), DELAY_SECONDS, DELAY_SECONDS, TimeUnit.SECONDS);
ConfigExecutor.scheduleWithFixedDelay(new PrintGetConfigResponeTask(), DELAY_SECONDS,
DELAY_SECONDS, TimeUnit.SECONDS);
ConfigExecutor.scheduleWithFixedDelay(new PrintGetConfigResponeTask(), DELAY_SECONDS, DELAY_SECONDS,
TimeUnit.SECONDS);
ConfigExecutor.scheduleWithFixedDelay(new NotifyTaskQueueMonitorTask(notifySingleService), DELAY_SECONDS,
DELAY_SECONDS, TimeUnit.SECONDS);
@ -60,6 +60,7 @@ public class MemoryMonitor {
}
class PrintGetConfigResponeTask implements Runnable {
@Override
public void run() {
memoryLog.info(ResponseMonitor.getStringForPrint());
@ -80,6 +81,7 @@ class PrintMemoryTask implements Runnable {
}
class NotifyTaskQueueMonitorTask implements Runnable {
final private AsyncNotifyService notifySingleService;
NotifyTaskQueueMonitorTask(AsyncNotifyService notifySingleService) {

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.monitor;
import io.micrometer.core.instrument.*;
@ -27,11 +28,17 @@ import java.util.concurrent.atomic.AtomicInteger;
* @author Nacos
*/
public class MetricsMonitor {
private static AtomicInteger getConfig = new AtomicInteger();
private static AtomicInteger publish = new AtomicInteger();
private static AtomicInteger longPolling = new AtomicInteger();
private static AtomicInteger configCount = new AtomicInteger();
private static AtomicInteger notifyTask = new AtomicInteger();
private static AtomicInteger dumpTask = new AtomicInteger();
static {
@ -92,33 +99,27 @@ public class MetricsMonitor {
}
public static Timer getNotifyRtTimer() {
return Metrics.timer("nacos_timer",
"module", "config", "name", "notifyRt");
return Metrics.timer("nacos_timer", "module", "config", "name", "notifyRt");
}
public static Counter getIllegalArgumentException() {
return Metrics.counter("nacos_exception",
"module", "config", "name", "illegalArgument");
return Metrics.counter("nacos_exception", "module", "config", "name", "illegalArgument");
}
public static Counter getNacosException() {
return Metrics.counter("nacos_exception",
"module", "config", "name", "nacos");
return Metrics.counter("nacos_exception", "module", "config", "name", "nacos");
}
public static Counter getDbException() {
return Metrics.counter("nacos_exception",
"module", "config", "name", "db");
return Metrics.counter("nacos_exception", "module", "config", "name", "db");
}
public static Counter getConfigNotifyException() {
return Metrics.counter("nacos_exception",
"module", "config", "name", "configNotify");
return Metrics.counter("nacos_exception", "module", "config", "name", "configNotify");
}
public static Counter getUnhealthException() {
return Metrics.counter("nacos_exception",
"module", "config", "name", "unhealth");
return Metrics.counter("nacos_exception", "module", "config", "name", "unhealth");
}
}

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.monitor;
import java.text.DecimalFormat;
@ -24,14 +25,23 @@ import java.util.concurrent.atomic.AtomicLong;
* @author Nacos
*/
public class ResponseMonitor {
private static AtomicLong[] getConfigCountDetail = new AtomicLong[8];
private static AtomicLong getConfigCount = new AtomicLong();
private static final int MS_50 = 50;
private static final int MS_100 = 100;
private static final int MS_200 = 200;
private static final int MS_500 = 500;
private static final int MS_1000 = 1000;
private static final int MS_2000 = 2000;
private static final int MS_3000 = 3000;
static {
@ -68,18 +78,18 @@ public class ResponseMonitor {
public static String getStringForPrint() {
DecimalFormat df = new DecimalFormat("##.0");
StringBuilder s = new StringBuilder("getConfig monitor:\r\n");
s.append("0-50ms:" + df.format(getConfigCountDetail[0].getAndSet(0) * 100 / getConfigCount.get())).append(
"%\r\n");
s.append("100-200ms:" + df.format(getConfigCountDetail[2].getAndSet(0) * 100 / getConfigCount.get())).append(
"%\r\n");
s.append("200-500ms:" + df.format(getConfigCountDetail[3].getAndSet(0) * 100 / getConfigCount.get())).append(
"%\r\n");
s.append("500-1000ms:" + df.format(getConfigCountDetail[4].getAndSet(0) * 100 / getConfigCount.get())).append(
"%\r\n");
s.append("1000-2000ms:" + df.format(getConfigCountDetail[5].getAndSet(0) * 100 / getConfigCount.get())).append(
"%\r\n");
s.append("2000-3000ms:" + df.format(getConfigCountDetail[6].getAndSet(0) * 100 / getConfigCount.get())).append(
"%\r\n");
s.append("0-50ms:" + df.format(getConfigCountDetail[0].getAndSet(0) * 100 / getConfigCount.get()))
.append("%\r\n");
s.append("100-200ms:" + df.format(getConfigCountDetail[2].getAndSet(0) * 100 / getConfigCount.get()))
.append("%\r\n");
s.append("200-500ms:" + df.format(getConfigCountDetail[3].getAndSet(0) * 100 / getConfigCount.get()))
.append("%\r\n");
s.append("500-1000ms:" + df.format(getConfigCountDetail[4].getAndSet(0) * 100 / getConfigCount.get()))
.append("%\r\n");
s.append("1000-2000ms:" + df.format(getConfigCountDetail[5].getAndSet(0) * 100 / getConfigCount.get()))
.append("%\r\n");
s.append("2000-3000ms:" + df.format(getConfigCountDetail[6].getAndSet(0) * 100 / getConfigCount.get()))
.append("%\r\n");
s.append("3000以上ms:" + df.format(getConfigCountDetail[7].getAndSet(0) * 100 / getConfigCount.getAndSet(0)))
.append("%\r\n");
return s.toString();

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.result;
import com.alibaba.nacos.common.model.RestResult;

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.result.code;
import com.alibaba.nacos.config.server.result.core.IResultCode;
@ -46,7 +47,6 @@ public enum ResultCodeEnum implements IResultCode {
NO_SELECTED_CONFIG(100006, "没有选择任何配制"),
;
private int code;

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.result.core;
/**
@ -26,20 +27,20 @@ public interface IResultCode {
/**
* get the result code
*
* @return java.lang.String
* @author klw
* @Date 2019/6/28 14:56
* @Param []
* @return java.lang.String
*/
int getCode();
/**
* get the result code's message
*
* @return java.lang.String
* @author klw
* @Date 2019/6/28 14:56
* @Param []
* @return java.lang.String
*/
String getCodeMsg();
}

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.service;
import com.alibaba.nacos.common.utils.IoUtils;

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.service;
import com.alibaba.nacos.config.server.model.ACLInfo;
@ -73,8 +74,7 @@ public class ClientIpWhiteList {
isOpen = acl.getIsOpen();
CLIENT_IP_WHITELIST.set(acl.getIps());
} catch (Exception ioe) {
defaultLog.error(
"failed to load clientIpWhiteList, " + ioe.toString(), ioe);
defaultLog.error("failed to load clientIpWhiteList, " + ioe.toString(), ioe);
}
}
@ -84,5 +84,6 @@ public class ClientIpWhiteList {
static final AtomicReference<List<String>> CLIENT_IP_WHITELIST = new AtomicReference<List<String>>(
new ArrayList<String>());
static Boolean isOpen = false;
}

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.service;
import com.alibaba.nacos.config.server.model.SubscriberStatus;
@ -28,6 +29,7 @@ import java.util.concurrent.ConcurrentMap;
* @author Nacos
*/
public class ClientTrackService {
/**
* 跟踪客户端md5.
*/
@ -168,9 +170,13 @@ public class ClientTrackService {
* 保存客户端拉数据的记录
*/
class ClientRecord {
final String ip;
volatile long lastTime;
final ConcurrentMap<String, String> groupKey2md5Map;
final ConcurrentMap<String, Long> groupKey2pollingTsMap;
ClientRecord(String clientIp) {

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.service;
import com.alibaba.nacos.common.utils.MD5Utils;
@ -59,7 +60,8 @@ public class ConfigCacheService {
/**
* 保存配置文件并缓存md5.
*/
static public boolean dump(String dataId, String group, String tenant, String content, long lastModifiedTs, String type) {
static public boolean dump(String dataId, String group, String tenant, String content, long lastModifiedTs,
String type) {
String groupKey = GroupKey2.getKey(dataId, group, tenant);
CacheItem ci = makeSure(groupKey);
ci.setType(type);
@ -75,10 +77,9 @@ public class ConfigCacheService {
final String md5 = MD5Utils.md5Hex(content, Constants.ENCODE);
if (md5.equals(ConfigCacheService.getContentMd5(groupKey))) {
dumpLog.warn(
"[dump-ignore] ignore to save cache file. groupKey={}, md5={}, lastModifiedOld={}, "
+ "lastModifiedNew={}",
groupKey, md5, ConfigCacheService.getLastModifiedTs(groupKey), lastModifiedTs);
dumpLog.warn("[dump-ignore] ignore to save cache file. groupKey={}, md5={}, lastModifiedOld={}, "
+ "lastModifiedNew={}", groupKey, md5, ConfigCacheService.getLastModifiedTs(groupKey),
lastModifiedTs);
} else if (!PropertyUtil.isDirectRead()) {
DiskUtil.saveToDisk(dataId, group, tenant, content);
}
@ -88,8 +89,8 @@ public class ConfigCacheService {
dumpLog.error("[dump-exception] save disk error. " + groupKey + ", " + ioe.toString(), ioe);
if (ioe.getMessage() != null) {
String errMsg = ioe.getMessage();
if (NO_SPACE_CN.equals(errMsg) || NO_SPACE_EN.equals(errMsg) || errMsg.contains(DISK_QUATA_CN)
|| errMsg.contains(DISK_QUATA_EN)) {
if (NO_SPACE_CN.equals(errMsg) || NO_SPACE_EN.equals(errMsg) || errMsg.contains(DISK_QUATA_CN) || errMsg
.contains(DISK_QUATA_EN)) {
// 磁盘写满保护代码
fatalLog.error("磁盘满自杀退出", ioe);
System.exit(0);
@ -120,10 +121,9 @@ public class ConfigCacheService {
try {
final String md5 = MD5Utils.md5Hex(content, Constants.ENCODE);
if (md5.equals(ConfigCacheService.getContentBetaMd5(groupKey))) {
dumpLog.warn(
"[dump-beta-ignore] ignore to save cache file. groupKey={}, md5={}, lastModifiedOld={}, "
+ "lastModifiedNew={}",
groupKey, md5, ConfigCacheService.getLastModifiedTs(groupKey), lastModifiedTs);
dumpLog.warn("[dump-beta-ignore] ignore to save cache file. groupKey={}, md5={}, lastModifiedOld={}, "
+ "lastModifiedNew={}", groupKey, md5, ConfigCacheService.getLastModifiedTs(groupKey),
lastModifiedTs);
} else if (!PropertyUtil.isDirectRead()) {
DiskUtil.saveBetaToDisk(dataId, group, tenant, content);
}
@ -132,8 +132,7 @@ public class ConfigCacheService {
updateBetaMd5(groupKey, md5, Arrays.asList(betaIpsArr), lastModifiedTs);
return true;
} catch (IOException ioe) {
dumpLog.error("[dump-beta-exception] save disk error. " + groupKey + ", " + ioe.toString(),
ioe);
dumpLog.error("[dump-beta-exception] save disk error. " + groupKey + ", " + ioe.toString(), ioe);
return false;
} finally {
releaseWriteLock(groupKey);
@ -159,10 +158,9 @@ public class ConfigCacheService {
try {
final String md5 = MD5Utils.md5Hex(content, Constants.ENCODE);
if (md5.equals(ConfigCacheService.getContentTagMd5(groupKey, tag))) {
dumpLog.warn(
"[dump-tag-ignore] ignore to save cache file. groupKey={}, md5={}, lastModifiedOld={}, "
+ "lastModifiedNew={}",
groupKey, md5, ConfigCacheService.getLastModifiedTs(groupKey), lastModifiedTs);
dumpLog.warn("[dump-tag-ignore] ignore to save cache file. groupKey={}, md5={}, lastModifiedOld={}, "
+ "lastModifiedNew={}", groupKey, md5, ConfigCacheService.getLastModifiedTs(groupKey),
lastModifiedTs);
} else if (!PropertyUtil.isDirectRead()) {
DiskUtil.saveTagToDisk(dataId, group, tenant, tag, content);
}
@ -170,8 +168,7 @@ public class ConfigCacheService {
updateTagMd5(groupKey, tag, md5, lastModifiedTs);
return true;
} catch (IOException ioe) {
dumpLog.error("[dump-tag-exception] save disk error. " + groupKey + ", " + ioe.toString(),
ioe);
dumpLog.error("[dump-tag-exception] save disk error. " + groupKey + ", " + ioe.toString(), ioe);
return false;
} finally {
releaseWriteLock(groupKey);
@ -198,10 +195,9 @@ public class ConfigCacheService {
if (!PropertyUtil.isDirectRead()) {
String loacalMd5 = DiskUtil.getLocalConfigMd5(dataId, group, tenant);
if (md5.equals(loacalMd5)) {
dumpLog.warn(
"[dump-ignore] ignore to save cache file. groupKey={}, md5={}, lastModifiedOld={}, "
+ "lastModifiedNew={}",
groupKey, md5, ConfigCacheService.getLastModifiedTs(groupKey), lastModifiedTs);
dumpLog.warn("[dump-ignore] ignore to save cache file. groupKey={}, md5={}, lastModifiedOld={}, "
+ "lastModifiedNew={}", groupKey, md5, ConfigCacheService.getLastModifiedTs(groupKey),
lastModifiedTs);
} else {
DiskUtil.saveToDisk(dataId, group, tenant, content);
}
@ -209,8 +205,7 @@ public class ConfigCacheService {
updateMd5(groupKey, md5, lastModifiedTs);
return true;
} catch (IOException ioe) {
dumpLog.error("[dump-exception] save disk error. " + groupKey + ", " + ioe.toString(),
ioe);
dumpLog.error("[dump-exception] save disk error. " + groupKey + ", " + ioe.toString(), ioe);
return false;
} finally {
releaseWriteLock(groupKey);
@ -221,14 +216,13 @@ public class ConfigCacheService {
String aggreds = null;
try {
if (PropertyUtil.isEmbeddedStorage()) {
ConfigInfoBase config = persistService.findConfigInfoBase(AggrWhitelist.AGGRIDS_METADATA,
"DEFAULT_GROUP");
ConfigInfoBase config = persistService
.findConfigInfoBase(AggrWhitelist.AGGRIDS_METADATA, "DEFAULT_GROUP");
if (config != null) {
aggreds = config.getContent();
}
} else {
aggreds = DiskUtil.getConfig(AggrWhitelist.AGGRIDS_METADATA,
"DEFAULT_GROUP", StringUtils.EMPTY);
aggreds = DiskUtil.getConfig(AggrWhitelist.AGGRIDS_METADATA, "DEFAULT_GROUP", StringUtils.EMPTY);
}
if (aggreds != null) {
AggrWhitelist.load(aggreds);
@ -240,34 +234,33 @@ public class ConfigCacheService {
String clientIpWhitelist = null;
try {
if (PropertyUtil.isEmbeddedStorage()) {
ConfigInfoBase config = persistService.findConfigInfoBase(
ClientIpWhiteList.CLIENT_IP_WHITELIST_METADATA, "DEFAULT_GROUP");
ConfigInfoBase config = persistService
.findConfigInfoBase(ClientIpWhiteList.CLIENT_IP_WHITELIST_METADATA, "DEFAULT_GROUP");
if (config != null) {
clientIpWhitelist = config.getContent();
}
} else {
clientIpWhitelist = DiskUtil.getConfig(ClientIpWhiteList.CLIENT_IP_WHITELIST_METADATA, "DEFAULT_GROUP",
StringUtils.EMPTY);
clientIpWhitelist = DiskUtil
.getConfig(ClientIpWhiteList.CLIENT_IP_WHITELIST_METADATA, "DEFAULT_GROUP", StringUtils.EMPTY);
}
if (clientIpWhitelist != null) {
ClientIpWhiteList.load(clientIpWhitelist);
}
} catch (IOException e) {
dumpLog.error("reload fail:"
+ ClientIpWhiteList.CLIENT_IP_WHITELIST_METADATA, e);
dumpLog.error("reload fail:" + ClientIpWhiteList.CLIENT_IP_WHITELIST_METADATA, e);
}
String switchContent = null;
try {
if (PropertyUtil.isEmbeddedStorage()) {
ConfigInfoBase config = persistService.findConfigInfoBase(SwitchService.SWITCH_META_DATAID,
"DEFAULT_GROUP");
ConfigInfoBase config = persistService
.findConfigInfoBase(SwitchService.SWITCH_META_DATAID, "DEFAULT_GROUP");
if (config != null) {
switchContent = config.getContent();
}
} else {
switchContent = DiskUtil.getConfig(
SwitchService.SWITCH_META_DATAID, "DEFAULT_GROUP", StringUtils.EMPTY);
switchContent = DiskUtil
.getConfig(SwitchService.SWITCH_META_DATAID, "DEFAULT_GROUP", StringUtils.EMPTY);
}
if (switchContent != null) {
SwitchService.load(switchContent);
@ -290,18 +283,15 @@ public class ConfigCacheService {
try {
String loacalMd5 = DiskUtil.getLocalConfigMd5(dataId, group, tenant);
if (!entry.getValue().md5.equals(loacalMd5)) {
defaultLog.warn("[md5-different] dataId:{},group:{}",
dataId, group);
defaultLog.warn("[md5-different] dataId:{},group:{}", dataId, group);
diffList.add(groupKey);
}
} catch (IOException e) {
defaultLog.error("getLocalConfigMd5 fail,dataId:{},group:{}",
dataId, group);
defaultLog.error("getLocalConfigMd5 fail,dataId:{},group:{}", dataId, group);
}
}
long endTime = System.currentTimeMillis();
defaultLog.warn("checkMd5 cost:{}; diffCount:{}", endTime - startTime,
diffList.size());
defaultLog.warn("checkMd5 cost:{}; diffCount:{}", endTime - startTime, diffList.size());
return diffList;
}
@ -583,14 +573,18 @@ public class ConfigCacheService {
}
private final static String NO_SPACE_CN = "设备上没有空间";
private final static String NO_SPACE_EN = "No space left on device";
private final static String DISK_QUATA_CN = "超出磁盘限额";
private final static String DISK_QUATA_EN = "Disk quota exceeded";
static final Logger log = LoggerFactory.getLogger(ConfigCacheService.class);
/**
* groupKey -> cacheItem
*/
static private final ConcurrentHashMap<String, CacheItem> CACHE =
new ConcurrentHashMap<String, CacheItem>();
static private final ConcurrentHashMap<String, CacheItem> CACHE = new ConcurrentHashMap<String, CacheItem>();
}

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.service;
import com.alibaba.nacos.common.utils.ThreadUtils;
@ -28,6 +29,7 @@ import org.apache.commons.lang3.StringUtils;
import com.fasterxml.jackson.core.type.TypeReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.net.HttpURLConnection;
import java.net.URLEncoder;
import java.util.ArrayList;
@ -54,8 +56,7 @@ public class ConfigSubService {
public ConfigSubService(ServerMemberManager memberManager) {
this.memberManager = memberManager;
scheduler = Executors.newScheduledThreadPool(
ThreadUtils.getSuitableThreadCount(), new ThreadFactory() {
scheduler = Executors.newScheduledThreadPool(ThreadUtils.getSuitableThreadCount(), new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r);
@ -82,28 +83,24 @@ public class ConfigSubService {
}
private List<SampleResult> runCollectionJob(String url, Map<String, String> params,
CompletionService<SampleResult> completionService,
List<SampleResult> resultList) {
CompletionService<SampleResult> completionService, List<SampleResult> resultList) {
Collection<Member> ipList = memberManager.allMembers();
List<SampleResult> collectionResult = new ArrayList<SampleResult>(
ipList.size());
List<SampleResult> collectionResult = new ArrayList<SampleResult>(ipList.size());
// 提交查询任务
for (Member ip : ipList) {
try {
completionService.submit(new Job(ip.getAddress(), url, params));
} catch (Exception e) { // 发送请求失败
LogUtil.defaultLog
.warn("Get client info from {} with exception: {} during submit job",
ip, e.getMessage());
.warn("Get client info from {} with exception: {} during submit job", ip, e.getMessage());
}
}
// 获取结果并合并
SampleResult sampleResults = null;
for (Member member : ipList) {
try {
Future<SampleResult> f = completionService.poll(1000,
TimeUnit.MILLISECONDS);
Future<SampleResult> f = completionService.poll(1000, TimeUnit.MILLISECONDS);
try {
if (f != null) {
sampleResults = f.get(500, TimeUnit.MILLISECONDS);
@ -111,26 +108,18 @@ public class ConfigSubService {
collectionResult.add(sampleResults);
}
} else {
LogUtil.defaultLog
.warn("The task in ip: {} did not completed in 1000ms ",
member);
LogUtil.defaultLog.warn("The task in ip: {} did not completed in 1000ms ", member);
}
} catch (TimeoutException e) {
if (f != null) {
f.cancel(true);
}
LogUtil.defaultLog.warn(
"get task result with TimeoutException: {} ", e
.getMessage());
LogUtil.defaultLog.warn("get task result with TimeoutException: {} ", e.getMessage());
}
} catch (InterruptedException e) {
LogUtil.defaultLog.warn(
"get task result with InterruptedException: {} ", e
.getMessage());
LogUtil.defaultLog.warn("get task result with InterruptedException: {} ", e.getMessage());
} catch (ExecutionException e) {
LogUtil.defaultLog.warn(
"get task result with ExecutionException: {} ", e
.getMessage());
LogUtil.defaultLog.warn("get task result with ExecutionException: {} ", e.getMessage());
}
}
return collectionResult;
@ -139,8 +128,8 @@ public class ConfigSubService {
public SampleResult mergeSampleResult(SampleResult sampleCollectResult, List<SampleResult> sampleResults) {
SampleResult mergeResult = new SampleResult();
Map<String, String> lisentersGroupkeyStatus = null;
if (sampleCollectResult.getLisentersGroupkeyStatus() == null
|| sampleCollectResult.getLisentersGroupkeyStatus().isEmpty()) {
if (sampleCollectResult.getLisentersGroupkeyStatus() == null || sampleCollectResult.getLisentersGroupkeyStatus()
.isEmpty()) {
lisentersGroupkeyStatus = new HashMap<String, String>(10);
} else {
lisentersGroupkeyStatus = sampleCollectResult.getLisentersGroupkeyStatus();
@ -162,8 +151,11 @@ public class ConfigSubService {
* @author Nacos
*/
class Job implements Callable<SampleResult> {
private String ip;
private String url;
private Map<String, String> params;
public Job(String ip, String url, Map<String, String> params) {
@ -190,22 +182,17 @@ public class ConfigSubService {
*/
if (result.code == HttpURLConnection.HTTP_OK) {
String json = result.content;
SampleResult resultObj = JSONUtils.deserializeObject(json,
new TypeReference<SampleResult>() {
SampleResult resultObj = JSONUtils.deserializeObject(json, new TypeReference<SampleResult>() {
});
return resultObj;
} else {
LogUtil.defaultLog.info(
"Can not get clientInfo from {} with {}", ip,
result.code);
LogUtil.defaultLog.info("Can not get clientInfo from {} with {}", ip, result.code);
return null;
}
} catch (Exception e) {
LogUtil.defaultLog.warn(
"Get client info from {} with exception: {}", ip, e
.getMessage());
LogUtil.defaultLog.warn("Get client info from {} with exception: {}", ip, e.getMessage());
return null;
}
}
@ -236,8 +223,7 @@ public class ConfigSubService {
return sampleCollectResult;
}
public SampleResult getCollectSampleResultByIp(String ip, int sampleTime)
throws Exception {
public SampleResult getCollectSampleResultByIp(String ip, int sampleTime) throws Exception {
List<SampleResult> resultList = new ArrayList<SampleResult>(10);
String url = Constants.COMMUNICATION_CONTROLLER_PATH + "/watcherConfigs";
Map<String, String> params = new HashMap<String, String>(50);

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.service;
import com.alibaba.nacos.common.utils.CollectionUtils;
@ -133,8 +134,8 @@ public class LongPollingService extends AbstractEventListener {
}
HashMap<String, Set<String>> app2Groupkeys = new HashMap<String, Set<String>>(50);
for (ClientLongPolling clientLongPolling : allSubs) {
if (StringUtils.isEmpty(clientLongPolling.appName) || "unknown".equalsIgnoreCase(
clientLongPolling.appName)) {
if (StringUtils.isEmpty(clientLongPolling.appName) || "unknown"
.equalsIgnoreCase(clientLongPolling.appName)) {
continue;
}
Set<String> appSubscribeConfigs = app2Groupkeys.get(clientLongPolling.appName);
@ -175,8 +176,8 @@ public class LongPollingService extends AbstractEventListener {
for (int i = 0; i < SAMPLE_TIMES; i++) {
SampleResult sampleTmp = getSubscribleInfoByIp(ip);
if (sampleTmp != null) {
if (sampleTmp.getLisentersGroupkeyStatus() != null
&& !sampleResult.getLisentersGroupkeyStatus().equals(sampleTmp.getLisentersGroupkeyStatus())) {
if (sampleTmp.getLisentersGroupkeyStatus() != null && !sampleResult.getLisentersGroupkeyStatus()
.equals(sampleTmp.getLisentersGroupkeyStatus())) {
sampleResult.getLisentersGroupkeyStatus().putAll(sampleTmp.getLisentersGroupkeyStatus());
}
}
@ -227,9 +228,9 @@ public class LongPollingService extends AbstractEventListener {
List<String> changedGroups = MD5Util.compareMd5(req, rsp, clientMd5Map);
if (changedGroups.size() > 0) {
generateResponse(req, rsp, changedGroups);
LogUtil.clientLog.info("{}|{}|{}|{}|{}|{}|{}",
System.currentTimeMillis() - start, "instant", RequestUtil.getRemoteIp(req), "polling",
clientMd5Map.size(), probeRequestSize, changedGroups.size());
LogUtil.clientLog.info("{}|{}|{}|{}|{}|{}|{}", System.currentTimeMillis() - start, "instant",
RequestUtil.getRemoteIp(req), "polling", clientMd5Map.size(), probeRequestSize,
changedGroups.size());
return;
} else if (noHangUpFlag != null && noHangUpFlag.equalsIgnoreCase(TRUE_STR)) {
LogUtil.clientLog.info("{}|{}|{}|{}|{}|{}|{}", System.currentTimeMillis() - start, "nohangup",
@ -290,6 +291,7 @@ public class LongPollingService extends AbstractEventListener {
// =================
static public final String LONG_POLLING_HEADER = "Long-Pulling-Timeout";
static public final String LONG_POLLING_NO_HANG_UP_HEADER = "Long-Pulling-Timeout-No-Hangup";
final ScheduledExecutorService scheduler;
@ -302,6 +304,7 @@ public class LongPollingService extends AbstractEventListener {
// =================
class DataChangeTask implements Runnable {
@Override
public void run() {
try {
@ -321,12 +324,11 @@ public class LongPollingService extends AbstractEventListener {
getRetainIps().put(clientSub.ip, System.currentTimeMillis());
iter.remove(); // 删除订阅关系
LogUtil.clientLog.info("{}|{}|{}|{}|{}|{}|{}",
(System.currentTimeMillis() - changeTime),
"in-advance",
RequestUtil.getRemoteIp((HttpServletRequest)clientSub.asyncContext.getRequest()),
"polling",
clientSub.clientMd5Map.size(), clientSub.probeRequestSize, groupKey);
LogUtil.clientLog
.info("{}|{}|{}|{}|{}|{}|{}", (System.currentTimeMillis() - changeTime), "in-advance",
RequestUtil
.getRemoteIp((HttpServletRequest) clientSub.asyncContext.getRequest()),
"polling", clientSub.clientMd5Map.size(), clientSub.probeRequestSize, groupKey);
clientSub.sendResponse(Arrays.asList(groupKey));
}
}
@ -347,15 +349,20 @@ public class LongPollingService extends AbstractEventListener {
}
final String groupKey;
final long changeTime = System.currentTimeMillis();
final boolean isBeta;
final List<String> betaIps;
final String tag;
}
// =================
class StatTask implements Runnable {
@Override
public void run() {
memoryLog.info("[long-pulling] client count " + allSubs.size());
@ -380,13 +387,12 @@ public class LongPollingService extends AbstractEventListener {
allSubs.remove(ClientLongPolling.this);
if (isFixedPolling()) {
LogUtil.clientLog.info("{}|{}|{}|{}|{}|{}",
(System.currentTimeMillis() - createTime),
"fix", RequestUtil.getRemoteIp((HttpServletRequest)asyncContext.getRequest()),
"polling",
clientMd5Map.size(), probeRequestSize);
List<String> changedGroups = MD5Util.compareMd5(
(HttpServletRequest)asyncContext.getRequest(),
LogUtil.clientLog
.info("{}|{}|{}|{}|{}|{}", (System.currentTimeMillis() - createTime), "fix",
RequestUtil.getRemoteIp((HttpServletRequest) asyncContext.getRequest()),
"polling", clientMd5Map.size(), probeRequestSize);
List<String> changedGroups = MD5Util
.compareMd5((HttpServletRequest) asyncContext.getRequest(),
(HttpServletResponse) asyncContext.getResponse(), clientMd5Map);
if (changedGroups.size() > 0) {
sendResponse(changedGroups);
@ -394,11 +400,10 @@ public class LongPollingService extends AbstractEventListener {
sendResponse(null);
}
} else {
LogUtil.clientLog.info("{}|{}|{}|{}|{}|{}",
(System.currentTimeMillis() - createTime),
"timeout", RequestUtil.getRemoteIp((HttpServletRequest)asyncContext.getRequest()),
"polling",
clientMd5Map.size(), probeRequestSize);
LogUtil.clientLog
.info("{}|{}|{}|{}|{}|{}", (System.currentTimeMillis() - createTime), "timeout",
RequestUtil.getRemoteIp((HttpServletRequest) asyncContext.getRequest()),
"polling", clientMd5Map.size(), probeRequestSize);
sendResponse(null);
}
} catch (Throwable t) {
@ -464,22 +469,28 @@ public class LongPollingService extends AbstractEventListener {
// =================
final AsyncContext asyncContext;
final Map<String, String> clientMd5Map;
final long createTime;
final String ip;
final String appName;
final String tag;
final int probeRequestSize;
final long timeoutTime;
Future<?> asyncTimeoutFuture;
@Override
public String toString() {
return "ClientLongPolling{" + "clientMd5Map=" + clientMd5Map + ", createTime="
+ createTime + ", ip='" + ip + '\'' + ", appName='" + appName + '\''
+ ", tag='" + tag + '\'' + ", probeRequestSize=" + probeRequestSize
+ ", timeoutTime=" + timeoutTime + '}';
return "ClientLongPolling{" + "clientMd5Map=" + clientMd5Map + ", createTime=" + createTime + ", ip='" + ip
+ '\'' + ", appName='" + appName + '\'' + ", tag='" + tag + '\'' + ", probeRequestSize="
+ probeRequestSize + ", timeoutTime=" + timeoutTime + '}';
}
}

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.service;
import com.alibaba.nacos.common.utils.IoUtils;
@ -35,9 +36,11 @@ import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog;
*/
@Service
public class SwitchService {
public static final String SWITCH_META_DATAID = "com.alibaba.nacos.meta.switch";
public static final String FIXED_POLLING = "isFixedPolling";
public static final String FIXED_POLLING_INTERVAL = "fixedPollingInertval";
public static final String FIXED_DELAY_TIME = "fixedDelayTime";

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.service.capacity;
import com.alibaba.nacos.config.server.constant.CounterMode;
@ -49,15 +50,19 @@ import java.util.concurrent.TimeUnit;
*/
@Service
public class CapacityService {
private static final Logger LOGGER = LoggerFactory.getLogger(CapacityService.class);
private static final Integer ZERO = 0;
private static final int INIT_PAGE_SIZE = 500;
@Autowired
private GroupCapacityPersistService groupCapacityPersistService;
@Autowired
private TenantCapacityPersistService tenantCapacityPersistService;
@Autowired
private PersistService persistService;
@ -67,8 +72,8 @@ public class CapacityService {
@SuppressWarnings("PMD.ThreadPoolCreationRule")
public void init() {
// 每个Server都有修正usage的Job在跑幂等
ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat(
"com.alibaba.nacos.CapacityManagement-%d").setDaemon(true).build();
ThreadFactory threadFactory = new ThreadFactoryBuilder()
.setNameFormat("com.alibaba.nacos.CapacityManagement-%d").setDaemon(true).build();
scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(threadFactory);
scheduledExecutorService.scheduleWithFixedDelay(new Runnable() {
@Override
@ -142,8 +147,8 @@ public class CapacityService {
long lastId = 0;
int pageSize = 100;
while (true) {
List<GroupCapacity> groupCapacityList = groupCapacityPersistService.getCapacityList4CorrectUsage(lastId,
pageSize);
List<GroupCapacity> groupCapacityList = groupCapacityPersistService
.getCapacityList4CorrectUsage(lastId, pageSize);
if (groupCapacityList.isEmpty()) {
break;
}
@ -167,8 +172,8 @@ public class CapacityService {
long lastId = 0;
int pageSize = 100;
while (true) {
List<TenantCapacity> tenantCapacityList = tenantCapacityPersistService.getCapacityList4CorrectUsage(lastId,
pageSize);
List<TenantCapacity> tenantCapacityList = tenantCapacityPersistService
.getCapacityList4CorrectUsage(lastId, pageSize);
if (tenantCapacityList.isEmpty()) {
break;
}
@ -197,13 +202,13 @@ public class CapacityService {
if (capacity == null) {
insertGroupCapacity(GroupCapacityPersistService.CLUSTER);
}
return updateGroupUsage(counterMode, GroupCapacityPersistService.CLUSTER,
PropertyUtil.getDefaultClusterQuota(), ignoreQuotaLimit);
return updateGroupUsage(counterMode, GroupCapacityPersistService.CLUSTER, PropertyUtil.getDefaultClusterQuota(),
ignoreQuotaLimit);
}
public boolean updateClusterUsage(CounterMode counterMode) {
return updateGroupUsage(counterMode, GroupCapacityPersistService.CLUSTER,
PropertyUtil.getDefaultClusterQuota(), false);
return updateGroupUsage(counterMode, GroupCapacityPersistService.CLUSTER, PropertyUtil.getDefaultClusterQuota(),
false);
}
/**
@ -266,12 +271,13 @@ public class CapacityService {
int finalQuota = (int) (usage + defaultQuota * (1.0 * initialExpansionPercent / 100));
if (tenant != null) {
tenantCapacityPersistService.updateQuota(tenant, finalQuota);
LogUtil.defaultLog.warn("[capacityManagement] 初始化的时候该租户({})使用量({})就已经到达限额{},自动扩容到{}", tenant,
usage, defaultQuota, finalQuota);
LogUtil.defaultLog
.warn("[capacityManagement] 初始化的时候该租户({})使用量({})就已经到达限额{},自动扩容到{}", tenant, usage, defaultQuota,
finalQuota);
} else {
groupCapacityPersistService.updateQuota(group, finalQuota);
LogUtil.defaultLog.warn("[capacityManagement] 初始化的时候该Group{})使用量({})就已经到达限额{},自动扩容到{}", group,
usage, defaultQuota, finalQuota);
LogUtil.defaultLog.warn("[capacityManagement] 初始化的时候该Group{})使用量({})就已经到达限额{},自动扩容到{}", group, usage,
defaultQuota, finalQuota);
}
}
}
@ -480,15 +486,14 @@ public class CapacityService {
* @param maxSize 配置内容content大小限制
* @return 是否操作成功
*/
public boolean insertOrUpdateCapacity(String group, String tenant, Integer quota, Integer maxSize, Integer
maxAggrCount, Integer maxAggrSize) {
public boolean insertOrUpdateCapacity(String group, String tenant, Integer quota, Integer maxSize,
Integer maxAggrCount, Integer maxAggrSize) {
if (StringUtils.isNotBlank(tenant)) {
Capacity capacity = tenantCapacityPersistService.getTenantCapacity(tenant);
if (capacity == null) {
return initTenantCapacity(tenant, quota, maxSize, maxAggrCount, maxAggrSize);
}
return tenantCapacityPersistService.updateTenantCapacity(tenant, quota, maxSize, maxAggrCount,
maxAggrSize);
return tenantCapacityPersistService.updateTenantCapacity(tenant, quota, maxSize, maxAggrCount, maxAggrSize);
}
Capacity capacity = groupCapacityPersistService.getGroupCapacity(group);
if (capacity == null) {

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.service.capacity;
import com.alibaba.nacos.config.server.model.capacity.Capacity;
@ -43,10 +44,11 @@ import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog;
*/
@Service
public class GroupCapacityPersistService {
static final String CLUSTER = "";
private static final GroupCapacityRowMapper
GROUP_CAPACITY_ROW_MAPPER = new GroupCapacityRowMapper();
private static final GroupCapacityRowMapper GROUP_CAPACITY_ROW_MAPPER = new GroupCapacityRowMapper();
private JdbcTemplate jdbcTemplate;
private DataSourceService dataSourceService;
@ -57,8 +59,8 @@ public class GroupCapacityPersistService {
this.jdbcTemplate = dataSourceService.getJdbcTemplate();
}
private static final class GroupCapacityRowMapper implements
RowMapper<GroupCapacity> {
private static final class GroupCapacityRowMapper implements RowMapper<GroupCapacity> {
@Override
public GroupCapacity mapRow(ResultSet rs, int rowNum) throws SQLException {
GroupCapacity groupCapacity = new GroupCapacity();
@ -74,11 +76,10 @@ public class GroupCapacityPersistService {
}
public GroupCapacity getGroupCapacity(String groupId) {
String sql
= "SELECT id, quota, `usage`, `max_size`, max_aggr_count, max_aggr_size, group_id FROM group_capacity "
String sql =
"SELECT id, quota, `usage`, `max_size`, max_aggr_count, max_aggr_size, group_id FROM group_capacity "
+ "WHERE group_id=?";
List<GroupCapacity> list = jdbcTemplate.query(sql, new Object[] {groupId},
GROUP_CAPACITY_ROW_MAPPER);
List<GroupCapacity> list = jdbcTemplate.query(sql, new Object[] {groupId}, GROUP_CAPACITY_ROW_MAPPER);
if (list.isEmpty()) {
return null;
}
@ -92,13 +93,11 @@ public class GroupCapacityPersistService {
public boolean insertGroupCapacity(final GroupCapacity capacity) {
String sql;
if (CLUSTER.equals(capacity.getGroup())) {
sql
= "insert into group_capacity (group_id, quota, `usage`, `max_size`, max_aggr_count, max_aggr_size, "
sql = "insert into group_capacity (group_id, quota, `usage`, `max_size`, max_aggr_count, max_aggr_size, "
+ "gmt_create, gmt_modified) select ?, ?, count(*), ?, ?, ?, ?, ? from config_info;";
} else {
// 注意这里要加"tenant_id = ''"条件
sql =
"insert into group_capacity (group_id, quota, `usage`, `max_size`, max_aggr_count, max_aggr_size, "
sql = "insert into group_capacity (group_id, quota, `usage`, `max_size`, max_aggr_count, max_aggr_size, "
+ "gmt_create, gmt_modified) select ?, ?, count(*), ?, ?, ?, ?, ? from config_info where "
+ "group_id=? and tenant_id = '';";
}
@ -152,8 +151,8 @@ public class GroupCapacityPersistService {
"UPDATE group_capacity SET `usage` = `usage` + 1, gmt_modified = ? WHERE group_id = ? AND `usage` <"
+ " ? AND quota = 0";
try {
int affectRow = jdbcTemplate.update(sql,
groupCapacity.getGmtModified(), groupCapacity.getGroup(), groupCapacity.getQuota());
int affectRow = jdbcTemplate
.update(sql, groupCapacity.getGmtModified(), groupCapacity.getGroup(), groupCapacity.getQuota());
return affectRow == 1;
} catch (CannotGetJdbcConnectionException e) {
fatalLog.error("[db-error]", e);
@ -162,12 +161,11 @@ public class GroupCapacityPersistService {
}
public boolean incrementUsageWithQuotaLimit(GroupCapacity groupCapacity) {
String sql
= "UPDATE group_capacity SET `usage` = `usage` + 1, gmt_modified = ? WHERE group_id = ? AND `usage` < "
String sql =
"UPDATE group_capacity SET `usage` = `usage` + 1, gmt_modified = ? WHERE group_id = ? AND `usage` < "
+ "quota AND quota != 0";
try {
return jdbcTemplate.update(sql,
groupCapacity.getGmtModified(), groupCapacity.getGroup()) == 1;
return jdbcTemplate.update(sql, groupCapacity.getGmtModified(), groupCapacity.getGroup()) == 1;
} catch (CannotGetJdbcConnectionException e) {
fatalLog.error("[db-error]", e);
throw e;
@ -178,8 +176,7 @@ public class GroupCapacityPersistService {
public boolean incrementUsage(GroupCapacity groupCapacity) {
String sql = "UPDATE group_capacity SET `usage` = `usage` + 1, gmt_modified = ? WHERE group_id = ?";
try {
int affectRow = jdbcTemplate.update(sql,
groupCapacity.getGmtModified(), groupCapacity.getGroup());
int affectRow = jdbcTemplate.update(sql, groupCapacity.getGmtModified(), groupCapacity.getGroup());
return affectRow == 1;
} catch (CannotGetJdbcConnectionException e) {
fatalLog.error("[db-error]", e);
@ -188,11 +185,9 @@ public class GroupCapacityPersistService {
}
public boolean decrementUsage(GroupCapacity groupCapacity) {
String sql =
"UPDATE group_capacity SET `usage` = `usage` - 1, gmt_modified = ? WHERE group_id = ? AND `usage` > 0";
String sql = "UPDATE group_capacity SET `usage` = `usage` - 1, gmt_modified = ? WHERE group_id = ? AND `usage` > 0";
try {
return jdbcTemplate.update(sql,
groupCapacity.getGmtModified(), groupCapacity.getGroup()) == 1;
return jdbcTemplate.update(sql, groupCapacity.getGmtModified(), groupCapacity.getGroup()) == 1;
} catch (CannotGetJdbcConnectionException e) {
fatalLog.error("[db-error]", e);
throw e;
@ -278,8 +273,7 @@ public class GroupCapacityPersistService {
sql = "SELECT id, group_id FROM group_capacity WHERE id>? OFFSET 0 ROWS FETCH NEXT ? ROWS ONLY";
}
try {
return jdbcTemplate.query(sql, new Object[] {lastId, pageSize},
new RowMapper<GroupCapacity>() {
return jdbcTemplate.query(sql, new Object[] {lastId, pageSize}, new RowMapper<GroupCapacity>() {
@Override
public GroupCapacity mapRow(ResultSet rs, int rowNum) throws SQLException {
GroupCapacity groupCapacity = new GroupCapacity();
@ -299,8 +293,8 @@ public class GroupCapacityPersistService {
PreparedStatementCreator preparedStatementCreator = new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
PreparedStatement ps = connection.prepareStatement(
"DELETE FROM group_capacity WHERE group_id = ?;");
PreparedStatement ps = connection
.prepareStatement("DELETE FROM group_capacity WHERE group_id = ?;");
ps.setString(1, group);
return ps;
}

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.service.capacity;
import com.alibaba.nacos.config.server.model.capacity.TenantCapacity;
@ -43,8 +44,8 @@ import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog;
@Service
public class TenantCapacityPersistService {
private static final TenantCapacityRowMapper
TENANT_CAPACITY_ROW_MAPPER = new TenantCapacityRowMapper();
private static final TenantCapacityRowMapper TENANT_CAPACITY_ROW_MAPPER = new TenantCapacityRowMapper();
private JdbcTemplate jdbcTemplate;
private DataSourceService dataSourceService;
@ -55,8 +56,8 @@ public class TenantCapacityPersistService {
this.jdbcTemplate = dataSourceService.getJdbcTemplate();
}
private static final class TenantCapacityRowMapper implements
RowMapper<TenantCapacity> {
private static final class TenantCapacityRowMapper implements RowMapper<TenantCapacity> {
@Override
public TenantCapacity mapRow(ResultSet rs, int rowNum) throws SQLException {
TenantCapacity tenantCapacity = new TenantCapacity();
@ -72,11 +73,10 @@ public class TenantCapacityPersistService {
}
public TenantCapacity getTenantCapacity(String tenantId) {
String sql
= "SELECT id, quota, `usage`, `max_size`, max_aggr_count, max_aggr_size, tenant_id FROM tenant_capacity "
String sql =
"SELECT id, quota, `usage`, `max_size`, max_aggr_count, max_aggr_size, tenant_id FROM tenant_capacity "
+ "WHERE tenant_id=?";
List<TenantCapacity> list = jdbcTemplate.query(sql, new Object[] {tenantId},
TENANT_CAPACITY_ROW_MAPPER);
List<TenantCapacity> list = jdbcTemplate.query(sql, new Object[] {tenantId}, TENANT_CAPACITY_ROW_MAPPER);
if (list.isEmpty()) {
return null;
}
@ -119,8 +119,8 @@ public class TenantCapacityPersistService {
"UPDATE tenant_capacity SET `usage` = `usage` + 1, gmt_modified = ? WHERE tenant_id = ? AND `usage` <"
+ " ? AND quota = 0";
try {
int affectRow = jdbcTemplate.update(sql,
tenantCapacity.getGmtModified(), tenantCapacity.getTenant(), tenantCapacity.getQuota());
int affectRow = jdbcTemplate.update(sql, tenantCapacity.getGmtModified(), tenantCapacity.getTenant(),
tenantCapacity.getQuota());
return affectRow == 1;
} catch (CannotGetJdbcConnectionException e) {
fatalLog.error("[db-error]", e);
@ -129,12 +129,11 @@ public class TenantCapacityPersistService {
}
public boolean incrementUsageWithQuotaLimit(TenantCapacity tenantCapacity) {
String sql
= "UPDATE tenant_capacity SET `usage` = `usage` + 1, gmt_modified = ? WHERE tenant_id = ? AND `usage` < "
String sql =
"UPDATE tenant_capacity SET `usage` = `usage` + 1, gmt_modified = ? WHERE tenant_id = ? AND `usage` < "
+ "quota AND quota != 0";
try {
return jdbcTemplate.update(sql,
tenantCapacity.getGmtModified(), tenantCapacity.getTenant()) == 1;
return jdbcTemplate.update(sql, tenantCapacity.getGmtModified(), tenantCapacity.getTenant()) == 1;
} catch (CannotGetJdbcConnectionException e) {
fatalLog.error("[db-error]", e);
throw e;
@ -145,8 +144,7 @@ public class TenantCapacityPersistService {
public boolean incrementUsage(TenantCapacity tenantCapacity) {
String sql = "UPDATE tenant_capacity SET `usage` = `usage` + 1, gmt_modified = ? WHERE tenant_id = ?";
try {
int affectRow = jdbcTemplate.update(sql,
tenantCapacity.getGmtModified(), tenantCapacity.getTenant());
int affectRow = jdbcTemplate.update(sql, tenantCapacity.getGmtModified(), tenantCapacity.getTenant());
return affectRow == 1;
} catch (CannotGetJdbcConnectionException e) {
fatalLog.error("[db-error]", e);
@ -155,11 +153,9 @@ public class TenantCapacityPersistService {
}
public boolean decrementUsage(TenantCapacity tenantCapacity) {
String sql =
"UPDATE tenant_capacity SET `usage` = `usage` - 1, gmt_modified = ? WHERE tenant_id = ? AND `usage` > 0";
String sql = "UPDATE tenant_capacity SET `usage` = `usage` - 1, gmt_modified = ? WHERE tenant_id = ? AND `usage` > 0";
try {
return jdbcTemplate.update(sql,
tenantCapacity.getGmtModified(), tenantCapacity.getTenant()) == 1;
return jdbcTemplate.update(sql, tenantCapacity.getGmtModified(), tenantCapacity.getTenant()) == 1;
} catch (CannotGetJdbcConnectionException e) {
fatalLog.error("[db-error]", e);
throw e;
@ -229,8 +225,7 @@ public class TenantCapacityPersistService {
}
try {
return jdbcTemplate.query(sql, new Object[] {lastId, pageSize},
new RowMapper<TenantCapacity>() {
return jdbcTemplate.query(sql, new Object[] {lastId, pageSize}, new RowMapper<TenantCapacity>() {
@Override
public TenantCapacity mapRow(ResultSet rs, int rowNum) throws SQLException {
TenantCapacity tenantCapacity = new TenantCapacity();
@ -250,8 +245,8 @@ public class TenantCapacityPersistService {
PreparedStatementCreator preparedStatementCreator = new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection connection) throws SQLException {
PreparedStatement ps = connection.prepareStatement(
"DELETE FROM tenant_capacity WHERE tenant_id = ?;");
PreparedStatement ps = connection
.prepareStatement("DELETE FROM tenant_capacity WHERE tenant_id = ?;");
ps.setString(1, tenant);
return ps;
}

View File

@ -13,9 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.service.datasource;
import java.io.IOException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.transaction.support.TransactionTemplate;

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.service.datasource;
import com.alibaba.nacos.config.server.utils.PropertyUtil;
@ -25,6 +26,7 @@ import com.alibaba.nacos.config.server.utils.PropertyUtil;
public class DynamicDataSource {
private DataSourceService localDataSourceService = null;
private DataSourceService basicDataSourceService = null;
private static final DynamicDataSource INSTANCE = new DynamicDataSource();
@ -45,8 +47,7 @@ public class DynamicDataSource {
localDataSourceService.init();
}
return localDataSourceService;
}
else {
} else {
if (basicDataSourceService == null) {
basicDataSourceService = new ExternalDataSourceServiceImpl();
basicDataSourceService.init();

View File

@ -10,6 +10,7 @@
* 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.config.server.service.datasource;
import static com.alibaba.nacos.common.utils.CollectionUtils.getOrDefault;
@ -35,17 +36,27 @@ import com.zaxxer.hikari.HikariDataSource;
public class ExternalDataSourceProperties {
private final static String JDBC_DRIVER_NAME = "com.mysql.cj.jdbc.Driver";
public static final long CONNECTION_TIMEOUT_MS = 3000L;
public static final long VALIDATION_TIMEOUT = 10L;
public static final String TEST_QUERY = "SELECT 1 FROM dual";
public static final int DEFAULT_MAX_POOL_SIZE = 20;
public static final int DEFAULT_MINIMUM_IDLE = 50;
private Integer num;
private List<String> url = new ArrayList<>();
private List<String> user = new ArrayList<>();
private List<String> password = new ArrayList<>();
private List<Integer> maxPoolSize = new ArrayList<>();
private List<Integer> minIdle = new ArrayList<>();
public void setNum(Integer num) {
@ -73,11 +84,8 @@ public class ExternalDataSourceProperties {
}
/**
*
* @param environment
* {@link Environment}
* @param callback
* Callback function when constructing data source
* @param environment {@link Environment}
* @param callback Callback function when constructing data source
* @return List of {@link HikariDataSource}
*/
List<HikariDataSource> build(Environment environment, Callback<HikariDataSource> callback) {
@ -112,6 +120,7 @@ public class ExternalDataSourceProperties {
/**
* Perform custom logic
*
* @param dataSource
*/
void accept(DataSource dataSource);

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.service.datasource;
import static com.alibaba.nacos.config.server.service.repository.RowMapperManager.CONFIG_INFO4BETA_ROW_MAPPER;
@ -51,8 +52,8 @@ import com.zaxxer.hikari.HikariDataSource;
*/
public class ExternalDataSourceServiceImpl implements DataSourceService {
private static final Logger log = LoggerFactory.getLogger(
ExternalDataSourceServiceImpl.class);
private static final Logger log = LoggerFactory.getLogger(ExternalDataSourceServiceImpl.class);
private final static String JDBC_DRIVER_NAME = "com.mysql.cj.jdbc.Driver";
/**
@ -65,18 +66,24 @@ public class ExternalDataSourceServiceImpl implements DataSourceService {
private static final String DB_LOAD_ERROR_MSG = "[db-load-error]load jdbc.properties error";
private List<HikariDataSource> dataSourceList = new ArrayList<>();
private JdbcTemplate jt;
private DataSourceTransactionManager tm;
private TransactionTemplate tjt;
private JdbcTemplate testMasterJT;
private JdbcTemplate testMasterWritableJT;
volatile private List<JdbcTemplate> testJTList;
volatile private List<Boolean> isHealthList;
private volatile int masterIndex;
private static Pattern ipPattern = Pattern.compile("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}");
volatile private List<Boolean> isHealthList;
private volatile int masterIndex;
private static Pattern ipPattern = Pattern.compile("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}");
@Override
@ -113,10 +120,8 @@ public class ExternalDataSourceServiceImpl implements DataSourceService {
throw new RuntimeException(DB_LOAD_ERROR_MSG);
}
ConfigExecutor.scheduleWithFixedDelay(new SelectMasterTask(), 10, 10,
TimeUnit.SECONDS);
ConfigExecutor.scheduleWithFixedDelay(new CheckDBHealthTask(), 10, 10,
TimeUnit.SECONDS);
ConfigExecutor.scheduleWithFixedDelay(new SelectMasterTask(), 10, 10, TimeUnit.SECONDS);
ConfigExecutor.scheduleWithFixedDelay(new CheckDBHealthTask(), 10, 10, TimeUnit.SECONDS);
}
}
@ -229,9 +234,7 @@ public class ExternalDataSourceServiceImpl implements DataSourceService {
testMasterJT.setDataSource(ds);
testMasterJT.setQueryTimeout(queryTimeout);
try {
testMasterJT
.update(
"DELETE FROM config_info WHERE data_id='com.alibaba.nacos.testMasterDB'");
testMasterJT.update("DELETE FROM config_info WHERE data_id='com.alibaba.nacos.testMasterDB'");
if (jt.getDataSource() != ds) {
fatalLog.warn("[master-db] {}", ds.getJdbcUrl());
}

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.service.datasource;
import com.alibaba.nacos.api.exception.NacosException;
@ -23,6 +24,7 @@ import com.alibaba.nacos.config.server.utils.PropertyUtil;
import com.alibaba.nacos.core.utils.DiskUtils;
import com.alibaba.nacos.core.utils.ApplicationUtils;
import com.zaxxer.hikari.HikariDataSource;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
@ -36,6 +38,7 @@ import java.util.List;
import java.util.concurrent.Callable;
import javax.annotation.PostConstruct;
import javax.sql.DataSource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
@ -50,15 +53,21 @@ import org.springframework.transaction.support.TransactionTemplate;
public class LocalDataSourceServiceImpl implements DataSourceService {
private final String jdbcDriverName = "org.apache.derby.jdbc.EmbeddedDriver";
private final String userName = "nacos";
private final String password = "nacos";
private final String derbyBaseDir = "data" + File.separator + "derby-data";
private final String derbyShutdownErrMsg = "Derby system shutdown.";
private volatile JdbcTemplate jt;
private volatile TransactionTemplate tjt;
private boolean initialize = false;
private boolean jdbcTemplateInit = false;
private String healthStatus = "UP";
@ -69,8 +78,9 @@ public class LocalDataSourceServiceImpl implements DataSourceService {
if (!PropertyUtil.isUseExternalDB()) {
if (!initialize) {
LogUtil.defaultLog.info("use local db service for init");
final String jdbcUrl = "jdbc:derby:" + Paths.get(ApplicationUtils.getNacosHome(),
derbyBaseDir).toString() + ";create=true";
final String jdbcUrl =
"jdbc:derby:" + Paths.get(ApplicationUtils.getNacosHome(), derbyBaseDir).toString()
+ ";create=true";
initialize(jdbcUrl);
initialize = true;
}
@ -99,8 +109,8 @@ public class LocalDataSourceServiceImpl implements DataSourceService {
public void cleanAndReopenDerby() throws Exception {
doDerbyClean();
final String jdbcUrl = "jdbc:derby:" + Paths.get(ApplicationUtils.getNacosHome(),
derbyBaseDir).toString() + ";create=true";
final String jdbcUrl =
"jdbc:derby:" + Paths.get(ApplicationUtils.getNacosHome(), derbyBaseDir).toString() + ";create=true";
initialize(jdbcUrl);
}
@ -166,8 +176,7 @@ public class LocalDataSourceServiceImpl implements DataSourceService {
@Override
public String getCurrentDBUrl() {
return "jdbc:derby:" + ApplicationUtils.getNacosHome() + File.separator + derbyBaseDir
+ ";create=true";
return "jdbc:derby:" + ApplicationUtils.getNacosHome() + File.separator + derbyBaseDir + ";create=true";
}
@Override

View File

@ -43,23 +43,16 @@ public class DumpConfigHandler implements Subscribe<ConfigDumpEvent> {
if (event.isRemove()) {
result = ConfigCacheService.removeBeta(dataId, group, namespaceId);
if (result) {
ConfigTraceService
.logDumpEvent(dataId, group, namespaceId, null, lastModified,
event.getHandleIp(),
ConfigTraceService.DUMP_EVENT_REMOVE_OK,
System.currentTimeMillis() - lastModified, 0);
ConfigTraceService.logDumpEvent(dataId, group, namespaceId, null, lastModified, event.getHandleIp(),
ConfigTraceService.DUMP_EVENT_REMOVE_OK, System.currentTimeMillis() - lastModified, 0);
}
return result;
}
else {
} else {
result = ConfigCacheService
.dumpBeta(dataId, group, namespaceId, content, lastModified,
event.getBetaIps());
.dumpBeta(dataId, group, namespaceId, content, lastModified, event.getBetaIps());
if (result) {
ConfigTraceService
.logDumpEvent(dataId, group, namespaceId, null, lastModified,
event.getHandleIp(), ConfigTraceService.DUMP_EVENT_OK,
System.currentTimeMillis() - lastModified,
ConfigTraceService.logDumpEvent(dataId, group, namespaceId, null, lastModified, event.getHandleIp(),
ConfigTraceService.DUMP_EVENT_OK, System.currentTimeMillis() - lastModified,
content.length());
}
}
@ -81,54 +74,37 @@ public class DumpConfigHandler implements Subscribe<ConfigDumpEvent> {
boolean result;
if (!event.isRemove()) {
result = ConfigCacheService
.dump(dataId, group, namespaceId, content, lastModified, type);
result = ConfigCacheService.dump(dataId, group, namespaceId, content, lastModified, type);
if (result) {
ConfigTraceService
.logDumpEvent(dataId, group, namespaceId, null, lastModified,
event.getHandleIp(), ConfigTraceService.DUMP_EVENT_OK,
System.currentTimeMillis() - lastModified,
ConfigTraceService.logDumpEvent(dataId, group, namespaceId, null, lastModified, event.getHandleIp(),
ConfigTraceService.DUMP_EVENT_OK, System.currentTimeMillis() - lastModified,
content.length());
}
}
else {
} else {
result = ConfigCacheService.remove(dataId, group, namespaceId);
if (result) {
ConfigTraceService
.logDumpEvent(dataId, group, namespaceId, null, lastModified,
event.getHandleIp(),
ConfigTraceService.DUMP_EVENT_REMOVE_OK,
System.currentTimeMillis() - lastModified, 0);
ConfigTraceService.logDumpEvent(dataId, group, namespaceId, null, lastModified, event.getHandleIp(),
ConfigTraceService.DUMP_EVENT_REMOVE_OK, System.currentTimeMillis() - lastModified, 0);
}
}
return result;
}
else {
} else {
//
boolean result;
if (!event.isRemove()) {
result = ConfigCacheService
.dumpTag(dataId, group, namespaceId, event.getTag(), content,
lastModified);
result = ConfigCacheService.dumpTag(dataId, group, namespaceId, event.getTag(), content, lastModified);
if (result) {
ConfigTraceService
.logDumpEvent(dataId, group, namespaceId, null, lastModified,
event.getHandleIp(), ConfigTraceService.DUMP_EVENT_OK,
System.currentTimeMillis() - lastModified,
ConfigTraceService.logDumpEvent(dataId, group, namespaceId, null, lastModified, event.getHandleIp(),
ConfigTraceService.DUMP_EVENT_OK, System.currentTimeMillis() - lastModified,
content.length());
}
}
else {
result = ConfigCacheService
.removeTag(dataId, group, namespaceId, event.getTag());
} else {
result = ConfigCacheService.removeTag(dataId, group, namespaceId, event.getTag());
if (result) {
ConfigTraceService
.logDumpEvent(dataId, group, namespaceId, null, lastModified,
event.getHandleIp(),
ConfigTraceService.DUMP_EVENT_REMOVE_OK,
System.currentTimeMillis() - lastModified, 0);
ConfigTraceService.logDumpEvent(dataId, group, namespaceId, null, lastModified, event.getHandleIp(),
ConfigTraceService.DUMP_EVENT_REMOVE_OK, System.currentTimeMillis() - lastModified, 0);
}
}
return result;

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.service.dump;
import com.alibaba.nacos.api.exception.NacosException;
@ -67,16 +68,20 @@ import static com.alibaba.nacos.config.server.utils.LogUtil.fatalLog;
public abstract class DumpService {
protected DumpProcessor processor;
protected DumpAllProcessor dumpAllProcessor;
protected DumpAllBetaProcessor dumpAllBetaProcessor;
protected DumpAllTagProcessor dumpAllTagProcessor;
protected final PersistService persistService;
protected final ServerMemberManager memberManager;
/**
* Here you inject the dependent objects constructively, ensuring that some
* of the dependent functionality is initialized ahead of time
* Here you inject the dependent objects constructively, ensuring that some of the dependent functionality is
* initialized ahead of time
*
* @param persistService {@link PersistService}
* @param memberManager {@link ServerMemberManager}
@ -98,7 +103,6 @@ public abstract class DumpService {
this.dumpAllTaskMgr.addProcessor(DumpAllBetaTask.TASK_ID, dumpAllBetaProcessor);
this.dumpAllTaskMgr.addProcessor(DumpAllTagTask.TASK_ID, dumpAllTagProcessor);
DynamicDataSource.getInstance().getDataSource();
}
@ -118,34 +122,27 @@ public abstract class DumpService {
protected abstract void init() throws Throwable;
protected void dumpOperate(DumpProcessor processor, DumpAllProcessor dumpAllProcessor,
DumpAllBetaProcessor dumpAllBetaProcessor,
DumpAllTagProcessor dumpAllTagProcessor) throws NacosException {
DumpAllBetaProcessor dumpAllBetaProcessor, DumpAllTagProcessor dumpAllTagProcessor) throws NacosException {
TimerContext.start("CONFIG_DUMP_TO_FILE");
try {
LogUtil.defaultLog.warn("DumpService start");
Runnable dumpAll = () -> dumpAllTaskMgr
.addTask(DumpAllTask.TASK_ID, new DumpAllTask());
Runnable dumpAll = () -> dumpAllTaskMgr.addTask(DumpAllTask.TASK_ID, new DumpAllTask());
Runnable dumpAllBeta = () -> dumpAllTaskMgr
.addTask(DumpAllBetaTask.TASK_ID, new DumpAllBetaTask());
Runnable dumpAllBeta = () -> dumpAllTaskMgr.addTask(DumpAllBetaTask.TASK_ID, new DumpAllBetaTask());
Runnable dumpAllTag = () -> dumpAllTaskMgr
.addTask(DumpAllTagTask.TASK_ID, new DumpAllTagTask());
Runnable dumpAllTag = () -> dumpAllTaskMgr.addTask(DumpAllTagTask.TASK_ID, new DumpAllTagTask());
Runnable clearConfigHistory = () -> {
log.warn("clearConfigHistory start");
if (canExecute()) {
try {
Timestamp startTime = getBeforeStamp(TimeUtils.getCurrentTime(),
24 * getRetentionDays());
int totalCount = persistService
.findConfigHistoryCountByTime(startTime);
Timestamp startTime = getBeforeStamp(TimeUtils.getCurrentTime(), 24 * getRetentionDays());
int totalCount = persistService.findConfigHistoryCountByTime(startTime);
if (totalCount > 0) {
int pageSize = 1000;
int removeTime = (totalCount + pageSize - 1) / pageSize;
log.warn(
"clearConfigHistory, getBeforeStamp:{}, totalCount:{}, pageSize:{}, removeTime:{}",
log.warn("clearConfigHistory, getBeforeStamp:{}, totalCount:{}, pageSize:{}, removeTime:{}",
startTime, totalCount, pageSize, removeTime);
while (removeTime > 0) {
// 分页删除以免批量太大报错
@ -153,8 +150,7 @@ public abstract class DumpService {
removeTime--;
}
}
}
catch (Throwable e) {
} catch (Throwable e) {
log.error("clearConfigHistory error : {}", e.toString());
}
}
@ -167,37 +163,33 @@ public abstract class DumpService {
LogUtil.defaultLog.info("start clear all config-info-beta.");
DiskUtil.clearAllBeta();
if (persistService.isExistTable(BETA_TABLE_NAME)) {
dumpAllBetaProcessor
.process(DumpAllBetaTask.TASK_ID, new DumpAllBetaTask());
dumpAllBetaProcessor.process(DumpAllBetaTask.TASK_ID, new DumpAllBetaTask());
}
// 更新Tag缓存
LogUtil.defaultLog.info("start clear all config-info-tag.");
DiskUtil.clearAllTag();
if (persistService.isExistTable(TAG_TABLE_NAME)) {
dumpAllTagProcessor
.process(DumpAllTagTask.TASK_ID, new DumpAllTagTask());
dumpAllTagProcessor.process(DumpAllTagTask.TASK_ID, new DumpAllTagTask());
}
// add to dump aggr
List<ConfigInfoChanged> configList = persistService.findAllAggrGroup();
if (configList != null && !configList.isEmpty()) {
total = configList.size();
List<List<ConfigInfoChanged>> splitList = splitList(configList,
INIT_THREAD_COUNT);
List<List<ConfigInfoChanged>> splitList = splitList(configList, INIT_THREAD_COUNT);
for (List<ConfigInfoChanged> list : splitList) {
MergeAllDataWorker work = new MergeAllDataWorker(list);
work.start();
}
log.info("server start, schedule merge end.");
}
}
catch (Exception e) {
} catch (Exception e) {
LogUtil.fatalLog
.error("Nacos Server did not start because dumpservice bean construction failure :\n"
+ e.toString());
.error("Nacos Server did not start because dumpservice bean construction failure :\n" + e
.toString());
throw new NacosException(NacosException.SERVER_ERROR,
"Nacos Server did not start because dumpservice bean construction failure :\n"
+ e.getMessage(), e);
"Nacos Server did not start because dumpservice bean construction failure :\n" + e.getMessage(),
e);
}
if (!ApplicationUtils.getStandaloneMode()) {
Runnable heartbeat = () -> {
@ -205,32 +197,28 @@ public abstract class DumpService {
// write disk
try {
DiskUtil.saveHeartBeatToDisk(heartBeatTime);
}
catch (IOException e) {
} catch (IOException e) {
LogUtil.fatalLog.error("save heartbeat fail" + e.getMessage());
}
};
ConfigExecutor
.scheduleWithFixedDelay(heartbeat, 0, 10, TimeUnit.SECONDS);
ConfigExecutor.scheduleWithFixedDelay(heartbeat, 0, 10, TimeUnit.SECONDS);
long initialDelay = new Random().nextInt(INITIAL_DELAY_IN_MINUTE) + 10;
LogUtil.defaultLog.warn("initialDelay:{}", initialDelay);
ConfigExecutor.scheduleWithFixedDelay(dumpAll, initialDelay,
DUMP_ALL_INTERVAL_IN_MINUTE, TimeUnit.MINUTES);
ConfigExecutor.scheduleWithFixedDelay(dumpAllBeta, initialDelay,
DUMP_ALL_INTERVAL_IN_MINUTE, TimeUnit.MINUTES);
ConfigExecutor.scheduleWithFixedDelay(dumpAllTag, initialDelay,
DUMP_ALL_INTERVAL_IN_MINUTE, TimeUnit.MINUTES);
}
ConfigExecutor
.scheduleWithFixedDelay(clearConfigHistory, 10, 10, TimeUnit.MINUTES);
.scheduleWithFixedDelay(dumpAll, initialDelay, DUMP_ALL_INTERVAL_IN_MINUTE, TimeUnit.MINUTES);
ConfigExecutor.scheduleWithFixedDelay(dumpAllBeta, initialDelay, DUMP_ALL_INTERVAL_IN_MINUTE,
TimeUnit.MINUTES);
ConfigExecutor.scheduleWithFixedDelay(dumpAllTag, initialDelay, DUMP_ALL_INTERVAL_IN_MINUTE,
TimeUnit.MINUTES);
}
finally {
ConfigExecutor.scheduleWithFixedDelay(clearConfigHistory, 10, 10, TimeUnit.MINUTES);
} finally {
TimerContext.end(LogUtil.dumpLog);
}
@ -249,8 +237,8 @@ public abstract class DumpService {
fis = new FileInputStream(heartbeatFile);
String heartheatTempLast = IoUtils.toString(fis, Constants.ENCODE);
heartheatLastStamp = Timestamp.valueOf(heartheatTempLast);
if (TimeUtils.getCurrentTime().getTime() - heartheatLastStamp
.getTime() < timeStep * 60 * 60 * 1000) {
if (TimeUtils.getCurrentTime().getTime() - heartheatLastStamp.getTime()
< timeStep * 60 * 60 * 1000) {
isAllDump = false;
}
}
@ -259,11 +247,10 @@ public abstract class DumpService {
LogUtil.defaultLog.info("start clear all config-info.");
DiskUtil.clearAll();
dumpAllProcessor.process(DumpAllTask.TASK_ID, new DumpAllTask());
}
else {
} else {
Timestamp beforeTimeStamp = getBeforeStamp(heartheatLastStamp, timeStep);
DumpChangeProcessor dumpChangeProcessor = new DumpChangeProcessor(this,
beforeTimeStamp, TimeUtils.getCurrentTime());
DumpChangeProcessor dumpChangeProcessor = new DumpChangeProcessor(this, beforeTimeStamp,
TimeUtils.getCurrentTime());
dumpChangeProcessor.process(DumpChangeTask.TASK_ID, new DumpChangeTask());
Runnable checkMd5Task = () -> {
LogUtil.defaultLog.error("start checkMd5Task");
@ -273,27 +260,22 @@ public abstract class DumpService {
String dataId = dg[0];
String group = dg[1];
String tenant = dg[2];
ConfigInfoWrapper configInfo = persistService
.queryConfigInfo(dataId, group, tenant);
ConfigCacheService.dumpChange(dataId, group, tenant,
configInfo.getContent(), configInfo.getLastModified());
ConfigInfoWrapper configInfo = persistService.queryConfigInfo(dataId, group, tenant);
ConfigCacheService.dumpChange(dataId, group, tenant, configInfo.getContent(),
configInfo.getLastModified());
}
LogUtil.defaultLog.error("end checkMd5Task");
};
ConfigExecutor
.scheduleWithFixedDelay(checkMd5Task, 0, 12, TimeUnit.HOURS);
ConfigExecutor.scheduleWithFixedDelay(checkMd5Task, 0, 12, TimeUnit.HOURS);
}
}
catch (IOException e) {
} catch (IOException e) {
LogUtil.fatalLog.error("dump config fail" + e.getMessage());
throw e;
}
finally {
} finally {
if (null != fis) {
try {
fis.close();
}
catch (IOException e) {
} catch (IOException e) {
LogUtil.defaultLog.warn("close file failed");
}
}
@ -322,8 +304,7 @@ public abstract class DumpService {
isQuickStart = true;
}
fatalLog.warn("isQuickStart:{}", isQuickStart);
}
catch (Exception e) {
} catch (Exception e) {
fatalLog.error("read application.properties wrong", e);
}
return isQuickStart;
@ -341,46 +322,38 @@ public abstract class DumpService {
if (tmp > 0) {
retentionDays = tmp;
}
}
catch (NumberFormatException nfe) {
} catch (NumberFormatException nfe) {
fatalLog.error("read nacos.config.retention.days wrong", nfe);
}
return retentionDays;
}
public void dump(String dataId, String group, String tenant, String tag,
long lastModified, String handleIp) {
public void dump(String dataId, String group, String tenant, String tag, long lastModified, String handleIp) {
dump(dataId, group, tenant, tag, lastModified, handleIp, false);
}
public void dump(String dataId, String group, String tenant, long lastModified,
String handleIp) {
public void dump(String dataId, String group, String tenant, long lastModified, String handleIp) {
dump(dataId, group, tenant, lastModified, handleIp, false);
}
public void dump(String dataId, String group, String tenant, long lastModified,
String handleIp, boolean isBeta) {
public void dump(String dataId, String group, String tenant, long lastModified, String handleIp, boolean isBeta) {
String groupKey = GroupKey2.getKey(dataId, group, tenant);
dumpTaskMgr.addTask(groupKey,
new DumpTask(groupKey, lastModified, handleIp, isBeta));
dumpTaskMgr.addTask(groupKey, new DumpTask(groupKey, lastModified, handleIp, isBeta));
}
public void dump(String dataId, String group, String tenant, String tag,
long lastModified, String handleIp, boolean isBeta) {
public void dump(String dataId, String group, String tenant, String tag, long lastModified, String handleIp,
boolean isBeta) {
String groupKey = GroupKey2.getKey(dataId, group, tenant);
dumpTaskMgr.addTask(groupKey,
new DumpTask(groupKey, tag, lastModified, handleIp, isBeta));
dumpTaskMgr.addTask(groupKey, new DumpTask(groupKey, tag, lastModified, handleIp, isBeta));
}
public void dumpAll() {
dumpAllTaskMgr.addTask(DumpAllTask.TASK_ID, new DumpAllTask());
}
static List<List<ConfigInfoChanged>> splitList(List<ConfigInfoChanged> list,
int count) {
List<List<ConfigInfoChanged>> result = new ArrayList<List<ConfigInfoChanged>>(
count);
static List<List<ConfigInfoChanged>> splitList(List<ConfigInfoChanged> list, int count) {
List<List<ConfigInfoChanged>> result = new ArrayList<List<ConfigInfoChanged>>(count);
for (int i = 0; i < count; i++) {
result.add(new ArrayList<ConfigInfoChanged>());
}
@ -392,6 +365,7 @@ public abstract class DumpService {
}
class MergeAllDataWorker extends Thread {
static final int PAGE_SIZE = 10000;
private List<ConfigInfoChanged> configInfoList;
@ -412,54 +386,42 @@ public abstract class DumpService {
String tenant = configInfo.getTenant();
try {
List<ConfigInfoAggr> datumList = new ArrayList<ConfigInfoAggr>();
int rowCount = persistService
.aggrConfigInfoCount(dataId, group, tenant);
int rowCount = persistService.aggrConfigInfoCount(dataId, group, tenant);
int pageCount = (int) Math.ceil(rowCount * 1.0 / PAGE_SIZE);
for (int pageNo = 1; pageNo <= pageCount; pageNo++) {
Page<ConfigInfoAggr> page = persistService
.findConfigInfoAggrByPage(dataId, group, tenant, pageNo,
PAGE_SIZE);
.findConfigInfoAggrByPage(dataId, group, tenant, pageNo, PAGE_SIZE);
if (page != null) {
datumList.addAll(page.getPageItems());
log.info("[merge-query] {}, {}, size/total={}/{}", dataId,
group, datumList.size(), rowCount);
log.info("[merge-query] {}, {}, size/total={}/{}", dataId, group, datumList.size(),
rowCount);
}
}
final Timestamp time = TimeUtils.getCurrentTime();
// 聚合
if (datumList.size() > 0) {
ConfigInfo cf = MergeTaskProcessor
.merge(dataId, group, tenant, datumList);
ConfigInfo cf = MergeTaskProcessor.merge(dataId, group, tenant, datumList);
String aggrContent = cf.getContent();
String localContentMD5 = ConfigCacheService
.getContentMd5(GroupKey.getKey(dataId, group));
String aggrConetentMD5 = MD5Utils
.md5Hex(aggrContent, Constants.ENCODE);
String localContentMD5 = ConfigCacheService.getContentMd5(GroupKey.getKey(dataId, group));
String aggrConetentMD5 = MD5Utils.md5Hex(aggrContent, Constants.ENCODE);
if (!StringUtils.equals(localContentMD5, aggrConetentMD5)) {
persistService
.insertOrUpdate(null, null, cf, time, null, false);
log.info(
"[merge-ok] {}, {}, size={}, length={}, md5={}, content={}",
dataId, group, datumList.size(),
cf.getContent().length(), cf.getMd5(),
persistService.insertOrUpdate(null, null, cf, time, null, false);
log.info("[merge-ok] {}, {}, size={}, length={}, md5={}, content={}", dataId, group,
datumList.size(), cf.getContent().length(), cf.getMd5(),
ContentUtils.truncateContent(cf.getContent()));
}
}
// 删除
else {
persistService.removeConfigInfo(dataId, group, tenant,
InetUtils.getSelfIp(), null);
log.warn(
"[merge-delete] delete config info because no datum. dataId="
+ dataId + ", groupId=" + group);
persistService.removeConfigInfo(dataId, group, tenant, InetUtils.getSelfIp(), null);
log.warn("[merge-delete] delete config info because no datum. dataId=" + dataId + ", groupId="
+ group);
}
}
catch (Throwable e) {
log.info("[merge-error] " + dataId + ", " + group + ", " + e
.toString(), e);
} catch (Throwable e) {
log.info("[merge-error] " + dataId + ", " + group + ", " + e.toString(), e);
}
FINISHED.incrementAndGet();
if (FINISHED.get() % 100 == 0) {
@ -481,12 +443,14 @@ public abstract class DumpService {
* 全量dump间隔
*/
static final int DUMP_ALL_INTERVAL_IN_MINUTE = 6 * 60;
/**
* 全量dump间隔
*/
static final int INITIAL_DELAY_IN_MINUTE = 6 * 60;
private TaskManager dumpTaskMgr;
private TaskManager dumpAllTaskMgr;
private static final Logger log = LoggerFactory.getLogger(DumpService.class);
@ -494,9 +458,13 @@ public abstract class DumpService {
static final AtomicInteger FINISHED = new AtomicInteger();
static final int INIT_THREAD_COUNT = 10;
int total = 0;
private final static String TRUE_STR = "true";
private final static String BETA_TABLE_NAME = "config_info_beta";
private final static String TAG_TABLE_NAME = "config_info_tag";
Boolean isQuickStart = false;

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.config.server.service.dump;
import com.alibaba.nacos.common.utils.MD5Utils;
@ -87,13 +88,18 @@ public class DumpTask extends AbstractTask {
}
final String groupKey;
final long lastModified;
final String handleIp;
final boolean isBeta;
final String tag;
}
class DumpAllTask extends AbstractTask {
@Override
public void merge(AbstractTask task) {
}
@ -102,6 +108,7 @@ class DumpAllTask extends AbstractTask {
}
class DumpAllBetaTask extends AbstractTask {
@Override
public void merge(AbstractTask task) {
}
@ -110,6 +117,7 @@ class DumpAllBetaTask extends AbstractTask {
}
class DumpAllTagTask extends AbstractTask {
@Override
public void merge(AbstractTask task) {
}
@ -118,6 +126,7 @@ class DumpAllTagTask extends AbstractTask {
}
class DumpChangeTask extends AbstractTask {
@Override
public void merge(AbstractTask task) {
}
@ -144,14 +153,8 @@ class DumpProcessor implements TaskProcessor {
boolean isBeta = dumpTask.isBeta;
String tag = dumpTask.tag;
ConfigDumpEvent.ConfigDumpEventBuilder build = ConfigDumpEvent.builder()
.namespaceId(tenant)
.dataId(dataId)
.group(group)
.isBeta(isBeta)
.tag(tag)
.lastModifiedTs(lastModified)
.handleIp(handleIp);
ConfigDumpEvent.ConfigDumpEventBuilder build = ConfigDumpEvent.builder().namespaceId(tenant).dataId(dataId)
.group(group).isBeta(isBeta).tag(tag).lastModifiedTs(lastModified).handleIp(handleIp);
if (isBeta) {
// beta发布则dump数据更新beta缓存
@ -198,8 +201,7 @@ class DumpAllProcessor implements TaskProcessor {
long currentMaxId = persistService.findConfigMaxId();
long lastMaxId = 0;
while (lastMaxId < currentMaxId) {
Page<ConfigInfoWrapper> page = persistService.findAllConfigInfoFragment(lastMaxId,
PAGE_SIZE);
Page<ConfigInfoWrapper> page = persistService.findAllConfigInfoFragment(lastMaxId, PAGE_SIZE);
if (page != null && page.getPageItems() != null && !page.getPageItems().isEmpty()) {
for (ConfigInfoWrapper cf : page.getPageItems()) {
long id = cf.getId();
@ -217,13 +219,14 @@ class DumpAllProcessor implements TaskProcessor {
}
boolean result = ConfigCacheService
.dump(cf.getDataId(), cf.getGroup(), cf.getTenant(), cf.getContent(),
cf.getLastModified(), cf.getType());
.dump(cf.getDataId(), cf.getGroup(), cf.getTenant(), cf.getContent(), cf.getLastModified(),
cf.getType());
final String content = cf.getContent();
final String md5 = MD5Utils.md5Hex(content, Constants.ENCODE);
LogUtil.dumpLog.info("[dump-all-ok] {}, {}, length={}, md5={}",
GroupKey2.getKey(cf.getDataId(), cf.getGroup()), cf.getLastModified(), content.length(), md5);
GroupKey2.getKey(cf.getDataId(), cf.getGroup()), cf.getLastModified(), content.length(),
md5);
}
defaultLog.info("[all-dump] {} / {}", lastMaxId, currentMaxId);
} else {
@ -236,6 +239,7 @@ class DumpAllProcessor implements TaskProcessor {
static final int PAGE_SIZE = 1000;
final DumpService dumpService;
final PersistService persistService;
}
@ -257,11 +261,11 @@ class DumpAllBetaProcessor implements TaskProcessor {
if (page != null) {
for (ConfigInfoBetaWrapper cf : page.getPageItems()) {
boolean result = ConfigCacheService
.dumpBeta(cf.getDataId(), cf.getGroup(), cf.getTenant(),
cf.getContent(), cf.getLastModified(), cf.getBetaIps());
.dumpBeta(cf.getDataId(), cf.getGroup(), cf.getTenant(), cf.getContent(),
cf.getLastModified(), cf.getBetaIps());
LogUtil.dumpLog.info("[dump-all-beta-ok] result={}, {}, {}, length={}, md5={}", result,
GroupKey2.getKey(cf.getDataId(), cf.getGroup()), cf.getLastModified(), cf.getContent()
.length(), cf.getMd5());
GroupKey2.getKey(cf.getDataId(), cf.getGroup()), cf.getLastModified(),
cf.getContent().length(), cf.getMd5());
}
actualRowCount += page.getPageItems().size();
@ -274,6 +278,7 @@ class DumpAllBetaProcessor implements TaskProcessor {
static final int PAGE_SIZE = 1000;
final DumpService dumpService;
final PersistService persistService;
}
@ -295,11 +300,11 @@ class DumpAllTagProcessor implements TaskProcessor {
if (page != null) {
for (ConfigInfoTagWrapper cf : page.getPageItems()) {
boolean result = ConfigCacheService
.dumpTag(cf.getDataId(), cf.getGroup(), cf.getTenant(), cf.getTag(),
cf.getContent(), cf.getLastModified());
.dumpTag(cf.getDataId(), cf.getGroup(), cf.getTenant(), cf.getTag(), cf.getContent(),
cf.getLastModified());
LogUtil.dumpLog.info("[dump-all-Tag-ok] result={}, {}, {}, length={}, md5={}", result,
GroupKey2.getKey(cf.getDataId(), cf.getGroup()), cf.getLastModified(), cf.getContent()
.length(), cf.getMd5());
GroupKey2.getKey(cf.getDataId(), cf.getGroup()), cf.getLastModified(),
cf.getContent().length(), cf.getMd5());
}
actualRowCount += page.getPageItems().size();
@ -312,13 +317,13 @@ class DumpAllTagProcessor implements TaskProcessor {
static final int PAGE_SIZE = 1000;
final DumpService dumpService;
final PersistService persistService;
}
class DumpChangeProcessor implements TaskProcessor {
DumpChangeProcessor(DumpService dumpService, Timestamp startTime,
Timestamp endTime) {
DumpChangeProcessor(DumpService dumpService, Timestamp startTime, Timestamp endTime) {
this.dumpService = dumpService;
this.persistService = dumpService.getPersistService();
this.startTime = startTime;
@ -327,67 +332,57 @@ class DumpChangeProcessor implements TaskProcessor {
@Override
public boolean process(String taskType, AbstractTask task) {
LogUtil.defaultLog.warn("quick start; startTime:{},endTime:{}",
startTime, endTime);
LogUtil.defaultLog.warn("quick start; startTime:{},endTime:{}", startTime, endTime);
LogUtil.defaultLog.warn("updateMd5 start");
long startUpdateMd5 = System.currentTimeMillis();
List<ConfigInfoWrapper> updateMd5List = persistService
.listAllGroupKeyMd5();
List<ConfigInfoWrapper> updateMd5List = persistService.listAllGroupKeyMd5();
LogUtil.defaultLog.warn("updateMd5 count:{}", updateMd5List.size());
for (ConfigInfoWrapper config : updateMd5List) {
final String groupKey = GroupKey2.getKey(config.getDataId(),
config.getGroup());
ConfigCacheService.updateMd5(groupKey, config.getMd5(),
config.getLastModified());
final String groupKey = GroupKey2.getKey(config.getDataId(), config.getGroup());
ConfigCacheService.updateMd5(groupKey, config.getMd5(), config.getLastModified());
}
long endUpdateMd5 = System.currentTimeMillis();
LogUtil.defaultLog.warn("updateMd5 done,cost:{}", endUpdateMd5
- startUpdateMd5);
LogUtil.defaultLog.warn("updateMd5 done,cost:{}", endUpdateMd5 - startUpdateMd5);
LogUtil.defaultLog.warn("deletedConfig start");
long startDeletedConfigTime = System.currentTimeMillis();
List<ConfigInfo> configDeleted = persistService.findDeletedConfig(
startTime, endTime);
List<ConfigInfo> configDeleted = persistService.findDeletedConfig(startTime, endTime);
LogUtil.defaultLog.warn("deletedConfig count:{}", configDeleted.size());
for (ConfigInfo configInfo : configDeleted) {
if (persistService.findConfigInfo(configInfo.getDataId(), configInfo.getGroup(),
configInfo.getTenant()) == null) {
ConfigCacheService
.remove(configInfo.getDataId(), configInfo.getGroup(), configInfo.getTenant());
if (persistService.findConfigInfo(configInfo.getDataId(), configInfo.getGroup(), configInfo.getTenant())
== null) {
ConfigCacheService.remove(configInfo.getDataId(), configInfo.getGroup(), configInfo.getTenant());
}
}
long endDeletedConfigTime = System.currentTimeMillis();
LogUtil.defaultLog.warn("deletedConfig done,cost:{}",
endDeletedConfigTime - startDeletedConfigTime);
LogUtil.defaultLog.warn("deletedConfig done,cost:{}", endDeletedConfigTime - startDeletedConfigTime);
LogUtil.defaultLog.warn("changeConfig start");
long startChangeConfigTime = System.currentTimeMillis();
List<ConfigInfoWrapper> changeConfigs = persistService
.findChangeConfig(startTime, endTime);
List<ConfigInfoWrapper> changeConfigs = persistService.findChangeConfig(startTime, endTime);
LogUtil.defaultLog.warn("changeConfig count:{}", changeConfigs.size());
for (ConfigInfoWrapper cf : changeConfigs) {
boolean result = ConfigCacheService
.dumpChange(cf.getDataId(), cf.getGroup(), cf.getTenant(),
cf.getContent(), cf.getLastModified());
.dumpChange(cf.getDataId(), cf.getGroup(), cf.getTenant(), cf.getContent(), cf.getLastModified());
final String content = cf.getContent();
final String md5 = MD5Utils.md5Hex(content, Constants.ENCODE);
LogUtil.defaultLog.info(
"[dump-change-ok] {}, {}, length={}, md5={}",
new Object[] {
GroupKey2.getKey(cf.getDataId(), cf.getGroup()),
cf.getLastModified(), content.length(), md5});
LogUtil.defaultLog.info("[dump-change-ok] {}, {}, length={}, md5={}",
new Object[] {GroupKey2.getKey(cf.getDataId(), cf.getGroup()), cf.getLastModified(),
content.length(), md5});
}
ConfigCacheService.reloadConfig();
long endChangeConfigTime = System.currentTimeMillis();
LogUtil.defaultLog.warn("changeConfig done,cost:{}",
endChangeConfigTime - startChangeConfigTime);
LogUtil.defaultLog.warn("changeConfig done,cost:{}", endChangeConfigTime - startChangeConfigTime);
return true;
}
// =====================
final DumpService dumpService;
final PersistService persistService;
final Timestamp startTime;
final Timestamp endTime;
}

Some files were not shown because too many files have changed in this diff Show More