ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [23/23] ignite git commit: Removed table name from "drop index" message.
Date Wed, 22 Mar 2017 11:13:09 GMT
Removed table name from "drop index" message.


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

Branch: refs/heads/ignite-4565-ddl
Commit: 815f0cbdcc84433ff4dde5d61a6bdd3e25979889
Parents: f39de03
Author: devozerov <vozerov@gridgain.com>
Authored: Wed Mar 22 13:43:17 2017 +0300
Committer: devozerov <vozerov@gridgain.com>
Committed: Wed Mar 22 13:43:17 2017 +0300

----------------------------------------------------------------------
 .../processors/query/GridQueryProcessor.java    | 137 +++++++++++++++----
 .../processors/query/QueryIndexState.java       |   2 +-
 .../processors/query/QueryIndexStates.java      |  10 +-
 .../query/ddl/AbstractIndexOperation.java       |  14 +-
 .../query/ddl/CreateIndexOperation.java         |  13 +-
 .../query/ddl/DropIndexOperation.java           |   5 +-
 .../query/ddl/IndexOperationHandler.java        |   2 +-
 7 files changed, 133 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/815f0cbd/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 c27b2f9..4eda6fc 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
@@ -78,6 +78,8 @@ import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
+import java.util.IdentityHashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -322,36 +324,119 @@ public class GridQueryProcessor extends GridProcessorAdapter {
             }
         }
 
