-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
require cdc users to create publications & update docs #2818
Changes from all commits
4ea7438
a3ce24e
cdedd8c
3c81120
0fc0170
0384f54
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 |
---|---|---|
|
@@ -33,11 +33,13 @@ | |
import io.debezium.engine.ChangeEvent; | ||
import io.debezium.engine.DebeziumEngine; | ||
import io.debezium.engine.format.Json; | ||
import io.debezium.engine.spi.OffsetCommitPolicy.AlwaysCommitOffsetPolicy; | ||
import io.debezium.engine.spi.OffsetCommitPolicy; | ||
import java.util.Properties; | ||
import java.util.Queue; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
import java.util.stream.Collectors; | ||
|
@@ -58,6 +60,7 @@ public class DebeziumRecordPublisher implements AutoCloseable { | |
private final AtomicBoolean hasClosed; | ||
private final AtomicBoolean isClosing; | ||
private final AtomicReference<Throwable> thrownError; | ||
private final CountDownLatch engineLatch; | ||
|
||
public DebeziumRecordPublisher(JsonNode config, ConfiguredAirbyteCatalog catalog, AirbyteFileOffsetBackingStore offsetManager) { | ||
this.config = config; | ||
|
@@ -67,12 +70,13 @@ public DebeziumRecordPublisher(JsonNode config, ConfiguredAirbyteCatalog catalog | |
this.isClosing = new AtomicBoolean(false); | ||
this.thrownError = new AtomicReference<>(); | ||
this.executor = Executors.newSingleThreadExecutor(); | ||
this.engineLatch = new CountDownLatch(1); | ||
} | ||
|
||
public void start(Queue<ChangeEvent<String, String>> queue) { | ||
engine = DebeziumEngine.create(Json.class) | ||
.using(getDebeziumProperties(config, catalog, offsetManager)) | ||
.using(new AlwaysCommitOffsetPolicy()) | ||
.using(new OffsetCommitPolicy.AlwaysCommitOffsetPolicy()) | ||
.notifying(e -> { | ||
// debezium outputs a tombstone event that has a value of null. this is an artifact of how it | ||
// interacts with kafka. we want to ignore it. | ||
|
@@ -85,6 +89,7 @@ public void start(Queue<ChangeEvent<String, String>> queue) { | |
.using((success, message, error) -> { | ||
LOGGER.info("Debezium engine shutdown."); | ||
thrownError.set(error); | ||
engineLatch.countDown(); | ||
}) | ||
.build(); | ||
|
||
|
@@ -103,10 +108,15 @@ public void close() throws Exception { | |
engine.close(); | ||
} | ||
|
||
// announce closure only engine is off. | ||
hasClosed.set(true); | ||
// wait for closure before shutting down executor service | ||
engineLatch.await(5, TimeUnit.MINUTES); | ||
|
||
// shut down and await for thread to actually go down | ||
executor.shutdown(); | ||
executor.awaitTermination(5, TimeUnit.MINUTES); | ||
|
||
// after the engine is completely off, we can mark this as closed | ||
hasClosed.set(true); | ||
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. i think this can go before the execute shutdown. it just had to be after the latch. not that its'a big difference either way. 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. Yeah I didn't notice any difference. I just wanted to be as conservative as possible. |
||
|
||
if (thrownError.get() != null) { | ||
throw new RuntimeException(thrownError.get()); | ||
|
@@ -145,12 +155,16 @@ protected static Properties getDebeziumProperties(JsonNode config, ConfiguredAir | |
} | ||
|
||
props.setProperty("slot.name", config.get("replication_slot").asText()); | ||
props.setProperty("publication.name", "airbyte_publication"); // todo: allow as configured input | ||
|
||
// table selection | ||
final String tableWhitelist = getTableWhitelist(catalog); | ||
props.setProperty("table.include.list", tableWhitelist); | ||
props.setProperty("database.include.list", config.get("database").asText()); | ||
|
||
// recommended when using pgoutput | ||
props.setProperty("publication.autocreate.mode", "disabled"); | ||
|
||
return props; | ||
} | ||
|
||
|
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 callback only gets invoked when the engine is totally off i'm assuming?
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.
yep, it's the last thing