From 8b8249d678b54fdba80edd27e9b6e61df8126815 Mon Sep 17 00:00:00 2001
From: "1437892690@qq.com" <1437892690@qq.com>
Date: Fri, 23 May 2025 19:11:24 +0800
Subject: [PATCH] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=A2=9E=E5=8A=A0?=
=?UTF-8?q?=E4=B8=80=E4=B8=AA=E5=8F=AF=E4=BB=A5=E5=9C=A8=E9=AB=98=E5=B9=B6?=
=?UTF-8?q?=E5=8F=91=E5=9C=BA=E6=99=AF=E4=B8=8B=E9=98=B2=E6=AD=A2=E8=A2=AB?=
=?UTF-8?q?=E5=87=BB=E7=A9=BF=E7=9A=84Mybaties=E4=BA=8C=E7=BA=A7=E7=BC=93?=
=?UTF-8?q?=E5=AD=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
关联 #[1421727635046400]增加一个可以在高并发场景下防止被击穿的Mybaties二级缓存 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1421727635046400
---
...eatLogicConcurrentSafeCacheLockKeyApi.java | 118 ++++++++++++++++++
.../tenant/api/util/GetServerInfoApi.java | 23 +++-
.../tenant/api/util/RefreshConfigApi.java | 11 +-
3 files changed, 146 insertions(+), 6 deletions(-)
create mode 100644 src/main/java/neatlogic/module/tenant/api/util/GetNeatLogicConcurrentSafeCacheLockKeyApi.java
diff --git a/src/main/java/neatlogic/module/tenant/api/util/GetNeatLogicConcurrentSafeCacheLockKeyApi.java b/src/main/java/neatlogic/module/tenant/api/util/GetNeatLogicConcurrentSafeCacheLockKeyApi.java
new file mode 100644
index 00000000..d9e76521
--- /dev/null
+++ b/src/main/java/neatlogic/module/tenant/api/util/GetNeatLogicConcurrentSafeCacheLockKeyApi.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2025 深圳极向量科技有限公司 All Rights Reserved.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package neatlogic.module.tenant.api.util;
+
+import com.alibaba.fastjson.JSONObject;
+import neatlogic.framework.asynchronization.threadlocal.RequestContext;
+import neatlogic.framework.asynchronization.threadlocal.TenantContext;
+import neatlogic.framework.auth.core.AuthAction;
+import neatlogic.framework.auth.label.ADMIN;
+import neatlogic.framework.common.config.Config;
+import neatlogic.framework.common.constvalue.ApiParamType;
+import neatlogic.framework.dao.cache.NeatLogicConcurrentSafeCache;
+import neatlogic.framework.exception.core.ApiRuntimeException;
+import neatlogic.framework.heartbeat.dao.mapper.ServerMapper;
+import neatlogic.framework.heartbeat.dto.ServerClusterVo;
+import neatlogic.framework.integration.authentication.enums.AuthenticateType;
+import neatlogic.framework.restful.annotation.Description;
+import neatlogic.framework.restful.annotation.Input;
+import neatlogic.framework.restful.annotation.OperationType;
+import neatlogic.framework.restful.annotation.Param;
+import neatlogic.framework.restful.constvalue.OperationTypeEnum;
+import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase;
+import neatlogic.framework.util.HttpRequestUtil;
+import org.apache.commons.collections4.MapUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Objects;
+
+@Service
+@AuthAction(action = ADMIN.class)
+@OperationType(type = OperationTypeEnum.SEARCH)
+public class GetNeatLogicConcurrentSafeCacheLockKeyApi extends PrivateApiComponentBase {
+
+ @Resource
+ private ServerMapper serverMapper;
+
+ @Override
+ public String getName() {
+ return "获取Mybaties二级缓存NeatLogicConcurrentSafeCache中lockKey列表";
+ }
+
+ @Input({
+ @Param(name = "serverId", type = ApiParamType.INTEGER, desc = "服务器ID")
+ })
+ @Description(desc = "获取Mybaties二级缓存NeatLogicConcurrentSafeCache中lockKey列表")
+ @Override
+ public Object myDoService(JSONObject paramObj) throws Exception {
+ JSONObject resultObj = new JSONObject(new LinkedHashMap<>());
+ Integer serverId = paramObj.getInteger("serverId");
+ if (serverId == null) {
+ serverId = Config.SCHEDULE_SERVER_ID;
+ }
+ if (Objects.equals(serverId, Config.SCHEDULE_SERVER_ID)) {
+ List lockKeyList = NeatLogicConcurrentSafeCache.getAllLockKeyList();
+ resultObj.put("lockKeyList", lockKeyList);
+ resultObj.put("serverId", serverId);
+ } else {
+ TenantContext.get().setUseMasterDatabase(true);
+ ServerClusterVo serverClusterVo = serverMapper.getServerByServerId(serverId);
+ TenantContext.get().setUseMasterDatabase(false);
+ if (serverClusterVo != null) {
+ String host = serverClusterVo.getHost();
+ if (StringUtils.isNotBlank(host)) {
+ HttpServletRequest request = RequestContext.get().getRequest();
+ String url = host + request.getRequestURI();
+ HttpRequestUtil httpRequestUtil = HttpRequestUtil.post(url)
+ .setPayload(paramObj.toJSONString())
+ .setAuthType(AuthenticateType.BUILDIN)
+ .setConnectTimeout(5000)
+ .setReadTimeout(5000)
+ .sendRequest();
+ String error = httpRequestUtil.getError();
+ if (StringUtils.isNotBlank(error)) {
+ throw new ApiRuntimeException(error);
+ }
+ JSONObject resultJson = httpRequestUtil.getResultJson();
+ if (MapUtils.isNotEmpty(resultJson)) {
+ String status = resultJson.getString("Status");
+ if (!"OK".equals(status)) {
+ throw new RuntimeException(resultJson.getString("Message"));
+ }
+ resultObj = resultJson.getJSONObject("Return");
+ }
+ } else {
+ resultObj.put("message", "serverId为" + serverId + "的应用服务器的`server_status`表中对应数据没有配置host");
+ }
+ } else {
+ resultObj.put("message", "找不到serverId为" + serverId + "的应用服务器");
+ }
+ }
+ return resultObj;
+ }
+
+ @Override
+ public String getToken() {
+ return "util/neatlogicconcurrentsafecache/lockkeylist";
+ }
+}
diff --git a/src/main/java/neatlogic/module/tenant/api/util/GetServerInfoApi.java b/src/main/java/neatlogic/module/tenant/api/util/GetServerInfoApi.java
index 7145900a..e84fca31 100644
--- a/src/main/java/neatlogic/module/tenant/api/util/GetServerInfoApi.java
+++ b/src/main/java/neatlogic/module/tenant/api/util/GetServerInfoApi.java
@@ -44,9 +44,8 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.lang.management.ManagementFactory;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
+import java.util.stream.Collectors;
@Service
@AuthAction(action = ADMIN.class)
@@ -88,8 +87,22 @@ public class GetServerInfoApi extends PrivateApiComponentBase {
JSONArray array = new JSONArray();
array.addAll(args);
resultObj.put("命令行参数", array);
- resultObj.put("Java虚拟机的系统属性", System.getProperties());
- resultObj.put("操作系统的环境变量", System.getenv());
+ {
+ Properties prop = System.getProperties();
+ Map map = new LinkedHashMap<>();
+ for (Map.Entry