comphead commented on code in PR #7016:
URL: https://github.com/apache/datafusion-comet/pull/7016#discussion_r4338820310


##########
spark/src/test/scala/org/apache/spark/sql/comet/DecodedBroadcastCacheSuite.scala:
##########
@@ -0,0 +1,471 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.spark.sql.comet
+
+import java.nio.charset.StandardCharsets
+import java.util.Properties
+import java.util.concurrent.{CountDownLatch, TimeUnit}
+import java.util.concurrent.atomic.AtomicInteger
+
+import scala.concurrent.{Await, Future, Promise}
+import scala.concurrent.duration._
+import scala.util.Try
+
+import org.apache.arrow.vector.{IntVector, VarCharVector}
+import org.apache.arrow.vector.dictionary.{Dictionary, DictionaryProvider}
+import org.apache.arrow.vector.types.pojo.{ArrowType, DictionaryEncoding, 
FieldType}
+import org.apache.spark.{SparkConf, TaskContextImpl, TaskKilledException}
+import org.apache.spark.executor.TaskMetrics
+import org.apache.spark.memory.{TaskMemoryManager, TestMemoryManager}
+import org.apache.spark.sql.CometTestBase
+import org.apache.spark.sql.comet.util.Utils
+import org.apache.spark.sql.internal.SQLConf
+import org.apache.spark.sql.vectorized.{ColumnarBatch, ColumnVector}
+import org.apache.spark.util.io.ChunkedByteBuffer
+
+import org.apache.comet.{CometArrowAllocator, CometConf}
+import org.apache.comet.vector.CometVector
+
+class DecodedBroadcastCacheSuite extends CometTestBase {
+
+  private val Timeout = 30.seconds
+
+  test("tasks that read a broadcast at the same time decode it once") {
+    val value = broadcastValue(rows(1000))
+    val (cache, decodes) = countingCache()
+    val before = CometArrowAllocator.getAllocatedMemory
+    val tasks = (1 to 4).map(i => newTask(i.toLong))
+
+    assert(readAll(cache.batches(value, tasks.head, "test")) == rows(1000))
+    val sharedCopy = CometArrowAllocator.getAllocatedMemory - before
+    assert(sharedCopy > 0)
+    tasks.tail.init.foreach { task =>
+      assert(readAll(cache.batches(value, task, "test")) == rows(1000))
+    }
+    assert(decodes.get == 1)
+    assert(cache.holders(value) == 3)
+    // Each task closed what it read, the way the native input reader does, so 
the one shared
+    // copy is all that the three tasks hold.
+    assert(CometArrowAllocator.getAllocatedMemory - before == sharedCopy)
+
+    // A consumer that leaves its batches open, as the JVM columnar-to-row 
path does, has them
+    // closed when it moves on and when its task completes.
+    assert(readAll(cache.batches(value, tasks.last, "test"), close = false) == 
rows(1000))
+    assert(decodes.get == 1)
+    tasks.foreach(_.markTaskCompleted(None))
+    assert(cache.size == 0)
+    assert(CometArrowAllocator.getAllocatedMemory == before)
+  }
+
+  test("the last task holding a broadcast frees it, and a later task decodes 
it again") {

Review Comment:
   This repeats most of the first test: one decode, freed when the last task 
completes, allocator back to `before`. Only the third task's second decode is 
new, and that fits in a few lines at the end of the first test.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to