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 5695C200CB5 for ; Wed, 28 Jun 2017 08:10:25 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 55442160BE9; Wed, 28 Jun 2017 06:10: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 6FAC9160C03 for ; Wed, 28 Jun 2017 08:10:23 +0200 (CEST) Received: (qmail 71585 invoked by uid 500); 28 Jun 2017 06:10:22 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 71542 invoked by uid 99); 28 Jun 2017 06:10:22 -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; Wed, 28 Jun 2017 06:10:22 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 719F9DFA6C; Wed, 28 Jun 2017 06:10:21 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sboikov@apache.org To: commits@ignite.apache.org Date: Wed, 28 Jun 2017 06:10:35 -0000 Message-Id: In-Reply-To: <20d935b1912245c69094970716b8c3d5@git.apache.org> References: <20d935b1912245c69094970716b8c3d5@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [15/26] ignite git commit: IGNITE-5548 Deadlock Detection uses IgniteCheckedException instead of TransactionTimeoutException archived-at: Wed, 28 Jun 2017 06:10:25 -0000 IGNITE-5548 Deadlock Detection uses IgniteCheckedException instead of TransactionTimeoutException Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/07bf0f6f Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/07bf0f6f Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/07bf0f6f Branch: refs/heads/ignite-2.1.2-exchange Commit: 07bf0f6f3ab5333ba42808c6b39000cf13b77f5c Parents: acf0441 Author: Igor Seliverstov Authored: Wed Jun 21 15:05:05 2017 +0300 Committer: Igor Seliverstov Committed: Tue Jun 27 15:53:55 2017 +0300 ---------------------------------------------------------------------- .../colocated/GridDhtColocatedLockFuture.java | 4 +- .../distributed/near/GridNearLockFuture.java | 4 +- .../cache/local/GridLocalLockFuture.java | 5 +- .../cache/transactions/TxDeadlockCauseTest.java | 279 +++++++++++++++++++ 4 files changed, 289 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/07bf0f6f/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java index fb4f28b..40eb371 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedLockFuture.java @@ -1409,7 +1409,9 @@ public final class GridDhtColocatedLockFuture extends GridCacheCompoundIdentityF TxDeadlock deadlock = fut.get(); if (deadlock != null) - err = new TransactionDeadlockException(deadlock.toString(cctx.shared())); + err = new IgniteTxTimeoutCheckedException("Failed to acquire lock within provided timeout for " + + "transaction [timeout=" + tx.timeout() + ", tx=" + tx + ']', + new TransactionDeadlockException(deadlock.toString(cctx.shared()))); } catch (IgniteCheckedException e) { err = e; http://git-wip-us.apache.org/repos/asf/ignite/blob/07bf0f6f/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java index 4f8d433..db030b0 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearLockFuture.java @@ -1466,7 +1466,9 @@ public final class GridNearLockFuture extends GridCacheCompoundIdentityFuture cache = ignite.cache(DEFAULT_CACHE_NAME); + final List keys = new ArrayList<>(keysCnt); + + for (int i = 0; i < keysCnt; i ++) { + keys.add(i); + cache.put(i, new Account(i, i * 100)); + } + + final List keysReversed = new ArrayList<>(keys); + Collections.reverse(keysReversed); + + final AtomicBoolean reverse = new AtomicBoolean(); + final AtomicReference ex = new AtomicReference<>(); + final CyclicBarrier barrier = new CyclicBarrier(2); + + IgniteInternalFuture fut = GridTestUtils.runMultiThreadedAsync(new CAX() { + @Override + public void applyx() throws IgniteCheckedException { + try (Transaction tx = ignite.transactions().txStart(TransactionConcurrency.PESSIMISTIC, isolation, timeout, keys.size())) { + + List keys0 = getAndFlip(reverse) ? keys : keysReversed; + + for (int i = 0; i < keys0.size(); i++) { + Integer key = keys0.get(i); + + if(oneOp) + cache.getAndPut(key, new Account(key, (key + 1) * 100)); + else + cache.put(key, new Account(cache.get(key).id, (key + 1) * 100)); + + if (i == 0) + barrier.await(timeout >> 1, TimeUnit.MILLISECONDS); + } + + tx.commit(); + } catch (Exception e) { + ex.compareAndSet(null, e); + } + } + }, 2, "tx"); + + fut.get(timeout << 1); + + Exception e = ex.get(); + + assertNotNull(e); + + boolean detected = X.hasCause(e, TransactionDeadlockException.class); + + if(!detected) + U.error(log, "Failed to detect a deadlock.", e); + else + log.info(X.cause(e, TransactionDeadlockException.class).getMessage()); + + assertTrue(detected); + + try { + assertEquals(TransactionTimeoutException.class, e.getCause().getClass()); + assertEquals(TransactionDeadlockException.class, e.getCause().getCause().getClass()); + } + catch (AssertionError err) { + U.error(log, "Unexpected exception structure.", e); + + throw err; + } + } + + /** + * @param b AtomicBoolean. + * @return Current value. + */ + private boolean getAndFlip(AtomicBoolean b) { + while (true) { + boolean res = b.get(); + + if(b.compareAndSet(res, !res)) + return res; + } + } + + /** */ + static class Account implements Serializable { + /** Account ID. */ + private int id; + + /** Account balance. */ + private double balance; + + /** + * @param id Account ID. + * @param balance Balance. + */ + Account(int id, double balance) { + this.id = id; + this.balance = balance; + } + + /** + * Change balance by specified amount. + * + * @param amount Amount to add to balance (may be negative). + */ + void update(double amount) { + balance += amount; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return "Account [id=" + id + ", balance=$" + balance + ']'; + } + } +}