mirror of https://github.com/apache/lucene.git
Make memory fence in `ByteBufferGuard` explicit (#12290)
This commit is contained in:
parent
40b582ab18
commit
45110a6a46
|
@ -156,6 +156,8 @@ Improvements
|
||||||
* GITHUB#12333: NumericLeafComparator#competitiveIterator makes better use of a "search after" value when paginating.
|
* GITHUB#12333: NumericLeafComparator#competitiveIterator makes better use of a "search after" value when paginating.
|
||||||
(Chaitanya Gohel)
|
(Chaitanya Gohel)
|
||||||
|
|
||||||
|
* GITHUB#12290: Make memory fence in ByteBufferGuard explicit using `VarHandle.fullFence()`
|
||||||
|
|
||||||
Optimizations
|
Optimizations
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
|
|
|
@ -17,11 +17,11 @@
|
||||||
package org.apache.lucene.store;
|
package org.apache.lucene.store;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.invoke.VarHandle;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.FloatBuffer;
|
import java.nio.FloatBuffer;
|
||||||
import java.nio.IntBuffer;
|
import java.nio.IntBuffer;
|
||||||
import java.nio.LongBuffer;
|
import java.nio.LongBuffer;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A guard that is created for every {@link ByteBufferIndexInput} that tries on best effort to
|
* A guard that is created for every {@link ByteBufferIndexInput} that tries on best effort to
|
||||||
|
@ -49,9 +49,6 @@ final class ByteBufferGuard {
|
||||||
/** Not volatile; see comments on visibility below! */
|
/** Not volatile; see comments on visibility below! */
|
||||||
private boolean invalidated = false;
|
private boolean invalidated = false;
|
||||||
|
|
||||||
/** Used as a store-store barrier; see comments below! */
|
|
||||||
private final AtomicInteger barrier = new AtomicInteger();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an instance to be used for a single {@link ByteBufferIndexInput} which must be shared
|
* Creates an instance to be used for a single {@link ByteBufferIndexInput} which must be shared
|
||||||
* by all of its clones.
|
* by all of its clones.
|
||||||
|
@ -69,10 +66,9 @@ final class ByteBufferGuard {
|
||||||
// the "invalidated" field update visible to other threads. We specifically
|
// the "invalidated" field update visible to other threads. We specifically
|
||||||
// don't make "invalidated" field volatile for performance reasons, hoping the
|
// don't make "invalidated" field volatile for performance reasons, hoping the
|
||||||
// JVM won't optimize away reads of that field and hardware should ensure
|
// JVM won't optimize away reads of that field and hardware should ensure
|
||||||
// caches are in sync after this call. This isn't entirely "fool-proof"
|
// caches are in sync after this call.
|
||||||
// (see LUCENE-7409 discussion), but it has been shown to work in practice
|
// For previous implementation (based on `AtomicInteger#lazySet(0)`) see LUCENE-7409.
|
||||||
// and we count on this behavior.
|
VarHandle.fullFence();
|
||||||
barrier.lazySet(0);
|
|
||||||
// we give other threads a bit of time to finish reads on their ByteBuffer...:
|
// we give other threads a bit of time to finish reads on their ByteBuffer...:
|
||||||
Thread.yield();
|
Thread.yield();
|
||||||
// finally unmap the ByteBuffers:
|
// finally unmap the ByteBuffers:
|
||||||
|
|
Loading…
Reference in New Issue