You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/05/06 08:11:01 UTC

[GitHub] [spark] LuciferYang opened a new pull request, #36467: [DON'T MERGE] Replace `finalize()` with custom ReferenceQueue for `RocksDBIterator` cleanup

LuciferYang opened a new pull request, #36467:
URL: https://github.com/apache/spark/pull/36467

   ### What changes were proposed in this pull request?
   This pr try to use a custom `ReferenceQueue + cleanupThread` instead of `Finalization` mechanism to automatically clean up `RocksDBIterator` resources that are not explicitly closed in Spark code.
   
   
   ### Why are the changes needed?
   Fix potential vm crash and `RocksDBIterator` resource leaks caused by lock contention.
   
   Will added
   
   
   ### Does this PR introduce _any_ user-facing change?
   No
   
   
   ### How was this patch tested?
   Pass GA
   


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [spark] mridulm commented on pull request #36467: [SPARK-39063][CORE] Fix potential risk of JVM crash and `RocksDBIterator` resource leak

Posted by GitBox <gi...@apache.org>.
mridulm commented on PR #36467:
URL: https://github.com/apache/spark/pull/36467#issuecomment-1123118193

   > If the definition of iteratorTracker is changed from ConcurrentLinkedQueue<Reference<RocksDBIterator<?>>> to ConcurrentLinkedQueue<RocksDBIterator<?>> , then you are right.
   
   It should not need change types.
   In the current code, `ConcurrentLinkedQueue<Reference<RocksDBIterator<?>>>` allows us to keep a reference to the `RocksDBIterator`, without holding a strong reference to it (so it can be gc'ed if there are no other references to it).
   
   To sketch a possible solution:
   
   
   ```
   RocksDBIterator:
   public synchronized void close() throws IOException {
     close(false);
   }
   
   // accessible from RocksDB
   void close(boolean forceClose) {
     if (db.notifyIteratorClosed(this) || forceClose) {
       if (!closed) {
         it.close();
         closed = true;
       }
     }
   }
   
   RocksDB:
   In close() : call it.close(true), instead.
   
   For notifyIteratorClosed:
   // return true if DB is still open
   boolean notifyIteratorClosed(RocksDBIterator<?> it) {
     iteratorTracker.removeIf(ref -> it.equals(ref.get()));
     return _db.get() != null;
   }
   
   
   
   
   ```
   
   
   
   
   


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [spark] LuciferYang commented on a diff in pull request #36467: [SPARK-39063][CORE] Fix potential JVM crash and `RocksDBIterator` resource leak

Posted by GitBox <gi...@apache.org>.
LuciferYang commented on code in PR #36467:
URL: https://github.com/apache/spark/pull/36467#discussion_r867443554


##########
common/kvstore/src/main/java/org/apache/spark/util/kvstore/RocksDB.java:
##########
@@ -418,6 +414,33 @@ private byte[] getTypeAlias(Class<?> klass) throws Exception {
     return alias;
   }
 
+  private void stopCleanupThread() throws InterruptedException {
+    if (cleaningThread != null) {
+      stopped = true;
+      cleaningThread.join();
+    }
+  }
+
+  private void keepCleaning() {
+    boolean lastIsPresent = false;

Review Comment:
   Added `lastIsPresent` to ensure all `RocksDBIterator`s dropped by GC are closed  , otherwise `testAllRocksDBIteratorNotExplicitClosed` will lead JVM crash
   
   



##########
common/kvstore/src/main/java/org/apache/spark/util/kvstore/RocksDB.java:
##########
@@ -418,6 +414,33 @@ private byte[] getTypeAlias(Class<?> klass) throws Exception {
     return alias;
   }
 
+  private void stopCleanupThread() throws InterruptedException {
+    if (cleaningThread != null) {
+      stopped = true;
+      cleaningThread.join();
+    }
+  }
+
+  private void keepCleaning() {
+    boolean lastIsPresent = false;

Review Comment:
   Add `lastIsPresent` to ensure all `RocksDBIterator`s dropped by GC are closed  , otherwise `testAllRocksDBIteratorNotExplicitClosed` will lead JVM crash
   
   



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [spark] LuciferYang commented on pull request #36467: [SPARK-39063][CORE] Fix potential risk of JVM crash and `RocksDBIterator` resource leak

Posted by GitBox <gi...@apache.org>.
LuciferYang commented on PR #36467:
URL: https://github.com/apache/spark/pull/36467#issuecomment-1123072697

   > (This will also mean that it.close within db.close will need to handle the corner case - pass a forceClose even if notifyIteratorClosed returns false)
   
   Sorry that I didn't understand that clearly. `it.close()` is always executed in the current code and the return value of `db.notifyIteratorClosed(this)` is ignored, do you mean that if `db.notifyIteratorClosed(this)` returns `false`, then not execute `it.close()` or do other processing?


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [spark] srowen commented on pull request #36467: [SPARK-39063][CORE] Fix potential risk of JVM crash and `RocksDBIterator` resource leak

Posted by GitBox <gi...@apache.org>.
srowen commented on PR #36467:
URL: https://github.com/apache/spark/pull/36467#issuecomment-1121345960

   This seems like a well thought-out change, though it's complex compared to the issue it's trying to solve - a setting of a non-default third party library. I'm neutral about bothering with it if 'normal' rocksdb does not have this issue.


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [spark] dongjoon-hyun commented on pull request #36467: [SPARK-39063][CORE] Fix potential risk of JVM crash and `RocksDBIterator` resource leak

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on PR #36467:
URL: https://github.com/apache/spark/pull/36467#issuecomment-1120612686

   > I want this pr to focus on `RocksDB` first, so `LevelDB` is not changed not in this pr
   
   Can we proceed `LevelDB` first because it's enabled by default? `RocksDB` is not used by default and it's not tested widely.


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [spark] LuciferYang commented on pull request #36467: [SPARK-39063][CORE] Fix potential risk of JVM crash and `RocksDBIterator` resource leak

Posted by GitBox <gi...@apache.org>.
LuciferYang commented on PR #36467:
URL: https://github.com/apache/spark/pull/36467#issuecomment-1121389575

   DEBUG_LEVEL will  manually set to 0 to disable all assertions when normal rocksdb release,  so it won't really crash the VM, but I think the issue still exists


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [spark] LuciferYang commented on pull request #36467: [DON'T MERGE] Replace `finalize()` with custom ReferenceQueue for `RocksDBIterator` cleanup

Posted by GitBox <gi...@apache.org>.
LuciferYang commented on PR #36467:
URL: https://github.com/apache/spark/pull/36467#issuecomment-1120124977

   https://github.com/apache/spark/pull/36403#issuecomment-1114466277


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [spark] LuciferYang commented on a diff in pull request #36467: [SPARK-39063][CORE] Fix potential risk of JVM crash and `RocksDBIterator` resource leak

Posted by GitBox <gi...@apache.org>.
LuciferYang commented on code in PR #36467:
URL: https://github.com/apache/spark/pull/36467#discussion_r867603816


##########
common/kvstore/src/main/java/org/apache/spark/util/kvstore/RocksDB.java:
##########
@@ -457,4 +480,19 @@ byte[] getPrefix(RocksDBTypeInfo.Index idx) throws Exception {
 
   }
 
+  private static class RocksDBIteratorWeakReference extends WeakReference<RocksDBIterator<?>> {

Review Comment:
   [65e0c00](https://github.com/apache/spark/pull/36467/commits/65e0c00077906ce8a2ff0640278395a7b4e3f914) move `RocksDBIteratorWeakReference` to `RocksDBIterator` first to avoid  add `Getter` of `o.rocksdb.RocksIterator` 



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [spark] LuciferYang commented on pull request #36467: [SPARK-39063][CORE] Fix potential risk of JVM crash and `RocksDBIterator` resource leak

Posted by GitBox <gi...@apache.org>.
LuciferYang commented on PR #36467:
URL: https://github.com/apache/spark/pull/36467#issuecomment-1120581971

   > Finally, is this ready for review, @LuciferYang ? :)
   
   Yes, can you help to review this? @dongjoon-hyun 
   
   


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [spark] mridulm commented on pull request #36467: [SPARK-39063][CORE] Fix potential risk of JVM crash and `RocksDBIterator` resource leak

Posted by GitBox <gi...@apache.org>.
mridulm commented on PR #36467:
URL: https://github.com/apache/spark/pull/36467#issuecomment-1121625153

   I have not looked into this in great detail, but why not simply return a boolean from `notifyIteratorClosed` to indicate if the underlying db has been closed or not ?
   This can be used to determine if the iterator needs to be closed ? This is similar to what `closeIterator` does in RocksDb (for example)


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [spark] LuciferYang commented on pull request #36467: [DON'T MERGE] Replace `finalize()` with custom ReferenceQueue for `RocksDBIterator` cleanup

Posted by GitBox <gi...@apache.org>.
LuciferYang commented on PR #36467:
URL: https://github.com/apache/spark/pull/36467#issuecomment-1120148690

   Description of `DEBUG_LEVEL` as follows:
   
   https://github.com/facebook/rocksdb/blob/7b55b508390d792ff31a416b63d474a2a6780588/Makefile#L31-L42
   
   ```
   # DEBUG_LEVEL can have three values:
   # * DEBUG_LEVEL=2; this is the ultimate debug mode. It will compile rocksdb
   # without any optimizations. To compile with level 2, issue `make dbg`
   # * DEBUG_LEVEL=1; debug level 1 enables all assertions and debug code, but
   # compiles rocksdb with -O2 optimizations. this is the default debug level.
   # `make all` or `make <binary_target>` compile RocksDB with debug level 1.
   # We use this debug level when developing RocksDB.
   # * DEBUG_LEVEL=0; this is the debug level we use for release. If you're
   # running rocksdb in production you most definitely want to compile RocksDB
   # with debug level 0. To compile with level 0, run `make shared_lib`,
   # `make install-shared`, `make static_lib`, `make install-static` or
   # `make install`
   ```


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [spark] LuciferYang commented on pull request #36467: [SPARK-39063][CORE] Fix potential risk of JVM crash and `RocksDBIterator` resource leak

Posted by GitBox <gi...@apache.org>.
LuciferYang commented on PR #36467:
URL: https://github.com/apache/spark/pull/36467#issuecomment-1170801552

   @dongjoon-hyun @srowen @mridulm Thanks for your review. I will close this pr
   
   


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [spark] LuciferYang closed pull request #36467: [SPARK-39063][CORE] Fix potential risk of JVM crash and `RocksDBIterator` resource leak

Posted by GitBox <gi...@apache.org>.
LuciferYang closed pull request #36467: [SPARK-39063][CORE]  Fix potential risk of JVM crash and `RocksDBIterator` resource leak
URL: https://github.com/apache/spark/pull/36467


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [spark] LuciferYang commented on a diff in pull request #36467: [SPARK-39063][CORE] Fix potential risk of JVM crash and `RocksDBIterator` resource leak

Posted by GitBox <gi...@apache.org>.
LuciferYang commented on code in PR #36467:
URL: https://github.com/apache/spark/pull/36467#discussion_r867596466


##########
common/kvstore/src/main/java/org/apache/spark/util/kvstore/RocksDB.java:
##########
@@ -457,4 +480,19 @@ byte[] getPrefix(RocksDBTypeInfo.Index idx) throws Exception {
 
   }
 
+  private static class RocksDBIteratorWeakReference extends WeakReference<RocksDBIterator<?>> {

Review Comment:
   `RocksDBIteratorWeakReference` use to hold `RocksIterator`,  better as the inner class of `RocksDB` or `RocksDBIterator`? I want your suggestion @dongjoon-hyun 
   
   



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [spark] LuciferYang commented on pull request #36467: [SPARK-39063][CORE] Fix potential risk of JVM crash and `RocksDBIterator` resource leak

Posted by GitBox <gi...@apache.org>.
LuciferYang commented on PR #36467:
URL: https://github.com/apache/spark/pull/36467#issuecomment-1121718336

   > I have not looked into this in great detail, but why not simply return a boolean from `notifyIteratorClosed` to indicate if the underlying db has been closed or not ? This can be used to determine if the iterator needs to be closed ? This is similar to what `closeIterator` does in RocksDb (for example)
   
   The issue to be solved is:
   Ensure all RocksDBIterators are clsoed before the RocksDB is closed, otherwise the JVM will crash when use a rocksdb with debug mode enable
   


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [spark] LuciferYang commented on pull request #36467: [SPARK-39063][CORE] Fix potential risk of JVM crash and `RocksDBIterator` resource leak

Posted by GitBox <gi...@apache.org>.
LuciferYang commented on PR #36467:
URL: https://github.com/apache/spark/pull/36467#issuecomment-1123039782

   > > The issue to be solved is: Ensure all RocksDBIterators are clsoed before the RocksDB is closed, otherwise the JVM will crash when use a rocksdb with debug mode enabled.
   > 
   > This is already handled by `iteratorTracker`, right ? RocksDB.close() already iterates over all `RocksDBIterator` and closes them before closing itself. (This will also mean that it.close within db.close will need to handle the corner case - pass a forceClose even if `notifyIteratorClosed` returns `false`)
   
   If the definition of `iteratorTracker` is changed from `ConcurrentLinkedQueue<Reference<RocksDBIterator<?>>>` to `ConcurrentLinkedQueue<RocksDBIterator<?>> `, then you are right.
   
   However, `iteratorTracker` holds `RocksDBIterator` WeakReference now, so it doesn't hold all unclosed `RocksDBIterator` due to JVM GC, some `RocksDBIterator` will be held by the JVM `Finalizer` thread. We cannot interfere with the running state of `Finalizer`, so there is no guarantee that all not closed `RocksDBIterator` in `Finalizer` have been closed before `RocksDB.close` is executed. At the same time, The thread executing `RocksDB.close()` and `Finalizer` thread need the same lock, so if `RocksDB.close()` executes first, pending `db.closeIterator(this)` in `Finalizer` can only wait.
   
   
   
   
   
   
   


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [spark] LuciferYang commented on pull request #36467: [DON'T MERGE] Replace `finalize()` with custom ReferenceQueue for `RocksDBIterator` cleanup

Posted by GitBox <gi...@apache.org>.
LuciferYang commented on PR #36467:
URL: https://github.com/apache/spark/pull/36467#issuecomment-1119368808

   Just for test now


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [spark] LuciferYang commented on pull request #36467: [DON'T MERGE] Replace `finalize()` with custom ReferenceQueue for `RocksDBIterator` cleanup

Posted by GitBox <gi...@apache.org>.
LuciferYang commented on PR #36467:
URL: https://github.com/apache/spark/pull/36467#issuecomment-1120149831

   If `DEBUG_LEVEL=1`
   
   https://github.com/facebook/rocksdb/blob/b7119ff818f83b54a46602ac1f23d4fe2add1bfc/db/column_family.cc#L1488-L1495
   
   ```c
   ColumnFamilySet::~ColumnFamilySet() {
     while (column_family_data_.size() > 0) {
       // cfd destructor will delete itself from column_family_data_
       auto cfd = column_family_data_.begin()->second;
       bool last_ref __attribute__((__unused__));
       last_ref = cfd->UnrefAndTryDelete();
       assert(last_ref); // this assert will lead jvm crash
     }
   ```


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [spark] LuciferYang commented on pull request #36467: [SPARK-39063][CORE] Fix potential risk of JVM crash and `RocksDBIterator` resource leak

Posted by GitBox <gi...@apache.org>.
LuciferYang commented on PR #36467:
URL: https://github.com/apache/spark/pull/36467#issuecomment-1120640586

   @dongjoon-hyun LevelDB one: https://github.com/apache/spark/pull/36484


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [spark] LuciferYang commented on pull request #36467: [SPARK-39063][CORE] Fix potential risk of JVM crash and `RocksDBIterator` resource leak

Posted by GitBox <gi...@apache.org>.
LuciferYang commented on PR #36467:
URL: https://github.com/apache/spark/pull/36467#issuecomment-1120624390

   Let me give a `LevelDB` pr first 


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [spark] LuciferYang commented on pull request #36467: [DON'T MERGE] Replace `finalize()` with custom ReferenceQueue for `RocksDBIterator` cleanup

Posted by GitBox <gi...@apache.org>.
LuciferYang commented on PR #36467:
URL: https://github.com/apache/spark/pull/36467#issuecomment-1120131542

   @dongjoon-hyun 
   
   After SPARK-38896, I think all `LevelDB/RocksDBIterator` has been explicitly closed in Spark code, so I want to clean up the code related to `finalize()` in `LevelDB/RocksDBIterator` to avoid the negative impact of `Finalization`:
   
   1. As described in https://github.com/apache/spark/pull/36403#issuecomment-1114466277,  there is lock contention between the code to be executed through `Finalizer` and the `RocksDB.close()` method. If the `RocksDB.close()` method is executed first, the `RocksDBIterator`s hold by `Finalizer`  cannot be closed before the `DB` close. if use a `rocksdbjni` without link `jemalloc`(The official rocksdbjni will linked `jemalloc`),  the above issue will lead to vm crash and it can be reproduced by testCloseRocksDBIterator in RocksDBSuite.
   2. Others: [JEP 421: Deprecate Finalization for Removal](https://openjdk.java.net/jeps/421)
   
   But it seems that we still need `finalize()` to ensure that `RocksDBIterator` has a chance to be closed which is not explicitly closed in Spark code at present, so in the current pr, I try to use a custom `ReferenceQueue + cleanupThread` instead of `finalize()`


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [spark] LuciferYang commented on pull request #36467: [DON'T MERGE] Replace `finalize()` with custom ReferenceQueue for `RocksDBIterator` cleanup

Posted by GitBox <gi...@apache.org>.
LuciferYang commented on PR #36467:
URL: https://github.com/apache/spark/pull/36467#issuecomment-1120132321

   The issue will not cause vm crash when using the official release `rocksdbjni`, so if it's not worth fixing, I can close this pr .


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [spark] LuciferYang commented on pull request #36467: [SPARK-39063][CORE] Fix potential risk of JVM crash and `RocksDBIterator` resource leak

Posted by GitBox <gi...@apache.org>.
LuciferYang commented on PR #36467:
URL: https://github.com/apache/spark/pull/36467#issuecomment-1120602819

   I want this pr to focus on `RocksDB` first, so `LevelDB` is not changed not in this pr
   
   


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [spark] LuciferYang commented on pull request #36467: [SPARK-39063][CORE] Fix potential risk of JVM crash and `RocksDBIterator` resource leak

Posted by GitBox <gi...@apache.org>.
LuciferYang commented on PR #36467:
URL: https://github.com/apache/spark/pull/36467#issuecomment-1120622694

   > > I want this pr to focus on `RocksDB` first, so `LevelDB` is not changed not in this pr
   > 
   > Can we proceed `LevelDB` first because it's enabled by default? `RocksDB` is not used by default and it's not tested widely.
   
   `LevelDB` can only be explained theoretically, but I can't reproduce it manually now. Is this acceptable ...
   
   


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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


[GitHub] [spark] mridulm commented on pull request #36467: [SPARK-39063][CORE] Fix potential risk of JVM crash and `RocksDBIterator` resource leak

Posted by GitBox <gi...@apache.org>.
mridulm commented on PR #36467:
URL: https://github.com/apache/spark/pull/36467#issuecomment-1122644890

   > The issue to be solved is: Ensure all RocksDBIterators are clsoed before the RocksDB is closed, otherwise the JVM will crash when use a rocksdb with debug mode enabled.
   
   This is already handled by `iteratorTracker`, right ?
   RocksDB.close() already iterates over all `RocksDBIterator` and closes them before closing itself.


-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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