ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [3/3] ignite git commit: Creating correct path for index create.
Date Thu, 09 Mar 2017 11:05:38 GMT
Creating correct path for index create.


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

Branch: refs/heads/ignite-4565-ddl
Commit: f6fa2659d88994f7942f1ac5e1fff65e697ac541
Parents: 19f0568
Author: devozerov <vozerov@gridgain.com>
Authored: Thu Mar 9 14:05:27 2017 +0300
Committer: devozerov <vozerov@gridgain.com>
Committed: Thu Mar 9 14:05:27 2017 +0300

----------------------------------------------------------------------
 .../processors/cache/GridCacheProcessor.java    | 21 +++++++
 .../cache/query/GridCacheQueryManager.java      | 27 +++++++++
 .../processors/query/GridQueryProcessor.java    | 63 ++++++++++++++++++++
 .../query/h2/ddl/DdlStatementsProcessor.java    |  4 +-
 4 files changed, 113 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/f6fa2659/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 b1644d1..868cabf 100755
--- 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
@@ -48,6 +48,7 @@ import org.apache.ignite.cache.CacheExistsException;
 import org.apache.ignite.cache.CacheMemoryMode;
 import org.apache.ignite.cache.CacheMode;
 import org.apache.ignite.cache.CacheRebalanceMode;
+import org.apache.ignite.cache.QueryIndex;
 import org.apache.ignite.cache.affinity.AffinityFunction;
 import org.apache.ignite.cache.affinity.AffinityFunctionContext;
 import org.apache.ignite.cache.affinity.AffinityNodeAddressHashResolver;
@@ -150,6 +151,7 @@ import static org.apache.ignite.internal.GridComponent.DiscoveryDataExchangeType
 import static org.apache.ignite.internal.IgniteComponentType.JTA;
 import static org.apache.ignite.internal.IgniteNodeAttributes.ATTR_CONSISTENCY_CHECK_SKIPPED;
 import static org.apache.ignite.internal.IgniteNodeAttributes.ATTR_TX_CONFIG;
