You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2017/03/14 10:22:10 UTC

ignite git commit: Implemented init checks.

Repository: ignite
Updated Branches:
  refs/heads/ignite-4565-ddl 4a5bb9375 -> b0c3be09d


Implemented init checks.


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

Branch: refs/heads/ignite-4565-ddl
Commit: b0c3be09d1c0cf2fd808488fe137e2171556bb0d
Parents: 4a5bb93
Author: devozerov <vo...@gridgain.com>
Authored: Tue Mar 14 13:22:02 2017 +0300
Committer: devozerov <vo...@gridgain.com>
Committed: Tue Mar 14 13:22:02 2017 +0300

----------------------------------------------------------------------
 .../processors/cache/GridCacheProcessor.java    | 17 +----
 .../processors/query/GridQueryProcessor.java    | 66 ++++++++++++++++----
 2 files changed, 55 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/b0c3be09/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 9b33df0..e28c8ef 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
@@ -66,8 +66,6 @@ import org.apache.ignite.events.EventType;
 import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.processors.query.QueryUtils;
 import org.apache.ignite.internal.processors.query.ddl.AbstractIndexOperation;
-import org.apache.ignite.internal.processors.query.ddl.CreateIndexOperation;
-import org.apache.ignite.internal.processors.query.ddl.DropIndexOperation;
 import org.apache.ignite.internal.processors.query.ddl.IndexAbstractDiscoveryMessage;
 import org.apache.ignite.internal.processors.query.ddl.IndexAckDiscoveryMessage;
 import org.apache.ignite.internal.processors.query.ddl.IndexInitDiscoveryMessage;
@@ -2734,7 +2732,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
             return;
         }
 
-        // Validate request on descriptor level.
+        // Validate request at descriptor level.
         AbstractIndexOperation oldOp = desc.indexInitOperation();
 
         if (oldOp != null) {
@@ -2744,19 +2742,6 @@ public class GridCacheProcessor extends GridProcessorAdapter {
             return;
         }
 
-        if (op instanceof CreateIndexOperation) {
-            CreateIndexOperation op0 = (CreateIndexOperation)op;
-
-            // TODO
-        }
-        else if (op instanceof DropIndexOperation) {
-            DropIndexOperation op0 = (DropIndexOperation)op;
-
-            // TODO
-        }
-        else
-            U.warn(log, "Received index init message with unsupported operation (will ignore): " + msg);
-
         // For already started cache we must make sure that indexing manager will be able to accommodate it.
         if (isMissingQueryCache(desc))
             cache(op.space()).context().queries().onIndexInitDiscoveryMessage(msg);

http://git-wip-us.apache.org/repos/asf/ignite/blob/b0c3be09/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 b8fa36f..eb984c9 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
@@ -59,7 +59,6 @@ import org.apache.ignite.internal.processors.cache.query.GridCacheQueryType;
 import org.apache.ignite.internal.processors.query.ddl.AbstractIndexOperation;
 import org.apache.ignite.internal.processors.query.ddl.CreateIndexOperation;
 import org.apache.ignite.internal.processors.query.ddl.DropIndexOperation;
-import org.apache.ignite.internal.processors.query.ddl.IndexAbstractDiscoveryMessage;
 import org.apache.ignite.internal.processors.query.ddl.IndexAckDiscoveryMessage;
 import org.apache.ignite.internal.processors.query.ddl.IndexInitDiscoveryMessage;
 import org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor;
@@ -72,7 +71,6 @@ import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteBiTuple;
 import org.apache.ignite.lang.IgniteFuture;
-import org.apache.ignite.lang.IgniteUuid;
 import org.apache.ignite.spi.indexing.IndexingQueryFilter;
 import org.jetbrains.annotations.Nullable;
 
@@ -303,12 +301,63 @@ public class GridQueryProcessor extends GridProcessorAdapter {
             if (op instanceof CreateIndexOperation) {
                 CreateIndexOperation op0 = (CreateIndexOperation)op;
 
-                // TODO
+                QueryIndex idx = op0.index();
+
+                // Check conflict with other indexes.
+                String idxName = op0.index().getName();
+
+                QueryIndexKey idxKey = new QueryIndexKey(space, idxName);
+
+                QueryIndexDescriptorImpl oldIdx = idxs.get(idxKey);
+
+                if (oldIdx != null) {
+                    if (!op0.ifNotExists())
+                        msg.onError(ctx.localNodeId(), "Index already exists [space=" + space + ", index=" + idxName);
+
+                    return;
+                }
+
+                // Make sure table exists.
+                String tblName = op0.tableName();
+
+                QueryTypeDescriptorImpl typeDesc = null;
+
+                for (QueryTypeDescriptorImpl type : types.values()) {
+                    if (F.eq(tblName, type.tableName())) {
+                        typeDesc = type;
+
+                        break;
+                    }
+                }
+
+                if (typeDesc == null) {
+                    msg.onError(ctx.localNodeId(), "Table doesn't exist: " + tblName);
+
+                    return;
+                }
+
+                // Make sure that index can be applied to the given table.
+                for (String idxField : idx.getFieldNames()) {
+                    if (!typeDesc.fields().containsKey(idxField)) {
+                        msg.onError(ctx.localNodeId(), "Field doesn't exist: " + idxField);
+
+                        return;
+                    }
+                }
             }
             else if (op instanceof DropIndexOperation) {
                 DropIndexOperation op0 = (DropIndexOperation)op;
 
-                // TODO
+                String idxName = op0.indexName();
+
+                QueryIndexKey idxKey = new QueryIndexKey(space, idxName);
+
+                QueryIndexDescriptorImpl oldIdx = idxs.get(idxKey);
+
+                if (oldIdx == null) {
+                    if (!op0.ifExists())
+                        msg.onError(ctx.localNodeId(), "Index doesn't exist: " + idxName);
+                }
             }
             else
                 msg.onError(ctx.localNodeId(), "Unsupported operation: " + op);
@@ -319,18 +368,11 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     }
 
     /**
-     * Index operation context. Represents pending operations
-     */
-    private class IndexOperationContext {
-
-    }
-
-    /**
      * Handle index ack discovery message.
      *
      * @param msg Message.
      */
-    private void onIndexAckDiscoveryMessage(IndexAckDiscoveryMessage msg) {
+    private void onIndexAckDiscoveryMessage(String space, IndexAckDiscoveryMessage msg) {
         // TODO
     }