MMapDirectory with MemorySegment: Confirm that scope/session is no longer alive before throwing AlreadyClosedException (#12707)

This commit is contained in:
Uwe Schindler 2023-10-22 19:14:29 +02:00 committed by GitHub
parent 9729123369
commit bbf197fdc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 11 deletions

View File

@ -183,8 +183,8 @@ Improvements
* GITHUB#12586: Remove over-counting of deleted terms. (Guo Feng)
* GITHUB#12705: Improve handling of NullPointerException in MMapDirectory's IndexInputs.
(Uwe Schindler, Michael Sokolov)
* GITHUB#12705, GITHUB#12705: Improve handling of NullPointerException and IllegalStateException
in MMapDirectory's IndexInputs. (Uwe Schindler, Michael Sokolov)
Optimizations
---------------------

View File

@ -105,9 +105,11 @@ abstract class MemorySegmentIndexInput extends IndexInput implements RandomAcces
AlreadyClosedException alreadyClosed(RuntimeException e) {
// we use NPE to signal if this input is closed (to not have checks everywhere). If NPE happens,
// we check the "is closed" condition explicitly by checking that our "curSegment" is null.
// if it is an IllegalStateException, it can only come from MemorySegment API (other thread has
// closed input)
if (this.curSegment == null || e instanceof IllegalStateException) {
if (this.curSegment == null) {
return new AlreadyClosedException("Already closed: " + this);
}
// we also check if the session of all segments is still alive:
if (Arrays.stream(segments).allMatch(s -> s.session().isAlive()) == false) {
return new AlreadyClosedException("Already closed: " + this);
}
// otherwise rethrow unmodified NPE/ISE (as it possibly a bug with passing a null parameter to

View File

@ -103,9 +103,11 @@ abstract class MemorySegmentIndexInput extends IndexInput implements RandomAcces
AlreadyClosedException alreadyClosed(RuntimeException e) {
// we use NPE to signal if this input is closed (to not have checks everywhere). If NPE happens,
// we check the "is closed" condition explicitly by checking that our "curSegment" is null.
// if it is an IllegalStateException, it can only come from MemorySegment API (other thread has
// closed input)
if (this.curSegment == null || e instanceof IllegalStateException) {
if (this.curSegment == null) {
return new AlreadyClosedException("Already closed: " + this);
}
// we also check if the scope of all segments is still alive:
if (Arrays.stream(segments).allMatch(s -> s.scope().isAlive()) == false) {
return new AlreadyClosedException("Already closed: " + this);
}
// otherwise rethrow unmodified NPE/ISE (as it possibly a bug with passing a null parameter to

View File

@ -103,9 +103,11 @@ abstract class MemorySegmentIndexInput extends IndexInput implements RandomAcces
AlreadyClosedException alreadyClosed(RuntimeException e) {
// we use NPE to signal if this input is closed (to not have checks everywhere). If NPE happens,
// we check the "is closed" condition explicitly by checking that our "curSegment" is null.
// if it is an IllegalStateException, it can only come from MemorySegment API (other thread has
// closed input)
if (this.curSegment == null || e instanceof IllegalStateException) {
if (this.curSegment == null) {
return new AlreadyClosedException("Already closed: " + this);
}
// we also check if the scope of all segments is still alive:
if (Arrays.stream(segments).allMatch(s -> s.scope().isAlive()) == false) {
return new AlreadyClosedException("Already closed: " + this);
}
// otherwise rethrow unmodified NPE/ISE (as it possibly a bug with passing a null parameter to