ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject ignite git commit: Moved all indexing-related logic back to GridQueryProcessor.
Date Mon, 13 Mar 2017 11:28:37 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-4565-ddl f8a426445 -> 7ed196a0e


Moved all indexing-related logic back to GridQueryProcessor.


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

Branch: refs/heads/ignite-4565-ddl
Commit: 7ed196a0e44594b5503006b7e61add21baa242ad
Parents: f8a4264
Author: devozerov <vozerov@gridgain.com>
Authored: Mon Mar 13 14:28:28 2017 +0300
Committer: devozerov <vozerov@gridgain.com>
Committed: Mon Mar 13 14:28:28 2017 +0300

----------------------------------------------------------------------
 .../processors/query/GridQueryProcessor.java    | 276 ++++++++++++-----
 .../query/QueryIndexClientFuture.java           |  79 +++++
 .../query/QueryIndexDescriptorImpl.java         |  16 +-
 .../processors/query/QueryIndexKey.java         |  80 +++++
 .../query/QueryTypeDescriptorImpl.java          |   4 +-
 .../query/index/QueryIndexClientFuture.java     |  79 -----
 .../query/index/QueryIndexHandler.java          | 307 -------------------
 .../processors/query/index/QueryIndexKey.java   |  80 -----
 8 files changed, 379 insertions(+), 542 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/7ed196a0/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 6903704..49e4f38 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
@@ -25,7 +25,11 @@ import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
 import javax.cache.Cache;
 import javax.cache.CacheException;
 import org.apache.ignite.IgniteCheckedException;
@@ -52,9 +56,9 @@ import org.apache.ignite.internal.processors.cache.QueryCursorImpl;
 import org.apache.ignite.internal.processors.cache.query.CacheQueryFuture;
 import org.apache.ignite.internal.processors.cache.query.CacheQueryType;
 import org.apache.ignite.internal.processors.cache.query.GridCacheQueryType;
-import org.apache.ignite.internal.processors.query.index.QueryIndexHandler;
 import org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor;
 import org.apache.ignite.internal.util.GridSpinBusyLock;
+import org.apache.ignite.internal.util.future.GridFinishedFuture;
 import org.apache.ignite.internal.util.lang.GridCloseableIterator;
 import org.apache.ignite.internal.util.lang.GridClosureException;
 import org.apache.ignite.internal.util.lang.IgniteOutClosureX;
@@ -64,7 +68,6 @@ import org.apache.ignite.lang.IgniteBiTuple;
 import org.apache.ignite.lang.IgniteFuture;
 import org.apache.ignite.spi.indexing.IndexingQueryFilter;
 import org.jetbrains.annotations.Nullable;
-import org.jsr166.ConcurrentHashMap8;
 
 import static org.apache.ignite.events.EventType.EVT_CACHE_QUERY_EXECUTED;
 import static org.apache.ignite.internal.IgniteComponentType.INDEXING;
@@ -83,16 +86,22 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     private final GridSpinBusyLock busyLock = new GridSpinBusyLock();
 
     /** Type descriptors. */
-    private final Map<QueryTypeIdKey, QueryTypeDescriptorImpl> types = new ConcurrentHashMap8<>();
+    private final Map<QueryTypeIdKey, QueryTypeDescriptorImpl> types = new ConcurrentHashMap<>();
 
     /** Type descriptors. */
-    private final ConcurrentMap<QueryTypeNameKey, QueryTypeDescriptorImpl> typesByName
= new ConcurrentHashMap8<>();
+    private final ConcurrentMap<QueryTypeNameKey, QueryTypeDescriptorImpl> typesByName
= new ConcurrentHashMap<>();
 
     /** */
     private final GridQueryIndexing idx;
 
-    /** Index handler. */
-    private final QueryIndexHandler idxHnd;
+    /** RW lock for dynamic index create. */
+    private final ReadWriteLock idxLock = new ReentrantReadWriteLock();
+
+    /** All indexes. */
+    private final ConcurrentMap<QueryIndexKey, QueryIndexDescriptorImpl> idxs = new
ConcurrentHashMap<>();
+
+    /** Index create/drop client futures. */
+    private final ConcurrentMap<UUID, QueryIndexClientFuture> idxCliFuts = new ConcurrentHashMap<>();
 
     /** */
     private GridTimeoutProcessor.CancelableTask qryDetailMetricsEvictTask;
