ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject ignite git commit: Better index state.
Date Tue, 14 Mar 2017 13:33:49 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-4565-ddl 8e9ba9751 -> cec52fd44


Better index state.


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

Branch: refs/heads/ignite-4565-ddl
Commit: cec52fd44db52c4cb1510ec37b98ac1ae32ae715
Parents: 8e9ba97
Author: devozerov <vozerov@gridgain.com>
Authored: Tue Mar 14 16:33:40 2017 +0300
Committer: devozerov <vozerov@gridgain.com>
Committed: Tue Mar 14 16:33:40 2017 +0300

----------------------------------------------------------------------
 .../cache/DynamicCacheChangeRequest.java        |  32 ++---
 .../query/QueryIndexActiveOperation.java        |  71 ++++++++++
 .../processors/query/QueryIndexState.java       |  10 +-
 .../processors/query/QueryIndexStates.java      | 131 +++++++++++++++++++
 .../query/ddl/AbstractIndexOperation.java       |   5 +
 .../query/ddl/CreateIndexOperation.java         |   5 +
 .../query/ddl/DropIndexOperation.java           |   6 +-
 7 files changed, 228 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/cec52fd4/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeRequest.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeRequest.java
index aaab4e2..5d274b4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/DynamicCacheChangeRequest.java
@@ -17,21 +17,21 @@
 
 package org.apache.ignite.internal.processors.cache;
 
-import java.io.Serializable;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.NearCacheConfiguration;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
-import org.apache.ignite.internal.processors.query.QueryIndexState;
+import org.apache.ignite.internal.processors.query.QueryIndexStates;
 import org.apache.ignite.internal.processors.query.ddl.AbstractIndexOperation;
 import org.apache.ignite.internal.util.tostring.GridToStringExclude;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.lang.IgniteUuid;
 import org.jetbrains.annotations.Nullable;
 
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.Map;
+import java.util.UUID;
+
 /**
  * Cache start/stop request.
  */
