LuciferYang commented on code in PR #43502:
URL: https://github.com/apache/spark/pull/43502#discussion_r1398623958


##########
common/kvstore/src/main/java/org/apache/spark/util/kvstore/LevelDB.java:
##########
@@ -322,26 +323,15 @@ public void close() throws IOException {
     }
   }
 
-  /**
-   * Closes the given iterator if the DB is still open. Trying to close a JNI 
LevelDB handle
-   * with a closed DB can cause JVM crashes, so this ensures that situation 
does not happen.
-   */
-  void closeIterator(LevelDBIterator<?> it) throws IOException {
-    notifyIteratorClosed(it);
-    synchronized (this._db) {
-      DB _db = this._db.get();
-      if (_db != null) {
-        it.close();
-      }
-    }
-  }

Review Comment:
   We can revert change of `closeIterator` method in `LevelDB` and refactor it 
as :
   
   ```java
     void closeIterator(DBIterator it) throws IOException {
       notifyIteratorClosed(it);
       synchronized (this._db) {
         DB _db = this._db.get();
         if (_db != null) {
           it.close();
         }
       }
     }
   ```
   
   then there we can call `closeIterator` directly like:
   
   ```java
   public void run() {
         if (started.compareAndSet(true, false)) {
           try {
             levelDB.closeIterator(dbIterator);
           } catch (IOException e) {
             // logXXX("Failed to close iterator", e);
           }
         }
       }
   ```
   
   Do you mean this idea? @mridulm 



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