@@ -113,8 +122,6 @@ public class GridQueryProcessor extends GridProcessorAdapter {
         }
         else
             idx = INDEXING.inClassPath() ? U.<GridQueryIndexing>newInstance(INDEXING.className())
: null;
-
-        idxHnd = new QueryIndexHandler(ctx);
     }
 
     /** {@inheritDoc} */
@@ -127,8 +134,6 @@ public class GridQueryProcessor extends GridProcessorAdapter {
             idx.start(ctx, busyLock);
         }
 
-        idxHnd.onStart();
-
         // Schedule queries detail metrics eviction.
         qryDetailMetricsEvictTask = ctx.timeout().schedule(new Runnable() {
             @Override public void run() {
@@ -138,11 +143,6 @@ public class GridQueryProcessor extends GridProcessorAdapter {
         }, QRY_DETAIL_METRICS_EVICTION_FREQ, QRY_DETAIL_METRICS_EVICTION_FREQ);
     }
 
-    /** {@inheritDoc} */
-    @Override public void onKernalStart() throws IgniteCheckedException {
-        idxHnd.onKernalStart();
-    }
-
     /**
      * @return {@code true} If indexing module is in classpath and successfully initialized.
      */
@@ -192,38 +192,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
             }
         }
 
-        // Register candidates.
-        idx.registerCache(space, cctx, cctx.config());
-
-        try {
-            Collection<QueryTypeDescriptorImpl> typeDescs = new ArrayList<>();
-
-            for (QueryTypeCandidate cand : cands) {
-                QueryTypeIdKey typeId = cand.typeId();
-                QueryTypeIdKey altTypeId = cand.alternativeTypeId();
-                QueryTypeDescriptorImpl desc = cand.descriptor();
-
-                if (typesByName.putIfAbsent(new QueryTypeNameKey(space, desc.name()), desc)
!= null)
-                    throw new IgniteCheckedException("Type with name '" + desc.name() + "'
already indexed " +
-                        "in cache '" + space + "'.");
-
-                types.put(typeId, desc);
-
-                if (altTypeId != null)
-                    types.put(altTypeId, desc);
-
-                desc.registered(idx.registerType(space, desc));
-
-                typeDescs.add(desc);
-            }
-
-            idxHnd.onCacheCreated(cctx.name(), typeDescs);
-        }
-        catch (IgniteCheckedException | RuntimeException e) {
-            unregisterCache0(space);
-
-            throw e;
-        }
+        registerCache0(space, cctx, cands);
 
         // Warn about possible implicit deserialization.
         if (!mustDeserializeClss.isEmpty()) {
@@ -253,8 +222,6 @@ public class GridQueryProcessor extends GridProcessorAdapter {
             }
         }
 
-        idxHnd.onKernalStop();
-
         busyLock.block();
     }
 
