From commits-return-22358-archive-asf-public=cust-asf.ponee.io@accumulo.apache.org Tue Nov 27 18:42:22 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 4A5DA180670 for ; Tue, 27 Nov 2018 18:42:21 +0100 (CET) Received: (qmail 98115 invoked by uid 500); 27 Nov 2018 17:42:16 -0000 Mailing-List: contact commits-help@accumulo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@accumulo.apache.org Delivered-To: mailing list commits@accumulo.apache.org Received: (qmail 97992 invoked by uid 99); 27 Nov 2018 17:42:16 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 27 Nov 2018 17:42:16 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 576A18518F; Tue, 27 Nov 2018 17:42:15 +0000 (UTC) Date: Tue, 27 Nov 2018 17:42:15 +0000 To: "commits@accumulo.apache.org" Subject: [accumulo] branch master updated: fixes #774 removed race condition in lru cache (#775) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <154334053526.12998.9414961945625451313@gitbox.apache.org> From: kturner@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: accumulo X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 529c975f91e8f2f0a43a985a6274b50605f794bb X-Git-Newrev: 378514bd5e35ccf99e7fd14c948437098c96902b X-Git-Rev: 378514bd5e35ccf99e7fd14c948437098c96902b X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated 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 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 { 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(); } }