From 105e473b5a4b9710832a60be81396d6ba1f1b4b4 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Thu, 12 Jun 2025 18:03:45 +0800 Subject: [PATCH 1/2] =?UTF-8?q?[=E4=BF=AE=E5=A4=8D]=20=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E4=BB=93=E5=BA=93=E7=AC=AC=E4=B8=89=E6=96=B9=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=BA=90=E5=AF=BC=E8=87=B4java.lang.OutOfMemoryError:=20Metasp?= =?UTF-8?q?ace?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1442121129623552]数据仓库第三方数据源导致java.lang.OutOfMemoryError: Metaspace http://192.168.0.96:8090/demo/rdm.html#/bug-detail/939050947543040/939050947543057/1442121129623552 --- .../database/DestroyDataBaseDriverApi.java | 56 +++++++++++++++++++ .../tenant/api/database/TestDataBaseApi.java | 53 ++++++++++++++---- 2 files changed, 98 insertions(+), 11 deletions(-) create mode 100644 src/main/java/neatlogic/module/tenant/api/database/DestroyDataBaseDriverApi.java diff --git a/src/main/java/neatlogic/module/tenant/api/database/DestroyDataBaseDriverApi.java b/src/main/java/neatlogic/module/tenant/api/database/DestroyDataBaseDriverApi.java new file mode 100644 index 00000000..730c1074 --- /dev/null +++ b/src/main/java/neatlogic/module/tenant/api/database/DestroyDataBaseDriverApi.java @@ -0,0 +1,56 @@ +/* + * 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.database; + +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.auth.core.AuthAction; +import neatlogic.framework.auth.label.DATA_WAREHOUSE_MODIFY; +import neatlogic.framework.common.constvalue.ApiParamType; +import neatlogic.framework.datawarehouse.utils.DriverHolder; +import neatlogic.framework.restful.annotation.*; +import neatlogic.framework.restful.constvalue.OperationTypeEnum; +import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import org.springframework.stereotype.Service; + +@Service +@AuthAction(action = DATA_WAREHOUSE_MODIFY.class) +@OperationType(type = OperationTypeEnum.OPERATE) +public class DestroyDataBaseDriverApi extends PrivateApiComponentBase { + + @Override + public String getName() { + return "卸载数据库驱动"; + } + + @Input({ + @Param(name = "id", type = ApiParamType.LONG, isRequired = true, desc = "common.id") + }) + @Output({}) + @Description(desc = "卸载数据库驱动") + @Override + public Object myDoService(JSONObject paramObj) throws Exception { + Long id = paramObj.getLong("id"); + DriverHolder.destroyDriver(id); + return null; + } + + @Override + public String getToken() { + return "database/destroy"; + } +} diff --git a/src/main/java/neatlogic/module/tenant/api/database/TestDataBaseApi.java b/src/main/java/neatlogic/module/tenant/api/database/TestDataBaseApi.java index e254d47a..6e4b47db 100644 --- a/src/main/java/neatlogic/module/tenant/api/database/TestDataBaseApi.java +++ b/src/main/java/neatlogic/module/tenant/api/database/TestDataBaseApi.java @@ -21,16 +21,25 @@ import com.alibaba.fastjson.JSONObject; import neatlogic.framework.auth.core.AuthAction; import neatlogic.framework.auth.label.DATA_WAREHOUSE_MODIFY; import neatlogic.framework.common.constvalue.ApiParamType; +import neatlogic.framework.datawarehouse.dao.mapper.DatabaseMapper; import neatlogic.framework.datawarehouse.dto.DatabaseVo; -import neatlogic.framework.datawarehouse.service.DatabaseService; +import neatlogic.framework.datawarehouse.exceptions.DatabaseConnectionFailedException; +import neatlogic.framework.datawarehouse.exceptions.DatabaseNotFoundException; +import neatlogic.framework.datawarehouse.utils.DriverHolder; +import neatlogic.framework.file.dao.mapper.FileMapper; +import neatlogic.framework.file.dto.FileVo; import neatlogic.framework.restful.annotation.*; import neatlogic.framework.restful.constvalue.OperationTypeEnum; import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.net.URLClassLoader; -import java.sql.Connection; +import java.sql.Driver; +import java.util.List; +import java.util.Properties; @Service @AuthAction(action = DATA_WAREHOUSE_MODIFY.class) @@ -38,7 +47,10 @@ import java.sql.Connection; public class TestDataBaseApi extends PrivateApiComponentBase { @Resource - private DatabaseService databaseService; + private DatabaseMapper databaseMapper; + + @Resource + private FileMapper fileMapper; @Override public String getName() { @@ -55,15 +67,34 @@ public class TestDataBaseApi extends PrivateApiComponentBase { @Override public Object myDoService(JSONObject paramObj) throws Exception { Long id = paramObj.getLong("id"); - Connection conn = databaseService.getConnectionByDatabaseId(id); - if (conn != null) { - ClassLoader classLoader = conn.getClass().getClassLoader(); - conn.close(); - if (classLoader instanceof URLClassLoader) { - ((URLClassLoader) classLoader).close(); + DatabaseVo databaseVo = databaseMapper.getDataBaseById(id); + if (databaseVo == null) { + throw new DatabaseNotFoundException(id); + } + List fileIdList = databaseVo.getFileIdList(); + if (CollectionUtils.isNotEmpty(fileIdList)) { + List fileList = fileMapper.getFileListByIdList(fileIdList); + databaseVo.setFileList(fileList); + } else { + throw new DatabaseConnectionFailedException(DatabaseConnectionFailedException.Type.FILE_ID_LIST_IS_EMPTY, databaseVo.getName()); + } + Driver driver = DriverHolder.borrowDriver(databaseVo); + JSONObject config = databaseVo.getConfig(); + if (MapUtils.isNotEmpty(config)) { + String user = config.getString("user"); + String password = config.getString("password"); + String url = config.getString("url"); + Properties props = new Properties(); + if (StringUtils.isNoneBlank(user)) { + props.put("user", user); + } + if (StringUtils.isNotBlank(password)) { + props.put("password", password); } + return driver.connect(url, props); + } else { + throw new DatabaseConnectionFailedException(DatabaseConnectionFailedException.Type.CONFIG_IS_EMPTY, databaseVo.getName()); } - return null; } @Override -- Gitee From 31243c0c0e54286b2360218d4a17fa0eef7c9421 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Thu, 12 Jun 2025 18:13:01 +0800 Subject: [PATCH 2/2] =?UTF-8?q?[=E4=BF=AE=E5=A4=8D]=20=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E4=BB=93=E5=BA=93=E7=AC=AC=E4=B8=89=E6=96=B9=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=BA=90=E5=AF=BC=E8=87=B4java.lang.OutOfMemoryError:=20Metasp?= =?UTF-8?q?ace?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1442121129623552]数据仓库第三方数据源导致java.lang.OutOfMemoryError: Metaspace http://192.168.0.96:8090/demo/rdm.html#/bug-detail/939050947543040/939050947543057/1442121129623552 --- .../module/tenant/api/database/TestDataBaseApi.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/neatlogic/module/tenant/api/database/TestDataBaseApi.java b/src/main/java/neatlogic/module/tenant/api/database/TestDataBaseApi.java index 6e4b47db..31acf784 100644 --- a/src/main/java/neatlogic/module/tenant/api/database/TestDataBaseApi.java +++ b/src/main/java/neatlogic/module/tenant/api/database/TestDataBaseApi.java @@ -37,6 +37,7 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.sql.Connection; import java.sql.Driver; import java.util.List; import java.util.Properties; @@ -91,7 +92,11 @@ public class TestDataBaseApi extends PrivateApiComponentBase { if (StringUtils.isNotBlank(password)) { props.put("password", password); } - return driver.connect(url, props); + Connection conn = driver.connect(url, props); + if (conn != null) { + conn.close(); + } + return null; } else { throw new DatabaseConnectionFailedException(DatabaseConnectionFailedException.Type.CONFIG_IS_EMPTY, databaseVo.getName()); } -- Gitee