Repository: ignite Updated Branches: refs/heads/ignite-5075 6e8c83115 -> 19ed098ee
ignite-5075 Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/19ed098e Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/19ed098e Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/19ed098e Branch: refs/heads/ignite-5075 Commit: 19ed098ee02667c2b6e359f6f0c39cead8b01569 Parents: 6e8c831 Author: sboikov <[email protected]> Authored: Tue May 23 14:44:42 2017 +0300 Committer: sboikov <[email protected]> Committed: Tue May 23 14:44:42 2017 +0300 ---------------------------------------------------------------------- .../cache/CacheGroupInfrastructure.java | 172 ++++++++++--------- 1 file changed, 90 insertions(+), 82 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/19ed098e/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupInfrastructure.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupInfrastructure.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupInfrastructure.java index 6d61ab1..7c07d2d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupInfrastructure.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupInfrastructure.java @@ -20,6 +20,7 @@ package org.apache.ignite.internal.processors.cache; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Iterator; import java.util.List; import java.util.UUID; import org.apache.ignite.IgniteCheckedException; @@ -97,7 +98,7 @@ public class CacheGroupInfrastructure { private boolean needsRecovery; /** */ - private final List<GridCacheContext> caches; + private volatile List<GridCacheContext> caches; /** */ private final IgniteLogger log; @@ -235,14 +236,14 @@ public class CacheGroupInfrastructure { * @return {@code True} if group contains cache with given name. */ public boolean hasCache(String cacheName) { - synchronized (caches) { - for (int i = 0; i < caches.size(); i++) { - if (caches.get(i).name().equals(cacheName)) - return true; - } + List<GridCacheContext> caches = this.caches; - return false; + for (int i = 0; i < caches.size(); i++) { + if (caches.get(i).name().equals(cacheName)) + return true; } + + return false; } /** @@ -252,51 +253,58 @@ public class CacheGroupInfrastructure { assert cacheType.userCache() == cctx.userCache() : cctx.name(); assert grpId == cctx.groupId() : cctx.name(); - synchronized (caches) { - assert sharedGroup() || caches.isEmpty(); + ArrayList<GridCacheContext> caches = new ArrayList<>(this.caches); - boolean add = caches.add(cctx); + assert sharedGroup() || caches.isEmpty(); - assert add : cctx.name(); - } + boolean add = caches.add(cctx); + + assert add : cctx.name(); + + this.caches = caches; } /** * @param cctx Cache context. */ private void removeCacheContext(GridCacheContext cctx) { - synchronized (caches) { - if (caches.contains(cctx)) { // It is possible cache is not added in case of errors on cache start. - assert sharedGroup() || caches.size() == 1 : caches.size(); + ArrayList<GridCacheContext> caches = new ArrayList<>(this.caches); + + // It is possible cache was not added in case of errors on cache start. + for (Iterator<GridCacheContext> it = caches.iterator(); it.hasNext();) { + GridCacheContext next = it.next(); - boolean rmv = caches.remove(cctx); + if (next == cctx) { + assert sharedGroup() || caches.size() == 1 : caches.size(); - assert rmv : cctx.name(); + it.remove(); } } + + this.caches = caches; } /** * @return Cache context if group contains single cache. */ public GridCacheContext singleCacheContext() { - synchronized (caches) { - assert !sharedGroup() && caches.size() == 1; + List<GridCacheContext> caches = this.caches; - return caches.get(0); - } + assert !sharedGroup() && caches.size() == 1; + + return caches.get(0); } /** * */ public void unwindUndeploys() { - synchronized (caches) { - for (int i = 0; i < caches.size(); i++) { - GridCacheContext cctx = caches.get(i); + List<GridCacheContext> caches = this.caches; - cctx.deploy().unwind(cctx); - } + for (int i = 0; i < caches.size(); i++) { + GridCacheContext cctx = caches.get(i); + + cctx.deploy().unwind(cctx); } } @@ -326,20 +334,20 @@ public class CacheGroupInfrastructure { if (!eventRecordable(type)) LT.warn(log, "Added event without checking if event is recordable: " + U.gridEventName(type)); - synchronized (caches) { - for (int i = 0; i < caches.size(); i++) { - GridCacheContext cctx = caches.get(i); - - if (cctx.recordEvent(type)) { - cctx.gridEvents().record(new CacheRebalancingEvent(cctx.name(), - cctx.localNode(), - "Cache rebalancing event.", - type, - part, - discoNode, - discoType, - discoTs)); - } + List<GridCacheContext> caches = this.caches; + + for (int i = 0; i < caches.size(); i++) { + GridCacheContext cctx = caches.get(i); + + if (cctx.recordEvent(type)) { + cctx.gridEvents().record(new CacheRebalancingEvent(cctx.name(), + cctx.localNode(), + "Cache rebalancing event.", + type, + part, + discoNode, + discoType, + discoTs)); } } } @@ -353,19 +361,19 @@ public class CacheGroupInfrastructure { LT.warn(log, "Added event without checking if event is recordable: " + U.gridEventName(EVT_CACHE_REBALANCE_PART_UNLOADED)); - synchronized (caches) { - for (int i = 0; i < caches.size(); i++) { - GridCacheContext cctx = caches.get(i); + List<GridCacheContext> caches = this.caches; - cctx.gridEvents().record(new CacheRebalancingEvent(cctx.name(), - cctx.localNode(), - "Cache unloading event.", - EVT_CACHE_REBALANCE_PART_UNLOADED, - part, - null, - 0, - 0)); - } + for (int i = 0; i < caches.size(); i++) { + GridCacheContext cctx = caches.get(i); + + cctx.gridEvents().record(new CacheRebalancingEvent(cctx.name(), + cctx.localNode(), + "Cache unloading event.", + EVT_CACHE_REBALANCE_PART_UNLOADED, + part, + null, + 0, + 0)); } } @@ -391,25 +399,25 @@ public class CacheGroupInfrastructure { boolean hasOldVal, boolean keepBinary ) { - synchronized (caches) { - for (int i = 0; i < caches.size(); i++) { - GridCacheContext cctx = caches.get(i); - - cctx.events().addEvent(part, - key, - evtNodeId, - (IgniteUuid)null, - null, - type, - newVal, - hasNewVal, - oldVal, - hasOldVal, - null, - null, - null, - keepBinary); - } + List<GridCacheContext> caches = this.caches; + + for (int i = 0; i < caches.size(); i++) { + GridCacheContext cctx = caches.get(i); + + cctx.events().addEvent(part, + key, + evtNodeId, + (IgniteUuid)null, + null, + type, + newVal, + hasNewVal, + oldVal, + hasOldVal, + null, + null, + null, + keepBinary); } } @@ -620,26 +628,26 @@ public class CacheGroupInfrastructure { * @return {@code True} if group contains caches. */ boolean hasCaches() { - synchronized (caches) { - return !caches.isEmpty(); - } + List<GridCacheContext> caches = this.caches; + + return !caches.isEmpty(); } /** * @param part Partition ID. */ public void onPartitionEvicted(int part) { - synchronized (caches) { - for (int i = 0; i < caches.size(); i++) { - GridCacheContext cctx = caches.get(i); + List<GridCacheContext> caches = this.caches; - if (cctx.isDrEnabled()) - cctx.dr().partitionEvicted(part); + for (int i = 0; i < caches.size(); i++) { + GridCacheContext cctx = caches.get(i); - cctx.continuousQueries().onPartitionEvicted(part); + if (cctx.isDrEnabled()) + cctx.dr().partitionEvicted(part); - cctx.dataStructures().onPartitionEvicted(part); - } + cctx.continuousQueries().onPartitionEvicted(part); + + cctx.dataStructures().onPartitionEvicted(part); } }
