ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [2/2] incubator-ignite git commit: #ignite-180: Utility data cache
Date Mon, 06 Apr 2015 20:36:11 GMT
#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 <ivasilinets@gridgain.com>
Authored: Mon Apr 6 23:35:55 2015 +0300
Committer: ivasilinets <ivasilinets@gridgain.com>
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<CacheDataStructuresConfigurationKey, Map<String,
DataStructureInfo>> utilityCache;
 
+    /** */
+    private GridCacheProjectionEx<CacheDataStructuresCacheKey, List<CacheConfiguration>>
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<CacheConfiguration> 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<CacheConfiguration> 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<CacheConfiguration> newVal = oldVal != null ? new ArrayList(oldVal)
:
+                            new ArrayList<CacheConfiguration>();
+
+                    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> T retryRemove(final GridCache cache, final Object key) throws
IgniteCheckedException {
+    @Nullable
+    private <T> T retryRemove(final GridCache cache, final Object key) throws IgniteCheckedException
{
         return retry(log, new Callable<T>() {
             @Nullable @Override public T call() throws Exception {
                 return (T)cache.remove(key);


Mime
View raw message