+import static org.apache.ignite.internal.processors.cache.GridCacheUtils.cacheId;
 import static org.apache.ignite.internal.processors.cache.GridCacheUtils.isNearEnabled;
 
 /**
@@ -2514,6 +2516,25 @@ public class GridCacheProcessor extends GridProcessorAdapter {
     }
 
     /**
+     * Dynamically create index.
+     *
+     * @param cacheName Cache name.
+     * @param tblName Table name.
+     * @param idx Index.
+     * @param ifNotExists When set to {@code true} operation will fail if index already exists.
+     * @return Future completed when index is created.
+     */
+    public IgniteInternalFuture<?> dynamicIndexCreate(String cacheName, String tblName,
QueryIndex idx,
+        boolean ifNotExists) {
+        IgniteInternalCache cache = cache(cacheName);
+
+        if (cache == null)
+            return new GridFinishedFuture<>(new IgniteException("Cache doesn't exist:
" + cacheName));
+
+        return cache.context().queries().createIndex(tblName, idx, ifNotExists);
+    }
+
+    /**
      * @param reqs Requests.
      * @param failIfExists Fail if exists flag.
      * @return Collection of futures.

http://git-wip-us.apache.org/repos/asf/ignite/blob/f6fa2659/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
index 8e3f2a9..28a5886 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryManager.java
@@ -46,6 +46,7 @@ import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.IgniteSystemProperties;
+import org.apache.ignite.cache.QueryIndex;
 import org.apache.ignite.cache.query.QueryMetrics;
 import org.apache.ignite.cluster.ClusterNode;
 import org.apache.ignite.configuration.CacheConfiguration;
@@ -92,6 +93,7 @@ import org.apache.ignite.internal.util.GridEmptyIterator;
 import org.apache.ignite.internal.util.GridLeanMap;
 import org.apache.ignite.internal.util.GridSpiCloseableIteratorWrapper;
 import org.apache.ignite.internal.util.GridSpinBusyLock;
+import org.apache.ignite.internal.util.future.GridFinishedFuture;
 import org.apache.ignite.internal.util.future.GridFutureAdapter;
 import org.apache.ignite.internal.util.lang.GridCloseableIterator;
 import org.apache.ignite.internal.util.lang.GridIterator;
@@ -526,6 +528,31 @@ public abstract class GridCacheQueryManager<K, V> extends GridCacheManagerAdapte
     }
 
     /**
+     * Create index dynamically.
+     *
+     * @param tblName Table name.
+     * @param idx Index.
+     * @param ifNotExists When set to {@code true} operation will fail if index already exists.
+     * @return Future completed when index is created.
+     */
+    public IgniteInternalFuture<?> createIndex(String tblName, QueryIndex idx, boolean
ifNotExists) {
+        if (!enterBusy())
+            return new GridFinishedFuture<>(new IgniteException("Failed to create index
because " +
+                "local node is stopping."));
+
+        try {
+            return qryProc.createIndex(space, tblName, idx, ifNotExists);
+        }
+        catch (Exception e) {
+            return new GridFinishedFuture<>(
+                new IgniteException("Index creation failed due to unexpected exception.",
e));
+        }
+        finally {
+            leaveBusy();
+        }
+    }
+
+    /**
      * Undeploys given class loader.
      *
      * @param ldr Class loader to undeploy.

http://git-wip-us.apache.org/repos/asf/ignite/blob/f6fa2659/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 42e7c49..ad900ea 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
@@ -247,6 +247,8 @@ public class GridQueryProcessor extends GridProcessorAdapter {
 
                     TypeDescriptor desc = new TypeDescriptor();
 
+                    desc.space(cctx.name());
+
                     // Key and value classes still can be available if they are primitive
or JDK part.
                     // We need that to set correct types for _key and _val columns.
                     Class<?> keyCls = U.classForName(qryEntity.getKeyType(), null);
@@ -363,6 +365,8 @@ public class GridQueryProcessor extends GridProcessorAdapter {
 
                     TypeDescriptor desc = new TypeDescriptor();
 
+                    desc.space(cctx.name());
+
                     // Key and value classes still can be available if they are primitive
or JDK part.
                     // We need that to set correct types for _key and _val columns.
                     Class<?> keyCls = U.classForName(meta.getKeyType(), null);
@@ -953,6 +957,25 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     }
 
     /**
+     * Create index.
+     *
+     * @param space Space name.
+     * @param tblName Table name.
+     * @param idx Index.
+     * @param ifNotExists When set to {@code true} operation will fail if index already exists.
+     * @return Future completed when index is created.
+     */
+    public IgniteInternalFuture<?> createIndex(String space, String tblName, QueryIndex
idx, boolean ifNotExists) {
+        for (TypeDescriptor desc : types.values()) {
+            if (desc.matchSpaceAndTable(space, tblName))
+                return desc.createIndexAsync(idx, ifNotExists);
+        }
+
+        return new GridFinishedFuture<>(new IgniteException("Failed to create index
becase table is not found [" +
+            "space=" + space + ", table=" + tblName + ']'));
+    }
+
+    /**
      * @param sqlQry Sql query.
      * @param params Params.
      */
@@ -2278,6 +2301,9 @@ public class GridQueryProcessor extends GridProcessorAdapter {
      * Descriptor of type.
      */
     private static class TypeDescriptor implements GridQueryTypeDescriptor {
+        /** Space. */
+        private String space;
+
         /** */
         private String name;
 
@@ -2324,6 +2350,20 @@ public class GridQueryProcessor extends GridProcessorAdapter {
         private boolean registered;
 
         /**
+         * @return Space.
+         */
+        String space() {
+            return space;
+        }
+
+        /**
+         * @param space Space.
+         */
+        void space(String space) {
+            this.space = space;
+        }
+
+        /**
          * @return {@code True} if type registration in SPI was finished and type was not
rejected.
          */
         boolean registered() {
@@ -2568,6 +2608,29 @@ public class GridQueryProcessor extends GridProcessorAdapter {
             this.affKey = affKey;
         }
 
+        /**
+         * Check whether space and table name matches.
+         *
+         * @param space Space.
+         * @param tblName Table name.
+         * @return {@code True} if matches.
+         */
+        public boolean matchSpaceAndTable(String space, String tblName) {
+            return F.eq(space, this.space) && F.eq(tblName, this.tblName);
+        }
+
+        /**
+         * Initiate asynchronous index creation.
+         *
+         * @param idx Index description.
+         * @param ifNotExists When set to {@code true} operation will fail if index already
exists.
+         * @return Future completed when index is created.
+         */
+        public IgniteInternalFuture<?> createIndexAsync(QueryIndex idx, boolean ifNotExists)
{
+            // TODO
+            return null;
+        }
+
         /** {@inheritDoc} */
         @Override public String toString() {
             return S.toString(TypeDescriptor.class, this);

http://git-wip-us.apache.org/repos/asf/ignite/blob/f6fa2659/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ddl/DdlStatementsProcessor.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ddl/DdlStatementsProcessor.java
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ddl/DdlStatementsProcessor.java
index 1c558c5..d13feb2 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ddl/DdlStatementsProcessor.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/ddl/DdlStatementsProcessor.java
@@ -185,7 +185,7 @@ public class DdlStatementsProcessor {
             res.setOperationId(msg.operation().operationId());
             res.setError(exceptionToBytes(ex));
 
-            ctx.io().send(snd, GridTopic.TOPIC_QUERY, res, GridIoPolicy.IDX_POOL);
+            ctx.io().sendToGridTopic(snd, GridTopic.TOPIC_QUERY, res, GridIoPolicy.IDX_POOL);
         }
         catch (Throwable e) {
             U.error(log, "Failed to notify coordinator about local DLL operation completion
[opId=" +
@@ -270,7 +270,7 @@ public class DdlStatementsProcessor {
         res.setOperationId(args.operationId());
 
         try {
-            ctx.io().send(args.clientNodeId(), GridTopic.TOPIC_QUERY, res, GridIoPolicy.IDX_POOL);
+            ctx.io().sendToGridTopic(args.clientNodeId(), GridTopic.TOPIC_QUERY, res, GridIoPolicy.IDX_POOL);
         }
         catch (IgniteCheckedException e) {
             U.error(log, "Failed to notify client node about DDL operation failure " +


Mime
View raw message