-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
š Source CockroachDB: fix connector replication failure due to multipā¦
ā¦le open portals error (#10235) * fix cockroachdb connector replication failure due to multiple open portals error * bump connector version Co-authored-by: marcosmarxm <[email protected]>
- Loading branch information
1 parent
e21ec5a
commit 658efc8
Showing
7 changed files
with
120 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
...achdb/src/main/java/io/airbyte/integrations/source/cockroachdb/CockroachJdbcDatabase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Copyright (c) 2021 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.integrations.source.cockroachdb; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import io.airbyte.commons.functional.CheckedConsumer; | ||
import io.airbyte.commons.functional.CheckedFunction; | ||
import io.airbyte.db.JdbcCompatibleSourceOperations; | ||
import io.airbyte.db.jdbc.JdbcDatabase; | ||
import io.airbyte.db.jdbc.JdbcStreamingQueryConfiguration; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import java.sql.Connection; | ||
import java.sql.DatabaseMetaData; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
/** | ||
* This implementation uses non-streamed queries to CockroachDB. CockroachDB | ||
* does not currently support multiple active pgwire portals on the same session, | ||
* which makes it impossible to replicate tables that have over ~1000 rows | ||
* using StreamingJdbcDatabase. See: https://go.crdb.dev/issue-v/40195/v21.2 | ||
* and in particular, the comment: | ||
* https://github.com/cockroachdb/cockroach/issues/40195?version=v21.2#issuecomment-870570351 | ||
* The same situation as kafka-connect applies to StreamingJdbcDatabase | ||
*/ | ||
public class CockroachJdbcDatabase | ||
extends JdbcDatabase | ||
{ | ||
|
||
private final JdbcDatabase database; | ||
|
||
public CockroachJdbcDatabase(final JdbcDatabase database, | ||
final JdbcCompatibleSourceOperations<?> sourceOperations) { | ||
super(sourceOperations); | ||
this.database = database; | ||
} | ||
|
||
@Override | ||
public DatabaseMetaData getMetaData() throws SQLException { | ||
return database.getMetaData(); | ||
} | ||
|
||
@Override | ||
public void execute(final CheckedConsumer<Connection, SQLException> query) throws SQLException { | ||
database.execute(query); | ||
} | ||
|
||
@Override | ||
public <T> List<T> bufferedResultSetQuery(final CheckedFunction<Connection, ResultSet, SQLException> query, | ||
final CheckedFunction<ResultSet, T, SQLException> recordTransform) | ||
throws SQLException { | ||
return database.bufferedResultSetQuery(query, recordTransform); | ||
} | ||
|
||
@Override | ||
public <T> Stream<T> resultSetQuery(final CheckedFunction<Connection, ResultSet, SQLException> query, | ||
final CheckedFunction<ResultSet, T, SQLException> recordTransform) | ||
throws SQLException { | ||
return database.resultSetQuery(query, recordTransform); | ||
} | ||
|
||
@Override | ||
public <T> Stream<T> query(final CheckedFunction<Connection, PreparedStatement, SQLException> statementCreator, | ||
final CheckedFunction<ResultSet, T, SQLException> recordTransform) | ||
throws SQLException { | ||
return database.query(statementCreator, recordTransform); | ||
} | ||
|
||
@Override | ||
public Stream<JsonNode> query(final String sql, final String... params) throws SQLException { | ||
return bufferedResultSetQuery(connection -> { | ||
final PreparedStatement statement = connection.prepareStatement(sql); | ||
int i = 1; | ||
for (final String param : params) { | ||
statement.setString(i, param); | ||
++i; | ||
} | ||
return statement.executeQuery(); | ||
}, sourceOperations::rowToJson).stream(); | ||
|
||
} | ||
|
||
@Override | ||
public void close() throws Exception { | ||
database.close(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters