-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
🐛 Source CockroachDB: fix connector replication failure due to multiple open portals error #10235
Merged
marcosmarxm
merged 4 commits into
airbytehq:master
from
lshrinivas:lshrinivas/issue-7933
Feb 25, 2022
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ce8f6db
fix cockroachdb connector replication failure due to multiple open po…
lshrinivas ab57a03
Merge branch 'lshrinivas/issue-7933' of github.com:lshrinivas/airbyte…
marcosmarxm 7bc045b
bump connector version
marcosmarxm d98edee
Merge branch 'master' into marcos/test-pr-10235
marcosmarxm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is unrelated to the bug, but without this, tables in the
public
schema are not visible in the Airbyte UI (which feels odd, since tables in thepublic
schema in CockroachDB are visible to all users regardless of explicit grants). Feel free to undo this if this isn't a change you'd like to incorporate in the connector