Skip to content

fix: reconnect when auth error occurs in runDropStage method #77

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

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions src/main/java/org/embulk/output/SnowflakeOutputPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.sql.Types;
import java.util.*;
import java.util.function.BiFunction;
import net.snowflake.client.jdbc.SnowflakeSQLException;
import net.snowflake.client.jdbc.internal.org.bouncycastle.operator.OperatorCreationException;
import net.snowflake.client.jdbc.internal.org.bouncycastle.pkcs.PKCSException;
import org.embulk.config.ConfigDiff;
Expand Down Expand Up @@ -204,12 +205,12 @@ public ConfigDiff transaction(
snowflakeCon.runCreateStage(stageIdentifier);
configDiff = super.transaction(config, schema, taskCount, control);
if (t.getDeleteStage()) {
snowflakeCon.runDropStage(stageIdentifier);
runDropStage(snowflakeCon, stageIdentifier, task);
}
} catch (Exception e) {
if (t.getDeleteStage() && t.getDeleteStageOnError()) {
try {
snowflakeCon.runDropStage(stageIdentifier);
runDropStage(snowflakeCon, stageIdentifier, task);
} catch (SQLException ex) {
throw new RuntimeException(ex);
}
Expand All @@ -220,6 +221,27 @@ public ConfigDiff transaction(
return configDiff;
}

private void runDropStage(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

復帰処理も含んでのものだと思うので、名前に含んでおきたい気がしました

Suggested change
private void runDropStage(
private void runDropStageWithRecovery(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

こちら、trocco.io の外からPR出すとCIでエラーになるので、trocco.io内でブランチ切り直してPRだしました。
#82

指摘の修正も含まれています 🙇
ed4f320

SnowflakeOutputConnection snowflakeCon, StageIdentifier stageIdentifier, PluginTask task)
throws SQLException {
try {
snowflakeCon.runDropStage(stageIdentifier);
} catch (SnowflakeSQLException ex) {
logger.info("SnowflakeSQLException was caught: {}", ex.getMessage());

if (ex.getMessage().startsWith("Authentication token has expired.")
|| ex.getMessage().startsWith("Session no longer exists.")) {

// INFO: If runCreateStage consumed a lot of time, authentication might be expired.
// In this case, retry to drop stage.
snowflakeCon = (SnowflakeOutputConnection) getConnector(task, true).connect(true);
snowflakeCon.runDropStage(stageIdentifier);
} else {
throw ex;
}
}
}

@Override
public ConfigDiff resume(
TaskSource taskSource, Schema schema, int taskCount, OutputPlugin.Control control) {
Expand Down