You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by ka...@apache.org on 2024/12/16 03:38:21 UTC

(spark) branch master updated: [SPARK-50360][SS][FOLLOWUP][MINOR] Make readVersion lazy value

This is an automated email from the ASF dual-hosted git repository.

kabhwan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new 15dcd21323fa [SPARK-50360][SS][FOLLOWUP][MINOR] Make readVersion lazy value
15dcd21323fa is described below

commit 15dcd21323fa0cc015e965c6443ff3875108342a
Author: Zhihong Yu <yu...@gmail.com>
AuthorDate: Mon Dec 16 12:38:07 2024 +0900

    [SPARK-50360][SS][FOLLOWUP][MINOR] Make readVersion lazy value
    
    ### What changes were proposed in this pull request?
    This is followup to https://github.com/apache/spark/pull/48880
    `readVersion` is made a `lazy` value.
    After `input` is closed, its value is not changed to `null` because `input` is only used by `readVersion`.
    
    ### Why are the changes needed?
    `StateStoreChangelogReaderFactory` is able to produce more than one reader.
    
    ### Does this PR introduce _any_ user-facing change?
    No
    
    ### How was this patch tested?
    Existing test suite.
    
    ### Was this patch authored or co-authored using generative AI tooling?
    No
    
    Closes #49091 from tedyu/null-input.
    
    Authored-by: Zhihong Yu <yu...@gmail.com>
    Signed-off-by: Jungtaek Lim <ka...@gmail.com>
---
 .../spark/sql/execution/streaming/state/StateStoreChangelog.scala    | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/StateStoreChangelog.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/StateStoreChangelog.scala
index f6787a37bc80..b4fbb5560f2f 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/StateStoreChangelog.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/StateStoreChangelog.scala
@@ -353,7 +353,7 @@ class StateStoreChangelogReaderFactory(
   }
   protected val input: DataInputStream = decompressStream(sourceStream)
 
-  private def readVersion(): Short = {
+  private lazy val changeLogVersion: Short = {
     try {
       val versionStr = input.readUTF()
       // Versions in the first line are prefixed with "v", e.g. "v2"
@@ -379,7 +379,7 @@ class StateStoreChangelogReaderFactory(
   def constructChangelogReader(): StateStoreChangelogReader = {
     var reader: StateStoreChangelogReader = null
     try {
-      reader = readVersion() match {
+      reader = changeLogVersion match {
         case 1 => new StateStoreChangelogReaderV1(fm, fileToRead, compressionCodec)
         case 2 => new StateStoreChangelogReaderV2(fm, fileToRead, compressionCodec)
         case 3 => new StateStoreChangelogReaderV3(fm, fileToRead, compressionCodec)
@@ -389,6 +389,7 @@ class StateStoreChangelogReaderFactory(
     } finally {
       if (input != null) {
         input.close()
+        // input is not set to null because it is effectively lazy.
       }
     }
     reader


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org