You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@beam.apache.org by "Sylvain Veyrié (Jira)" <ji...@apache.org> on 2021/03/24 09:57:00 UTC

[jira] [Updated] (BEAM-12044) JdbcIO should explicitly setAutoCommit to false

     [ https://issues.apache.org/jira/browse/BEAM-12044?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sylvain Veyrié updated BEAM-12044:
----------------------------------
    Description: 
Hello,

Per [PostgreSQL JDBC documentation|https://jdbc.postgresql.org/documentation/head/query.html#query-with-cursor], autocommit must be explicitly disabled on the connection to allow cursor streaming.

[~jkff] mentionned it [on the mailing list|https://www.mail-archive.com/dev@beam.apache.org/msg16808.html], however even if there is:

{code:java}
poolableConnectionFactory.setDefaultAutoCommit(false);
{code}

in JdbcIO:1555, currently, at least with JDBC driver 42.2.16, any read with JdbcIO will memoize the whole dataset (which leads to OOM), since 
{code:java}
connection.getAutoCommit()
{code}

returns true in JdbcIO#ReadFn#processElement.

I can provide a PR — the patch is pretty simple (and solves the problem for us in 2.28.0):

{code:java}
if (connection == null) {
        connection = dataSource.getConnection();
}
connection.setAutoCommit(false); // line added
{code}

Thanks!

  was:
Hello,

Per [PostgreSQL JDBC documentation|[https://jdbc.postgresql.org/documentation/head/query.html#query-with-cursor],] autocommit must be explicitly disabled on the connection to allow cursor streaming.

[~jkff] mentionned it [on the mailing list|https://www.mail-archive.com/dev@beam.apache.org/msg16808.html], however even if there is:

{code:java}
poolableConnectionFactory.setDefaultAutoCommit(false);
{code}

in JdbcIO:1555, currently, at least with JDBC driver 42.2.16, any read with JdbcIO will memoize the whole dataset, since 
{code:java}
connection.getAutoCommit()
{code}

returns true in JdbcIO#ReadFn#processElement.

I can provide a PR — the patch is pretty simple (and solves the problem for us in 2.28.0):

{code:java}
if (connection == null) {
        connection = dataSource.getConnection();
}
connection.setAutoCommit(false); // line added
{code}

Thanks!


> JdbcIO should explicitly setAutoCommit to false
> -----------------------------------------------
>
>                 Key: BEAM-12044
>                 URL: https://issues.apache.org/jira/browse/BEAM-12044
>             Project: Beam
>          Issue Type: Bug
>          Components: sdk-java-core
>    Affects Versions: 2.28.0
>            Reporter: Sylvain Veyrié
>            Priority: P2
>
> Hello,
> Per [PostgreSQL JDBC documentation|https://jdbc.postgresql.org/documentation/head/query.html#query-with-cursor], autocommit must be explicitly disabled on the connection to allow cursor streaming.
> [~jkff] mentionned it [on the mailing list|https://www.mail-archive.com/dev@beam.apache.org/msg16808.html], however even if there is:
> {code:java}
> poolableConnectionFactory.setDefaultAutoCommit(false);
> {code}
> in JdbcIO:1555, currently, at least with JDBC driver 42.2.16, any read with JdbcIO will memoize the whole dataset (which leads to OOM), since 
> {code:java}
> connection.getAutoCommit()
> {code}
> returns true in JdbcIO#ReadFn#processElement.
> I can provide a PR — the patch is pretty simple (and solves the problem for us in 2.28.0):
> {code:java}
> if (connection == null) {
>         connection = dataSource.getConnection();
> }
> connection.setAutoCommit(false); // line added
> {code}
> Thanks!



--
This message was sent by Atlassian Jira
(v8.3.4#803005)