Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

🐛 [Bug] [SPI] Data source concurrency exception #513

Closed
2 of 4 tasks
Smilewh888 opened this issue Nov 13, 2023 · 5 comments
Closed
2 of 4 tasks

🐛 [Bug] [SPI] Data source concurrency exception #513

Smilewh888 opened this issue Nov 13, 2023 · 5 comments
Labels
bug Something isn't working
Milestone

Comments

@Smilewh888
Copy link
Contributor

Contribution guidelines

I've found a bug and checked that ...

  • ... the problem doesn't occur with the server or web themes
  • ... the documentation does not mention anything about my problem
  • ... there are no open or closed issues that are related to my problem

Description

当创建多个同类型数据源的时候,这种情况是比较常见的。
例如:mysql1 与mysql2 ,每1s重新加载数据源
mysql2的连接信息很可能覆盖掉mysql1的连接,导致执行sql在其他连接导致不可预知的错误。

成员变量:
image
方法引用变量:
image

Expected behaviour

.

Actual behaviour

.

Steps to reproduce

1.准备俩个不同的连接,mysql1,mysql2

2.mysql1 执行慢查询,mysql2 执行将会覆盖 mysq1 的成员属性,MySQLConnection mySQLConnection; Response response;

3.此时mysql1 在执行一条sql语句,导致错误。

Package versions

  • Java: java --version
  • Node: node --version
  • Npm: npm -v
  • Server: ./mvnw -Dexec.executable='echo' -Dexec.args='${project.version}' --non-recursive exec:exec -Dorg.slf4j.simpleLogger.defaultLogLevel=WARN -Dorg.slf4j.simpleLogger.log.org.apache.maven.plugins.help=INFO | tail -1

Configuration

.

System information

  • Operating system: ...
  • Browser: ...
@Smilewh888 Smilewh888 added the bug Something isn't working label Nov 13, 2023
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Title: 🐛 [Bug] Data source concurrency exception

@qianmoQ
Copy link
Member

qianmoQ commented Nov 13, 2023

Message that will be displayed on users' first issue

@qianmoQ qianmoQ changed the title 🐛 [Bug] 数据源并发异常 🐛 [Bug] Data source concurrency exception Nov 13, 2023
@qianmoQ
Copy link
Member

qianmoQ commented Nov 13, 2023

感谢您的反馈,我们将会按照您提供的步骤进行测试并修复它


Thanks for your feedback, we will follow the steps you provided to test and fix it

@qianmoQ qianmoQ changed the title 🐛 [Bug] Data source concurrency exception 🐛 [Bug] [SPI] Data source concurrency exception Nov 13, 2023
@Smilewh888
Copy link
Contributor Author

代码中存在大量的插件,这是否是一种好的修改方式? 或者修改为原型模式可能不需要修改这么多代码,作为底层插件代码修改是否合理?
@slf4j
public class MySQLPlugin
implements Plugin
{
private final ThreadLocal mySQLConnectionThreadLocal =new ThreadLocal<>();

@Override
public String name()
{
    return "mysql";
}

@Override
public String description()
{
    return "Integrate MySQL data sources";
}

@Override
public PluginType type()
{
    return PluginType.JDBC;
}

@Override
public void connect(Configure configure)
{
    try {
        Response response = new Response();
        JdbcConfigure jdbcConfigure = new JdbcConfigure();
        BeanUtils.copyProperties(jdbcConfigure, configure);
        jdbcConfigure.setJdbcDriver("com.mysql.jdbc.Driver");
        jdbcConfigure.setJdbcType("mysql");
        this.mySQLConnectionThreadLocal.set(new MySQLConnection(jdbcConfigure, response));
    }
    catch (Exception ex) {
        log.error("连接失败:",ex);
    }
}

@Override
public Response execute(String content)
{
    Response response=null;
    if (ObjectUtils.isNotEmpty(this.mySQLConnectionThreadLocal.get())) {
        log.info("Execute mysql plugin logic started");
        MySQLAdapter processor = new MySQLAdapter(this.mySQLConnectionThreadLocal.get());
        response = processor.handlerExecute(content);
        log.info("Execute mysql plugin logic end");
    }
    return response;
}

@Override
public void destroy()
{
    if (ObjectUtils.isNotEmpty(this.mySQLConnectionThreadLocal)) {
        this.mySQLConnectionThreadLocal.get().destroy();
        this.mySQLConnectionThreadLocal.remove();
    }
}

}

@qianmoQ
Copy link
Member

qianmoQ commented Nov 13, 2023

代码中存在大量的插件,这是否是一种好的修改方式? 或者修改为原型模式可能不需要修改这么多代码,作为底层插件代码修改是否合理? @slf4j public class MySQLPlugin implements Plugin { private final ThreadLocal mySQLConnectionThreadLocal =new ThreadLocal<>();

@Override
public String name()
{
    return "mysql";
}

@Override
public String description()
{
    return "Integrate MySQL data sources";
}

@Override
public PluginType type()
{
    return PluginType.JDBC;
}

@Override
public void connect(Configure configure)
{
    try {
        Response response = new Response();
        JdbcConfigure jdbcConfigure = new JdbcConfigure();
        BeanUtils.copyProperties(jdbcConfigure, configure);
        jdbcConfigure.setJdbcDriver("com.mysql.jdbc.Driver");
        jdbcConfigure.setJdbcType("mysql");
        this.mySQLConnectionThreadLocal.set(new MySQLConnection(jdbcConfigure, response));
    }
    catch (Exception ex) {
        log.error("连接失败:",ex);
    }
}

@Override
public Response execute(String content)
{
    Response response=null;
    if (ObjectUtils.isNotEmpty(this.mySQLConnectionThreadLocal.get())) {
        log.info("Execute mysql plugin logic started");
        MySQLAdapter processor = new MySQLAdapter(this.mySQLConnectionThreadLocal.get());
        response = processor.handlerExecute(content);
        log.info("Execute mysql plugin logic end");
    }
    return response;
}

@Override
public void destroy()
{
    if (ObjectUtils.isNotEmpty(this.mySQLConnectionThreadLocal)) {
        this.mySQLConnectionThreadLocal.get().destroy();
        this.mySQLConnectionThreadLocal.remove();
    }
}

}

建议通过 https://github.com/devlive-community/datacap/blob/dev/CONTRIBUTING.md 这种方式提交代码

@qianmoQ qianmoQ added this to the 2024.01.1 milestone Dec 23, 2023
@qianmoQ qianmoQ closed this as completed Dec 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants