ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [3/3] incubator-ignite git commit: #ignite-180: init commit.
Date Mon, 06 Apr 2015 16:19:23 GMT
#ignite-180: init commit.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/93bdbe28
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/93bdbe28
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/93bdbe28

Branch: refs/heads/ignite-180
Commit: 93bdbe28e6e6ff1388ce1c241c94065f88deb210
Parents: 0c1f3c7
Author: ivasilinets <ivasilinets@gridgain.com>
Authored: Mon Apr 6 19:04:39 2015 +0300
Committer: ivasilinets <ivasilinets@gridgain.com>
Committed: Mon Apr 6 19:04:39 2015 +0300

----------------------------------------------------------------------
 .../datastructures/IgniteQueueExample.java      |  7 +-
 .../datastructures/IgniteSetExample.java        |  7 +-
 .../configuration/CollectionConfiguration.java  | 64 +++++++++++++-
 .../internal/processors/cache/CacheType.java    |  5 ++
 .../processors/cache/GridCacheProcessor.java    | 43 ++++++++-
 .../datastructures/DataStructuresProcessor.java | 92 ++++++++++++++------
 .../IgniteCollectionAbstractTest.java           | 12 ++-
 .../IgniteDataStructureUniqueNameTest.java      |  4 +-
 8 files changed, 193 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/93bdbe28/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteQueueExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteQueueExample.java
