-
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
🐛 Do not propagate exceptions on source close. #33609
Draft
davinchia
wants to merge
10
commits into
master
Choose a base branch
from
davinchia/source-read-ignore-exception-close
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+35
−22
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ee02942
Checkpoint: tentative implementation.
davinchia bf6ef3e
Remove WIP.
davinchia ba9dd59
Move things back.
davinchia 2913a66
Remove bad import.
davinchia f7042f0
Revert "Checkpoint: tentative implementation."
davinchia 3e4aa52
Revert "Remove WIP."
davinchia 797d0f7
Checkpoint: implement for readSerial.
davinchia 6af53c5
Better ignore exception on close.
davinchia e197441
Undo WIP.
davinchia 0776977
Merge branch 'master' into davinchia/source-read-ignore-exception-close
davinchia 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,10 +32,12 @@ | |
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.concurrent.Callable; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
import java.util.function.Predicate; | ||
import java.util.stream.Collectors; | ||
import org.apache.commons.lang3.ThreadUtils; | ||
|
@@ -168,11 +170,19 @@ private void runInternal(final IntegrationConfig parsed) throws Exception { | |
try { | ||
if (featureFlags.concurrentSourceStreamRead()) { | ||
LOGGER.info("Concurrent source stream read enabled."); | ||
readConcurrent(config, catalog, stateOptional); | ||
final Collection<AutoCloseableIterator<AirbyteMessage>> streams = source.readStreams(config, catalog, stateOptional.orElse(null)); | ||
final ConcurrentStreamConsumer streamConsumer = new ConcurrentStreamConsumer(this::consumeFromStream, streams.size()); | ||
readConcurrent(streams, streamConsumer); | ||
} else { | ||
readSerial(config, catalog, stateOptional); | ||
AutoCloseableIterator<AirbyteMessage> messageIterator = source.read(config, catalog, stateOptional.orElse(null)); | ||
readSerial(messageIterator, outputRecordCollector); | ||
} | ||
} finally { | ||
stopOrphanedThreads(EXIT_HOOK, | ||
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. call this only once instead of twice in each method. |
||
INTERRUPT_THREAD_DELAY_MINUTES, | ||
TimeUnit.MINUTES, | ||
EXIT_THREAD_DELAY_MINUTES, | ||
TimeUnit.MINUTES); | ||
if (source instanceof AutoCloseable) { | ||
((AutoCloseable) source).close(); | ||
} | ||
|
@@ -231,17 +241,16 @@ private void runInternal(final IntegrationConfig parsed) throws Exception { | |
LOGGER.info("Completed integration: {}", integration.getClass().getName()); | ||
} | ||
|
||
private void produceMessages(final AutoCloseableIterator<AirbyteMessage> messageIterator, final Consumer<AirbyteMessage> recordCollector) { | ||
private static void produceMessages(final AutoCloseableIterator<AirbyteMessage> messageIterator, final Consumer<AirbyteMessage> recordCollector) { | ||
messageIterator.getAirbyteStream().ifPresent(s -> LOGGER.debug("Producing messages for stream {}...", s)); | ||
messageIterator.forEachRemaining(recordCollector); | ||
messageIterator.getAirbyteStream().ifPresent(s -> LOGGER.debug("Finished producing messages for stream {}...")); | ||
} | ||
|
||
private void readConcurrent(final JsonNode config, final ConfiguredAirbyteCatalog catalog, final Optional<JsonNode> stateOptional) | ||
@VisibleForTesting | ||
private static void readConcurrent(final Collection<AutoCloseableIterator<AirbyteMessage>> streams, final ConcurrentStreamConsumer streamConsumer) | ||
throws Exception { | ||
final Collection<AutoCloseableIterator<AirbyteMessage>> streams = source.readStreams(config, catalog, stateOptional.orElse(null)); | ||
|
||
try (final ConcurrentStreamConsumer streamConsumer = new ConcurrentStreamConsumer(this::consumeFromStream, streams.size())) { | ||
try { | ||
/* | ||
* Break the streams into partitions equal to the number of concurrent streams supported by the | ||
* stream consumer. | ||
|
@@ -262,24 +271,28 @@ private void readConcurrent(final JsonNode config, final ConfiguredAirbyteCatalo | |
} catch (final Exception e) { | ||
LOGGER.error("Unable to perform concurrent read.", e); | ||
throw e; | ||
} finally { | ||
stopOrphanedThreads(EXIT_HOOK, | ||
INTERRUPT_THREAD_DELAY_MINUTES, | ||
TimeUnit.MINUTES, | ||
EXIT_THREAD_DELAY_MINUTES, | ||
TimeUnit.MINUTES); | ||
} | ||
// It is generally safe to ignore exceptions on close. | ||
try { | ||
streamConsumer.close(); | ||
for (AutoCloseableIterator<AirbyteMessage> stream : streams) { | ||
stream.close(); | ||
} | ||
} catch (final Exception e) { | ||
LOGGER.warn("Exception closing connection: {}. This is generally fine as we've moved all data & are terminating everything. ", | ||
e.getMessage()); | ||
} | ||
} | ||
|
||
private void readSerial(final JsonNode config, final ConfiguredAirbyteCatalog catalog, final Optional<JsonNode> stateOptional) throws Exception { | ||
try (final AutoCloseableIterator<AirbyteMessage> messageIterator = source.read(config, catalog, stateOptional.orElse(null))) { | ||
produceMessages(messageIterator, outputRecordCollector); | ||
} finally { | ||
stopOrphanedThreads(EXIT_HOOK, | ||
INTERRUPT_THREAD_DELAY_MINUTES, | ||
TimeUnit.MINUTES, | ||
EXIT_THREAD_DELAY_MINUTES, | ||
TimeUnit.MINUTES); | ||
@VisibleForTesting | ||
static private void readSerial(final AutoCloseableIterator<AirbyteMessage> iter, Consumer<AirbyteMessage> outputRecordCollector) throws Exception { | ||
produceMessages(iter, outputRecordCollector); | ||
// It is generally safe to ignore exceptions on close. | ||
try { | ||
iter.close(); | ||
} catch (Exception e) { | ||
LOGGER.warn("Exception closing connection: {}. This is generally fine as we've moved all data & are terminating everything. ", | ||
e.getMessage()); | ||
} | ||
} | ||
|
||
|
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.
generally: