You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2016/08/12 20:20:30 UTC
[1/2] lucene-solr:master: LUCENE-7409: Fix comments as suggested by
Dawid
Repository: lucene-solr
Updated Branches:
refs/heads/master f485d29ca -> 8f9c04e4a
LUCENE-7409: Fix comments as suggested by Dawid
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/97f6bb7d
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/97f6bb7d
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/97f6bb7d
Branch: refs/heads/master
Commit: 97f6bb7d7ff43f4501492eee07e6a9200b402b13
Parents: 48cc599
Author: Uwe Schindler <us...@apache.org>
Authored: Fri Aug 12 22:16:04 2016 +0200
Committer: Uwe Schindler <us...@apache.org>
Committed: Fri Aug 12 22:16:04 2016 +0200
----------------------------------------------------------------------
.../apache/lucene/store/ByteBufferGuard.java | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/97f6bb7d/lucene/core/src/java/org/apache/lucene/store/ByteBufferGuard.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/store/ByteBufferGuard.java b/lucene/core/src/java/org/apache/lucene/store/ByteBufferGuard.java
index 2e7ce26..95fa17d 100644
--- a/lucene/core/src/java/org/apache/lucene/store/ByteBufferGuard.java
+++ b/lucene/core/src/java/org/apache/lucene/store/ByteBufferGuard.java
@@ -26,10 +26,8 @@ import java.util.concurrent.atomic.AtomicInteger;
* of this is used for the original and all clones, so once the original is closed and unmapped
* all clones also throw {@link AlreadyClosedException}, triggered by a {@link NullPointerException}.
* <p>
- * This code uses the trick that is also used in
- * {@link java.lang.invoke.MutableCallSite#syncAll(java.lang.invoke.MutableCallSite[])} to
- * invalidate switch points. It also yields the current thread to give other threads a chance
- * to finish in-flight requests...
+ * This code tries to hopefully flush any CPU caches using a store-store barrier. It also yields the
+ * current thread to give other threads a chance to finish in-flight requests...
*/
final class ByteBufferGuard {
@@ -45,10 +43,10 @@ final class ByteBufferGuard {
private final String resourceDescription;
private final BufferCleaner cleaner;
- /** not volatile, we use store-store barrier! */
+ /** Not volatile; see comments on visibility below! */
private boolean invalidated = false;
- /** the actual store-store barrier. */
+ /** Used as a store-store barrier; see comments below! */
private final AtomicInteger barrier = new AtomicInteger();
/**
@@ -66,9 +64,17 @@ final class ByteBufferGuard {
public void invalidateAndUnmap(ByteBuffer... bufs) throws IOException {
if (cleaner != null) {
invalidated = true;
- // this should trigger a happens-before - so flushes all caches
+ // This call should hopefully flush any CPU caches and as a result make
+ // the "invalidated" field update visible to other threads. We specifically
+ // don't make "invalidated" field volatile for performance reasons, hoping the
+ // 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"
+ // (see LUCENE-7409 discussion), but it has been shown to work in practice
+ // and we count on this behavior.
barrier.lazySet(0);
+ // we give other threads a bit of time to finish reads on their ByteBuffer...:
Thread.yield();
+ // finally unmap the ByteBuffers:
for (ByteBuffer b : bufs) {
cleaner.freeBuffer(resourceDescription, b);
}
[2/2] lucene-solr:master: Merge branch 'master' of
https://git-wip-us.apache.org/repos/asf/lucene-solr
Posted by us...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/lucene-solr
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/8f9c04e4
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/8f9c04e4
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/8f9c04e4
Branch: refs/heads/master
Commit: 8f9c04e4a1c1c1c8af942c41068484d9018c93d2
Parents: 97f6bb7 f485d29
Author: Uwe Schindler <us...@apache.org>
Authored: Fri Aug 12 22:19:47 2016 +0200
Committer: Uwe Schindler <us...@apache.org>
Committed: Fri Aug 12 22:19:47 2016 +0200
----------------------------------------------------------------------
.../core/src/test/org/apache/lucene/store/TestMmapDirectory.java | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------