You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucenenet.apache.org by GitBox <gi...@apache.org> on 2021/10/17 15:52:51 UTC

[GitHub] [lucenenet] NightOwl888 opened a new issue #526: Task: Replace Thread.Interrupt() with a safer shutdown mechanism

NightOwl888 opened a new issue #526:
URL: https://github.com/apache/lucenenet/issues/526


   In #525, we discovered that using `Thread.Interrupt()` is not practical in .NET because it may throw on any `lock` statement that has contention on it. This makes it too unpredictable to use in conjunction with a transaction (i.e. `IndexWriter.Commit()`) and we will need to redesign it so transactions are guaranteed to succeed.
   
   Some preliminary research:
   
   1. https://stackoverflow.com/a/3632642
   2. https://jonskeet.uk/csharp/threads/abort.html
   
   2 of the contenders are already in use throughout the project - using `ManualResetEvent` and using a `bool` switch. Lucene makes it pretty clear where it is safe to assume we are in a consistent state (wherever we see `IsInterruptedException()` in a catch block and rethrown as `Lucene.Net.Util.ThreadInterruptedException`).
   
   There are just a few places in Lucene where `Interrupt()` is called:
   
   - [ConcurrentMergeScheduler](https://github.com/apache/lucene/blob/releases/lucene-solr/4.8.0/lucene/core/src/java/org/apache/lucene/index/ConcurrentMergeScheduler.java#L292)
   - [IndexWriter](https://github.com/apache/lucene/blob/releases/lucene-solr/4.8.0/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java#L1080)
   - [ControlledRealTimeReopenThread](https://github.com/apache/lucene/blob/releases/lucene-solr/4.8.0/lucene/core/src/java/org/apache/lucene/search/ControlledRealTimeReopenThread.java#L228)
   - [TestIndexWriter (1)](https://github.com/apache/lucene/blob/releases/lucene-solr/4.8.0/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java#L1212)
   - [TestIndexWriter (2)](https://github.com/apache/lucene/blob/releases/lucene-solr/4.8.0/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java#L1249)
   - [TestControlledRealTimeReopenThread (1)](https://github.com/apache/lucene/blob/releases/lucene-solr/4.8.0/lucene/core/src/test/org/apache/lucene/search/TestControlledRealTimeReopenThread.java#L359)
   - [TestControlledRealTimeReopenThread (2)](https://github.com/apache/lucene/blob/releases/lucene-solr/4.8.0/lucene/core/src/test/org/apache/lucene/search/TestControlledRealTimeReopenThread.java#L369)
   - [ReplicationClient (1)](https://github.com/apache/lucene/blob/releases/lucene-solr/4.8.0/lucene/replicator/src/java/org/apache/lucene/replicator/ReplicationClient.java#L97)
   - [ReplicationClient (2)](https://github.com/apache/lucene/blob/releases/lucene-solr/4.8.0/lucene/replicator/src/java/org/apache/lucene/replicator/ReplicationClient.java#L367)
   
   And here is a list of all of the locations where `InterruptException` is handled:
   
   [InterruptedException Investigation Table.xlsx](https://github.com/apache/lucenenet/files/7360268/InterruptedException.Investigation.Table.xlsx)
   
   A logical approach would be to create a subclass of [`J2N.Threading.ThreadJob`](https://github.com/NightOwl888/J2N/blob/3d3c7211a39395c00aa3dfd1cdf9c01501391d87/src/J2N/Threading/ThreadJob.cs) and add the boilerplate code for shutting down the thread, then swap the base class throughout Lucene along with the code to call the new shutdown mechanism.
   


-- 
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: dev-unsubscribe@lucenenet.apache.org

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



[GitHub] [lucenenet] NightOwl888 closed issue #526: Task: Change documentation about Thread.Interrupt() to indicate this is not safe to use with Lucene.NET

Posted by GitBox <gi...@apache.org>.
NightOwl888 closed issue #526:
URL: https://github.com/apache/lucenenet/issues/526


   


-- 
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: dev-unsubscribe@lucenenet.apache.org

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