-        // Apply dynamic changes to candidates.
-        Collection<AbstractIndexOperation> ops = new ArrayList<>();
+        // Ensure that candidates has unique index names. Otherwise we will not be able to
apply pending operations.
+        Map<String, QueryTypeDescriptorImpl> idxTypMap = new HashMap<>();
+
+        for (QueryTypeCandidate cand : cands) {
+            QueryTypeDescriptorImpl desc = cand.descriptor();
+
+            for (String idxName : desc.indexes().keySet()) {
+                QueryTypeDescriptorImpl oldDesc = idxTypMap.put(idxName, desc);
+
+                if (oldDesc != null)
+                    throw new IgniteException("Duplicate index name [idxName=" + idxName
+
+                        ", type1=" + desc.name() + ", type2=" + oldDesc.name() + ']');
+            }
+        }
+
+        IdentityHashMap<AbstractIndexOperation, String> activeOps = new IdentityHashMap<>();
 
         if (initIdxStates != null) {
-            Map<String, QueryIndexState> readyIdxStates = initIdxStates.readyOperations();
-            Map<String, QueryIndexActiveOperation> acceptedOps = initIdxStates.acceptedActiveOperations();
+            // Apply ready operations.
+            for (Map.Entry<String, QueryIndexState> entry : initIdxStates.readyOperations().entrySet())
{
+                String idxName = entry.getKey();
+                QueryIndexState idxState = entry.getValue();
+
+                if (idxState.removed()) {
+                    // Handle remove. If relevant index is not found, this is not a problem
as consistency between
+                    // nodes are not compromised
+                    QueryTypeDescriptorImpl desc = idxTypMap.remove(idxState.indexName());
+
+                    if (desc != null)
+                        QueryUtils.processDynamicIndexChange(idxName, null, desc);
+                }
+                else {
+                    // Handle create.
+                    QueryTypeDescriptorImpl desc = null;
 
-            for (QueryTypeCandidate cand : cands) {
-                QueryTypeDescriptorImpl desc = cand.descriptor();
+                    for (QueryTypeCandidate cand : cands) {
+                        if (F.eq(cand.descriptor().tableName(), idxState.tableName())) {
+                            desc = cand.descriptor();
 
-                for (Map.Entry<String, QueryIndexState> entry : readyIdxStates.entrySet())
{
-                    String idxName = entry.getKey();
-                    QueryIndexState idxState = entry.getValue();
+                            break;
+                        }
+                    }
 
-                    if (F.eq(desc.tableName(), idxState.tableName()))
-                        QueryUtils.processDynamicIndexChange(idxName, idxState.index(), desc);
+                    if (desc == null)
+                        throw new IgniteException("Table not found for index remove [idxName="
+ idxName +
+                            ", tblName=" + idxState.tableName() + ']');
+
+                    QueryTypeDescriptorImpl oldDesc = idxTypMap.put(idxName, desc);
+
+                    if (oldDesc != null)
+                        throw new IgniteException("Duplicate index name [idxName=" + idxName
+
+                            ", type1=" + desc.name() + ", type2=" + oldDesc.name() + ']');
+
+                    QueryUtils.processDynamicIndexChange(idxName, idxState.index(), desc);
                 }
+            }
+
+            // Apply pending operations.
+            for (Map.Entry<String, QueryIndexActiveOperation> acceptedOpEntry :
+                initIdxStates.acceptedActiveOperations().entrySet()) {
+                String errMsg = null;
+
+                String idxName = acceptedOpEntry.getKey();
+                AbstractIndexOperation op = acceptedOpEntry.getValue().operation();
+
+                if (op instanceof CreateIndexOperation) {
+                    // Handle create.
+                    CreateIndexOperation op0 = (CreateIndexOperation)op;
+
+                    QueryTypeDescriptorImpl desc = null;
+
+                    for (QueryTypeCandidate cand : cands) {
+                        if (F.eq(cand.descriptor().tableName(), op0.tableName())) {
+                            desc = cand.descriptor();
+
+                            break;
+                        }
+                    }
 
-                for (Map.Entry<String, QueryIndexActiveOperation> acceptedOpEntry :
acceptedOps.entrySet()) {
-                    String idxName = acceptedOpEntry.getKey();
-                    AbstractIndexOperation op = acceptedOpEntry.getValue().operation();
+                    if (desc == null)
+                        errMsg = "Table not found: " + op0.tableName();
+                    else {
+                        QueryTypeDescriptorImpl oldDesc = idxTypMap.get(idxName);
 
-                    if (F.eq(desc.tableName(), op.tableName())) {
-                        QueryIndex idx = op instanceof CreateIndexOperation ? ((CreateIndexOperation)op).index()
: null;
+                        if (oldDesc != null) {
+                            if (!op0.ifNotExists())
+                                errMsg = "Index already exists: " + idxName;
+                        }
+                        else {
+                            idxTypMap.put(idxName, desc);
 
-                        QueryUtils.processDynamicIndexChange(idxName, idx, desc);
+                            QueryUtils.processDynamicIndexChange(idxName, op0.index(), desc);
+                        }
                     }
+                }
+                else {
+                    // Handle drop.
+                    DropIndexOperation op0 = (DropIndexOperation)op;
+
+                    QueryTypeDescriptorImpl desc = idxTypMap.get(op0.indexName());
 
-                    ops.add(op);
+                    if (desc == null) {
+                        if (!op0.ifExists())
+                            errMsg = "Index doesn't exist: " + idxName;
+                    }
+                    else {
+                        idxTypMap.remove(idxName);
+
+                        QueryUtils.processDynamicIndexChange(idxName, null, desc);
+                    }
                 }
+
+                activeOps.put(op, errMsg);
             }
         }
 
@@ -359,8 +444,13 @@ public class GridQueryProcessor extends GridProcessorAdapter {
         registerCache0(space, cctx, cands);
 
         // If cache was registered successfully, start pending operations.
-        for (AbstractIndexOperation op : ops)
-            startIndexOperation(op, true, null);
+        for (Map.Entry<AbstractIndexOperation, String> activeOp : activeOps.entrySet())
{
+            String errMsg = activeOp.getValue();
+
+            Exception err = errMsg != null ? new IgniteException(errMsg) : null;
+
+            startIndexOperation(activeOp.getKey(), true, err);
+        }
 
         // Warn about possible implicit deserialization.
         if (!mustDeserializeClss.isEmpty()) {
@@ -501,13 +591,6 @@ public class GridQueryProcessor extends GridProcessorAdapter {
                     if (!op0.ifExists())
                         errMsg = "Index doesn't exist: " + idxName;
                 }
-                else {
-                    // Make sure that index relate to expected table.
-                    if (F.eq(oldIdx.typeDescriptor().tableName(), op.tableName())) {
-                        completed = true;
-                        errMsg = "Index doesn't exist: " + idxName;
-                    }
-                }
             }
             else {
                 completed = true;

http://git-wip-us.apache.org/repos/asf/ignite/blob/815f0cbd/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexState.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexState.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexState.java
index 71fd3d8..83ded3a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexState.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexState.java
@@ -65,7 +65,7 @@ public class QueryIndexState implements Serializable {
     /**
      * @return Table name.
      */
-    public String tableName() {
+    @Nullable public String tableName() {
         return tblName;
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/815f0cbd/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexStates.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexStates.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexStates.java
index a222203..cb1724d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexStates.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexStates.java
@@ -127,7 +127,6 @@ public class QueryIndexStates implements Serializable {
         synchronized (mux) {
             AbstractIndexOperation op = msg.operation();
 
-            String tblName = op.tableName();
             String idxName = op.indexName();
 
             QueryIndexActiveOperation curOp = activeOps.remove(idxName);
@@ -137,12 +136,15 @@ public class QueryIndexStates implements Serializable {
                     if (!msg.hasError()) {
                         QueryIndexState state;
 
-                        if (op instanceof CreateIndexOperation)
-                            state = new QueryIndexState(tblName, idxName, ((CreateIndexOperation)
op).index());
+                        if (op instanceof CreateIndexOperation) {
+                            CreateIndexOperation op0 = (CreateIndexOperation)op;
+
+                            state = new QueryIndexState(op0.tableName(), idxName, ((CreateIndexOperation)op).index());
+                        }
                         else {
                             assert op instanceof DropIndexOperation;
 
-                            state = new QueryIndexState(tblName, idxName, null);
+                            state = new QueryIndexState(null, idxName, null);
                         }
 
                         readyOps.put(idxName, state);

http://git-wip-us.apache.org/repos/asf/ignite/blob/815f0cbd/modules/core/src/main/java/org/apache/ignite/internal/processors/query/ddl/AbstractIndexOperation.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/ddl/AbstractIndexOperation.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/ddl/AbstractIndexOperation.java
index 6f5e35e..11e7966 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/ddl/AbstractIndexOperation.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/ddl/AbstractIndexOperation.java
@@ -36,22 +36,17 @@ public abstract class AbstractIndexOperation implements Serializable {
     /** Space. */
     private final String space;
 
-    /** Table name. */
-    private final String tblName;
-
     /**
      * Constructor.
      *
      * @param cliNodeId Client node ID.
      * @param opId Operation ID.
      * @param space Space.
-     * @param tblName Table name.
      */
-    public AbstractIndexOperation(UUID cliNodeId, UUID opId, String space, String tblName)
{
+    public AbstractIndexOperation(UUID cliNodeId, UUID opId, String space) {
         this.cliNodeId = cliNodeId;
         this.opId = opId;
         this.space = space;
-        this.tblName = tblName;
     }
 
     /**
@@ -76,13 +71,6 @@ public abstract class AbstractIndexOperation implements Serializable {
     }
 
     /**
-     * @return Table name.
-     */
-    public String tableName() {
-        return tblName;
-    }
-
-    /**
      * @return Index name.
      */
     public abstract String indexName();

http://git-wip-us.apache.org/repos/asf/ignite/blob/815f0cbd/modules/core/src/main/java/org/apache/ignite/internal/processors/query/ddl/CreateIndexOperation.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/ddl/CreateIndexOperation.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/ddl/CreateIndexOperation.java
index efbbb25..56f76e1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/ddl/CreateIndexOperation.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/ddl/CreateIndexOperation.java
@@ -30,6 +30,9 @@ public class CreateIndexOperation extends AbstractIndexOperation {
     /** */
     private static final long serialVersionUID = 0L;
 
+    /** Table name. */
+    private final String tblName;
+
     /** Index. */
     @GridToStringInclude
     private final QueryIndex idx;
@@ -49,8 +52,9 @@ public class CreateIndexOperation extends AbstractIndexOperation {
      */
     public CreateIndexOperation(UUID cliNodeId, UUID opId, String space, String tblName,
QueryIndex idx,
         boolean ifNotExists) {
-        super(cliNodeId, opId, space, tblName);
+        super(cliNodeId, opId, space);
 
+        this.tblName = tblName;
         this.idx = idx;
         this.ifNotExists = ifNotExists;
     }
@@ -61,6 +65,13 @@ public class CreateIndexOperation extends AbstractIndexOperation {
     }
 
     /**
+     * @return Table name.
+     */
+    public String tableName() {
+        return tblName;
+    }
+
+    /**
      * @return Index params.
      */
     public QueryIndex index() {

http://git-wip-us.apache.org/repos/asf/ignite/blob/815f0cbd/modules/core/src/main/java/org/apache/ignite/internal/processors/query/ddl/DropIndexOperation.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/ddl/DropIndexOperation.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/ddl/DropIndexOperation.java
index a8d646d..89db235 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/ddl/DropIndexOperation.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/ddl/DropIndexOperation.java
@@ -40,12 +40,11 @@ public class DropIndexOperation extends AbstractIndexOperation {
      * @param cliNodeId Client node ID.
      * @param opId Operation id.
      * @param space Space.
-     * @param tblName Table name.
      * @param idxName Index name.
      * @param ifExists Ignore operation if index doesn't exist.
      */
-    DropIndexOperation(UUID cliNodeId, UUID opId, String space, String tblName, String idxName,
boolean ifExists) {
-        super(cliNodeId, opId, space, tblName);
+    public DropIndexOperation(UUID cliNodeId, UUID opId, String space, String idxName, boolean
ifExists) {
+        super(cliNodeId, opId, space);
 
         this.idxName = idxName;
         this.ifExists = ifExists;

http://git-wip-us.apache.org/repos/asf/ignite/blob/815f0cbd/modules/core/src/main/java/org/apache/ignite/internal/processors/query/ddl/IndexOperationHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/ddl/IndexOperationHandler.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/ddl/IndexOperationHandler.java
index 7825877..f3c5ea3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/ddl/IndexOperationHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/ddl/IndexOperationHandler.java
@@ -140,7 +140,7 @@ public class IndexOperationHandler {
      * @return Worker name.
      */
     private String workerName() {
-        return "index-op-worker" + op.space() + "-" + op.tableName() + "-" + op.indexName();
+        return "index-op-worker" + op.space() + "-" + op.indexName();
     }
 
     /**


Mime
View raw message