-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 MongoDB Internal POC: CDC State Handling #29763
Merged
jdpgrailsdev
merged 19 commits into
jonathan/cdc-metadata-injector
from
jonathan/cdc-state-handler
Aug 28, 2023
Merged
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
f3f0ead
Add state management and handling for CDC integration
jdpgrailsdev 3ab0fe2
Formatting
jdpgrailsdev 4b5552f
Fix typo
jdpgrailsdev 2f2fe53
Merge branch 'master' into jonathan/cdc-state-handler
jdpgrailsdev f67aa27
Merge branch 'master' into jonathan/cdc-state-handler
jdpgrailsdev 9317ccf
Merge branch 'master' into jonathan/cdc-state-handler
jdpgrailsdev 9517f34
Merge branch 'master' into jonathan/cdc-state-handler
jdpgrailsdev fca3fbc
Merge branch 'master' into jonathan/cdc-state-handler
jdpgrailsdev b08b556
Automated Commit - Format and Process Resources Changes
jdpgrailsdev cbf5f09
Merge branch 'master' into jonathan/cdc-state-handler
jdpgrailsdev af7feba
Merge branch 'jonathan/cdc-metadata-injector' into jonathan/cdc-state…
jdpgrailsdev a8b2455
Merge branch 'jonathan/cdc-metadata-injector' into jonathan/cdc-state…
jdpgrailsdev 291f6ff
PR feedback
jdpgrailsdev 31726f3
Store offset map in CDC state
jdpgrailsdev ee781c1
Formatting
jdpgrailsdev 28e4dc0
Merge branch 'jonathan/cdc-metadata-injector' into jonathan/cdc-state…
jdpgrailsdev 971af01
disable checkpointing + saveStateAfterCompletionOfSnapshotOfNewStreams
subodh1810 9a13b5f
Merge branch 'jonathan/cdc-metadata-injector' into jonathan/cdc-state…
jdpgrailsdev 8743788
Automated Commit - Formatting Changes
jdpgrailsdev 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
14 changes: 14 additions & 0 deletions
14
...oc/src/main/java/io/airbyte/integrations/source/mongodb/internal/cdc/MongoDbCdcState.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,14 @@ | ||
/* | ||
* Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.integrations.source.mongodb.internal.cdc; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
|
||
/** | ||
* Represents the global CDC state that is used by Debezium as an offset. | ||
* | ||
* @param state The Debezium offset state as a {@link JsonNode}. | ||
*/ | ||
public record MongoDbCdcState(JsonNode state) {} |
51 changes: 51 additions & 0 deletions
51
...main/java/io/airbyte/integrations/source/mongodb/internal/cdc/MongoDbCdcStateHandler.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,51 @@ | ||
/* | ||
* Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.integrations.source.mongodb.internal.cdc; | ||
|
||
import io.airbyte.commons.json.Jsons; | ||
import io.airbyte.integrations.debezium.CdcStateHandler; | ||
import io.airbyte.integrations.source.mongodb.internal.state.MongoDbStateManager; | ||
import io.airbyte.protocol.models.v0.AirbyteMessage; | ||
import io.airbyte.protocol.models.v0.AirbyteStateMessage; | ||
import java.util.Map; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Implementation of the {@link CdcStateHandler} that handles saving the CDC offset as Airbyte state | ||
* for MongoDB. | ||
*/ | ||
public class MongoDbCdcStateHandler implements CdcStateHandler { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(MongoDbCdcStateHandler.class); | ||
|
||
private final MongoDbStateManager stateManager; | ||
|
||
public MongoDbCdcStateHandler(MongoDbStateManager stateManager) { | ||
this.stateManager = stateManager; | ||
} | ||
|
||
@Override | ||
public AirbyteMessage saveState(final Map<String, String> offset, String dbHistory) { | ||
final MongoDbCdcState cdcState = new MongoDbCdcState(Jsons.jsonNode(offset)); | ||
|
||
LOGGER.info("Saving Debezium state {}...", cdcState); | ||
stateManager.updateCdcState(cdcState); | ||
|
||
final AirbyteStateMessage stateMessage = stateManager.toState(); | ||
return new AirbyteMessage().withType(AirbyteMessage.Type.STATE).withState(stateMessage); | ||
} | ||
|
||
@Override | ||
public AirbyteMessage saveStateAfterCompletionOfSnapshotOfNewStreams() { | ||
throw new RuntimeException("Debezium is not used to carry out the snapshot of tables."); | ||
} | ||
|
||
@Override | ||
public boolean isCdcCheckpointEnabled() { | ||
return false; | ||
} | ||
|
||
} |
Oops, something went wrong.
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.
Not required right?