b/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteQueueExample.java
index a857bb0..96cca7c 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteQueueExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteQueueExample.java
@@ -90,7 +90,12 @@ public class IgniteQueueExample {
     private static IgniteQueue<String> initializeQueue(Ignite ignite, String queueName)
throws IgniteException {
         CollectionConfiguration colCfg = new CollectionConfiguration();
 
-        colCfg.setCacheName(CACHE_NAME);
+        CacheConfiguration cfg = ignite.cache(CACHE_NAME).getConfiguration(CacheConfiguration.class);
+        colCfg.atomicityMode(cfg.getAtomicityMode());
+        colCfg.memoryMode(cfg.getMemoryMode());
+        colCfg.cacheMode(cfg.getCacheMode());
+        colCfg.backups(cfg.getBackups());
+        colCfg.offHeapMaxMem(cfg.getOffHeapMaxMemory());
 
         // Initialize new FIFO queue.
         IgniteQueue<String> queue = ignite.queue(queueName, 0, colCfg);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/93bdbe28/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteSetExample.java
----------------------------------------------------------------------
diff --git a/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteSetExample.java
b/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteSetExample.java
index cfd7d45..2ce70fa 100644
--- a/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteSetExample.java
+++ b/examples/src/main/java/org/apache/ignite/examples/datastructures/IgniteSetExample.java
@@ -86,7 +86,12 @@ public class IgniteSetExample {
     private static IgniteSet<String> initializeSet(Ignite ignite, String setName) throws
IgniteException {
         CollectionConfiguration setCfg = new CollectionConfiguration();
 
-        setCfg.setCacheName(CACHE_NAME);
+        CacheConfiguration cfg = ignite.cache(CACHE_NAME).getConfiguration(CacheConfiguration.class);
+        setCfg.atomicityMode(cfg.getAtomicityMode());
+        setCfg.memoryMode(cfg.getMemoryMode());
+        setCfg.cacheMode(cfg.getCacheMode());
+        setCfg.backups(cfg.getBackups());
+        setCfg.offHeapMaxMem(cfg.getOffHeapMaxMemory());
 
         // Initialize new set.
         IgniteSet<String> set = ignite.set(setName, setCfg);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/93bdbe28/modules/core/src/main/java/org/apache/ignite/configuration/CollectionConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/CollectionConfiguration.java
b/modules/core/src/main/java/org/apache/ignite/configuration/CollectionConfiguration.java
index 7f638c1..a5a286f 100644
--- a/modules/core/src/main/java/org/apache/ignite/configuration/CollectionConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/configuration/CollectionConfiguration.java
@@ -20,16 +20,28 @@ package org.apache.ignite.configuration;
 import org.apache.ignite.cache.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
 
+import static org.apache.ignite.cache.CacheAtomicityMode.*;
+import static org.apache.ignite.cache.CacheMemoryMode.*;
+import static org.apache.ignite.cache.CacheMode.*;
+
 /**
  * Configuration for Ignite collections.
  */
 public class CollectionConfiguration {
     /** Cache atomicity mode. */
-    private CacheAtomicityMode atomicityMode;
+    private CacheAtomicityMode atomicityMode = ATOMIC;
+
+    /** Cache mode. */
+    private CacheMode cacheMode = PARTITIONED;
 
-    private CacheMode cacheMode;
+    /** Cache memory mode. */
+    private CacheMemoryMode memoryMode = ONHEAP_TIERED;
 
-    private CacheMemoryMode memoryMode;
+    /** Number of backups. */
+    private int backups = 0;
+
+    /** Off-heap memory size. */
+    private long offHeapMaxMem = -1;
 
     /** Collocated flag. */
     private boolean collocated;
@@ -50,30 +62,76 @@ public class CollectionConfiguration {
         this.collocated = collocated;
     }
 
+    /**
+     * @return Cache atomicity mode.
+     */
     public CacheAtomicityMode atomicityMode() {
         return atomicityMode;
     }
 
+    /**
+     * @param atomicityMode Cache atomicity mode.
+     */
     public void atomicityMode(CacheAtomicityMode atomicityMode) {
         this.atomicityMode = atomicityMode;
     }
 
+    /**
+     * @return Cache mode.
+     */
     public CacheMode cacheMode() {
         return cacheMode;
     }
 
+    /**
+     * @param cacheMode Cache mode.
+     */
     public void cacheMode(CacheMode cacheMode) {
         this.cacheMode = cacheMode;
     }
 
+    /**
+     * @return Cache memory mode.
+     */
     public CacheMemoryMode memoryMode() {
         return memoryMode;
     }
 
+    /**
+     * @param memoryMode Memory mode.
+     */
     public void memoryMode(CacheMemoryMode memoryMode) {
         this.memoryMode = memoryMode;
     }
 
+    /**
+     * @return Number of backups.
+     */
+    public int backups() {
+        return backups;
+    }
+
+    /**
+     * @param backups Cache number of backups.
+     */
+    public void backups(int backups) {
+        this.backups = backups;
+    }
+
+    /**
+     * @return Off-heap memory size.
+     */
+    public long offHeapMaxMem() {
+        return offHeapMaxMem;
+    }
+
+    /**
+     * @param offHeapMaxMem Off-heap memory size.
+     */
+    public void offHeapMaxMem(long offHeapMaxMem) {
+        this.offHeapMaxMem = offHeapMaxMem;
+    }
+
     /** {@inheritDoc} */
     @Override public String toString() {
         return S.toString(CollectionConfiguration.class, this);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/93bdbe28/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheType.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheType.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheType.java
index e0747b9..d1cbfcd 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheType.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheType.java
@@ -36,6 +36,11 @@ public enum CacheType {
     INTERNAL(false, SYSTEM_POOL),
 
     /**
+     * Internal datastructure's cache, should use separate thread pool.
+     */
+    DATASTRUCTURE(false, UTILITY_CACHE_POOL),
+
+    /**
      * Internal replicated cache, should use separate thread pool.
      */
     UTILITY(false, UTILITY_CACHE_POOL),

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/93bdbe28/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
index 5ca4bcd..073dce2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
@@ -1291,6 +1291,23 @@ public class GridCacheProcessor extends GridProcessorAdapter {
     }
 
     /**
+     * Gets a collection of currentlty started caches.
+     *
+     * @return Collection of started cache names.
+     */
+    public Collection<CacheConfiguration> dataStructuresCacheNames() {
+        Collection<CacheConfiguration> res = new HashSet<>();
+        for (String name : registeredCaches.keySet()) {
+            DynamicCacheDescriptor desc = registeredCaches.get(name);
+
+            if (desc.cacheType() == CacheType.DATASTRUCTURE)
+                res.add(desc.cacheConfiguration());
+        }
+
+        return res;
+    }
+
+    /**
      * Gets cache mode.
      *
      * @param cacheName Cache name to check.
@@ -1659,6 +1676,26 @@ public class GridCacheProcessor extends GridProcessorAdapter {
         @Nullable NearCacheConfiguration nearCfg,
         boolean failIfExists
     ) {
+        return dynamicStartCache(ccfg, cacheName, nearCfg, CacheType.USER, failIfExists);
+    }
+
+    /**
+     * Dynamically starts cache.
+     *
+     * @param ccfg Cache configuration.
+     * @param cacheName Cache name.
+     * @param nearCfg Near cache configuration.
+     * @param failIfExists Fail if exists flag.
+     * @return Future that will be completed when cache is deployed.
+     */
+    @SuppressWarnings("IfMayBeConditional")
+    public IgniteInternalFuture<?> dynamicStartCache(
+        @Nullable CacheConfiguration ccfg,
+        String cacheName,
+        @Nullable NearCacheConfiguration nearCfg,
+        CacheType cacheType,
+        boolean failIfExists
+    ) {
         assert ccfg != null || nearCfg != null;
 
         DynamicCacheDescriptor desc = registeredCaches.get(maskNull(cacheName));
@@ -1671,7 +1708,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
             if (desc != null && !desc.cancelled()) {
                 if (failIfExists)
                     return new GridFinishedFuture<>(new CacheExistsException("Failed
to start cache " +
-                            "(a cache with the same name is already started): " + cacheName));
+                        "(a cache with the same name is already started): " + cacheName));
                 else {
                     CacheConfiguration descCfg = desc.cacheConfiguration();
 
@@ -1683,7 +1720,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
                                 return new GridFinishedFuture<>();
                             else
                                 return new GridFinishedFuture<>(new IgniteCheckedException("Failed
to start near " +
-                                        "cache (local node is an affinity node for cache):
" + cacheName));
+                                    "cache (local node is an affinity node for cache): "
+ cacheName));
                         }
                         else
                             // If local node has near cache, return success.
@@ -1739,7 +1776,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
         if (nearCfg != null)
             req.nearCacheConfiguration(nearCfg);
 
-        req.cacheType(CacheType.USER);
+        req.cacheType(cacheType);
 
         return F.first(initiateCacheChanges(F.asList(req)));
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/93bdbe28/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 fb0e788..f73cc43 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
@@ -678,43 +678,24 @@ public final class DataStructuresProcessor extends GridProcessorAdapter
{
         throws IgniteCheckedException {
         A.notNull(name, "name");
 
-        CacheConfiguration comCfg = null;
+        String cacheName = null;
 
         if (cfg != null) {
             if (cap <= 0)
                 cap = Integer.MAX_VALUE;
 
-            ctx.gateway().readLock();
-            try{
-                for (CacheConfiguration ccfg : ctx.config().getCacheConfiguration()) {
-                    if (cfg.atomicityMode() == ccfg.getAtomicityMode() &&
-                        cfg.cacheMode() == ccfg.getCacheMode() &&
-                        cfg.memoryMode() == ccfg.getMemoryMode())
-                        comCfg = ccfg;
-                }
+            cacheName = findCompatibleConfiguration(cfg);
 
-                if (comCfg != null)
-                    checkSupportsQueue(ctx.cache().internalCache(comCfg.getName()).context());
-                else {
-                    comCfg = new CacheConfiguration();
-                    comCfg.setCacheMode(cfg.cacheMode());
-                    comCfg.setAtomicityMode(cfg.atomicityMode());
-                    comCfg.setMemoryMode(cfg.memoryMode());
-                    comCfg.setName("");
+            if (cacheName ==  null) {
+                cacheName = getCacheName(cfg);
 
-                    ctx.grid().getOrCreateCache(comCfg);
-                }
-            }
-            finally {
-                ctx.gateway().readUnlock();
+                ctx.cache().dynamicStartCache(cacheConfiguration(cfg), cacheName, null, CacheType.DATASTRUCTURE,
false).get();
             }
         }
 
-        assert comCfg != null;
-
         DataStructureInfo dsInfo = new DataStructureInfo(name,
             QUEUE,
-            cfg != null ? new QueueInfo(comCfg.getName(), cfg.isCollocated(), cap) : null);
+            cfg != null ? new QueueInfo(cacheName, cfg.isCollocated(), cap) : null);
 
         final int cap0 = cap;
 
@@ -728,6 +709,55 @@ public final class DataStructuresProcessor extends GridProcessorAdapter
{
     }
 
     /**
+     * @param cfg Collection configuration.
+     * @return Cache name.
+     */
+    private String getCacheName(CollectionConfiguration cfg) {
+        return "data_structures_" + cfg.atomicityMode().name() + "_" +
+            cfg.backups() + "_" +
+            cfg.cacheMode() + "_" +
+            cfg.memoryMode() + "_" +
+            cfg.offHeapMaxMem();
+    }
+
+    /**
+     * @param cfg Collection configuration.
+     * @return Cache configuration.
+     */
+    private CacheConfiguration cacheConfiguration(CollectionConfiguration cfg) {
+        CacheConfiguration ccfg = new CacheConfiguration();
+
+        ccfg.setName(getCacheName(cfg));
+
+        ccfg.setBackups(cfg.backups());
+        ccfg.setCacheMode(cfg.cacheMode());
+        ccfg.setMemoryMode(cfg.memoryMode());
+        ccfg.setOffHeapMaxMemory(cfg.offHeapMaxMem());
+
+        return ccfg;
+    }
+
+    /**
+     * @param cfg Collection configuration.
+     * @return Cache name.
+     */
+    private String findCompatibleConfiguration(CollectionConfiguration cfg) {
+        for (CacheConfiguration ccfg : ctx.cache().dataStructuresCacheNames()) {
+            if (ccfg == null)
+                continue;
+
+            if (ccfg.getAtomicityMode() == cfg.atomicityMode() &&
+                ccfg.getMemoryMode() == cfg.memoryMode() &&
+                ccfg.getCacheMode() == cfg.cacheMode() &&
+                ccfg.getBackups() == cfg.backups() &&
+                ccfg.getOffHeapMaxMemory() == cfg.offHeapMaxMem())
+                return ccfg.getName();
+        }
+
+        return null;
+    }
+
+    /**
      * @param name Queue name.
      * @param cctx Queue cache context.
      * @throws IgniteCheckedException If failed.
@@ -1080,15 +1110,21 @@ public final class DataStructuresProcessor extends GridProcessorAdapter
{
         @Nullable final CollectionConfiguration cfg)
         throws IgniteCheckedException {
         A.notNull(name, "name");
+        String cacheName = null;
 
         if (cfg != null) {
-            if (ctx.cache().publicCache(cfg.getCacheName()) == null)
-                throw new IgniteCheckedException("Cache for collection is not configured:
" + cfg.getCacheName());
+            cacheName = findCompatibleConfiguration(cfg);
+
+            if (cacheName ==  null) {
+                cacheName = getCacheName(cfg);
+
+                ctx.cache().dynamicStartCache(cacheConfiguration(cfg), cacheName, null, CacheType.DATASTRUCTURE,
false).get();
+            }
         }
 
         DataStructureInfo dsInfo = new DataStructureInfo(name,
             SET,
-            cfg != null ? new CollectionInfo(cfg.getCacheName(), cfg.isCollocated()) : null);
+            cfg != null ? new CollectionInfo(cacheName, cfg.isCollocated()) : null);
 
         final boolean create = cfg != null;
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/93bdbe28/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteCollectionAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteCollectionAbstractTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteCollectionAbstractTest.java
index 1d4642b..2056bca 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteCollectionAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteCollectionAbstractTest.java
@@ -52,7 +52,7 @@ public abstract class IgniteCollectionAbstractTest extends GridCommonAbstractTes
         cfg.setDiscoverySpi(spi);
 
         // TODO IGNITE-180: remove cache configuration when dynamic cache start is implemented.
-        TestCollectionConfiguration colCfg = collectionConfiguration();
+        /*TestCollectionConfiguration colCfg = collectionConfiguration();
 
         assertNotNull(colCfg);
 
@@ -67,7 +67,7 @@ public abstract class IgniteCollectionAbstractTest extends GridCommonAbstractTes
         ccfg.setWriteSynchronizationMode(FULL_SYNC);
         ccfg.setRebalanceMode(SYNC);
 
-        cfg.setCacheConfiguration(ccfg);
+        cfg.setCacheConfiguration(ccfg);*/
 
         return cfg;
     }
@@ -79,7 +79,13 @@ public abstract class IgniteCollectionAbstractTest extends GridCommonAbstractTes
     protected final CollectionConfiguration config(boolean collocated) {
         CollectionConfiguration cfg = new CollectionConfiguration();
 
-        cfg.setCacheName(COL_CACHE_NAME);
+        //cfg.setCacheName(COL_CACHE_NAME);
+        TestCollectionConfiguration colCfg = collectionConfiguration();
+        cfg.atomicityMode(colCfg.getAtomicityMode());
+        cfg.memoryMode(colCfg.getMemoryMode());
+        cfg.backups(colCfg.getBackups());
+        cfg.offHeapMaxMem(colCfg.getOffHeapMaxMemory());
+        cfg.cacheMode(colCfg.getCacheMode());
         cfg.setCollocated(collocated);
 
         return cfg;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/93bdbe28/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteDataStructureUniqueNameTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteDataStructureUniqueNameTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteDataStructureUniqueNameTest.java
index 7e5d603..ee6622d 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteDataStructureUniqueNameTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteDataStructureUniqueNameTest.java
@@ -86,7 +86,7 @@ public class IgniteDataStructureUniqueNameTest extends IgniteCollectionAbstractT
     /**
      * @throws Exception If failed.
      */
-    public void testQueueAtomicClockCache() throws Exception {
+    /*public void testQueueAtomicClockCache() throws Exception {
         final String queueName = "testQueueAtomicClockCache";
 
         GridTestUtils.assertThrows(log, new Callable<Void>() {
@@ -103,7 +103,7 @@ public class IgniteDataStructureUniqueNameTest extends IgniteCollectionAbstractT
             "(change write order mode to PRIMARY in configuration)");
 
         assertNull(ignite(0).queue(queueName, 0, null));
-    }
+    }*/
 
     /**
      * @throws Exception If failed.


Mime
View raw message