-
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
Check disabled connections after protocol update #18990
Changes from all commits
ed6add0
0be3711
f2305ea
535878f
5e472c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
|
||
package io.airbyte.config.persistence; | ||
|
||
import static io.airbyte.db.instance.configs.jooq.generated.Tables.ACTOR; | ||
import static io.airbyte.db.instance.configs.jooq.generated.Tables.ACTOR_DEFINITION; | ||
import static io.airbyte.db.instance.configs.jooq.generated.Tables.CONNECTION; | ||
import static io.airbyte.db.instance.configs.jooq.generated.Tables.CONNECTION_OPERATION; | ||
import static io.airbyte.db.instance.configs.jooq.generated.Tables.STATE; | ||
|
@@ -12,18 +14,25 @@ | |
|
||
import io.airbyte.commons.enums.Enums; | ||
import io.airbyte.commons.json.Jsons; | ||
import io.airbyte.commons.version.AirbyteProtocolVersion; | ||
import io.airbyte.commons.version.AirbyteProtocolVersionRange; | ||
import io.airbyte.commons.version.Version; | ||
import io.airbyte.config.ActorType; | ||
import io.airbyte.config.ConfigSchema; | ||
import io.airbyte.config.ConfigWithMetadata; | ||
import io.airbyte.config.StandardSync; | ||
import io.airbyte.config.helpers.ScheduleHelpers; | ||
import io.airbyte.db.Database; | ||
import io.airbyte.db.ExceptionWrappingDatabase; | ||
import io.airbyte.db.instance.configs.jooq.generated.tables.Actor; | ||
import io.airbyte.db.instance.configs.jooq.generated.tables.ActorDefinition; | ||
import java.io.IOException; | ||
import java.time.OffsetDateTime; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import java.util.stream.Stream; | ||
import org.jooq.DSLContext; | ||
import org.jooq.JSONB; | ||
import org.jooq.Record; | ||
|
@@ -32,6 +41,13 @@ | |
|
||
public class StandardSyncPersistence { | ||
|
||
private record StandardSyncIdsWithProtocolVersions( | ||
UUID standardSyncId, | ||
UUID sourceDefId, | ||
Version sourceProtocolVersion, | ||
UUID destinationDefId, | ||
Version destinationProtocolVersion) {} | ||
|
||
private final ExceptionWrappingDatabase database; | ||
|
||
public StandardSyncPersistence(final Database database) { | ||
|
@@ -78,6 +94,29 @@ public void deleteStandardSync(final UUID standardSyncId) throws IOException { | |
}); | ||
} | ||
|
||
/** | ||
* For the StandardSyncs related to actorDefinitionId, clear the unsupported protocol version flag | ||
* if both connectors are now within support range. | ||
* | ||
* @param actorDefinitionId the actorDefinitionId to query | ||
* @param actorType the ActorType of actorDefinitionId | ||
* @param supportedRange the supported range of protocol versions | ||
*/ | ||
public void clearUnsupportedProtocolVersionFlag(final UUID actorDefinitionId, | ||
final ActorType actorType, | ||
final AirbyteProtocolVersionRange supportedRange) | ||
throws IOException { | ||
final Stream<StandardSyncIdsWithProtocolVersions> candidateSyncs = database.query(ctx -> findDisabledSyncs(ctx, actorDefinitionId, actorType)); | ||
final List<UUID> standardSyncsToReEnable = candidateSyncs | ||
.filter(sync -> supportedRange.isSupported(sync.sourceProtocolVersion()) && supportedRange.isSupported(sync.destinationProtocolVersion())) | ||
.map(StandardSyncIdsWithProtocolVersions::standardSyncId) | ||
.toList(); | ||
database.query(ctx -> { | ||
clearProtocolVersionFlag(ctx, standardSyncsToReEnable); | ||
return null; | ||
}); | ||
} | ||
|
||
private List<ConfigWithMetadata<StandardSync>> listStandardSyncWithMetadata(final Optional<UUID> configId) throws IOException { | ||
final Result<Record> result = database.query(ctx -> { | ||
final SelectJoinStep<Record> query = ctx.select(asterisk()).from(CONNECTION); | ||
|
@@ -214,4 +253,41 @@ private void writeStandardSync(final StandardSync standardSync, final DSLContext | |
} | ||
} | ||
|
||
private Stream<StandardSyncIdsWithProtocolVersions> findDisabledSyncs(final DSLContext ctx, final UUID actorDefId, final ActorType actorType) { | ||
// Table aliasing to help have a readable join | ||
final Actor source = ACTOR.as("source"); | ||
final Actor destination = ACTOR.as("destination"); | ||
final ActorDefinition sourceDef = ACTOR_DEFINITION.as("sourceDef"); | ||
final ActorDefinition destDef = ACTOR_DEFINITION.as("destDef"); | ||
|
||
// Retrieve all the connections currently disabled due to a bad protocol version | ||
// where the actor definition is matching the one provided to this function | ||
final Stream<StandardSyncIdsWithProtocolVersions> results = ctx | ||
.select(CONNECTION.ID, sourceDef.ID, sourceDef.PROTOCOL_VERSION, destDef.ID, destDef.PROTOCOL_VERSION) | ||
.from(CONNECTION) | ||
.join(source).on(CONNECTION.SOURCE_ID.eq(source.ID)) | ||
.join(sourceDef).on(source.ACTOR_DEFINITION_ID.eq(sourceDef.ID)) | ||
.join(destination).on(CONNECTION.DESTINATION_ID.eq(destination.ID)) | ||
.join(destDef).on(destination.ACTOR_DEFINITION_ID.eq(destDef.ID)) | ||
.where( | ||
CONNECTION.UNSUPPORTED_PROTOCOL_VERSION.eq(true).and( | ||
(actorType == ActorType.DESTINATION ? destDef : sourceDef).ID.eq(actorDefId))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we do the same for the Source Actor type? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is what the inline if is doing here, based on the |
||
.fetchStream() | ||
.map(r -> new StandardSyncIdsWithProtocolVersions( | ||
r.get(CONNECTION.ID), | ||
r.get(sourceDef.ID), | ||
AirbyteProtocolVersion.getWithDefault(r.get(sourceDef.PROTOCOL_VERSION)), | ||
r.get(destDef.ID), | ||
AirbyteProtocolVersion.getWithDefault(r.get(destDef.PROTOCOL_VERSION)))); | ||
return results; | ||
} | ||
|
||
private void clearProtocolVersionFlag(final DSLContext ctx, final List<UUID> standardSyncIds) { | ||
ctx.update(CONNECTION) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Please update the modified_at collumn as well. I don't think that is being updated through a trigger. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, updated. |
||
.set(CONNECTION.UNSUPPORTED_PROTOCOL_VERSION, false) | ||
.set(CONNECTION.UPDATED_AT, OffsetDateTime.now()) | ||
.where(CONNECTION.ID.in(standardSyncIds)) | ||
.execute(); | ||
} | ||
|
||
} |
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.
Why do we need the join on the source / source def ? I think that it is missing in the where clause.
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.
To keep things simple, my approach here was to always retrieve
(ConnectionId, sourceDefId, sourceProtocolVersion, destDefId, destProtocolVersion)
.Since protocol version is store in the actor definition, we always need to join both sides (source+destination).
An alternative could be to have some specific logic to only filter source or destination, however, I think it adds a few more conditional blocks overall throughout the code base for an operation that in the end should be relatively rare.