@@ -80,7 +80,7 @@ public class DynamicCacheChangeRequest implements Serializable {
     private AbstractIndexOperation idxInitOp;
 
     /** Dynamic index states. */
-    private Map<String, QueryIndexState> idxStates;
+    private Map<String, QueryIndexStates> idxStates;
 
     /** */
     private transient boolean exchangeNeeded;
@@ -312,22 +312,8 @@ public class DynamicCacheChangeRequest implements Serializable {
     /**
      * @return Dynamic index states.
      */
-    public Map<String, QueryIndexState> indexStates() {
-        return idxStates == null ? Collections.<String, QueryIndexState>emptyMap()
: idxStates;
-    }
-
-    /**
-     * Add dynamic index state.
-     *
-     * @param idxState Index state.
-     */
-    public void addIndexState(QueryIndexState idxState) {
-        if (idxStates == null)
-            idxStates = new HashMap<>();
-
-        String name = idxState.indexName();
-
-        idxStates.put(name, idxState);
+    public Map<String, QueryIndexStates> indexStates() {
+        return idxStates == null ? Collections.<String, QueryIndexStates>emptyMap()
: idxStates;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/cec52fd4/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexActiveOperation.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexActiveOperation.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexActiveOperation.java
new file mode 100644
index 0000000..77262b6
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexActiveOperation.java
@@ -0,0 +1,71 @@
+/*
+ * 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;
+
+import org.apache.ignite.internal.processors.query.ddl.AbstractIndexOperation;
+import org.apache.ignite.internal.util.tostring.GridToStringInclude;
+import org.apache.ignite.internal.util.typedef.internal.S;
+
+/**
+ * Active index operation.
+ */
+public class QueryIndexActiveOperation {
+    /** Operation. */
+    @GridToStringInclude
+    private final AbstractIndexOperation op;
+
+    /** Whether operation is accepted. */
+    private boolean accepted;
+
+    /**
+     * Constructor.
+     *
+     * @param op Operation.
+     */
+    public QueryIndexActiveOperation(AbstractIndexOperation op) {
+        this.op = op;
+    }
+
+    /**
+     * @return Operation.
+     */
+    public AbstractIndexOperation operation() {
+        return op;
+    }
+
+    /**
+     * @return Whether operation is accepted.
+     */
+    public boolean accepted() {
+        return accepted;
+    }
+
+    /**
+     * Accept operation.
+     */
+    public void accept() {
+        assert !accepted;
+
+        accepted = true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(QueryIndexActiveOperation.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/cec52fd4/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 1af7ff6..63ad8d4 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
@@ -25,7 +25,7 @@ import org.jetbrains.annotations.Nullable;
 import java.io.Serializable;
 
 /**
- * Dynamic index state
+ * Query index state.
  */
 public class QueryIndexState implements Serializable {
     /** */
@@ -39,12 +39,12 @@ public class QueryIndexState implements Serializable {
     private final QueryIndex idx;
 
     /**
-     * Constructor.
+     * Query index state.
      *
      * @param idxName Index name.
-     * @param idx Index descriptor.
+     * @param idx Index.
      */
-    public QueryIndexState(String idxName, @Nullable QueryIndex idx) {
+    public QueryIndexState(String idxName, QueryIndex idx) {
         this.idxName = idxName;
         this.idx = idx;
     }
@@ -57,7 +57,7 @@ public class QueryIndexState implements Serializable {
     }
 
     /**
-     * @return Index.
+     * @return Index
      */
     @Nullable public QueryIndex index() {
         return idx;

http://git-wip-us.apache.org/repos/asf/ignite/blob/cec52fd4/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
new file mode 100644
index 0000000..13b1525
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexStates.java
@@ -0,0 +1,131 @@
+/*
+ * 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;
+
+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.IndexAcceptDiscoveryMessage;
+import org.apache.ignite.internal.processors.query.ddl.IndexFinishDiscoveryMessage;
+import org.apache.ignite.internal.processors.query.ddl.IndexProposeDiscoveryMessage;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.S;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * Dynamic index states.
+ */
+public class QueryIndexStates implements Serializable {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Currently running operations in either proposed or accepted states. */
+    private final Map<String, QueryIndexActiveOperation> activeOps = new HashMap<>();
+
+    /** Finished operations. */
+    private final Map<String, QueryIndexState> readyOps = new HashMap<>();
+
+    /**
+     * Try propose new index operation.
+     *
+     * @param locNodeId Local node ID.
+     * @param msg Propose message.
+     * @return {@code True} if propose succeeded.
+     */
+    public boolean propose(UUID locNodeId, IndexProposeDiscoveryMessage msg) {
+        AbstractIndexOperation op = msg.operation();
+
+        String idxName = op.indexName();
+
+        if (activeOps.containsKey(idxName)) {
+            msg.onError(locNodeId, "Failed to initiate index create/drop because another
operation on the same " +
+                "index is in progress: " + idxName);
+
+            return false;
+        }
+
+        activeOps.put(idxName, new QueryIndexActiveOperation(op));
+
+        return true;
+    }
+
+    /**
+     * Process accept message propagating index from proposed to accepted state.
+     *
+     * @param msg Message.
+     */
+    public void accept(IndexAcceptDiscoveryMessage msg) {
+        AbstractIndexOperation op = msg.operation();
+
+        String idxName = op.indexName();
+
+        QueryIndexActiveOperation curOp = activeOps.get(idxName);
+
+        assert curOp != null && !curOp.accepted(); // Operation is found and is in
proposed ("false") state.
+        assert F.eq(curOp.operation().operationId(), op.operationId()); // Operation ID matches.
+
+        curOp.accept();
+    }
+
+    /**
+     * Process finish message.
+     *
+     * @param msg Message.
+     */
+    @SuppressWarnings("ConstantConditions")
+    public void finish(IndexFinishDiscoveryMessage msg) {
+        AbstractIndexOperation op = msg.operation();
+
+        String idxName = op.indexName();
+
+        QueryIndexActiveOperation curOp = activeOps.remove(idxName);
+
+        assert curOp != null; // Operation is found.
+        assert F.eq(curOp.operation().operationId(), op.operationId()); // Operation ID matches.
+
+        if (!msg.hasError()) {
+            QueryIndexState state;
+
+            if (op instanceof CreateIndexOperation)
+                state = new QueryIndexState(idxName, ((CreateIndexOperation)op).index());
+            else {
+                assert op instanceof DropIndexOperation;
+
+                state = new QueryIndexState(idxName, null);
+            }
+
+            readyOps.put(idxName, state);
+        }
+    }
+
+    /**
+     * @return Ready operations.
+     */
+    public Map<String, QueryIndexState> readyOperation() {
+        return new HashMap<>(readyOps);
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(QueryIndexStates.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/cec52fd4/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 24600e5..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
@@ -69,4 +69,9 @@ public abstract class AbstractIndexOperation implements Serializable {
     public String space() {
         return space;
     }
+
+    /**
+     * @return Index name.
+     */
+    public abstract String indexName();
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/cec52fd4/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 7030586..4127c2a 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
@@ -59,6 +59,11 @@ public class CreateIndexOperation extends AbstractIndexOperation {
         this.ifNotExists = ifNotExists;
     }
 
+    /** {@inheritDoc} */
+    @Override public String indexName() {
+        return idx.getName();
+    }
+
     /**
      * @return Index params.
      */

http://git-wip-us.apache.org/repos/asf/ignite/blob/cec52fd4/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 be2941c..88d6aab 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
@@ -50,10 +50,8 @@ public class DropIndexOperation extends AbstractIndexOperation {
         this.ifExists = ifExists;
     }
 
-    /**
-     * @return Index name.
-     */
-    public String indexName() {
+    /** {@inheritDoc} */
+    @Override public String indexName() {
         return idxName;
     }
 


Mime
View raw message