Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9416617CFB for ; Sun, 14 Jun 2015 17:59:52 +0000 (UTC) Received: (qmail 85340 invoked by uid 500); 14 Jun 2015 17:59:52 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 85308 invoked by uid 500); 14 Jun 2015 17:59:52 -0000 Mailing-List: contact commits-help@ignite.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.incubator.apache.org Delivered-To: mailing list commits@ignite.incubator.apache.org Received: (qmail 85298 invoked by uid 99); 14 Jun 2015 17:59:52 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 14 Jun 2015 17:59:52 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 073681A55DC for ; Sun, 14 Jun 2015 17:59:52 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.791 X-Spam-Level: * X-Spam-Status: No, score=1.791 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, T_RP_MATCHES_RCVD=-0.01, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id UIAjAvTVpwWF for ; Sun, 14 Jun 2015 17:59:45 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with SMTP id CDBCF47BE6 for ; Sun, 14 Jun 2015 17:59:38 +0000 (UTC) Received: (qmail 85067 invoked by uid 99); 14 Jun 2015 17:59:38 -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; Sun, 14 Jun 2015 17:59:38 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 1E528E03CF; Sun, 14 Jun 2015 17:59:38 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sergi@apache.org To: commits@ignite.incubator.apache.org Date: Sun, 14 Jun 2015 17:59:43 -0000 Message-Id: <2481fddcc6fd41c99b4ed3cd9db28878@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [6/6] incubator-ignite git commit: ignite-484-1 - tryEvict fix + minor refactor ignite-484-1 - tryEvict fix + minor refactor Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/7e3f924b Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/7e3f924b Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/7e3f924b Branch: refs/heads/ignite-484-1 Commit: 7e3f924b2f6f2dcc0a942cdc569b7e27647de5cb Parents: d7a18c4 Author: S.Vladykin Authored: Sun Jun 14 20:59:24 2015 +0300 Committer: S.Vladykin Committed: Sun Jun 14 20:59:24 2015 +0300 ---------------------------------------------------------------------- .../distributed/dht/GridDhtLocalPartition.java | 12 ++++++---- .../dht/GridDhtPartitionsReservation.java | 25 +++++++++++++------- .../IgniteCacheQueryNodeRestartSelfTest2.java | 2 +- 3 files changed, 25 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7e3f924b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java index 018ffd6..5938fc8 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLocalPartition.java @@ -137,7 +137,7 @@ public class GridDhtLocalPartition implements Comparable, * Adds group reservation to this partition. * * @param r Reservation. - * @return {@code true} If reservation added successfully. + * @return {@code false} If such reservation already added. */ public boolean addReservation(GridDhtPartitionsReservation r) { assert state.getReference() != EVICTED : "we can reserve only active partitions"; @@ -509,7 +509,7 @@ public class GridDhtLocalPartition implements Comparable, for (GridDhtPartitionsReservation reservation : reservations) { if (!reservation.canEvict()) - reserved = true; + reserved = true; // Calling all the reservations to allow them unregister themselves. } return reserved; @@ -520,11 +520,13 @@ public class GridDhtLocalPartition implements Comparable, * @return {@code True} if entry has been transitioned to state EVICTED. */ boolean tryEvict(boolean updateSeq) { + if (state.getReference() != RENTING || state.getStamp() != 0 || groupReserved()) + return false; + // Attempt to evict partition entries from cache. - if (state.getReference() == RENTING && state.getStamp() == 0 && !groupReserved()) - clearAll(); + clearAll(); - if (map.isEmpty() && !groupReserved() && state.compareAndSet(RENTING, EVICTED, 0, 0)) { + if (map.isEmpty() && state.compareAndSet(RENTING, EVICTED, 0, 0)) { if (log.isDebugEnabled()) log.debug("Evicted partition: " + this); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7e3f924b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionsReservation.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionsReservation.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionsReservation.java index 71a1859..a32946a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionsReservation.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionsReservation.java @@ -46,10 +46,10 @@ public class GridDhtPartitionsReservation implements GridReservable { private final AtomicReference parts = new AtomicReference<>(); /** */ - private final AtomicInteger reservations = new AtomicInteger(); + private final AtomicReference> unpublish = new AtomicReference<>(); /** */ - private volatile CI1 unpublish; + private final AtomicInteger reservations = new AtomicInteger(); /** * @param topVer AffinityTopologyVersion version. @@ -123,6 +123,8 @@ public class GridDhtPartitionsReservation implements GridReservable { if (!this.parts.compareAndSet(null, arr)) throw new IllegalStateException("Partitions can be registered only once."); + assert reservations.get() != -1 : "all the partitions must be reserved before register, we can't be invalidated"; + return true; } @@ -133,9 +135,9 @@ public class GridDhtPartitionsReservation implements GridReservable { */ public void onPublish(CI1 unpublish) { assert unpublish != null; - assert this.unpublish == null; - this.unpublish = unpublish; + if (!this.unpublish.compareAndSet(null, unpublish)) + throw new IllegalStateException("Unpublishing closure can be set only once."); if (reservations.get() == -1) unregister(); @@ -202,12 +204,13 @@ public class GridDhtPartitionsReservation implements GridReservable { } /** - * Unregisters this reservation from all the partitions. + * Unregisters from all the partitions and unpublishes this reservation. */ private void unregister() { GridDhtLocalPartition[] arr = parts.get(); - if (!F.isEmpty(arr) && unpublish != null && parts.compareAndSet(arr, EMPTY)) { + // Unregister from partitions. + if (!F.isEmpty(arr) && parts.compareAndSet(arr, EMPTY)) { // Reverse order makes sure that addReservation on the same topVer reservation will fail on the first partition. for (int i = arr.length - 1; i >= 0; i--) { GridDhtLocalPartition part = arr[i]; @@ -216,9 +219,13 @@ public class GridDhtPartitionsReservation implements GridReservable { tryEvict(part); } - - unpublish.apply(this); } + + // Unpublish. + CI1 u = unpublish.get(); + + if (u != null && unpublish.compareAndSet(u, null)) + u.apply(this); } /** @@ -231,6 +238,8 @@ public class GridDhtPartitionsReservation implements GridReservable { * @return {@code true} If this reservation is NOT reserved and partition CAN be evicted. */ public boolean canEvict() { + assert parts.get() != null : "all parts must be reserved before registration"; + int r = reservations.get(); assert r >= -1 : r; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/7e3f924b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryNodeRestartSelfTest2.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryNodeRestartSelfTest2.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryNodeRestartSelfTest2.java index 746cc45..e65cc13 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryNodeRestartSelfTest2.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/IgniteCacheQueryNodeRestartSelfTest2.java @@ -180,7 +180,7 @@ public class IgniteCacheQueryNodeRestartSelfTest2 extends GridCommonAbstractTest int qryThreadNum = 4; int restartThreadsNum = 2; // 4 + 2 = 6 nodes final int nodeLifeTime = 2 * 1000; - final int logFreq = 50; + final int logFreq = 10; startGridsMultiThreaded(GRID_CNT);