shrirangmhalgi commented on code in PR #56598:
URL: https://github.com/apache/spark/pull/56598#discussion_r3439738704


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDB.scala:
##########
@@ -1593,7 +1605,63 @@ class RocksDB(
       }
       writer.deleteRange(beginKeyWithPrefix, endKeyForChangelog)
     }
-    // TODO: Add metrics update for deleteRange operations
+  }
+
+  /** Count the keys currently present in `[beginKeyWithPrefix,
+    * endKeyWithPrefix)`, split into non-internal vs internal column-family
+    * buckets.
+    *
+    * @param beginKeyWithPrefix
+    *   Already-prefixed start key (inclusive)
+    * @param endKeyWithPrefix
+    *   Already-prefixed end key (exclusive); used as the iterator upper bound
+    *   so we never touch keys beyond it.
+    * @param cfName
+    *   Caller-supplied column family. Used when `includesPrefix` is false;
+    * @param includesPrefix
+    *   When true, the keys already carry their cfId prefix.
+    * @return
+    *   (numKeys, numInternalKeys) - the counts to subtract from
+    *   `numKeysOnWritingVersion` and `numInternalKeysOnWritingVersion`
+    *   respectively.
+    */
+  private def countKeysInRange(
+      beginKeyWithPrefix: Array[Byte],
+      endKeyWithPrefix: Array[Byte],
+      cfName: String,
+      includesPrefix: Boolean
+  ): (Long, Long) = {
+    val upperBoundSlice = new Slice(endKeyWithPrefix)
+    val rangeReadOptions = new ReadOptions()
+    rangeReadOptions.setIterateUpperBound(upperBoundSlice)
+    val iter = db.newIterator(rangeReadOptions)
+    try {

Review Comment:
   nit: `upperBoundSlice` and `rangeReadOptions` are allocated before the `try` 
block. If `db.newIterator(rangeReadOptions)` throws, neither native resource is 
closed - the `finally` only runs after the `try` starts. Consider wrapping each 
in its own try-finally, or moving the allocations inside the `try` with a 
null-check in `finally`.
   
   



-- 
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