You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@spark.apache.org by Akshat Aranya <aa...@gmail.com> on 2015/04/17 19:23:08 UTC

When are TaskCompletionListeners called?

Hi,

I'm trying to figure out when TaskCompletionListeners are called -- are
they called at the end of the RDD's compute() method, or after the
iteration through the iterator of the compute() method is completed.

To put it another way, is this OK:

class DatabaseRDD[T] extends RDD[T] {

  def compute(...): Iterator[T] = {
    val session = // acquire a DB session
    TaskContext.get.addTaskCompletionListener { (context) =>
      session.release()
    }

    val iterator = session.query(...)
    iterator
  }
}

Re: When are TaskCompletionListeners called?

Posted by Imran Rashid <ir...@cloudera.com>.
its the latter -- after spark gets to the end of the iterator (or if it
hits an exception)

so your example is good, that is exactly what it is intended for.

On Fri, Apr 17, 2015 at 12:23 PM, Akshat Aranya <aa...@gmail.com> wrote:

> Hi,
>
> I'm trying to figure out when TaskCompletionListeners are called -- are
> they called at the end of the RDD's compute() method, or after the
> iteration through the iterator of the compute() method is completed.
>
> To put it another way, is this OK:
>
> class DatabaseRDD[T] extends RDD[T] {
>
>   def compute(...): Iterator[T] = {
>     val session = // acquire a DB session
>     TaskContext.get.addTaskCompletionListener { (context) =>
>       session.release()
>     }
>
>     val iterator = session.query(...)
>     iterator
>   }
> }
>