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/09 13:07:47 UTC

ignite git commit: Started working on disco messages.

Repository: ignite
Updated Branches:
  refs/heads/ignite-4565-ddl d8d2ad8f9 -> fc2cf15fd


Started working on disco messages.


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

Branch: refs/heads/ignite-4565-ddl
Commit: fc2cf15fd31ebfb05052bf297aeaec959d61af1e
Parents: d8d2ad8
Author: devozerov <vo...@gridgain.com>
Authored: Thu Mar 9 16:07:42 2017 +0300
Committer: devozerov <vo...@gridgain.com>
Committed: Thu Mar 9 16:07:42 2017 +0300

----------------------------------------------------------------------
 .../processors/query/GridQueryProcessor.java    | 57 ++++++++++--
 .../query/ddl/DdlAbstractIndexOperation.java    | 60 ++++++++++++
 .../query/ddl/DdlCreateIndexOperation.java      | 98 ++++++++++++++++++++
 .../query/ddl/DdlDropIndexOperation.java        | 70 ++++++++++++++
 4 files changed, 277 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/fc2cf15f/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 bb237ab..ae281b3 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
@@ -84,6 +84,7 @@ import org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor;
 import org.apache.ignite.internal.util.GridSpinBusyLock;
 import org.apache.ignite.internal.util.future.GridCompoundFuture;
 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.GridClosureException;
 import org.apache.ignite.internal.util.lang.IgniteOutClosureX;
@@ -102,7 +103,6 @@ import org.apache.ignite.spi.indexing.IndexingQueryFilter;
 import org.jetbrains.annotations.Nullable;
 import org.jsr166.ConcurrentHashMap8;
 
-import static java.lang.Enum.valueOf;
 import static org.apache.ignite.events.EventType.EVT_CACHE_QUERY_EXECUTED;
 import static org.apache.ignite.internal.IgniteComponentType.INDEXING;
 
