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

Batch execution is incomplete when client doesn't request all results #193

Open
lukaseder opened this issue Apr 1, 2021 · 0 comments
Open

Comments

@lukaseder
Copy link
Contributor

Bug Report

Versions

  • Driver: 0.8.4.RELEASE
  • SPI: 0.9.0.M1
  • Database: 1.4.200
  • Java: openjdk version "11.0.9.1" 2020-11-04
  • OS: Microsoft Windows [Version 10.0.19042.867]

Current Behavior

The current implementation of r2dbc-h2 does not execute batches completely if clients don't consume (request?) all the results. In my opinion, a batch is an atomic unit of work, irrespective of whether all update counts are consumed, and must be executed atomically by the server.

Steps to reproduce

Run this code

ConnectionFactory connectionFactory = ConnectionFactories.get(
    ConnectionFactoryOptions
        .parse("r2dbc:h2:file://localhost/~/x")
        .mutate()
        .option(ConnectionFactoryOptions.USER, "sa")
        .option(ConnectionFactoryOptions.PASSWORD, "")
        .build()
);

Flux.from(connectionFactory.create())
    .flatMap(c -> c.createStatement("create table t (i int)").execute())
    .collectList()
    .block();

try {
    System.out.println((
        Flux.from(connectionFactory.create())
            .flatMap(c -> c.createBatch().add("insert into t values (1)").add("insert into t values (2)").execute())
            .flatMap(t -> t.getRowsUpdated())
            .blockFirst()
    ));

    System.out.println(
        Flux.from(connectionFactory.create())
            .flatMap(c -> c.createStatement("select * from t").execute())
            .flatMap(it -> it.map((r, m) -> r.get(0)))
            .collectList()
            .block()
    );
}
finally {
    Flux.from(connectionFactory.create())
        .flatMap(c -> c.createStatement("drop table t").execute())
        .collectList()
        .block();
}

The output is:

1
[1]

As can be seen, the second value 2 is never inserted.

Expected behavior/code

The output in r2dbc-postgresql is the expected one:

1
[1, 2]

Only one update count is consumed as requested, but two insertions are made

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant