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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 source-mssql: support Read Committed snapshot isolation level #28545

Merged
merged 7 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ static boolean isCdc(final JsonNode config) {
@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);
if (config.hasNonNull(LEGACY_REPLICATION_FIELD) && config.get(LEGACY_REPLICATION_FIELD).isObject()) {
Copy link
Contributor Author

@sh4sh sh4sh Jul 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I should also add isText case to these as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.isTextual() is for when replication_method was a string
.isObject() I think is suitable for a oneOf selection field.
Current implementation is with oneOf so it sounds like this is correct (?)

final JsonNode replicationConfig = config.get(LEGACY_REPLICATION_FIELD);
final JsonNode snapshotIsolation = replicationConfig.get(CDC_SNAPSHOT_ISOLATION_FIELD);
return SnapshotIsolation.from(snapshotIsolation.asText());
}
Expand All @@ -131,8 +131,8 @@ static SnapshotIsolation getSnapshotIsolationConfig(final JsonNode config) {
@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);
if (config.hasNonNull(LEGACY_REPLICATION_FIELD) && config.get(LEGACY_REPLICATION_FIELD).isObject()) {
final JsonNode replicationConfig = config.get(LEGACY_REPLICATION_FIELD);
final JsonNode dataToSync = replicationConfig.get(CDC_DATA_TO_SYNC_FIELD);
return DataToSync.from(dataToSync.asText());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,33 +62,33 @@ public void testGetSnapshotIsolation() {
assertEquals(SnapshotIsolation.SNAPSHOT, MssqlCdcHelper.getSnapshotIsolationConfig(LEGACY_CDC_CONFIG));

// new replication method config since version 0.4.0
final JsonNode newCdcNonSnapshot = Jsons.jsonNode(Map.of("replication",
final JsonNode newCdcNonSnapshot = Jsons.jsonNode(Map.of("replication_method",
Jsons.jsonNode(Map.of(
"replication_type", "CDC",
"method", "CDC",
"data_to_sync", "Existing and New",
"snapshot_isolation", "Read Committed"))));
assertEquals(SnapshotIsolation.READ_COMMITTED, MssqlCdcHelper.getSnapshotIsolationConfig(newCdcNonSnapshot));

final JsonNode newCdcSnapshot = Jsons.jsonNode(Map.of("replication",
final JsonNode newCdcSnapshot = Jsons.jsonNode(Map.of("replication_method",
Jsons.jsonNode(Map.of(
"replication_type", "CDC",
"method", "CDC",
"data_to_sync", "Existing and New",
"snapshot_isolation", "Snapshot"))));
assertEquals(SnapshotIsolation.SNAPSHOT, MssqlCdcHelper.getSnapshotIsolationConfig(newCdcSnapshot));

// migration from legacy to new config
final JsonNode mixCdcNonSnapshot = Jsons.jsonNode(Map.of(
"replication_method", "Standard",
"replication", Jsons.jsonNode(Map.of(
"replication_type", "CDC",
"replication", "Standard",
"replication_method", Jsons.jsonNode(Map.of(
"method", "CDC",
"data_to_sync", "Existing and New",
"snapshot_isolation", "Read Committed"))));
assertEquals(SnapshotIsolation.READ_COMMITTED, MssqlCdcHelper.getSnapshotIsolationConfig(mixCdcNonSnapshot));

final JsonNode mixCdcSnapshot = Jsons.jsonNode(Map.of(
"replication_method", "Standard",
"replication", Jsons.jsonNode(Map.of(
"replication_type", "CDC",
"replication", "Standard",
"replication_method", Jsons.jsonNode(Map.of(
"method", "CDC",
"data_to_sync", "Existing and New",
"snapshot_isolation", "Snapshot"))));
assertEquals(SnapshotIsolation.SNAPSHOT, MssqlCdcHelper.getSnapshotIsolationConfig(mixCdcSnapshot));
Expand All @@ -100,33 +100,33 @@ public void testGetDataToSyncConfig() {
assertEquals(DataToSync.EXISTING_AND_NEW, MssqlCdcHelper.getDataToSyncConfig(LEGACY_CDC_CONFIG));

// new replication method config since version 0.4.0
final JsonNode newCdcExistingAndNew = Jsons.jsonNode(Map.of("replication",
final JsonNode newCdcExistingAndNew = Jsons.jsonNode(Map.of("replication_method",
Jsons.jsonNode(Map.of(
"replication_type", "CDC",
"method", "CDC",
"data_to_sync", "Existing and New",
"snapshot_isolation", "Read Committed"))));
assertEquals(DataToSync.EXISTING_AND_NEW, MssqlCdcHelper.getDataToSyncConfig(newCdcExistingAndNew));

final JsonNode newCdcNewOnly = Jsons.jsonNode(Map.of("replication",
final JsonNode newCdcNewOnly = Jsons.jsonNode(Map.of("replication_method",
Jsons.jsonNode(Map.of(
"replication_type", "CDC",
"method", "CDC",
"data_to_sync", "New Changes Only",
"snapshot_isolation", "Snapshot"))));
assertEquals(DataToSync.NEW_CHANGES_ONLY, MssqlCdcHelper.getDataToSyncConfig(newCdcNewOnly));

final JsonNode mixCdcExistingAndNew = Jsons.jsonNode(Map.of(
"replication_method", "Standard",
"replication", Jsons.jsonNode(Map.of(
"replication_type", "CDC",
"replication", "Standard",
"replication_method", Jsons.jsonNode(Map.of(
"method", "CDC",
"data_to_sync", "Existing and New",
"snapshot_isolation", "Read Committed"))));
assertEquals(DataToSync.EXISTING_AND_NEW, MssqlCdcHelper.getDataToSyncConfig(mixCdcExistingAndNew));

final JsonNode mixCdcNewOnly = Jsons.jsonNode(Map.of(
"replication_method", "Standard",
"replication",
"replication", "Standard",
"replication_method",
Jsons.jsonNode(Map.of(
"replication_type", "CDC",
"method", "CDC",
"data_to_sync", "New Changes Only",
"snapshot_isolation", "Snapshot"))));
assertEquals(DataToSync.NEW_CHANGES_ONLY, MssqlCdcHelper.getDataToSyncConfig(mixCdcNewOnly));
Expand Down