Skip to content
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

Properly close Spark (streaming) context if Pipeline translation fails #23204

Merged
merged 1 commit into from
Sep 13, 2022
Merged
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,28 @@ public JavaStreamingContext call() throws Exception {
Duration batchDuration = new Duration(options.getBatchIntervalMillis());
LOG.info("Setting Spark streaming batchDuration to {} msec", batchDuration.milliseconds());

JavaSparkContext jsc = SparkContextFactory.getSparkContext(options);
JavaStreamingContext jssc = new JavaStreamingContext(jsc, batchDuration);
JavaSparkContext sparkCtx = SparkContextFactory.getSparkContext(options);
JavaStreamingContext streamingCtx = new JavaStreamingContext(sparkCtx, batchDuration);

// We must first init accumulators since translators expect them to be instantiated.
SparkRunner.initAccumulators(options, jsc);
SparkRunner.initAccumulators(options, sparkCtx);
// do not need to create a MetricsPusher instance here because if is called in SparkRunner.run()

EvaluationContext ctxt = new EvaluationContext(jsc, pipeline, options, jssc);
EvaluationContext evalCtx = new EvaluationContext(sparkCtx, pipeline, options, streamingCtx);
// update cache candidates
SparkRunner.updateCacheCandidates(pipeline, translator, ctxt);
pipeline.traverseTopologically(new SparkRunner.Evaluator(translator, ctxt));
ctxt.computeOutputs();
SparkRunner.updateCacheCandidates(pipeline, translator, evalCtx);
try {
pipeline.traverseTopologically(new SparkRunner.Evaluator(translator, evalCtx));
} catch (RuntimeException e) {
streamingCtx.stop(false, false);
SparkContextFactory.stopSparkContext(sparkCtx);
throw e;
}
evalCtx.computeOutputs();

checkpoint(jssc, checkpointDir);
checkpoint(streamingCtx, checkpointDir);

return jssc;
return streamingCtx;
}

private void checkpoint(JavaStreamingContext jssc, CheckpointDir checkpointDir) {
Expand Down