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 E192517E03 for ; Wed, 8 Apr 2015 14:03:08 +0000 (UTC) Received: (qmail 94247 invoked by uid 500); 8 Apr 2015 14:02:35 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 94219 invoked by uid 500); 8 Apr 2015 14:02:34 -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 94205 invoked by uid 99); 8 Apr 2015 14:02:34 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Apr 2015 14:02:34 +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; Wed, 08 Apr 2015 14:02:33 +0000 Received: (qmail 92256 invoked by uid 99); 8 Apr 2015 14:02: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; Wed, 08 Apr 2015 14:02:10 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 7C9CCE2F29; Wed, 8 Apr 2015 14:02: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: Wed, 08 Apr 2015 14:02:53 -0000 Message-Id: <1c7ed138adf447dda02bc8c3a313d4b3@git.apache.org> In-Reply-To: <7fed2b8568994458a66afac1f57e2fc4@git.apache.org> References: <7fed2b8568994458a66afac1f57e2fc4@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [44/50] incubator-ignite git commit: # IGNITE-685 NPE on node start if client discovery is used. X-Virus-Checked: Checked by ClamAV on apache.org # IGNITE-685 NPE on node start if client discovery is used. Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/654b4e98 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/654b4e98 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/654b4e98 Branch: refs/heads/ignite-635 Commit: 654b4e98f2f618e4ffffad6486d13f883a1a5d7d Parents: 0cf79e4 Author: sevdokimov Authored: Wed Apr 8 13:03:01 2015 +0300 Committer: sevdokimov Committed: Wed Apr 8 13:29:06 2015 +0300 ---------------------------------------------------------------------- .../org/apache/ignite/internal/IgnitionEx.java | 172 +++++++------------ 1 file changed, 65 insertions(+), 107 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/654b4e98/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java index fe81006..a4aea66 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java @@ -1675,23 +1675,32 @@ public class IgnitionEx { */ @SuppressWarnings("unchecked") public void initializeDefaultCacheConfiguration(IgniteConfiguration cfg) throws IgniteCheckedException { - CacheConfiguration[] cacheCfgs = cfg.getCacheConfiguration(); + List cacheCfgs = new ArrayList<>(); - final boolean hasHadoop = IgniteComponentType.HADOOP.inClassPath(); + boolean clientDisco = cfg.getDiscoverySpi() instanceof TcpClientDiscoverySpi; - final boolean hasAtomics = cfg.getAtomicConfiguration() != null; + // Add marshaller and utility caches. + if (!clientDisco) { + cacheCfgs.add(marshallerSystemCache()); - final boolean clientDisco = cfg.getDiscoverySpi() instanceof TcpClientDiscoverySpi; + cacheCfgs.add(utilitySystemCache()); + } + + if (IgniteComponentType.HADOOP.inClassPath()) + cacheCfgs.add(CU.hadoopSystemCache()); - CacheConfiguration[] copies; + if (cfg.getAtomicConfiguration() != null && !clientDisco) + cacheCfgs.add(atomicsSystemCache(cfg.getAtomicConfiguration())); - if (cacheCfgs != null && cacheCfgs.length > 0) { + CacheConfiguration[] userCaches = cfg.getCacheConfiguration(); + + if (userCaches != null && userCaches.length > 0) { if (!U.discoOrdered(cfg.getDiscoverySpi()) && !U.relaxDiscoveryOrdered()) throw new IgniteCheckedException("Discovery SPI implementation does not support node ordering and " + "cannot be used with cache (use SPI with @GridDiscoverySpiOrderSupport annotation, " + "like GridTcpDiscoverySpi)"); - for (CacheConfiguration ccfg : cacheCfgs) { + for (CacheConfiguration ccfg : userCaches) { if (CU.isHadoopSystemCache(ccfg.getName())) throw new IgniteCheckedException("Cache name cannot be \"" + CU.SYS_CACHE_HADOOP_MR + "\" because it is reserved for internal purposes."); @@ -1709,52 +1718,15 @@ public class IgnitionEx { "\" because it is reserved for internal purposes."); } - int addCacheCnt = 2; // Always add marshaller and utility caches. - - if (hasHadoop) - addCacheCnt++; - - if (hasAtomics) - addCacheCnt++; - - copies = new CacheConfiguration[cacheCfgs.length + addCacheCnt]; - - int cloneIdx = 2; - - if (hasHadoop) - copies[cloneIdx++] = CU.hadoopSystemCache(); - - if (hasAtomics) - copies[cloneIdx++] = atomicsSystemCache(cfg.getAtomicConfiguration(), clientDisco); - - for (CacheConfiguration ccfg : cacheCfgs) - copies[cloneIdx++] = new CacheConfiguration(ccfg); - } - else { - int cacheCnt = 2; // Always add marshaller and utility caches. - - if (hasHadoop) - cacheCnt++; - - if (hasAtomics) - cacheCnt++; + for (CacheConfiguration ccfg : userCaches) { + if (ccfg == null) + throw new NullPointerException("Cache configuration list must not contains null element"); - copies = new CacheConfiguration[cacheCnt]; - - int cacheIdx = 2; - - if (hasHadoop) - copies[cacheIdx++] = CU.hadoopSystemCache(); - - if (hasAtomics) - copies[cacheIdx] = atomicsSystemCache(cfg.getAtomicConfiguration(), clientDisco); + cacheCfgs.add(ccfg); + } } - // Always add marshaller and utility caches. - copies[0] = marshallerSystemCache(clientDisco); - copies[1] = utilitySystemCache(clientDisco); - - cfg.setCacheConfiguration(copies); + cfg.setCacheConfiguration(cacheCfgs.toArray(new CacheConfiguration[cacheCfgs.size()])); } /** @@ -1899,78 +1871,64 @@ public class IgnitionEx { * * @return Marshaller system cache configuration. */ - private static CacheConfiguration marshallerSystemCache(boolean client) { - if (!client) { - CacheConfiguration cache = new CacheConfiguration(); - - cache.setName(CU.MARSH_CACHE_NAME); - cache.setCacheMode(REPLICATED); - cache.setAtomicityMode(ATOMIC); - cache.setSwapEnabled(false); - cache.setRebalanceMode(SYNC); - cache.setWriteSynchronizationMode(FULL_SYNC); - cache.setAffinity(new RendezvousAffinityFunction(false, 20)); - cache.setNodeFilter(CacheConfiguration.ALL_NODES); - cache.setStartSize(300); - - return cache; - } - - return null; + private static CacheConfiguration marshallerSystemCache() { + CacheConfiguration cache = new CacheConfiguration(); + + cache.setName(CU.MARSH_CACHE_NAME); + cache.setCacheMode(REPLICATED); + cache.setAtomicityMode(ATOMIC); + cache.setSwapEnabled(false); + cache.setRebalanceMode(SYNC); + cache.setWriteSynchronizationMode(FULL_SYNC); + cache.setAffinity(new RendezvousAffinityFunction(false, 20)); + cache.setNodeFilter(CacheConfiguration.ALL_NODES); + cache.setStartSize(300); + + return cache; } /** * Creates utility system cache configuration. * - * @param client If {@code true} creates client-only cache configuration. * @return Utility system cache configuration. */ - private static CacheConfiguration utilitySystemCache(boolean client) { - if (!client) { - CacheConfiguration cache = new CacheConfiguration(); - - cache.setName(CU.UTILITY_CACHE_NAME); - cache.setCacheMode(REPLICATED); - cache.setAtomicityMode(TRANSACTIONAL); - cache.setSwapEnabled(false); - cache.setRebalanceMode(SYNC); - cache.setWriteSynchronizationMode(FULL_SYNC); - cache.setAffinity(new RendezvousAffinityFunction(false, 100)); - cache.setNodeFilter(CacheConfiguration.ALL_NODES); - - return cache; - } - - return null; + private static CacheConfiguration utilitySystemCache() { + CacheConfiguration cache = new CacheConfiguration(); + + cache.setName(CU.UTILITY_CACHE_NAME); + cache.setCacheMode(REPLICATED); + cache.setAtomicityMode(TRANSACTIONAL); + cache.setSwapEnabled(false); + cache.setRebalanceMode(SYNC); + cache.setWriteSynchronizationMode(FULL_SYNC); + cache.setAffinity(new RendezvousAffinityFunction(false, 100)); + cache.setNodeFilter(CacheConfiguration.ALL_NODES); + + return cache; } /** * Creates cache configuration for atomic data structures. * * @param cfg Atomic configuration. - * @param client If {@code true} creates client-only cache configuration. * @return Cache configuration for atomic data structures. */ - private static CacheConfiguration atomicsSystemCache(AtomicConfiguration cfg, boolean client) { - if (!client) { - CacheConfiguration ccfg = new CacheConfiguration(); - - ccfg.setName(CU.ATOMICS_CACHE_NAME); - ccfg.setAtomicityMode(TRANSACTIONAL); - ccfg.setSwapEnabled(false); - ccfg.setRebalanceMode(SYNC); - ccfg.setWriteSynchronizationMode(FULL_SYNC); - ccfg.setCacheMode(cfg.getCacheMode()); - ccfg.setNodeFilter(CacheConfiguration.ALL_NODES); - ccfg.setNearConfiguration(new NearCacheConfiguration()); - - if (cfg.getCacheMode() == PARTITIONED) - ccfg.setBackups(cfg.getBackups()); - - return ccfg; - } - - return null; + private static CacheConfiguration atomicsSystemCache(AtomicConfiguration cfg) { + CacheConfiguration ccfg = new CacheConfiguration(); + + ccfg.setName(CU.ATOMICS_CACHE_NAME); + ccfg.setAtomicityMode(TRANSACTIONAL); + ccfg.setSwapEnabled(false); + ccfg.setRebalanceMode(SYNC); + ccfg.setWriteSynchronizationMode(FULL_SYNC); + ccfg.setCacheMode(cfg.getCacheMode()); + ccfg.setNodeFilter(CacheConfiguration.ALL_NODES); + ccfg.setNearConfiguration(new NearCacheConfiguration()); + + if (cfg.getCacheMode() == PARTITIONED) + ccfg.setBackups(cfg.getBackups()); + + return ccfg; } /**