You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by kt...@apache.org on 2018/11/27 17:42:15 UTC
[accumulo] branch master updated: fixes #774 removed race condition
in lru cache (#775)
This is an automated email from the ASF dual-hosted git repository.
kturner pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/master by this push:
new 378514b fixes #774 removed race condition in lru cache (#775)
378514b is described below
commit 378514bd5e35ccf99e7fd14c948437098c96902b
Author: Keith Turner <kt...@apache.org>
AuthorDate: Tue Nov 27 12:42:10 2018 -0500
fixes #774 removed race condition in lru cache (#775)
---
.../core/file/blockfile/cache/lru/CachedBlock.java | 29 +++++++++++++++++-----
.../file/blockfile/cache/lru/LruBlockCache.java | 4 +--
2 files changed, 25 insertions(+), 8 deletions(-)
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 08282c0..14c71c3 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 class CachedBlock implements HeapSize, Comparable<CachedBlock> {
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 2da6356..cd2ffac 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 class LruBlockCache extends SynchronousLoadingBlockCache implements Block
@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();
}
}