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

Problems when warmup procedure and database query procedure running in parallel. #170

Open
1528110566 opened this issue Apr 22, 2023 · 0 comments
Labels
❓need-triage This issue needs triage, hasn't been looked at by a team member yet

Comments

@1528110566
Copy link

1528110566 commented Apr 22, 2023

I want to warmup connection pool when the application start, and I want get some configs from database.
So I wrote this, Test is the name of database table.

@Autowired
private ConnectionPool connectionPool;
@Autowired
private R2dbcEntityTemplate r2dbcEntityTemplate;
@PostConstruct
public void init() {
    connectionPool.warmup().subscribe();
    List<Test> block = r2dbcEntityTemplate.select(Test.class).all().collectList().block();
    System.out.println(block);
}

Expected Behavior

warmup procedure and database query procedure running in parallel, and database query procedure will be waited until there is available connection to use.

Actual Behavior

database query procedure is stuck even if warmup procedure is complete.

Steps to Reproduce

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>spring-boot-starter-parent</artifactId>
        <groupId>org.springframework.boot</groupId>
        <version>2.5.13</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>r2dbc-demo</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-r2dbc</artifactId>
        </dependency>
        <dependency>
            <groupId>dev.miku</groupId>
            <artifactId>r2dbc-mysql</artifactId>
        </dependency>
        <dependency>
            <groupId>io.r2dbc</groupId>
            <artifactId>r2dbc-spi</artifactId>
        </dependency>
        <dependency>
            <groupId>io.r2dbc</groupId>
            <artifactId>r2dbc-pool</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
        </dependency>
    </dependencies>
</project>

java code

@SpringBootApplication
@EnableR2dbcRepositories
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Autowired
    private ConnectionPool connectionPool;
    @Autowired
    private R2dbcEntityTemplate r2dbcEntityTemplate;
    @PostConstruct
    public void init() {
        connectionPool.warmup().subscribe();
        List<Test> block = r2dbcEntityTemplate.select(Test.class).all().collectList().block();
        System.out.println(block);
    }
}

// 1 million records
@Data
@Table("test")
public class Test {
    @Id
    private String name;
}

Possible Solution

change connectionPool.warmup().subscribe(); to connectionPool.warmup().block();
or
add spring.r2dbc.pool.max-acquire-time: 7s in application.yml, after 7 seconds, database query procedure go on and no errors in log file.

Your Environment

  • Reactor version(s) used: see pom.xml above
  • Other relevant libraries versions (eg. netty, ...): Mysql-5.7.41-winx64
  • JVM version (java -version): jdk 1.8.0_162
  • OS and version (eg uname -a): windows11 22621.1555
@reactorbot reactorbot added the ❓need-triage This issue needs triage, hasn't been looked at by a team member yet label Apr 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❓need-triage This issue needs triage, hasn't been looked at by a team member yet
Projects
None yet
Development

No branches or pull requests

2 participants