Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 source-mssql: connector forces snapshot isolation level #28543

Closed
1 task done
sh4sh opened this issue Jul 20, 2023 · 0 comments 路 Fixed by #28545 or #28964
Closed
1 task done

馃悰 source-mssql: connector forces snapshot isolation level #28543

sh4sh opened this issue Jul 20, 2023 · 0 comments 路 Fixed by #28545 or #28964
Labels
area/connectors Connector related issues autoteam connectors/source/mssql team/db-dw-sources Backlog for Database and Data Warehouse Sources team team/tse Technical Support Engineers type/bug Something isn't working

Comments

@sh4sh
Copy link
Contributor

sh4sh commented Jul 20, 2023

Connector Name

source-mssql

Connector Version

1.1.0

What step the error happened?

Configuring a new connector

Revelant information

PR with proposed fix: #28545

There appears to be a bug in source-mssql's support for CDC + Read Committed. Currently both snapshot isolation levels check the db for enabled full Snapshot Isolation, which it should not do when the Read Committed isolation level is selected.

Support for non-snapshot CDC is added here: #13168
In the connector spec we see a rework of replication_method to support the Read Committed isolation level. replication_method field is renamed to replication for hygiene.
We can see from comments that the new implementation since 0.4.0 should use the replication parameter instead of the replication_method. More recently however, the connector was modified in #16215 to use replication_method which has caused some problems.

In the original change to support Read Committed snapshot isolation level for MSSQL + CDC, we see the new REPLICATION_FIELD value pulled into CdcMssqlHelper.java:

// legacy replication method config before version 0.4.0
// it is an enum with possible values: STANDARD and CDC
private static final String LEGACY_REPLICATION_FIELD = "replication_method";
// new replication method config since version 0.4.0
// it is an oneOf object
private static final String REPLICATION_FIELD = "replication";

isCdc checks whether CDC is enabled. It supports both LEGACY_REPLICATION_FIELD and REPLICATION_FIELD:

@VisibleForTesting
static boolean isCdc(final JsonNode config) {
// legacy replication method config before version 0.4.0
if (config.hasNonNull(LEGACY_REPLICATION_FIELD)) {
return ReplicationMethod.valueOf(config.get(LEGACY_REPLICATION_FIELD).asText()) == ReplicationMethod.CDC;
}
// new replication method config since version 0.4.0
if (config.hasNonNull(REPLICATION_FIELD)) {
final JsonNode replicationConfig = config.get(REPLICATION_FIELD);
return ReplicationMethod.valueOf(replicationConfig.get(REPLICATION_TYPE_FIELD).asText()) == ReplicationMethod.CDC;
}
return false;
}

getSnapshotIsolationConfig checks the snapshot isolation level:

@VisibleForTesting
static SnapshotIsolation getSnapshotIsolationConfig(final JsonNode config) {
// legacy replication method config before version 0.4.0
if (config.hasNonNull(LEGACY_REPLICATION_FIELD)) {
return SnapshotIsolation.SNAPSHOT;
}
// new replication method config since version 0.4.0
if (config.hasNonNull(REPLICATION_FIELD)) {
final JsonNode replicationConfig = config.get(REPLICATION_FIELD);
final JsonNode snapshotIsolation = replicationConfig.get(CDC_SNAPSHOT_ISOLATION_FIELD);
return SnapshotIsolation.from(snapshotIsolation.asText());
}
return SnapshotIsolation.SNAPSHOT;
}

Since then, the spec parameter was modified from replication back to replication_method. This means that the getSnapshotIsolationConfig function still needs REPLICATION_FIELD to be hasNonNull. Unfortunately however it's always null, because REPLICATION_FIELD doesn't exist anymore, we only have LEGACY_REPLICATION_FIELD.

So now, if we look at master branch, we observe that the connector config is not passed into some functions.
i.e.,

@VisibleForTesting
static SnapshotIsolation getSnapshotIsolationConfig(final JsonNode config) {
// new replication method config since version 0.4.0
if (config.hasNonNull(REPLICATION_FIELD)) {
final JsonNode replicationConfig = config.get(REPLICATION_FIELD);
final JsonNode snapshotIsolation = replicationConfig.get(CDC_SNAPSHOT_ISOLATION_FIELD);
return SnapshotIsolation.from(snapshotIsolation.asText());
}
return SnapshotIsolation.SNAPSHOT;
}
@VisibleForTesting
static DataToSync getDataToSyncConfig(final JsonNode config) {
// new replication method config since version 0.4.0
if (config.hasNonNull(REPLICATION_FIELD)) {
final JsonNode replicationConfig = config.get(REPLICATION_FIELD);
final JsonNode dataToSync = replicationConfig.get(CDC_DATA_TO_SYNC_FIELD);
return DataToSync.from(dataToSync.asText());
}
return DataToSync.EXISTING_AND_NEW;
}

tl;dr quick/non-breaking-change fix is to update functions with the correct config parameter

Since this work was originally done to make naming consistent throughout CDC connectors (a reasonable goal) we should probably look at refactoring.

Relevant log output

No response

Contribute

  • Yes, I want to contribute
@sh4sh sh4sh added type/bug Something isn't working area/connectors Connector related issues connectors/source/mssql team/tse Technical Support Engineers labels Jul 20, 2023
@octavia-squidington-iii octavia-squidington-iii added autoteam team/db-dw-sources Backlog for Database and Data Warehouse Sources team labels Jul 20, 2023
@sh4sh sh4sh changed the title source-mssql: connector forces snapshot isolation level 馃悰 source-mssql: connector forces snapshot isolation level Jul 20, 2023
@rodireich rodireich linked a pull request Aug 2, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/connectors Connector related issues autoteam connectors/source/mssql team/db-dw-sources Backlog for Database and Data Warehouse Sources team team/tse Technical Support Engineers type/bug Something isn't working
Projects
None yet
2 participants