Skip to content

Commit f30aa96

Browse files
authored
Fix JdbcIO.read log spam when autocommit disabled (#35825)
1 parent 18ce59b commit f30aa96

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

  • sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc

sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/JdbcIO.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,6 +1709,15 @@ private Connection getConnection() throws SQLException {
17091709
try {
17101710
connection = validSource.getConnection();
17111711
this.connection = connection;
1712+
1713+
// PostgreSQL requires autocommit to be disabled to enable cursor streaming
1714+
// see https://jdbc.postgresql.org/documentation/head/query.html#query-with-cursor
1715+
// This option is configurable as Informix will error
1716+
// if calling setAutoCommit on a non-logged database
1717+
if (disableAutoCommit) {
1718+
LOG.info("Autocommit has been disabled");
1719+
connection.setAutoCommit(false);
1720+
}
17121721
} finally {
17131722
connectionLock.unlock();
17141723
}
@@ -1739,14 +1748,6 @@ private Connection getConnection() throws SQLException {
17391748
public void processElement(ProcessContext context) throws Exception {
17401749
// Only acquire the connection if we need to perform a read.
17411750
Connection connection = getConnection();
1742-
// PostgreSQL requires autocommit to be disabled to enable cursor streaming
1743-
// see https://jdbc.postgresql.org/documentation/head/query.html#query-with-cursor
1744-
// This option is configurable as Informix will error
1745-
// if calling setAutoCommit on a non-logged database
1746-
if (disableAutoCommit) {
1747-
LOG.info("Autocommit has been disabled");
1748-
connection.setAutoCommit(false);
1749-
}
17501751
try (PreparedStatement statement =
17511752
connection.prepareStatement(
17521753
query.get(), ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)) {

0 commit comments

Comments
 (0)