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 14:03:50 UTC
[5/5] ignite git commit: Finished refactoring.
Finished refactoring.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/a4d01a63
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/a4d01a63
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/a4d01a63
Branch: refs/heads/ignite-4565-ddl
Commit: a4d01a632506b82a1cedb9538a843229feb543be
Parents: 20bd9ed
Author: devozerov <vo...@gridgain.com>
Authored: Thu Mar 9 17:03:38 2017 +0300
Committer: devozerov <vo...@gridgain.com>
Committed: Thu Mar 9 17:03:38 2017 +0300
----------------------------------------------------------------------
.../processors/query/GridQueryProcessor.java | 2 +-
.../processors/query/QueryIndexHandler.java | 6 +-
.../query/QueryTypeDescriptorImpl.java | 69 +++++++++++++++++---
3 files changed, 65 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/a4d01a63/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 65d26dd..f2def38 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
@@ -959,7 +959,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
* @return Future completed when index is created.
*/
public IgniteInternalFuture<?> createIndex(String space, String tblName, QueryIndex idx, boolean ifNotExists) {
- for (TypeDescriptor desc : types.values()) {
+ for (QueryTypeDescriptorImpl desc : types.values()) {
if (desc.matchSpaceAndTable(space, tblName))
return desc.dynamicIndexCreate(idx, ifNotExists);
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/a4d01a63/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexHandler.java
index 4edb07d..7585dbb 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryIndexHandler.java
@@ -18,7 +18,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
*/
public class QueryIndexHandler {
/** Indexes. */
- private final Map<String, GridQueryProcessor.IndexDescriptor> idxs = new ConcurrentHashMap<>();
+ private final Map<String, QueryIndexDescriptorImpl> idxs = new ConcurrentHashMap<>();
/** Client futures. */
private final Map<UUID, GridFutureAdapter> cliFuts = new ConcurrentHashMap<>();
@@ -31,7 +31,7 @@ public class QueryIndexHandler {
*
* @param idxs Indexes.
*/
- public void onInitialStateReady(Map<String, GridQueryProcessor.IndexDescriptor> idxs) {
+ public void onInitialStateReady(Map<String, QueryIndexDescriptorImpl> idxs) {
this.idxs.putAll(idxs);
}
@@ -48,7 +48,7 @@ public class QueryIndexHandler {
try {
String idxName = idx.getName() != null ? idx.getName() : QueryEntity.defaultIndexName(idx);
- GridQueryProcessor.IndexDescriptor oldIdx = idxs.get(idxName);
+ QueryIndexDescriptorImpl oldIdx = idxs.get(idxName);
if (oldIdx != null) {
if (ifNotExists)
http://git-wip-us.apache.org/repos/asf/ignite/blob/a4d01a63/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 f22cc11..5b8efcc 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
@@ -18,9 +18,12 @@
package org.apache.ignite.internal.processors.query;
import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.cache.QueryIndex;
import org.apache.ignite.cache.QueryIndexType;
+import org.apache.ignite.internal.IgniteInternalFuture;
import org.apache.ignite.internal.util.tostring.GridToStringExclude;
import org.apache.ignite.internal.util.tostring.GridToStringInclude;
+import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.internal.A;
import org.apache.ignite.internal.util.typedef.internal.S;
@@ -33,6 +36,9 @@ import java.util.Map;
* Descriptor of type.
*/
public class QueryTypeDescriptorImpl implements GridQueryTypeDescriptor {
+ /** Space. */
+ private String space;
+
/** */
private String name;
@@ -54,6 +60,9 @@ public class QueryTypeDescriptorImpl implements GridQueryTypeDescriptor {
@GridToStringInclude
private final Map<String, QueryIndexDescriptorImpl> indexes = new HashMap<>();
+ /** Index state manager. */
+ private final QueryIndexHandler idxState = new QueryIndexHandler();
+
/** */
private QueryIndexDescriptorImpl fullTextIdx;
@@ -79,6 +88,20 @@ public class QueryTypeDescriptorImpl implements GridQueryTypeDescriptor {
private boolean registered;
/**
+ * @return Space.
+ */
+ public String space() {
+ return space;
+ }
+
+ /**
+ * @param space Space.
+ */
+ public void space(String space) {
+ this.space = space;
+ }
+
+ /**
* @return {@code True} if type registration in SPI was finished and type was not rejected.
*/
public boolean registered() {
@@ -177,6 +200,11 @@ public class QueryTypeDescriptorImpl implements GridQueryTypeDescriptor {
return Collections.<String, GridQueryIndexDescriptor>unmodifiableMap(indexes);
}
+ /** {@inheritDoc} */
+ @Override public GridQueryIndexDescriptor textIndex() {
+ return fullTextIdx;
+ }
+
/**
* Adds index.
*
@@ -203,12 +231,11 @@ public class QueryTypeDescriptorImpl implements GridQueryTypeDescriptor {
* @param descending Sorting order.
* @throws IgniteCheckedException If failed.
*/
- public void addFieldToIndex(String idxName, String field, int orderNum,
- boolean descending) throws IgniteCheckedException {
+ public void addFieldToIndex(String idxName, String field, int orderNum, boolean descending)
+ throws IgniteCheckedException {
QueryIndexDescriptorImpl desc = indexes.get(idxName);
- if (desc == null)
- desc = addIndex(idxName, QueryIndexType.SORTED);
+ assert desc != null;
desc.addField(field, orderNum, descending);
}
@@ -219,12 +246,9 @@ public class QueryTypeDescriptorImpl implements GridQueryTypeDescriptor {
* @param field Field name.
*/
public void addFieldToTextIndex(String field) {
- if (fullTextIdx == null) {
+ if (fullTextIdx == null)
fullTextIdx = new QueryIndexDescriptorImpl(QueryIndexType.FULLTEXT);
- indexes.put(null, fullTextIdx);
- }
-
fullTextIdx.addField(field, 0, false);
}
@@ -330,6 +354,35 @@ public class QueryTypeDescriptorImpl implements GridQueryTypeDescriptor {
this.affKey = affKey;
}
+ /**
+ * Check whether space and table name matches.
+ *
+ * @param space Space.
+ * @param tblName Table name.
+ * @return {@code True} if matches.
+ */
+ public boolean matchSpaceAndTable(String space, String tblName) {
+ return F.eq(space, this.space) && F.eq(tblName, this.tblName);
+ }
+
+ /**
+ * Callback invoked when initial type state is ready.
+ */
+ public void onInitialStateReady() {
+ idxState.onInitialStateReady(indexes);
+ }
+
+ /**
+ * Initiate asynchronous index creation.
+ *
+ * @param idx Index description.
+ * @param ifNotExists When set to {@code true} operation will fail if index already exists.
+ * @return Future completed when index is created.
+ */
+ public IgniteInternalFuture<?> dynamicIndexCreate(QueryIndex idx, boolean ifNotExists) {
+ return idxState.onCreateIndex(idx, ifNotExists);
+ }
+
/** {@inheritDoc} */
@Override public String toString() {
return S.toString(QueryTypeDescriptorImpl.class, this);