Return-Path: X-Original-To: apmail-cassandra-commits-archive@www.apache.org Delivered-To: apmail-cassandra-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id EBEB7C842 for ; Thu, 12 Sep 2013 15:19:59 +0000 (UTC) Received: (qmail 87353 invoked by uid 500); 12 Sep 2013 15:19:57 -0000 Delivered-To: apmail-cassandra-commits-archive@cassandra.apache.org Received: (qmail 87250 invoked by uid 500); 12 Sep 2013 15:19:57 -0000 Mailing-List: contact commits-help@cassandra.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cassandra.apache.org Delivered-To: mailing list commits@cassandra.apache.org Received: (qmail 86849 invoked by uid 99); 12 Sep 2013 15:19:52 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 12 Sep 2013 15:19:52 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id EB14D8BFDC9; Thu, 12 Sep 2013 15:19:51 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: aleksey@apache.org To: commits@cassandra.apache.org Date: Thu, 12 Sep 2013 15:19:51 -0000 Message-Id: <6ce821f623454fc284ce537c0304f183@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/3] git commit: Replace the deprecated MapMaker with CacheLoader Updated Branches: refs/heads/trunk 03f3642b1 -> 0ec68f557 Replace the deprecated MapMaker with CacheLoader patch by Aleksey Yeschenko; reviewed by Jonathan Ellis for CASSANDRA-6007 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/53e48edc Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/53e48edc Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/53e48edc Branch: refs/heads/trunk Commit: 53e48edc3062bafb7a8b5c3c301add5cd6a2cb19 Parents: 394b35e Author: Aleksey Yeschenko Authored: Thu Sep 12 18:10:16 2013 +0300 Committer: Aleksey Yeschenko Committed: Thu Sep 12 18:10:16 2013 +0300 ---------------------------------------------------------------------- CHANGES.txt | 1 + .../apache/cassandra/service/StorageProxy.java | 26 ++++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/53e48edc/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index 6ece609..1c09589 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -14,6 +14,7 @@ * Pass the updated cf to the PRSI index() method (CASSANDRA-5999) * Allow empty CQL3 batches (as no-op) (CASSANDRA-5994) * Support null in CQL3 functions (CASSANDRA-5910) + * Replace the deprecated MapMaker with CacheLoader (CASSANDRA-6007) 1.2.9 http://git-wip-us.apache.org/repos/asf/cassandra/blob/53e48edc/src/java/org/apache/cassandra/service/StorageProxy.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/service/StorageProxy.java b/src/java/org/apache/cassandra/service/StorageProxy.java index 94db26d..23d73ec 100644 --- a/src/java/org/apache/cassandra/service/StorageProxy.java +++ b/src/java/org/apache/cassandra/service/StorageProxy.java @@ -29,7 +29,7 @@ import java.util.concurrent.atomic.AtomicLong; import javax.management.MBeanServer; import javax.management.ObjectName; -import com.google.common.base.Function; +import com.google.common.cache.CacheLoader; import com.google.common.collect.*; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; @@ -83,13 +83,13 @@ public class StorageProxy implements StorageProxyMBean private static volatile int maxHintsInProgress = 1024 * FBUtilities.getAvailableProcessors(); private static final AtomicInteger totalHintsInProgress = new AtomicInteger(); - private static final Map hintsInProgress = new MapMaker().concurrencyLevel(1).makeComputingMap(new Function() + private static final CacheLoader hintsInProgress = new CacheLoader() { - public AtomicInteger apply(InetAddress inetAddress) + public AtomicInteger load(InetAddress inetAddress) { return new AtomicInteger(0); } - }); + }; private static final AtomicLong totalHints = new AtomicLong(); private static final ClientRequestMetrics readMetrics = new ClientRequestMetrics("Read"); private static final ClientRequestMetrics rangeMetrics = new ClientRequestMetrics("RangeSlice"); @@ -489,7 +489,7 @@ public class StorageProxy implements StorageProxyMBean // a small number of nodes causing problems, so we should avoid shutting down writes completely to // healthy nodes. Any node with no hintsInProgress is considered healthy. if (totalHintsInProgress.get() > maxHintsInProgress - && (hintsInProgress.get(destination).get() > 0 && shouldHint(destination))) + && (getHintsInProgressFor(destination).get() > 0 && shouldHint(destination))) { throw new OverloadedException("Too many in flight hints: " + totalHintsInProgress.get()); } @@ -538,6 +538,18 @@ public class StorageProxy implements StorageProxyMBean } } + private static AtomicInteger getHintsInProgressFor(InetAddress destination) + { + try + { + return hintsInProgress.load(destination); + } + catch (Exception e) + { + throw new AssertionError(e); + } + } + public static Future submitHint(final RowMutation mutation, final InetAddress target, final AbstractWriteResponseHandler responseHandler, @@ -572,7 +584,7 @@ public class StorageProxy implements StorageProxyMBean private static Future submitHint(HintRunnable runnable) { totalHintsInProgress.incrementAndGet(); - hintsInProgress.get(runnable.target).incrementAndGet(); + getHintsInProgressFor(runnable.target).incrementAndGet(); return (Future) StageManager.getStage(Stage.MUTATION).submit(runnable); } @@ -1674,7 +1686,7 @@ public class StorageProxy implements StorageProxyMBean finally { totalHintsInProgress.decrementAndGet(); - hintsInProgress.get(target).decrementAndGet(); + getHintsInProgressFor(target).decrementAndGet(); } }