ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject [8/9] incubator-ignite git commit: ignite-698 - fix for IGNITE-569 part2
Date Thu, 09 Apr 2015 21:54:57 GMT
ignite-698 - fix for IGNITE-569 part2


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

Branch: refs/heads/ignite-698
Commit: 4208c1219801aa0630d9fbb718ba2ace2af5fb8b
Parents: caa54a2
Author: S.Vladykin <svladykin@gridgain.com>
Authored: Fri Apr 10 00:54:21 2015 +0300
Committer: S.Vladykin <svladykin@gridgain.com>
Committed: Fri Apr 10 00:54:21 2015 +0300

----------------------------------------------------------------------
 .../processors/query/GridQueryProcessor.java    | 89 ++++++++++++--------
 .../processors/query/h2/IgniteH2Indexing.java   |  1 +
 2 files changed, 55 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4208c121/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
index 0ea0b99..7ce894d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
@@ -62,7 +62,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     private final Map<TypeId, TypeDescriptor> types = new ConcurrentHashMap8<>();
 
     /** Type descriptors. */
-    private final Map<TypeName, TypeDescriptor> typesByName = new ConcurrentHashMap8<>();
+    private final ConcurrentMap<TypeName, TypeDescriptor> typesByName = new ConcurrentHashMap8<>();
 
     /** */
     private ExecutorService execSvc;
@@ -108,62 +108,81 @@ public class GridQueryProcessor extends GridProcessorAdapter {
 
     /**
      * @param ccfg Cache configuration.
+     * @throws IgniteCheckedException If failed.
      */
     public void initializeCache(CacheConfiguration<?, ?> ccfg) throws IgniteCheckedException
{
         idx.registerCache(ccfg);
 
-        if (!F.isEmpty(ccfg.getTypeMetadata())) {
-            for (CacheTypeMetadata meta : ccfg.getTypeMetadata()) {
-                if (F.isEmpty(meta.getValueType()))
-                    throw new IgniteCheckedException("Value type is not set: " + meta);
+        try {
+            if (!F.isEmpty(ccfg.getTypeMetadata())) {
+                for (CacheTypeMetadata meta : ccfg.getTypeMetadata()) {
+                    if (F.isEmpty(meta.getValueType()))
+                        throw new IgniteCheckedException("Value type is not set: " + meta);
 
-                TypeDescriptor desc = new TypeDescriptor(ccfg);
+                    TypeDescriptor desc = new TypeDescriptor(ccfg);
 
-                Class<?> valCls = U.classForName(meta.getValueType(), null);
+                    Class<?> valCls = U.classForName(meta.getValueType(), null);
 
-                desc.name(valCls != null ? typeName(valCls) : meta.getValueType());
+                    desc.name(valCls != null ? typeName(valCls) : meta.getValueType());
 
-                desc.valueClass(valCls != null ? valCls : Object.class);
-                desc.keyClass(
-                    meta.getKeyType() == null ?
-                        Object.class :
-                        U.classForName(meta.getKeyType(), Object.class));
+                    desc.valueClass(valCls != null ? valCls : Object.class);
+                    desc.keyClass(
+                        meta.getKeyType() == null ?
+                            Object.class :
+                            U.classForName(meta.getKeyType(), Object.class));
 
-                TypeId typeId;
+                    TypeId typeId;
 
-                if (valCls == null || ctx.cacheObjects().isPortableClass(valCls)) {
-                    processPortableMeta(meta, desc);
+                    if (valCls == null || ctx.cacheObjects().isPortableClass(valCls)) {
+                        processPortableMeta(meta, desc);
 
-                    typeId = new TypeId(ccfg.getName(), ctx.cacheObjects().typeId(meta.getValueType()));
-                }
-                else {
-                    processClassMeta(meta, desc);
+                        typeId = new TypeId(ccfg.getName(), ctx.cacheObjects().typeId(meta.getValueType()));
+                    }
+                    else {
+                        processClassMeta(meta, desc);
 
-                    typeId = new TypeId(ccfg.getName(), valCls);
-                }
+                        typeId = new TypeId(ccfg.getName(), valCls);
+                    }
 
-                desc.registered(idx.registerType(ccfg.getName(), desc));
+                    addTypeByName(ccfg, desc);
+                    types.put(typeId, desc);
 
-                typesByName.put(new TypeName(ccfg.getName(), desc.name()), desc);
-                types.put(typeId, desc);
+                    desc.registered(idx.registerType(ccfg.getName(), desc));
+                }
             }
-        }
 
-        Class<?>[] clss = ccfg.getIndexedTypes();
+            Class<?>[] clss = ccfg.getIndexedTypes();
 
-        if (!F.isEmpty(clss)) {
-            for (int i = 0; i < clss.length; i += 2) {
-                Class<?> keyCls = clss[i];
-                Class<?> valCls = clss[i + 1];
+            if (!F.isEmpty(clss)) {
+                for (int i = 0; i < clss.length; i += 2) {
+                    Class<?> keyCls = clss[i];
+                    Class<?> valCls = clss[i + 1];
 
-                TypeDescriptor desc = processKeyAndValueClasses(ccfg, keyCls, valCls);
+                    TypeDescriptor desc = processKeyAndValueClasses(ccfg, keyCls, valCls);
 
-                desc.registered(idx.registerType(ccfg.getName(), desc));
+                    addTypeByName(ccfg, desc);
+                    types.put(new TypeId(ccfg.getName(), valCls), desc);
 
-                typesByName.put(new TypeName(ccfg.getName(), desc.name()), desc);
-                types.put(new TypeId(ccfg.getName(), valCls), desc);
+                    desc.registered(idx.registerType(ccfg.getName(), desc));
+                }
             }
         }
+        catch (IgniteCheckedException | RuntimeException e) {
+            idx.unregisterCache(ccfg);
+
+            throw e;
+        }
+    }
+
+    /**
+     * @param ccfg Cache configuration.
+     * @param desc Type descriptor.
+     * @throws IgniteCheckedException If failed.
+     */
+    private void addTypeByName(CacheConfiguration<?,?> ccfg, TypeDescriptor desc) throws
IgniteCheckedException {
+        if (typesByName.putIfAbsent(new TypeName(ccfg.getName(), desc.name()), desc) != null)
+            throw new IgniteCheckedException("Type with name '" + desc.name() + "' already
indexed " +
+                "in cache '" + ccfg.getName() + "'.");
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/4208c121/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
index c99b01c..6804f31 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java
@@ -1261,6 +1261,7 @@ public class IgniteH2Indexing implements GridQueryIndexing {
         createSqlFunctions(schema, ccfg.getSqlFunctionClasses());
     }
 
+    /** {@inheritDoc} */
     @Override public void unregisterCache(CacheConfiguration<?, ?> ccfg) {
         String schema = schema(ccfg.getName());
 


Mime
View raw message