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 D2C9917AD7 for ; Mon, 6 Apr 2015 20:36:45 +0000 (UTC) Received: (qmail 94387 invoked by uid 500); 6 Apr 2015 20:36:36 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 94358 invoked by uid 500); 6 Apr 2015 20:36:36 -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 94349 invoked by uid 99); 6 Apr 2015 20:36:36 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Apr 2015 20:36:36 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 06 Apr 2015 20:36:13 +0000 Received: (qmail 91204 invoked by uid 99); 6 Apr 2015 20:36:10 -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; Mon, 06 Apr 2015 20:36:10 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 6D41DE182A; Mon, 6 Apr 2015 20:36:10 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sboikov@apache.org To: commits@ignite.incubator.apache.org Date: Mon, 06 Apr 2015 20:36:11 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [2/2] incubator-ignite git commit: #ignite-180: Utility data cache X-Virus-Checked: Checked by ClamAV on apache.org #ignite-180: Utility data cache Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/063fee4a Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/063fee4a Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/063fee4a Branch: refs/heads/ignite-180-1 Commit: 063fee4a666eac5e7874b4c8c093e34d43ad0e44 Parents: 7f9b9cc Author: ivasilinets Authored: Mon Apr 6 23:35:55 2015 +0300 Committer: ivasilinets Committed: Mon Apr 6 23:35:55 2015 +0300 ---------------------------------------------------------------------- .../CacheDataStructuresCacheKey.java | 48 ++++++++++ .../datastructures/DataStructuresProcessor.java | 98 +++++++++++++------- 2 files changed, 113 insertions(+), 33 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/063fee4a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/CacheDataStructuresCacheKey.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/CacheDataStructuresCacheKey.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/CacheDataStructuresCacheKey.java new file mode 100644 index 0000000..5ac4f8c --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/CacheDataStructuresCacheKey.java @@ -0,0 +1,48 @@ +package org.apache.ignite.internal.processors.datastructures; + +import org.apache.ignite.internal.processors.cache.GridCacheInternal; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; + +/** + * Created by ira on 4/6/15. + */ +public class CacheDataStructuresCacheKey implements GridCacheInternal, Externalizable { + /** */ + private static final long serialVersionUID = 0L; + + /** + * + */ + public CacheDataStructuresCacheKey() { + // No-op. + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + return 33; + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object obj) { + return obj == this || (obj instanceof CacheDataStructuresCacheKey); + } + + /** {@inheritDoc} */ + @Override public void writeExternal(ObjectOutput out) throws IOException { + // No-op. + } + + /** {@inheritDoc} */ + @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // No-op. + } + + /** {@inheritDoc} */ + @Override public String toString() { + return "CacheDataStructuresCacheKey []"; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/063fee4a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresProcessor.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresProcessor.java index f73cc43..b8ace76 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresProcessor.java @@ -51,6 +51,10 @@ public final class DataStructuresProcessor extends GridProcessorAdapter { public static final CacheDataStructuresConfigurationKey DATA_STRUCTURES_KEY = new CacheDataStructuresConfigurationKey(); + /** */ + public static final CacheDataStructuresCacheKey DATA_STRUCTURES_CACHE_KEY = + new CacheDataStructuresCacheKey(); + /** Initial capacity. */ private static final int INITIAL_CAPACITY = 10; @@ -90,6 +94,9 @@ public final class DataStructuresProcessor extends GridProcessorAdapter { /** */ private GridCacheProjectionEx> utilityCache; + /** */ + private GridCacheProjectionEx> utilityDataCache; + /** * @param ctx Context. */ @@ -109,6 +116,8 @@ public final class DataStructuresProcessor extends GridProcessorAdapter { utilityCache = (GridCacheProjectionEx)ctx.cache().utilityCache(); + utilityDataCache = (GridCacheProjectionEx)ctx.cache().utilityCache(); + assert utilityCache != null; if (atomicCfg != null) { @@ -684,13 +693,7 @@ public final class DataStructuresProcessor extends GridProcessorAdapter { if (cap <= 0) cap = Integer.MAX_VALUE; - cacheName = findCompatibleConfiguration(cfg); - - if (cacheName == null) { - cacheName = getCacheName(cfg); - - ctx.cache().dynamicStartCache(cacheConfiguration(cfg), cacheName, null, CacheType.DATASTRUCTURE, false).get(); - } + cacheName = compatibleConfiguration(cfg); } DataStructureInfo dsInfo = new DataStructureInfo(name, @@ -710,24 +713,22 @@ public final class DataStructuresProcessor extends GridProcessorAdapter { /** * @param cfg Collection configuration. + * @param i Index. * @return Cache name. */ - private String getCacheName(CollectionConfiguration cfg) { - return "data_structures_" + cfg.atomicityMode().name() + "_" + - cfg.backups() + "_" + - cfg.cacheMode() + "_" + - cfg.memoryMode() + "_" + - cfg.offHeapMaxMem(); + private String getCacheName(CollectionConfiguration cfg, int i) { + return "data_structures_" + i; } /** * @param cfg Collection configuration. + * @param name Cache name. * @return Cache configuration. */ - private CacheConfiguration cacheConfiguration(CollectionConfiguration cfg) { + private CacheConfiguration cacheConfiguration(CollectionConfiguration cfg, String name) { CacheConfiguration ccfg = new CacheConfiguration(); - ccfg.setName(getCacheName(cfg)); + ccfg.setName(name); ccfg.setBackups(cfg.backups()); ccfg.setCacheMode(cfg.cacheMode()); @@ -741,16 +742,18 @@ public final class DataStructuresProcessor extends GridProcessorAdapter { * @param cfg Collection configuration. * @return Cache name. */ - private String findCompatibleConfiguration(CollectionConfiguration cfg) { - for (CacheConfiguration ccfg : ctx.cache().dataStructuresCacheNames()) { - if (ccfg == null) - continue; + private String findCompatibleConfiguration(CollectionConfiguration cfg) throws IgniteCheckedException { + List cfgs = utilityDataCache.get(DATA_STRUCTURES_CACHE_KEY); + if (cfgs == null) + return null; + + for (CacheConfiguration ccfg : cfgs) { if (ccfg.getAtomicityMode() == cfg.atomicityMode() && - ccfg.getMemoryMode() == cfg.memoryMode() && - ccfg.getCacheMode() == cfg.cacheMode() && - ccfg.getBackups() == cfg.backups() && - ccfg.getOffHeapMaxMemory() == cfg.offHeapMaxMem()) + ccfg.getMemoryMode() == cfg.memoryMode() && + ccfg.getCacheMode() == cfg.cacheMode() && + ccfg.getBackups() == cfg.backups() && + ccfg.getOffHeapMaxMemory() == cfg.offHeapMaxMem()) return ccfg.getName(); } @@ -758,6 +761,41 @@ public final class DataStructuresProcessor extends GridProcessorAdapter { } /** + * @param cfg Collection configuration. + * @return Cache name. + */ + private String compatibleConfiguration(CollectionConfiguration cfg) throws IgniteCheckedException { + String cacheName = findCompatibleConfiguration(cfg); + + if (cacheName == null) { + try (IgniteInternalTx tx = utilityDataCache.txStartEx(PESSIMISTIC, REPEATABLE_READ)) { + cacheName = findCompatibleConfiguration(cfg); + + if (cacheName == null) { + List oldVal = utilityDataCache.get(DATA_STRUCTURES_CACHE_KEY); + + cacheName = getCacheName(cfg, oldVal != null ? oldVal.size() : 0); + + CacheConfiguration newCfg = cacheConfiguration(cfg, cacheName); + + ctx.cache().dynamicStartCache(newCfg, cacheName, null, CacheType.DATASTRUCTURE, false).get(); + + List newVal = oldVal != null ? new ArrayList(oldVal) : + new ArrayList(); + + newVal.add(newCfg); + + utilityDataCache.put(DATA_STRUCTURES_CACHE_KEY, newVal); + } + + tx.commit(); + } + } + + return cacheName; + } + + /** * @param name Queue name. * @param cctx Queue cache context. * @throws IgniteCheckedException If failed. @@ -1112,15 +1150,8 @@ public final class DataStructuresProcessor extends GridProcessorAdapter { A.notNull(name, "name"); String cacheName = null; - if (cfg != null) { - cacheName = findCompatibleConfiguration(cfg); - - if (cacheName == null) { - cacheName = getCacheName(cfg); - - ctx.cache().dynamicStartCache(cacheConfiguration(cfg), cacheName, null, CacheType.DATASTRUCTURE, false).get(); - } - } + if (cfg != null) + cacheName = compatibleConfiguration(cfg); DataStructureInfo dsInfo = new DataStructureInfo(name, SET, @@ -1166,7 +1197,8 @@ public final class DataStructuresProcessor extends GridProcessorAdapter { * @return Removed value. */ @SuppressWarnings("unchecked") - @Nullable private T retryRemove(final GridCache cache, final Object key) throws IgniteCheckedException { + @Nullable + private T retryRemove(final GridCache cache, final Object key) throws IgniteCheckedException { return retry(log, new Callable() { @Nullable @Override public T call() throws Exception { return (T)cache.remove(key);