Skip to content

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

@lukaseder

Description

@lukaseder

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions