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

Handling exceptions while closing BeamSink #294

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions flink/src/main/scala/com/metamx/tranquility/flink/BeamSink.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
*/
package com.metamx.tranquility.flink

import com.metamx.common.scala.Logging
import com.metamx.common.scala.{Logger, Logging}
import com.metamx.tranquility.tranquilizer.MessageDroppedException
import com.metamx.tranquility.tranquilizer.Tranquilizer
import com.twitter.util.Return
import com.twitter.util.Throw
import java.util.concurrent.atomic.AtomicReference

import org.apache.flink.api.common.accumulators.LongCounter
import org.apache.flink.configuration.Configuration
import org.apache.flink.streaming.api.functions.sink.RichSinkFunction
Expand Down Expand Up @@ -66,9 +67,14 @@ class BeamSink[T](beamFactory: BeamFactory[T], reportDropsAsExceptions: Boolean
}

override def close() = {
sender.get.flush()
maybeThrow()
sender.get.stop()
try {
sender.get.flush()
maybeThrow()
sender.get.stop()
} catch {
case e : NoSuchElementException => log.warn(e, "No Tranquility object found while closing BeamSink")
case e : IllegalStateException => log.warn(e, "Exception while stopping Tranquility")
}
}

private def maybeThrow() {
Expand Down