Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id DA02F200BEF for ; Tue, 20 Dec 2016 15:19:25 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id D74F9160B1B; Tue, 20 Dec 2016 14:19:25 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 30398160B29 for ; Tue, 20 Dec 2016 15:19:25 +0100 (CET) Received: (qmail 725 invoked by uid 500); 20 Dec 2016 14:19:24 -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 444 invoked by uid 99); 20 Dec 2016 14:19:24 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 20 Dec 2016 14:19:24 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 19E39DFBA3; Tue, 20 Dec 2016 14:19:24 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: paulo@apache.org To: commits@cassandra.apache.org Date: Tue, 20 Dec 2016 14:19:25 -0000 Message-Id: In-Reply-To: <5af4c80d73d34bd0b6628e7ba2bcdd05@git.apache.org> References: <5af4c80d73d34bd0b6628e7ba2bcdd05@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/2] cassandra git commit: Merge branch 'cassandra-3.0' into cassandra-3.11 archived-at: Tue, 20 Dec 2016 14:19:26 -0000 Merge branch 'cassandra-3.0' into cassandra-3.11 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/4ed9df6d Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/4ed9df6d Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/4ed9df6d Branch: refs/heads/cassandra-3.11 Commit: 4ed9df6dfc2bb484c6fc5497a0bdc23dc076d04d Parents: e35f4f9 13e9396 Author: Paulo Motta Authored: Tue Dec 20 12:14:43 2016 -0200 Committer: Paulo Motta Committed: Tue Dec 20 12:15:20 2016 -0200 ---------------------------------------------------------------------- src/java/org/apache/cassandra/db/Keyspace.java | 24 +++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/4ed9df6d/src/java/org/apache/cassandra/db/Keyspace.java ---------------------------------------------------------------------- diff --cc src/java/org/apache/cassandra/db/Keyspace.java index d9f8f62,217cf54..6e7e141 --- a/src/java/org/apache/cassandra/db/Keyspace.java +++ b/src/java/org/apache/cassandra/db/Keyspace.java @@@ -488,54 -466,24 +494,54 @@@ public class Keyspac if (requiresViewUpdate) { mutation.viewLockAcquireStart.compareAndSet(0L, System.currentTimeMillis()); - while (true) - { - if (TEST_FAIL_MV_LOCKS_COUNT == 0) - lock = ViewManager.acquireLockFor(mutation.key().getKey()); - else - TEST_FAIL_MV_LOCKS_COUNT--; - if (lock == null) + // the order of lock acquisition doesn't matter (from a deadlock perspective) because we only use tryLock() + Collection columnFamilyIds = mutation.getColumnFamilyIds(); + Iterator idIterator = columnFamilyIds.iterator(); + + locks = new Lock[columnFamilyIds.size()]; + for (int i = 0; i < columnFamilyIds.size(); i++) + { + UUID cfid = idIterator.next(); + int lockKey = Objects.hash(mutation.key().getKey(), cfid); + while (true) { - //throw WTE only if request is droppable - if (isDroppable && (System.currentTimeMillis() - mutation.createdAt) > DatabaseDescriptor.getWriteRpcTimeout()) + Lock lock = null; + + if (TEST_FAIL_MV_LOCKS_COUNT == 0) + lock = ViewManager.acquireLockFor(lockKey); + else + TEST_FAIL_MV_LOCKS_COUNT--; + + if (lock == null) { - logger.trace("Could not acquire lock for {}", ByteBufferUtil.bytesToHex(mutation.key().getKey())); - Tracing.trace("Could not acquire MV lock"); - if (future != null) + //throw WTE only if request is droppable + if (isDroppable && (System.currentTimeMillis() - mutation.createdAt) > DatabaseDescriptor.getWriteRpcTimeout()) + { + for (int j = 0; j < i; j++) + locks[j].unlock(); + + logger.trace("Could not acquire lock for {} and table {}", ByteBufferUtil.bytesToHex(mutation.key().getKey()), columnFamilyStores.get(cfid).name); + Tracing.trace("Could not acquire MV lock"); + if (future != null) + { + future.completeExceptionally(new WriteTimeoutException(WriteType.VIEW, ConsistencyLevel.LOCAL_ONE, 0, 1)); + return future; + } + else + throw new WriteTimeoutException(WriteType.VIEW, ConsistencyLevel.LOCAL_ONE, 0, 1); + } + else if (isDeferrable) { - future.completeExceptionally(new WriteTimeoutException(WriteType.VIEW, ConsistencyLevel.LOCAL_ONE, 0, 1)); + for (int j = 0; j < i; j++) + locks[j].unlock(); + + // This view update can't happen right now. so rather than keep this thread busy + // we will re-apply ourself to the queue and try again later + final CompletableFuture mark = future; + StageManager.getStage(Stage.MUTATION).execute(() -> - apply(mutation, writeCommitLog, true, isDroppable, true, mark) ++ applyInternal(mutation, writeCommitLog, true, isDroppable, true, mark) + ); return future; } else