diff --git a/modules/core/src/main/java/org/apache/ignite/cache/QueryIndex.java b/modules/core/src/main/java/org/apache/ignite/cache/QueryIndex.java index df24cf9bcadc1..24d37cd6261e7 100644 --- a/modules/core/src/main/java/org/apache/ignite/cache/QueryIndex.java +++ b/modules/core/src/main/java/org/apache/ignite/cache/QueryIndex.java @@ -22,7 +22,7 @@ import java.util.LinkedHashMap; import java.util.Objects; import org.apache.ignite.configuration.CacheConfiguration; -import org.apache.ignite.internal.util.tostring.GridToStringInclude; +import org.apache.ignite.internal.cache.query.QueryIndexMessage; import org.apache.ignite.internal.util.typedef.internal.S; /** @@ -31,7 +31,7 @@ * the list can be provided as following {@code (id, name asc, age desc)}. */ @SuppressWarnings("TypeMayBeWeakened") -public class QueryIndex implements Serializable { +public class QueryIndex extends QueryIndexMessage implements Serializable { /** */ private static final long serialVersionUID = 0L; @@ -41,24 +41,12 @@ public class QueryIndex implements Serializable { /** Default index inline size. */ public static final int DFLT_INLINE_SIZE = -1; - /** Index name. */ - private String name; - - /** */ - @GridToStringInclude - private LinkedHashMap fields; - - /** */ - private QueryIndexType type = DFLT_IDX_TYP; - - /** */ - private int inlineSize = DFLT_INLINE_SIZE; - /** * Creates an empty index. Should be populated via setters. */ public QueryIndex() { - // Empty constructor. + type = DFLT_IDX_TYP; + inlineSize = DFLT_INLINE_SIZE; } /** @@ -114,10 +102,10 @@ public QueryIndex(String field, QueryIndexType type) { * @param asc Ascending flag. */ public QueryIndex(String field, QueryIndexType type, boolean asc) { - fields = new LinkedHashMap<>(); - fields.put(field, asc); - + inlineSize = DFLT_INLINE_SIZE; this.type = type; + + addField(field, asc); } /** @@ -129,11 +117,11 @@ public QueryIndex(String field, QueryIndexType type, boolean asc) { * @param name Index name. */ public QueryIndex(String field, QueryIndexType type, boolean asc, String name) { - fields = new LinkedHashMap<>(); - fields.put(field, asc); - + inlineSize = DFLT_INLINE_SIZE; this.type = type; this.name = name; + + addField(field, asc); } /** @@ -144,12 +132,11 @@ public QueryIndex(String field, QueryIndexType type, boolean asc, String name) { * @param type Index type. */ public QueryIndex(Collection fields, QueryIndexType type) { - this.fields = new LinkedHashMap<>(); + inlineSize = DFLT_INLINE_SIZE; + this.type = type; for (String field : fields) - this.fields.put(field, true); - - this.type = type; + addField(field, true); } /** @@ -160,8 +147,10 @@ public QueryIndex(Collection fields, QueryIndexType type) { * @param type Index type. */ public QueryIndex(LinkedHashMap fields, QueryIndexType type) { - this.fields = fields; + inlineSize = DFLT_INLINE_SIZE; this.type = type; + + this.fields = fields; } /** @@ -225,7 +214,7 @@ public QueryIndex setFieldNames(Collection fields, boolean asc) { this.fields = new LinkedHashMap<>(); for (String field : fields) - this.fields.put(field, asc); + addField(field, asc); return this; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/CoreMessagesProvider.java b/modules/core/src/main/java/org/apache/ignite/internal/CoreMessagesProvider.java index aa5d1e210cbaa..1ed439655b2b9 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/CoreMessagesProvider.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/CoreMessagesProvider.java @@ -19,6 +19,7 @@ import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.binary.BinaryMarshaller; +import org.apache.ignite.internal.cache.query.QueryIndexMessage; import org.apache.ignite.internal.cache.query.index.IndexQueryResultMeta; import org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition; import org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypeSettings; @@ -312,7 +313,11 @@ public CoreMessagesProvider(Marshaller schemaAwareMarsh, ClassLoader resolvedCls init(schemaAwareMarsh, resolvedClsLdr); } - /** The order is important. If wish to remove a message, put 'msgIdx++' on its place. */ + /** + * Registers all the messages into {@code factory}. + * The listing order is important here. If wish to remove a message, put 'msgIdx++' on its place. If wish to add, + * put it to end of a group. + */ @Override public void registerAll(MessageFactory factory) { assert this.factory == null; @@ -532,6 +537,7 @@ public CoreMessagesProvider(Marshaller schemaAwareMarsh, ClassLoader resolvedCls withNoSchema(SchemaProposeDiscoveryMessage.class); withNoSchema(SchemaFinishDiscoveryMessage.class); withNoSchema(QueryField.class); + withNoSchema(QueryIndexMessage.class); withNoSchema(GridCacheSqlQuery.class); withSchema(GridCacheQueryRequest.class); withSchema(GridCacheQueryResponse.class); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/cache/query/QueryIndexMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/cache/query/QueryIndexMessage.java new file mode 100644 index 0000000000000..8f07cd706a659 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/cache/query/QueryIndexMessage.java @@ -0,0 +1,53 @@ +/* + * 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.cache.query; + +import java.util.LinkedHashMap; +import org.apache.ignite.cache.QueryIndex; +import org.apache.ignite.cache.QueryIndexType; +import org.apache.ignite.internal.Order; +import org.apache.ignite.internal.util.tostring.GridToStringInclude; +import org.apache.ignite.plugin.extensions.communication.Message; + +/** Message for {@link QueryIndex}. */ +public class QueryIndexMessage implements Message { + /** Index name. */ + @Order(0) + public String name; + + /** */ + @GridToStringInclude + @Order(1) + public LinkedHashMap fields; + + /** */ + @Order(2) + public QueryIndexType type; + + /** */ + @Order(3) + public int inlineSize; + + /** */ + protected void addField(String fld, boolean ack) { + if (fields == null) + fields = new LinkedHashMap<>(); + + fields.put(fld, ack); + } +} diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIoManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIoManager.java index 8d0ffbb168f16..5c639d08b2596 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIoManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIoManager.java @@ -917,7 +917,7 @@ private void processFailedMessage(UUID nodeId, break; - case 10910: { + case 10911: { GridCacheQueryRequest req = (GridCacheQueryRequest)msg; GridCacheQueryResponse res = new GridCacheQueryResponse( diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/operation/SchemaIndexCreateOperation.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/operation/SchemaIndexCreateOperation.java index bf044295e6115..3d137b50a9be9 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/operation/SchemaIndexCreateOperation.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/operation/SchemaIndexCreateOperation.java @@ -18,20 +18,16 @@ package org.apache.ignite.internal.processors.query.schema.operation; import java.util.UUID; -import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.cache.QueryIndex; -import org.apache.ignite.internal.MarshallableMessage; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.processors.query.QueryUtils; import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.internal.S; -import org.apache.ignite.internal.util.typedef.internal.U; -import org.apache.ignite.marshaller.Marshaller; /** * Schema index create operation. */ -public class SchemaIndexCreateOperation extends SchemaIndexAbstractOperation implements MarshallableMessage { +public class SchemaIndexCreateOperation extends SchemaIndexAbstractOperation { /** */ private static final long serialVersionUID = 0L; @@ -41,11 +37,8 @@ public class SchemaIndexCreateOperation extends SchemaIndexAbstractOperation imp /** Index. */ @GridToStringInclude - private QueryIndex idx; - - /** Serialized form of 'query index'. */ @Order(1) - transient byte[] qryIdxBytes; + QueryIndex idx; /** Ignore operation if index exists. */ @Order(2) @@ -114,21 +107,6 @@ public int parallel() { return parallel; } - /** {@inheritDoc} */ - @Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException { - if (idx != null) - qryIdxBytes = U.marshal(marsh, idx); - } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException { - if (qryIdxBytes != null) { - idx = U.unmarshal(marsh, qryIdxBytes, clsLdr); - - qryIdxBytes = null; - } - } - /** {@inheritDoc} */ @Override public String toString() { return S.toString(SchemaIndexCreateOperation.class, this, "parent", super.toString());