You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by GitBox <gi...@apache.org> on 2018/11/27 17:42:12 UTC
[GitHub] keith-turner closed pull request #775: fixes #774 removed race
condition in lru cache
keith-turner closed pull request #775: fixes #774 removed race condition in lru cache
URL: https://github.com/apache/accumulo/pull/775
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/core/src/main/java/org/apache/accumulo/core/file/blockfile/cache/lru/CachedBlock.java b/core/src/main/java/org/apache/accumulo/core/file/blockfile/cache/lru/CachedBlock.java
index 08282c022f..14c71c3818 100644
--- a/core/src/main/java/org/apache/accumulo/core/file/blockfile/cache/lru/CachedBlock.java
+++ b/core/src/main/java/org/apache/accumulo/core/file/blockfile/cache/lru/CachedBlock.java
@@ -129,14 +129,31 @@ public BlockPriority getPriority() {
return (T) index;
}
+ private synchronized long _recordSize(AtomicLong totalSize) {
+ long indexSize = (index == null) ? 0 : index.weight();
+ long newSize = ClassSize.align(blockName.length()) + ClassSize.align(buffer.length)
+ + PER_BLOCK_OVERHEAD + indexSize;
+ long delta = newSize - recordedSize;
+ recordedSize = newSize;
+ return totalSize.addAndGet(delta);
+ }
+
+ /**
+ * Attempt to record size if not evicted.
+ *
+ * @return -1 if evicted
+ */
+ synchronized long tryRecordSize(AtomicLong totalSize) {
+ if (recordedSize >= 0) {
+ return _recordSize(totalSize);
+ }
+
+ return -1;
+ }
+
public synchronized long recordSize(AtomicLong totalSize) {
if (recordedSize >= 0) {
- long indexSize = (index == null) ? 0 : index.weight();
- long newSize = ClassSize.align(blockName.length()) + ClassSize.align(buffer.length)
- + PER_BLOCK_OVERHEAD + indexSize;
- long delta = newSize - recordedSize;
- recordedSize = newSize;
- return totalSize.addAndGet(delta);
+ return _recordSize(totalSize);
}
throw new IllegalStateException("Block was evicted");
diff --git a/core/src/main/java/org/apache/accumulo/core/file/blockfile/cache/lru/LruBlockCache.java b/core/src/main/java/org/apache/accumulo/core/file/blockfile/cache/lru/LruBlockCache.java
index 2da6356616..cd2ffacec1 100644
--- a/core/src/main/java/org/apache/accumulo/core/file/blockfile/cache/lru/LruBlockCache.java
+++ b/core/src/main/java/org/apache/accumulo/core/file/blockfile/cache/lru/LruBlockCache.java
@@ -186,8 +186,8 @@ public long getOverhead() {
@Override
public void indexWeightChanged() {
- long newSize = block.recordSize(size);
- if (newSize > acceptableSize() && !evictionInProgress) {
+ long newSize = block.tryRecordSize(size);
+ if (newSize >= 0 && newSize > acceptableSize() && !evictionInProgress) {
runEviction();
}
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services