-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Take semaphore after first stream batch is materialized (broadcast) (#…
…6709) * Fix semaphore acquisition before stream side IO in broadcast join Signed-off-by: Alessandro Bellina <abellina@nvidia.com> * Break up CloseableBufferedIterator into its own class * Fix typo Signed-off-by: Alessandro Bellina <abellina@nvidia.com>
- Loading branch information
Showing
4 changed files
with
100 additions
and
33 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
sql-plugin/src/main/scala/com/nvidia/spark/rapids/CloseableBufferedIterator.scala
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,45 @@ | ||
/* | ||
* Copyright (c) 2022, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.nvidia.spark.rapids | ||
|
||
import org.apache.spark.TaskContext | ||
|
||
/** | ||
* Helper iterator that wraps a BufferedIterator of AutoCloseable subclasses. | ||
* This iterator also implements AutoCloseable, so it can be closed in case | ||
* of exceptions. | ||
* | ||
* @param wrapped the buffered iterator | ||
* @tparam T an AutoCloseable subclass | ||
*/ | ||
class CloseableBufferedIterator[T <: AutoCloseable](wrapped: BufferedIterator[T]) | ||
extends BufferedIterator[T] with AutoCloseable { | ||
// register against task completion to close any leaked buffered items | ||
Option(TaskContext.get()).foreach(_.addTaskCompletionListener[Unit](_ => close())) | ||
|
||
private[this] var isClosed = false | ||
override def head: T = wrapped.head | ||
override def headOption: Option[T] = wrapped.headOption | ||
override def next: T = wrapped.next | ||
override def hasNext: Boolean = wrapped.hasNext | ||
override def close(): Unit = { | ||
if (!isClosed) { | ||
headOption.foreach(_.close()) | ||
isClosed = true | ||
} | ||
} | ||
} |
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