-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Stop using gentle close with heartbeat #8036
Merged
lmossman
merged 3 commits into
master
from
lmossman/stop-using-gentle-close-with-heartbeat
Nov 17, 2021
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
69 changes: 69 additions & 0 deletions
69
...est/src/main/java/io/airbyte/integrations/destination/e2e_test/FailAfterNDestination.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,69 @@ | ||
package io.airbyte.integrations.destination.e2e_test; | ||
|
||
import static java.lang.Thread.sleep; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import io.airbyte.integrations.BaseConnector; | ||
import io.airbyte.integrations.base.AirbyteMessageConsumer; | ||
import io.airbyte.integrations.base.Destination; | ||
import io.airbyte.protocol.models.AirbyteConnectionStatus; | ||
import io.airbyte.protocol.models.AirbyteConnectionStatus.Status; | ||
import io.airbyte.protocol.models.AirbyteMessage; | ||
import io.airbyte.protocol.models.AirbyteMessage.Type; | ||
import io.airbyte.protocol.models.ConfiguredAirbyteCatalog; | ||
import java.util.function.Consumer; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class FailAfterNDestination extends BaseConnector implements Destination { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(FailAfterNDestination.class); | ||
|
||
@Override | ||
public AirbyteConnectionStatus check(final JsonNode config) { | ||
return new AirbyteConnectionStatus().withStatus(Status.SUCCEEDED); | ||
} | ||
|
||
@Override | ||
public AirbyteMessageConsumer getConsumer(final JsonNode config, | ||
final ConfiguredAirbyteCatalog catalog, | ||
final Consumer<AirbyteMessage> outputRecordCollector) { | ||
return new FailAfterNConsumer(config.get("num_messages").asLong(), outputRecordCollector); | ||
} | ||
|
||
public static class FailAfterNConsumer implements AirbyteMessageConsumer { | ||
|
||
private final Consumer<AirbyteMessage> outputRecordCollector; | ||
private final long numMessagesAfterWhichToFail; | ||
private long numMessagesSoFar; | ||
|
||
public FailAfterNConsumer(final long numMessagesAfterWhichToFail, final Consumer<AirbyteMessage> outputRecordCollector) { | ||
this.numMessagesAfterWhichToFail = numMessagesAfterWhichToFail; | ||
this.outputRecordCollector = outputRecordCollector; | ||
this.numMessagesSoFar = 0; | ||
} | ||
|
||
@Override | ||
public void start() {} | ||
|
||
@Override | ||
public void accept(final AirbyteMessage message) throws Exception { | ||
LOGGER.info("received record: {}", message); | ||
numMessagesSoFar += 1; | ||
LOGGER.info("received {} messages so far", numMessagesSoFar); | ||
|
||
if (numMessagesSoFar > numMessagesAfterWhichToFail) { | ||
throw new IllegalStateException("Forcing a fail after processing " + numMessagesAfterWhichToFail + " messages."); | ||
} | ||
|
||
if (message.getType() == Type.STATE) { | ||
LOGGER.info("emitting state: {}", message); | ||
outputRecordCollector.accept(message); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() {} | ||
|
||
} | ||
} |
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
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 |
---|---|---|
|
@@ -59,7 +59,7 @@ public static void gentleClose(final Process process, final long timeout, final | |
} | ||
|
||
if (process.isAlive()) { | ||
forceShutdown(process, Duration.of(1, ChronoUnit.MINUTES)); | ||
closeProcess(process, Duration.of(1, ChronoUnit.MINUTES)); | ||
} | ||
} | ||
|
||
|
@@ -90,7 +90,7 @@ public static void gentleCloseWithHeartbeat(final Process process, | |
gracefulShutdownDuration, | ||
checkHeartbeatDuration, | ||
forcedShutdownDuration, | ||
WorkerUtils::forceShutdown); | ||
WorkerUtils::closeProcess); | ||
} | ||
|
||
@VisibleForTesting | ||
|
@@ -134,28 +134,15 @@ static void gentleCloseWithHeartbeat(final Process process, | |
} | ||
} | ||
|
||
@VisibleForTesting | ||
static void forceShutdown(final Process process, final Duration lastChanceDuration) { | ||
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 method was basically a copy of |
||
LOGGER.warn("Process is taking too long to finish. Killing it"); | ||
process.destroy(); | ||
try { | ||
process.waitFor(lastChanceDuration.toMillis(), TimeUnit.MILLISECONDS); | ||
} catch (final InterruptedException e) { | ||
LOGGER.error("Exception while while killing the process", e); | ||
} | ||
if (process.isAlive()) { | ||
LOGGER.error("Couldn't kill the process. You might have a zombie process."); | ||
} | ||
} | ||
|
||
public static void closeProcess(final Process process, final int duration, final TimeUnit timeUnit) { | ||
public static void closeProcess(final Process process, final Duration lastChanceDuration) { | ||
if (process == null) { | ||
return; | ||
} | ||
try { | ||
process.destroy(); | ||
process.waitFor(duration, timeUnit); | ||
process.waitFor(lastChanceDuration.toMillis(), TimeUnit.MILLISECONDS); | ||
if (process.isAlive()) { | ||
LOGGER.warn("Process is still alive after calling destroy. Attempting to destroy forcibly..."); | ||
process.destroyForcibly(); | ||
} | ||
} catch (final InterruptedException e) { | ||
|
@@ -172,7 +159,7 @@ public static void wait(final Process process) { | |
} | ||
|
||
public static void cancelProcess(final Process process) { | ||
closeProcess(process, 10, TimeUnit.SECONDS); | ||
closeProcess(process, Duration.of(10, ChronoUnit.SECONDS)); | ||
} | ||
|
||
/** | ||
|
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
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.
fwiw this field could probably be optional.