Skip to content
Open
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 @@ -27,7 +27,7 @@ import ai.rapids.cudf._
import ai.rapids.cudf.ParquetWriterOptions.StatisticsFrequency
import com.nvidia.spark.GpuCachedBatchSerializer
import com.nvidia.spark.rapids.{ColumnCastUtil, DecimalUtil, GpuColumnVector, GpuRowToColumnConverter, GpuSemaphore, RapidsConf, RequireSingleBatch, RowToColumnarIterator, SchemaUtils}
import com.nvidia.spark.rapids.Arm.withResource
import com.nvidia.spark.rapids.Arm.{closeOnExcept, withResource}
import com.nvidia.spark.rapids.GpuColumnVector.GpuColumnarBatchBuilder
import com.nvidia.spark.rapids.RapidsPluginImplicits._
import com.nvidia.spark.rapids.ScalableTaskCompletion.onTaskCompletion
Expand Down Expand Up @@ -58,7 +58,7 @@ import org.apache.spark.sql.execution.datasources.parquet.rapids.ParquetRecordMa
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.rapids.PCBSSchemaHelper
import org.apache.spark.sql.types._
import org.apache.spark.sql.vectorized.ColumnarBatch
import org.apache.spark.sql.vectorized.{ColumnarBatch, ColumnVector => SparkColumnVector}
import org.apache.spark.storage.StorageLevel
import org.apache.spark.unsafe.types.CalendarInterval

Expand Down Expand Up @@ -365,7 +365,7 @@ class ParquetCachedBatchSerializer extends GpuCachedBatchSerializer {
.getBase.getDeviceMemorySize / oldGpuCB.numRows()
}.sum

val columns = for (i <- 0 until oldGpuCB.numCols()) yield {
val columns: Array[SparkColumnVector] = (0 until oldGpuCB.numCols()).toArray.safeMap { i =>
val gpuVector = oldGpuCB.column(i).asInstanceOf[GpuColumnVector]
var dataType = origSchema(i).dataType
val v = ColumnCastUtil.ifTrueThenDeepConvertTypeAtoTypeB(gpuVector.getBase,
Expand All @@ -385,7 +385,10 @@ class ParquetCachedBatchSerializer extends GpuCachedBatchSerializer {
)
GpuColumnVector.from(v, schema(i).dataType)
Comment on lines 368 to 386

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Intermediate v resource still unguarded on exception path

ifTrueThenDeepConvertTypeAtoTypeB always returns an owned ColumnVector — either copyToColumnVector() (new allocation) or incRefCount() (bumped ref). If GpuColumnVector.from(v, schema(i).dataType) throws (e.g., the assert typeConversionAllowed(...) fires when running with -ea), v is leaked because nothing closes it on the failure path. Wrapping the from call with closeOnExcept(v) { v => GpuColumnVector.from(v, schema(i).dataType) } would close v only on exception while correctly leaving ownership with the new GpuColumnVector on success.

}
withResource(new ColumnarBatch(columns.toArray, oldGpuCB.numRows())) { gpuCB =>
val newGpuCB = closeOnExcept(columns) { columns =>
new ColumnarBatch(columns, oldGpuCB.numRows())
}
withResource(newGpuCB) { gpuCB =>
val rowsAllowedInBatch = (bytesAllowedPerBatch / estimatedRowSize).toInt
val splitIndices = scala.Range(rowsAllowedInBatch, gpuCB.numRows(), rowsAllowedInBatch)
val buffers = new ListBuffer[ParquetCachedBatch]
Expand Down