@@ -973,7 +973,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     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 desc.dynamicIndexCreate(idx, ifNotExists);
         }
 
         return new GridFinishedFuture<>(new IgniteException("Failed to create index becase table is not found [" +
@@ -2310,7 +2310,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     /**
      * Descriptor of type.
      */
-    private static class TypeDescriptor implements GridQueryTypeDescriptor {
+    private class TypeDescriptor implements GridQueryTypeDescriptor {
         /** Space. */
         private String space;
 
@@ -2647,9 +2647,8 @@ public class GridQueryProcessor extends GridProcessorAdapter {
          * @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;
+        public IgniteInternalFuture<?> dynamicIndexCreate(QueryIndex idx, boolean ifNotExists) {
+            return idxState.onCreateIndex(idx, ifNotExists);
         }
 
         /** {@inheritDoc} */
@@ -2735,21 +2734,63 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     /**
      * Index state manager.
      */
-    private static class IndexStateManager {
+    private class IndexStateManager {
         /** Indexes. */
         private final Map<String, IndexDescriptor> idxs = new ConcurrentHashMap<>();
 
+        /** Client futures. */
+        private final Map<UUID, GridFutureAdapter> cliFuts = new ConcurrentHashMap<>();
+
         /** RW lock. */
         private final ReadWriteLock lock = new ReentrantReadWriteLock();
 
         /**
-         * Callback invoked when original index state is ready.
+         * Handle initial index state.
          *
          * @param idxs Indexes.
          */
         public void onInitialStateReady(Map<String, IndexDescriptor> idxs) {
             this.idxs.putAll(idxs);
         }
+
+        /**
+         * Handle dynamic index creation.
+         *
+         * @param idx Index.
+         * @param ifNotExists IF-NOT-EXISTS flag.
+         * @return Future completed when index is created.
+         */
+        public IgniteInternalFuture<?> onCreateIndex(QueryIndex idx, boolean ifNotExists) {
+            lock.writeLock().lock();
+
+            try {
+                String idxName = idx.getName() != null ? idx.getName() : QueryEntity.defaultIndexName(idx);
+
+                IndexDescriptor oldIdx = idxs.get(idxName);
+
+                if (oldIdx != null) {
+                    if (ifNotExists)
+                        return new GridFinishedFuture<>();
+                    else
+                        return new GridFinishedFuture<>(new IgniteException("Index already exists [idxName=" +
+                            idxName + ']'));
+                }
+
+                UUID opId = UUID.randomUUID();
+                GridFutureAdapter fut = new GridFutureAdapter();
+
+                GridFutureAdapter oldFut = cliFuts.put(opId, fut);
+
+                assert oldFut == null;
+
+                // TODO: Start discovery.
+
+                return fut;
+            }
+            finally {
+                lock.writeLock().unlock();
+            }
+        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/fc2cf15f/modules/core/src/main/java/org/apache/ignite/internal/processors/query/ddl/DdlAbstractIndexOperation.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/ddl/DdlAbstractIndexOperation.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/ddl/DdlAbstractIndexOperation.java
new file mode 100644
index 0000000..c8fe544
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/ddl/DdlAbstractIndexOperation.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.ddl;
+
+import java.io.Serializable;
+import java.util.UUID;
+
+/**
+ * DDL index operation.
+ */
+public abstract class DdlAbstractIndexOperation implements Serializable {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** ID of node that initiated this operation. */
+    private final UUID cliNodeId;
+
+    /** Operation ID. */
+    private final UUID opId;
+
+    /**
+     * Constructor.
+     *
+     * @param cliNodeId Client node ID.
+     * @param opId Operation ID.
+     */
+    public DdlAbstractIndexOperation(UUID cliNodeId, UUID opId) {
+        this.cliNodeId = cliNodeId;
+        this.opId = opId;
+    }
+
+    /**
+     * @return Client node ID.
+     */
+    public UUID clientNodeId() {
+        return cliNodeId;
+    }
+
+    /**
+     * @return Operation id.
+     */
+    public UUID operationId() {
+        return opId;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/fc2cf15f/modules/core/src/main/java/org/apache/ignite/internal/processors/query/ddl/DdlCreateIndexOperation.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/ddl/DdlCreateIndexOperation.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/ddl/DdlCreateIndexOperation.java
new file mode 100644
index 0000000..dc8e85a
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/ddl/DdlCreateIndexOperation.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.ddl;
+
+import org.apache.ignite.cache.QueryIndex;
+import org.apache.ignite.internal.util.tostring.GridToStringInclude;
+import org.apache.ignite.internal.util.typedef.internal.S;
+
+import java.util.UUID;
+
+/**
+ * Arguments for {@code CREATE INDEX}.
+ */
+public class DdlCreateIndexOperation extends DdlAbstractIndexOperation {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Space. */
+    private final String space;
+
+    /** Table name. */
+    private final String tblName;
+
+    /** Index. */
+    @GridToStringInclude
+    private final QueryIndex idx;
+
+    /** Ignore operation if index exists. */
+    private final boolean ifNotExists;
+
+    /**
+     * Constructor.
+     *
+     * @param cliNodeId Id of node that initiated this operation.
+     * @param opId Operation id.
+     * @param space Space.
+     * @param tblName Table name.
+     * @param idx Index params.
+     * @param ifNotExists Ignore operation if index exists.
+     */
+    DdlCreateIndexOperation(UUID cliNodeId, UUID opId, String space, String tblName, QueryIndex idx,
+        boolean ifNotExists) {
+        super(cliNodeId, opId);
+
+        this.space = space;
+        this.tblName = tblName;
+        this.idx = idx;
+        this.ifNotExists = ifNotExists;
+    }
+
+    /**
+     * @return Index params.
+     */
+    public QueryIndex index() {
+        return idx;
+    }
+
+    /**
+     * @return Schema name.
+     */
+    public String space() {
+        return space;
+    }
+
+    /**
+     * @return Table name.
+     */
+    public String tableName() {
+        return tblName;
+    }
+
+    /**
+     * @return Ignore operation if index exists.
+     */
+    public boolean ifNotExists() {
+        return ifNotExists;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(DdlCreateIndexOperation.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/fc2cf15f/modules/core/src/main/java/org/apache/ignite/internal/processors/query/ddl/DdlDropIndexOperation.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/ddl/DdlDropIndexOperation.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/ddl/DdlDropIndexOperation.java
new file mode 100644
index 0000000..0fcdbbd
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/ddl/DdlDropIndexOperation.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.ddl;
+
+import org.apache.ignite.internal.util.typedef.internal.S;
+
+import java.util.UUID;
+
+/**
+ * Arguments for {@code CREATE INDEX}.
+ */
+public class DdlDropIndexOperation extends DdlAbstractIndexOperation {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Index name. */
+    private final String idxName;
+
+    /** Ignore operation if index doesn't exist. */
+    private final boolean ifExists;
+
+    /**
+     * Constructor.
+     *
+     * @param cliNodeId Client node ID.
+     * @param opId Operation id.
+     * @param idxName Index name.
+     * @param ifExists Ignore operation if index doesn't exist.
+     */
+    DdlDropIndexOperation(UUID cliNodeId, UUID opId, String idxName, boolean ifExists) {
+        super(cliNodeId, opId);
+
+        this.idxName = idxName;
+        this.ifExists = ifExists;
+    }
+
+    /**
+     * @return Index name.
+     */
+    public String indexName() {
+        return idxName;
+    }
+
+    /**
+     * @return Ignore operation if index doesn't exist.
+     */
+    public boolean ifExists() {
+        return ifExists;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(DdlDropIndexOperation.class, this);
+    }
+}