@@ -262,8 +229,6 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     @Override public void stop(boolean cancel) throws IgniteCheckedException {
         super.stop(cancel);
 
-        idxHnd.onStop();
-
         if (idx != null)
             idx.stop();
 
@@ -272,10 +237,10 @@ public class GridQueryProcessor extends GridProcessorAdapter {
 
     /** {@inheritDoc} */
     @Override public void onDisconnected(IgniteFuture<?> reconnectFut) throws IgniteCheckedException
{
-        idxHnd.onDisconnected();
-
         if (idx != null)
             idx.onDisconnected(reconnectFut);
+
+        // TODO: Complete index client futures, clear pending index state.
     }
 
     /**
@@ -316,22 +281,75 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     }
 
     /**
-     * Unregister cache.
+     * Register cache in indexing SPI.
      *
      * @param space Space.
+     * @param cctx Cache context.
+     * @param cands Candidates.
+     * @throws IgniteCheckedException If failed.
      */
-    private void unregisterCache0(String space) {
-        assert idx != null;
+    private void registerCache0(String space, GridCacheContext<?, ?> cctx, Collection<QueryTypeCandidate>
cands)
+        throws IgniteCheckedException {
+        idxLock.writeLock().lock();
 
         try {
-            idxHnd.onCacheStopped(space);
+            idx.registerCache(space, cctx, cctx.config());
 
-            idx.unregisterCache(space);
-        }
-        catch (Exception e) {
-            U.error(log, "Failed to clear indexing on cache unregister (will ignore): " +
space, e);
+            try {
+                for (QueryTypeCandidate cand : cands) {
+                    QueryTypeIdKey typeId = cand.typeId();
+                    QueryTypeIdKey altTypeId = cand.alternativeTypeId();
+                    QueryTypeDescriptorImpl desc = cand.descriptor();
+
+                    if (typesByName.putIfAbsent(new QueryTypeNameKey(space, desc.name()),
desc) != null)
+                        throw new IgniteCheckedException("Type with name '" + desc.name()
+ "' already indexed " +
+                            "in cache '" + space + "'.");
+
+                    types.put(typeId, desc);
+
+                    if (altTypeId != null)
+                        types.put(altTypeId, desc);
+
+                    for (QueryIndexDescriptorImpl idx : desc.indexes0()) {
+                        QueryIndexKey idxKey = new QueryIndexKey(space, idx.name());
+
+                        QueryIndexDescriptorImpl oldIdx = idxs.putIfAbsent(idxKey, idx);
+
+                        if (oldIdx != null) {
+                            throw new IgniteException("Duplicate index name [space=" + space
+ ", idxName=" + idx.name() +
+                                ", existingTable=" + oldIdx.typeDescriptor().tableName()
+
+                                ", table=" + desc.tableName() + ']');
+                        }
+                    }
+
+                    boolean registered = idx.registerType(space, desc);
+
+                    desc.registered(registered);
+                }
+            }
+            catch (IgniteCheckedException | RuntimeException e) {
+                unregisterCache0(space);
+
+                throw e;
+            }
         }
         finally {
+            idxLock.writeLock().unlock();
+        }
+    }
+
+    /**
+     * Unregister cache.
+     *
+     * @param space Space.
+     */
+    private void unregisterCache0(String space) {
+        assert idx != null;
+
+        idxLock.writeLock().lock();
+
+        try {
+            // Clear types.
             Iterator<Map.Entry<QueryTypeIdKey, QueryTypeDescriptorImpl>> it =
types.entrySet().iterator();
 
             while (it.hasNext()) {
@@ -343,6 +361,65 @@ public class GridQueryProcessor extends GridProcessorAdapter {
                     typesByName.remove(new QueryTypeNameKey(space, entry.getValue().name()));
                 }
             }
+
+            // Clear indexes.
+            removeIndexesOnSpaceUnregister(space);
+
+            completeIndexClientFuturesOnSpaceUnregister(space, true);
+
+            // Notify indexing.
+            try {
+                idx.unregisterCache(space);
+            }
+            catch (Exception e) {
+                U.error(log, "Failed to clear indexing on cache unregister (will ignore):
" + space, e);
+            }
+        }
+        finally {
+            idxLock.writeLock().unlock();
+        }
+    }
+
+    /**
+     * Remove indexes during complete space unregister.
+     *
+     * @param space Space.
+     */
+    private void removeIndexesOnSpaceUnregister(String space) {
+        Iterator<Map.Entry<QueryIndexKey, QueryIndexDescriptorImpl>> idxIt =
idxs.entrySet().iterator();
+
+        while (idxIt.hasNext()) {
+            Map.Entry<QueryIndexKey, QueryIndexDescriptorImpl> idxEntry = idxIt.next();
+
+            QueryIndexKey idxKey = idxEntry.getKey();
+
+            if (F.eq(space, idxKey.space()))
+                idxIt.remove();
+        }
+    }
+
+    /**
+     * Complete index client futures in case of cache stop or type unregistration.
+     *
+     * @param space Space.
+     * @param cacheStop {@code True} if completion caused by cache stop.
+     */
+    private void completeIndexClientFuturesOnSpaceUnregister(String space, boolean cacheStop)
{
+        Iterator<Map.Entry<UUID, QueryIndexClientFuture>> idxCliFutIt = idxCliFuts.entrySet().iterator();
+
+        while (idxCliFutIt.hasNext()) {
+            Map.Entry<UUID, QueryIndexClientFuture> idxCliFutEntry = idxCliFutIt.next();
+
+            QueryIndexClientFuture idxCliFut = idxCliFutEntry.getValue();
+
+            if (F.eq(space, idxCliFut.key().space())) {
+                if (cacheStop)
+                    idxCliFut.onCacheStopped();
+                else
+                    idxCliFut.onTypeUnregistered();
+
+                idxCliFutIt.remove();
+            }
         }
     }
 
@@ -597,7 +674,46 @@ public class GridQueryProcessor extends GridProcessorAdapter {
      * @return Future completed when index is created.
      */
     public IgniteInternalFuture<?> createIndex(String space, String tblName, QueryIndex
idx, boolean ifNotExists) {
-        return idxHnd.onCreateIndex(space, tblName, idx, ifNotExists);
+        String idxName = idx.getName() != null ? idx.getName() : QueryEntity.defaultIndexName(idx);
+
+        QueryIndexKey idxKey = new QueryIndexKey(space, idxName);
+
+        idxLock.readLock().lock();
+
+        try {
+            QueryIndexDescriptorImpl oldIdxDesc = idxs.get(idxKey);
+
+            if (oldIdxDesc != null) {
+                // Make sure that index is bound to the same table.
+                String oldTblName = oldIdxDesc.typeDescriptor().tableName();
+
+                if (!F.eq(oldTblName, tblName)) {
+                    return new GridFinishedFuture<>(new IgniteException("Index already
exists and is bound to " +
+                        "another table [space=" + space + ", idxName=" + idxName + ", expTblName="
+ oldTblName +
+                        ", actualTblName=" + tblName + ']'));
+                }
+
+                if (ifNotExists)
+                    return new GridFinishedFuture<>();
+                else
+                    return new GridFinishedFuture<>(new IgniteException("Index already
exists [space=" + space +
+                        ", idxName=" + idxName + ']'));
+            }
+
+            UUID opId = UUID.randomUUID();
+            QueryIndexClientFuture fut = new QueryIndexClientFuture(opId, idxKey);
+
+            QueryIndexClientFuture oldFut = idxCliFuts.put(opId, fut);
+
+            assert oldFut == null;
+
+            // TODO: Start discovery.
+
+            return fut;
+        }
+        finally {
+            idxLock.readLock().unlock();
+        }
     }
 
     /**
@@ -834,25 +950,39 @@ public class GridQueryProcessor extends GridProcessorAdapter {
             throw new IllegalStateException("Failed to process undeploy event (grid is stopping).");
 
         try {
-            Iterator<Map.Entry<QueryTypeIdKey, QueryTypeDescriptorImpl>> it =
types.entrySet().iterator();
+            idxLock.writeLock().lock();
 
-            while (it.hasNext()) {
-                Map.Entry<QueryTypeIdKey, QueryTypeDescriptorImpl> e = it.next();
+            try {
+                Iterator<Map.Entry<QueryTypeIdKey, QueryTypeDescriptorImpl>>
it = types.entrySet().iterator();
 
-                if (!F.eq(e.getKey().space(), space))
-                    continue;
+                while (it.hasNext()) {
+                    Map.Entry<QueryTypeIdKey, QueryTypeDescriptorImpl> entry = it.next();
 
-                QueryTypeDescriptorImpl desc = e.getValue();
+                    if (!F.eq(entry.getKey().space(), space))
+                        continue;
 
-                if (ldr.equals(U.detectClassLoader(desc.valueClass())) ||
-                    ldr.equals(U.detectClassLoader(desc.keyClass()))) {
-                    idxHnd.onTypeUnregistered(desc);
+                    QueryTypeDescriptorImpl desc = entry.getValue();
 
-                    idx.unregisterType(e.getKey().space(), desc);
+                    if (ldr.equals(U.detectClassLoader(desc.valueClass())) ||
+                        ldr.equals(U.detectClassLoader(desc.keyClass()))) {
+                        it.remove();
 
-                    it.remove();
+                        removeIndexesOnSpaceUnregister(space);
+
+                        completeIndexClientFuturesOnSpaceUnregister(space, false);
+
+                        try {
+                            idx.unregisterType(entry.getKey().space(), desc);
+                        }
+                        catch (Exception e) {
+                            U.error(log, "Failed to clear indexing on type unregister (will
ignore): " + space, e);
+                        }
+                    }
                 }
             }
+            finally {
+                idxLock.writeLock().unlock();
+            }
         }
         finally {
             busyLock.leaveBusy();

http://git-wip-us.apache.org/repos/asf/ignite/blob/7ed196a0/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexClientFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexClientFuture.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexClientFuture.java
new file mode 100644
index 0000000..58f4121
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexClientFuture.java
@@ -0,0 +1,79 @@
+/*
+ * 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.IgniteException;
+import org.apache.ignite.internal.util.future.GridFutureAdapter;
+import org.apache.ignite.internal.util.typedef.internal.S;
+
+import java.util.UUID;
+
+/**
+ * Future for dynamic index create/drop returned to the client..
+ */
+public class QueryIndexClientFuture extends GridFutureAdapter<Object> {
+    /** Operation ID. */
+    private final UUID opId;
+
+    /** Key. */
+    private final QueryIndexKey key;
+
+    /**
+     * Constructor.
+     *
+     * @param opId Operation ID.
+     * @param key Key.
+     */
+    public QueryIndexClientFuture(UUID opId, QueryIndexKey key) {
+        this.opId = opId;
+        this.key = key;
+    }
+
+    /**
+     * @return Operation ID.
+     */
+    public UUID operationId() {
+        return opId;
+    }
+
+    /**
+     * @return Index key.
+     */
+    public QueryIndexKey key() {
+        return key;
+    }
+
+    /**
+     * Handle cache stop.
+     */
+    public void onCacheStopped() {
+        onDone(new IgniteException("Operation failed because cache was stopped."));
+    }
+
+    /**
+     * Handle type undeploy.
+     */
+    public void onTypeUnregistered() {
+        onDone(new IgniteException("Operation failed because type was undeployed."));
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(QueryIndexClientFuture.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/7ed196a0/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexDescriptorImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexDescriptorImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexDescriptorImpl.java
index ad2ed6c..75dea0e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexDescriptorImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexDescriptorImpl.java
@@ -45,6 +45,9 @@ public class QueryIndexDescriptorImpl implements GridQueryIndexDescriptor
{
     /** Fields which should be indexed in descending order. */
     private Collection<String> descendings;
 
+    /** Type descriptor. */
+    private final QueryTypeDescriptorImpl typDesc;
+
     /** Index name. */
     private final String name;
 
@@ -52,17 +55,28 @@ public class QueryIndexDescriptorImpl implements GridQueryIndexDescriptor
{
     private final QueryIndexType type;
 
     /**
+     * Constructor.
+     *
+     * @param typDesc Type descriptor.
      * @param name Index name.
      * @param type Type.
      */
-    public QueryIndexDescriptorImpl(String name, QueryIndexType type) {
+    public QueryIndexDescriptorImpl(QueryTypeDescriptorImpl typDesc, String name, QueryIndexType
type) {
         assert type != null;
 
+        this.typDesc = typDesc;
         this.name = name;
         this.type = type;
     }
 
     /**
+     * @return Type descriptor.
+     */
+    public QueryTypeDescriptorImpl typeDescriptor() {
+        return typDesc;
+    }
+
+    /**
      * @return Index name.
      */
     public String name() {

http://git-wip-us.apache.org/repos/asf/ignite/blob/7ed196a0/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexKey.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexKey.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexKey.java
new file mode 100644
index 0000000..06dbdc7
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexKey.java
@@ -0,0 +1,80 @@
+/*
+ * 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.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.S;
+
+/**
+ * Index key.
+ */
+public class QueryIndexKey {
+    /** Space. */
+    private final String space;
+
+    /** Name. */
+    private final String name;
+
+    /**
+     * Constructor.
+     *
+     * @param space Space.
+     * @param name Name.
+     */
+    public QueryIndexKey(String space, String name) {
+        this.space = space;
+        this.name = name;
+    }
+
+    /**
+     * @return Space.
+     */
+    public String space() {
+        return space;
+    }
+
+    /**
+     * @return Name.
+     */
+    public String name() {
+        return name;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        return 31 * (space != null ? space.hashCode() : 0) + (name != null ? name.hashCode()
: 0);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (this == o)
+            return true;
+
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        QueryIndexKey other = (QueryIndexKey)o;
+
+        return F.eq(name, other.name) && F.eq(space, other.space);
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(QueryIndexKey.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/7ed196a0/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryTypeDescriptorImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryTypeDescriptorImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryTypeDescriptorImpl.java
index 7187713..0949b1b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryTypeDescriptorImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryTypeDescriptorImpl.java
@@ -218,7 +218,7 @@ public class QueryTypeDescriptorImpl implements GridQueryTypeDescriptor
{
      * @throws IgniteCheckedException In case of error.
      */
     public QueryIndexDescriptorImpl addIndex(String idxName, QueryIndexType type) throws
IgniteCheckedException {
-        QueryIndexDescriptorImpl idx = new QueryIndexDescriptorImpl(idxName, type);
+        QueryIndexDescriptorImpl idx = new QueryIndexDescriptorImpl(this, idxName, type);
 
         if (indexes.put(idxName, idx) != null)
             throw new IgniteCheckedException("Index with name '" + idxName + "' already exists.");
@@ -251,7 +251,7 @@ public class QueryTypeDescriptorImpl implements GridQueryTypeDescriptor
{
      */
     public void addFieldToTextIndex(String field) {
         if (fullTextIdx == null)
-            fullTextIdx = new QueryIndexDescriptorImpl(null, QueryIndexType.FULLTEXT);
+            fullTextIdx = new QueryIndexDescriptorImpl(this, null, QueryIndexType.FULLTEXT);
 
         fullTextIdx.addField(field, 0, false);
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/7ed196a0/modules/core/src/main/java/org/apache/ignite/internal/processors/query/index/QueryIndexClientFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/index/QueryIndexClientFuture.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/index/QueryIndexClientFuture.java
deleted file mode 100644
index 53a1770..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/index/QueryIndexClientFuture.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * 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.index;
-
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.internal.util.future.GridFutureAdapter;
-import org.apache.ignite.internal.util.typedef.internal.S;
-
-import java.util.UUID;
-
-/**
- * Future for dynamic index create/drop returned to the client..
- */
-public class QueryIndexClientFuture extends GridFutureAdapter<Object> {
-    /** Operation ID. */
-    private final UUID opId;
-
-    /** Key. */
-    private final QueryIndexKey key;
-
-    /**
-     * Constructor.
-     *
-     * @param opId Operation ID.
-     * @param key Key.
-     */
-    public QueryIndexClientFuture(UUID opId, QueryIndexKey key) {
-        this.opId = opId;
-        this.key = key;
-    }
-
-    /**
-     * @return Operation ID.
-     */
-    public UUID operationId() {
-        return opId;
-    }
-
-    /**
-     * @return Index key.
-     */
-    public QueryIndexKey getKey() {
-        return key;
-    }
-
-    /**
-     * Handle cache stop.
-     */
-    public void onCacheStop() {
-        onDone(new IgniteException("Operation failed because cache was stopped."));
-    }
-
-    /**
-     * Handle type undeploy.
-     */
-    public void onTypeUnregistered() {
-        onDone(new IgniteException("Operation failed because type was undeployed."));
-    }
-
-    /** {@inheritDoc} */
-    @Override public String toString() {
-        return S.toString(QueryIndexClientFuture.class, this);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/7ed196a0/modules/core/src/main/java/org/apache/ignite/internal/processors/query/index/QueryIndexHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/index/QueryIndexHandler.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/index/QueryIndexHandler.java
deleted file mode 100644
index 109adf1..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/index/QueryIndexHandler.java
+++ /dev/null
@@ -1,307 +0,0 @@
-/*
- * 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.index;
-
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.IgniteLogger;
-import org.apache.ignite.cache.QueryEntity;
-import org.apache.ignite.cache.QueryIndex;
-import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.IgniteInternalFuture;
-import org.apache.ignite.internal.processors.query.QueryIndexDescriptorImpl;
-import org.apache.ignite.internal.processors.query.QueryTypeDescriptorImpl;
-import org.apache.ignite.internal.util.future.GridFinishedFuture;
-import org.apache.ignite.internal.util.typedef.F;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-
-/**
- * Index state manager.
- */
-public class QueryIndexHandler {
-    /** Kernal context. */
-    private final GridKernalContext ctx;
-
-    /** Logger. */
-    private final IgniteLogger log;
-
-    /** All indexes. */
-    private final Map<QueryIndexKey, Descriptor> idxs = new ConcurrentHashMap<>();
-
-    /** Client futures. */
-    private final Map<UUID, QueryIndexClientFuture> cliFuts = new ConcurrentHashMap<>();
-
-    /** RW lock. */
-    private final ReadWriteLock lock = new ReentrantReadWriteLock();
-
-    /**
-     * Constructor.
-     *
-     * @param ctx Kernal context.
-     */
-    public QueryIndexHandler(GridKernalContext ctx) {
-        this.ctx = ctx;
-
-        log = ctx.log(QueryIndexHandler.class);
-    }
-
-    /**
-     * Handle start.
-     */
-    public void onStart() {
-        // TODO
-    }
-
-    /**
-     * Handle kernal start callback.
-     */
-    public void onKernalStart() {
-        // TODO
-    }
-
-    /**
-     * Handle kernal stop callback.
-     */
-    public void onKernalStop() {
-        // TODO
-    }
-
-    /**
-     * Handle stop callback.
-     */
-    public void onStop() {
-        // TODO
-    }
-
-    /**
-     * Handle disconnect.
-     */
-    public void onDisconnected() {
-        // TODO: Complete client futures, clear state.
-    }
-
-    /**
-     * Handle cache creation.
-     *
-     * @param space Space.
-     * @param typs Type descriptors.
-     */
-    public void onCacheCreated(String space, Collection<QueryTypeDescriptorImpl> typs)
{
-        lock.writeLock().lock();
-
-        try {
-            for (QueryTypeDescriptorImpl typ : typs) {
-                for (QueryIndexDescriptorImpl idx : typ.indexes0()) {
-                    QueryIndexKey idxKey = new QueryIndexKey(space, idx.name());
-
-                    Descriptor desc = idxs.get(idxKey);
-
-                    if (desc != null) {
-                        throw new IgniteException("Duplicate index name [space=" + space
+ ", idxName=" + idx.name() +
-                            ", existingTable=" + desc.type().tableName() + ", table=" + typ.tableName()
+ ']');
-                    }
-
-                    idxs.put(idxKey, new Descriptor(typ, idx));
-                }
-            }
-        }
-        finally {
-            lock.writeLock().unlock();
-        }
-    }
-
-    /**
-     * Handle cache stop.
-     *
-     * @param space Space.
-     */
-    public void onCacheStopped(String space) {
-        lock.writeLock().lock();
-
-        try {
-            // Find matching indexes.
-            Collection<QueryIndexKey> rmvIdxKeys = new HashSet<>();
-
-            for (QueryIndexKey key : idxs.keySet()) {
-                if (F.eq(space, key.space()))
-                    rmvIdxKeys.add(key);
-            }
-
-            removeIndexes(rmvIdxKeys, false);
-        }
-        finally {
-            lock.writeLock().unlock();
-        }
-    }
-
-    /**
-     * Handle type unregister.
-     *
-     * @param desc Descriptor.
-     */
-    public void onTypeUnregistered(QueryTypeDescriptorImpl desc) {
-        lock.writeLock().lock();
-
-        try {
-            // Find matching indexes.
-            Collection<QueryIndexKey> rmvKeys = new HashSet<>();
-
-            for (Map.Entry<QueryIndexKey, Descriptor> idxEntry : idxs.entrySet()) {
-                QueryIndexKey idxKey = idxEntry.getKey();
-                Descriptor idxDesc = idxEntry.getValue();
-
-                if (F.eq(desc, idxDesc.type()))
-                    rmvKeys.add(idxKey);
-            }
-
-            removeIndexes(rmvKeys, true);
-        }
-        finally {
-            lock.writeLock().unlock();
-        }
-    }
-
-    /**
-     * Remove indexes locally. Invoked when cache is either destroyed or type is unregistered.
-     *
-     * @param rmvIdxKeys Index keys to be removed.
-     * @param typUnregister {@code True} if type was undeployed, {@code false} if cache was
undeployed.
-     */
-    private void removeIndexes(Collection<QueryIndexKey> rmvIdxKeys, boolean typUnregister)
{
-        // Remove matched indexes
-        for (QueryIndexKey rmvIdxKey : rmvIdxKeys) {
-            // TODO: Callback to indexing SPI should be done from here
-            idxs.remove(rmvIdxKey);
-        }
-
-        // Complete pending futures.
-        Collection<UUID> rmvCliFutIds = new HashSet<>();
-
-        for (Map.Entry<UUID, QueryIndexClientFuture> cliFutEntry : cliFuts.entrySet())
{
-            UUID cliFutId = cliFutEntry.getKey();
-            QueryIndexClientFuture cliFut = cliFutEntry.getValue();
-
-            if (rmvIdxKeys.contains(cliFut.getKey()))
-                rmvCliFutIds.add(cliFutId);
-        }
-
-        for (UUID rmvCliFutId : rmvCliFutIds) {
-            QueryIndexClientFuture rmvCliFut = cliFuts.remove(rmvCliFutId);
-
-            if (typUnregister)
-                rmvCliFut.onTypeUnregistered();
-            else
-                rmvCliFut.onCacheStop();
-        }
-    }
-
-    /**
-     * Handle dynamic index creation.
-     *
-     * @param space Space.
-     * @param tblName Table name.
-     * @param idx Index.
-     * @param ifNotExists IF-NOT-EXISTS flag.
-     * @return Future completed when index is created.
-     */
-    public IgniteInternalFuture<?> onCreateIndex(String space, String tblName, QueryIndex
idx,
-        boolean ifNotExists) {
-        String idxName = idx.getName() != null ? idx.getName() : QueryEntity.defaultIndexName(idx);
-
-        QueryIndexKey idxKey = new QueryIndexKey(space, idxName);
-
-        lock.readLock().lock();
-
-        try {
-            Descriptor oldIdxDesc = idxs.get(idxKey);
-
-            if (oldIdxDesc != null) {
-                // Make sure that index is bound to the same table.
-                String oldTblName = oldIdxDesc.type().tableName();
-
-                if (!F.eq(oldTblName, tblName)) {
-                    return new GridFinishedFuture<>(new IgniteException("Index already
exists and is bound to " +
-                        "another table [space=" + space + ", idxName=" + idxName + ", expTblName="
+ oldTblName +
-                        ", actualTblName=" + tblName + ']'));
-                }
-
-                if (ifNotExists)
-                    return new GridFinishedFuture<>();
-                else
-                    return new GridFinishedFuture<>(new IgniteException("Index already
exists [space=" + space +
-                        ", idxName=" + idxName + ']'));
-            }
-
-            UUID opId = UUID.randomUUID();
-            QueryIndexClientFuture fut = new QueryIndexClientFuture(opId, idxKey);
-
-            QueryIndexClientFuture oldFut = cliFuts.put(opId, fut);
-
-            assert oldFut == null;
-
-            // TODO: Start discovery.
-
-            return fut;
-        }
-        finally {
-            lock.readLock().unlock();
-        }
-    }
-
-    /**
-     * Type and index descriptor.
-     */
-    private static class Descriptor {
-        /** Type. */
-        private final QueryTypeDescriptorImpl typ;
-
-        /** Index. */
-        private final QueryIndexDescriptorImpl idx;
-
-        /**
-         * Constructor.
-         *
-         * @param typ Type.
-         * @param idx Index.
-         */
-        private Descriptor(QueryTypeDescriptorImpl typ, QueryIndexDescriptorImpl idx) {
-            this.typ = typ;
-            this.idx = idx;
-        }
-
-        /**
-         * @return Type.
-         */
-        public QueryTypeDescriptorImpl type() {
-            return typ;
-        }
-
-        /**
-         * @return Index.
-         */
-        public QueryIndexDescriptorImpl index() {
-            return idx;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/7ed196a0/modules/core/src/main/java/org/apache/ignite/internal/processors/query/index/QueryIndexKey.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/index/QueryIndexKey.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/index/QueryIndexKey.java
deleted file mode 100644
index adf5df9..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/index/QueryIndexKey.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * 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.index;
-
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.util.typedef.internal.S;
-
-/**
- * Index key.
- */
-public class QueryIndexKey {
-    /** Space. */
-    private final String space;
-
-    /** Name. */
-    private final String name;
-
-    /**
-     * Constructor.
-     *
-     * @param space Space.
-     * @param name Name.
-     */
-    public QueryIndexKey(String space, String name) {
-        this.space = space;
-        this.name = name;
-    }
-
-    /**
-     * @return Space.
-     */
-    public String space() {
-        return space;
-    }
-
-    /**
-     * @return Name.
-     */
-    public String name() {
-        return name;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        return 31 * (space != null ? space.hashCode() : 0) + (name != null ? name.hashCode()
: 0);
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object o) {
-        if (this == o)
-            return true;
-
-        if (o == null || getClass() != o.getClass())
-            return false;
-
-        QueryIndexKey other = (QueryIndexKey)o;
-
-        return F.eq(name, other.name) && F.eq(space, other.space);
-    }
-
-    /** {@inheritDoc} */
-    @Override public String toString() {
-        return S.toString(QueryIndexKey.class, this);
-    }
-}


Mime
View raw message