Skip to content

Commit 938452e

Browse files
authored
IGNITE-28515 : Use MessageSerializer for QueryIndex (#13058)
1 parent 82f6223 commit 938452e

24 files changed

Lines changed: 184 additions & 63 deletions

modules/codegen/src/main/java/org/apache/ignite/internal/MessageSerializerGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ private void start(Collection<String> code, boolean write) {
296296

297297
indent++;
298298

299-
code.add(identedLine("throw new IgniteException(\"Failed to marshal object\" + msg.getClass().getSimpleName(), e);"));
299+
code.add(identedLine("throw new IgniteException(\"Failed to marshal object \" + msg.getClass().getSimpleName(), e);"));
300300

301301
indent--;
302302

@@ -957,7 +957,7 @@ private void finish(List<String> code, boolean read, boolean marshallable) {
957957

958958
indent++;
959959

960-
code.add(identedLine("throw new IgniteException(\"Failed to unmarshal object\" + msg.getClass().getSimpleName(), e);"));
960+
code.add(identedLine("throw new IgniteException(\"Failed to unmarshal object \" + msg.getClass().getSimpleName(), e);"));
961961

962962
indent--;
963963

modules/core/src/main/java/org/apache/ignite/internal/CoreMessagesProvider.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import org.apache.ignite.configuration.IgniteConfiguration;
2121
import org.apache.ignite.internal.binary.BinaryMarshaller;
22+
import org.apache.ignite.internal.cache.query.QueryIndexMessage;
2223
import org.apache.ignite.internal.cache.query.index.IndexQueryResultMeta;
2324
import org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition;
2425
import org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypeSettings;
@@ -232,6 +233,7 @@
232233
import org.apache.ignite.internal.util.distributed.SingleNodeMessage;
233234
import org.apache.ignite.lang.IgniteProductVersion;
234235
import org.apache.ignite.marshaller.Marshaller;
236+
import org.apache.ignite.marshaller.jdk.JdkMarshaller;
235237
import org.apache.ignite.plugin.extensions.communication.Message;
236238
import org.apache.ignite.plugin.extensions.communication.MessageFactory;
237239
import org.apache.ignite.spi.collision.jobstealing.JobStealingRequest;
@@ -296,23 +298,28 @@ public class CoreMessagesProvider extends AbstractMarshallableMessageFactoryProv
296298
/**
297299
* Default plugin-purposes constructor.
298300
*
299-
* @see #init(Marshaller, ClassLoader)
301+
* @see #init(Marshaller, Marshaller, ClassLoader)
300302
*/
301303
public CoreMessagesProvider() {
302304
// No-op.
303305
}
304306

305307
/**
306-
* Constructor allowing not to call {@link #init(Marshaller, ClassLoader)}.
308+
* Constructor allowing not to call {@link #init(Marshaller, Marshaller, ClassLoader)}.
307309
*
310+
* @param dfltMarsh Schema-less marshaller like {@link JdkMarshaller}.
308311
* @param schemaAwareMarsh Schema-aware marshaller like {@link BinaryMarshaller}.
309312
* @param resolvedClsLdr Resolved (configured) class loader like {@link IgniteConfiguration#setClassLoader(ClassLoader)}.
310313
*/
311-
public CoreMessagesProvider(Marshaller schemaAwareMarsh, ClassLoader resolvedClsLdr) {
312-
init(schemaAwareMarsh, resolvedClsLdr);
314+
public CoreMessagesProvider(Marshaller dfltMarsh, Marshaller schemaAwareMarsh, ClassLoader resolvedClsLdr) {
315+
init(dfltMarsh, schemaAwareMarsh, resolvedClsLdr);
313316
}
314317

315-
/** The order is important. If wish to remove a message, put 'msgIdx++' on its place. */
318+
/**
319+
* Registers all the messages into {@code factory}.
320+
* The listing order is important here. If wish to remove a message, put 'msgIdx++' on its place. If wish to add,
321+
* put it to end of a group.
322+
*/
316323
@Override public void registerAll(MessageFactory factory) {
317324
assert this.factory == null;
318325

@@ -532,6 +539,7 @@ public CoreMessagesProvider(Marshaller schemaAwareMarsh, ClassLoader resolvedCls
532539
withNoSchema(SchemaProposeDiscoveryMessage.class);
533540
withNoSchema(SchemaFinishDiscoveryMessage.class);
534541
withNoSchema(QueryField.class);
542+
withNoSchema(QueryIndexMessage.class);
535543
withNoSchema(GridCacheSqlQuery.class);
536544
withSchema(GridCacheQueryRequest.class);
537545
withSchema(GridCacheQueryResponse.class);
@@ -649,7 +657,7 @@ private <T extends Message> void withSchema(Class<T> cls) {
649657
register(cls, schemaAwareMarsh, dftlClsLdr);
650658
}
651659

652-
/** Registers message using {@link #schemaAwareMarsh} and {@link #resolvedClsLdr}. */
660+
/** Registers message using {@link #dfltMarsh} and {@link #resolvedClsLdr}. */
653661
private <T extends Message> void withNoSchemaResolvedClassLoader(Class<T> cls) {
654662
register(cls, dfltMarsh, resolvedClsLdr);
655663
}

modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,14 +1318,18 @@ private void initMessageFactory() throws IgniteCheckedException {
13181318

13191319
List<MessageFactoryProvider> compMsgs = new ArrayList<>();
13201320

1321-
compMsgs.add(new CoreMessagesProvider(ctx.marshaller(), U.resolveClassLoader(ctx.config())));
1321+
ClassLoader resolvedClsLdr = U.resolveClassLoader(ctx.config());
1322+
1323+
compMsgs.add(new CoreMessagesProvider(ctx.marshallerContext().jdkMarshaller(), ctx.marshaller(), resolvedClsLdr));
13221324

13231325
for (IgniteComponentType compType : IgniteComponentType.values()) {
13241326
MessageFactoryProvider f = compType.messageFactory();
13251327

13261328
if (f != null) {
1327-
if (f instanceof AbstractMarshallableMessageFactoryProvider)
1328-
((AbstractMarshallableMessageFactoryProvider)f).init(ctx.marshaller(), U.resolveClassLoader(ctx.config()));
1329+
if (f instanceof AbstractMarshallableMessageFactoryProvider) {
1330+
((AbstractMarshallableMessageFactoryProvider)f).init(ctx.marshallerContext().jdkMarshaller(),
1331+
ctx.marshaller(), resolvedClsLdr);
1332+
}
13291333

13301334
compMsgs.add(f);
13311335
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.ignite.internal.cache.query;
19+
20+
import java.io.Serializable;
21+
import java.util.LinkedHashMap;
22+
import org.apache.ignite.cache.QueryIndex;
23+
import org.apache.ignite.cache.QueryIndexType;
24+
import org.apache.ignite.internal.Order;
25+
import org.apache.ignite.internal.util.tostring.GridToStringInclude;
26+
import org.apache.ignite.internal.util.typedef.internal.S;
27+
import org.apache.ignite.plugin.extensions.communication.Message;
28+
import org.apache.ignite.plugin.extensions.communication.MessageFactory;
29+
30+
/** Message for {@link QueryIndex}. */
31+
public class QueryIndexMessage implements Serializable, Message {
32+
/** */
33+
private static final long serialVersionUID = 0L;
34+
35+
/** Index name. */
36+
@Order(0)
37+
public String name;
38+
39+
/** */
40+
@GridToStringInclude
41+
@Order(1)
42+
public LinkedHashMap<String, Boolean> fields;
43+
44+
/** */
45+
@Order(2)
46+
QueryIndexType type;
47+
48+
/** */
49+
@Order(3)
50+
int inlineSize;
51+
52+
/** Empty constructor for {@link MessageFactory}. */
53+
public QueryIndexMessage() {
54+
// No-op.
55+
}
56+
57+
/** Copies {@code idx}. */
58+
public QueryIndexMessage(QueryIndex idx) {
59+
name = idx.getName();
60+
fields = idx.getFields();
61+
type = idx.getIndexType();
62+
inlineSize = idx.getInlineSize();
63+
}
64+
65+
/** @return Copy of {@code msg} as {@link QueryIndex}. */
66+
public static QueryIndex queryIndex(QueryIndexMessage msg) {
67+
QueryIndex res = new QueryIndex();
68+
69+
res.setName(msg.name);
70+
res.setFields(msg.fields);
71+
res.setIndexType(msg.type);
72+
res.setInlineSize(msg.inlineSize);
73+
74+
return res;
75+
}
76+
77+
/** {@inheritDoc} */
78+
@Override public String toString() {
79+
return S.toString(QueryIndexMessage.class, this);
80+
}
81+
}

modules/core/src/main/java/org/apache/ignite/internal/plugin/AbstractMarshallableMessageFactoryProvider.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import org.apache.ignite.internal.binary.BinaryMarshaller;
2525
import org.apache.ignite.internal.util.typedef.internal.U;
2626
import org.apache.ignite.marshaller.Marshaller;
27-
import org.apache.ignite.marshaller.Marshallers;
27+
import org.apache.ignite.marshaller.jdk.JdkMarshaller;
2828
import org.apache.ignite.plugin.extensions.communication.Message;
2929
import org.apache.ignite.plugin.extensions.communication.MessageFactory;
3030
import org.apache.ignite.plugin.extensions.communication.MessageFactoryProvider;
@@ -36,7 +36,7 @@
3636
*/
3737
public abstract class AbstractMarshallableMessageFactoryProvider implements MessageFactoryProvider {
3838
/** Default schema-less marshaller. */
39-
protected final Marshaller dfltMarsh = Marshallers.jdk();
39+
protected Marshaller dfltMarsh;
4040

4141
/** Default class loader. */
4242
protected final ClassLoader dftlClsLdr = U.gridClassLoader();
@@ -48,10 +48,12 @@ public abstract class AbstractMarshallableMessageFactoryProvider implements Mess
4848
protected ClassLoader resolvedClsLdr;
4949

5050
/**
51+
* @param dfltMarsh Default schema-less marshaller like {@link JdkMarshaller}.
5152
* @param schemaAwareMarsh Schema-aware marshaller like {@link BinaryMarshaller}.
5253
* @param resolvedClsLdr Resolved (configured) class loader like {@link IgniteConfiguration#setClassLoader(ClassLoader)}.
5354
*/
54-
public void init(Marshaller schemaAwareMarsh, ClassLoader resolvedClsLdr) {
55+
public void init(Marshaller dfltMarsh, Marshaller schemaAwareMarsh, ClassLoader resolvedClsLdr) {
56+
this.dfltMarsh = dfltMarsh;
5557
this.schemaAwareMarsh = schemaAwareMarsh;
5658
this.resolvedClsLdr = resolvedClsLdr;
5759
}

modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIoManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ private void processFailedMessage(UUID nodeId,
917917

918918
break;
919919

920-
case 10910: {
920+
case 10911: {
921921
GridCacheQueryRequest req = (GridCacheQueryRequest)msg;
922922

923923
GridCacheQueryResponse res = new GridCacheQueryResponse(

modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,22 @@ public static String indexName(QueryEntity entity, QueryIndex idx) {
227227
* @return Index name.
228228
*/
229229
public static String indexName(String tblName, QueryIndex idx) {
230-
String res = idx.getName();
230+
return indexName(tblName, idx.getName(), idx.getFields());
231+
}
231232

232-
if (res == null) {
233+
/**
234+
* Get index name.
235+
*
236+
* @param tblName Table name.
237+
* @param name Index name.
238+
* @param fields Fields.
239+
* @return Index name.
240+
*/
241+
public static String indexName(String tblName, @Nullable String name, Map<String, Boolean> fields) {
242+
if (name == null) {
233243
StringBuilder idxName = new StringBuilder(tblName + "_");
234244

235-
for (Map.Entry<String, Boolean> field : idx.getFields().entrySet()) {
245+
for (Map.Entry<String, Boolean> field : fields.entrySet()) {
236246
idxName.append(field.getKey());
237247

238248
idxName.append('_');
@@ -253,7 +263,7 @@ public static String indexName(String tblName, QueryIndex idx) {
253263
return idxName.toString();
254264
}
255265

256-
return res;
266+
return name;
257267
}
258268

259269
/**

modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/operation/SchemaIndexCreateOperation.java

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,17 @@
1818
package org.apache.ignite.internal.processors.query.schema.operation;
1919

2020
import java.util.UUID;
21-
import org.apache.ignite.IgniteCheckedException;
2221
import org.apache.ignite.cache.QueryIndex;
23-
import org.apache.ignite.internal.MarshallableMessage;
2422
import org.apache.ignite.internal.Order;
23+
import org.apache.ignite.internal.cache.query.QueryIndexMessage;
2524
import org.apache.ignite.internal.processors.query.QueryUtils;
2625
import org.apache.ignite.internal.util.tostring.GridToStringInclude;
2726
import org.apache.ignite.internal.util.typedef.internal.S;
28-
import org.apache.ignite.internal.util.typedef.internal.U;
29-
import org.apache.ignite.marshaller.Marshaller;
3027

3128
/**
3229
* Schema index create operation.
3330
*/
34-
public class SchemaIndexCreateOperation extends SchemaIndexAbstractOperation implements MarshallableMessage {
31+
public class SchemaIndexCreateOperation extends SchemaIndexAbstractOperation {
3532
/** */
3633
private static final long serialVersionUID = 0L;
3734

@@ -41,11 +38,8 @@ public class SchemaIndexCreateOperation extends SchemaIndexAbstractOperation imp
4138

4239
/** Index. */
4340
@GridToStringInclude
44-
private QueryIndex idx;
45-
46-
/** Serialized form of 'query index'. */
4741
@Order(1)
48-
transient byte[] qryIdxBytes;
42+
QueryIndexMessage idxMsg;
4943

5044
/** Ignore operation if index exists. */
5145
@Order(2)
@@ -56,7 +50,9 @@ public class SchemaIndexCreateOperation extends SchemaIndexAbstractOperation imp
5650
int parallel;
5751

5852
/** */
59-
public SchemaIndexCreateOperation() {}
53+
public SchemaIndexCreateOperation() {
54+
// No-op.
55+
}
6056

6157
/**
6258
* Constructor.
@@ -74,14 +70,14 @@ public SchemaIndexCreateOperation(UUID opId, String cacheName, String schemaName
7470
super(opId, cacheName, schemaName);
7571

7672
this.tblName = tblName;
77-
this.idx = idx;
73+
this.idxMsg = new QueryIndexMessage(idx);
7874
this.ifNotExists = ifNotExists;
7975
this.parallel = parallel;
8076
}
8177

8278
/** {@inheritDoc} */
8379
@Override public String indexName() {
84-
return QueryUtils.indexName(tblName, idx);
80+
return QueryUtils.indexName(tblName, idxMsg.name, idxMsg.fields);
8581
}
8682

8783
/**
@@ -95,7 +91,7 @@ public String tableName() {
9591
* @return Index params.
9692
*/
9793
public QueryIndex index() {
98-
return idx;
94+
return QueryIndexMessage.queryIndex(idxMsg);
9995
}
10096

10197
/**
@@ -114,21 +110,6 @@ public int parallel() {
114110
return parallel;
115111
}
116112

117-
/** {@inheritDoc} */
118-
@Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException {
119-
if (idx != null)
120-
qryIdxBytes = U.marshal(marsh, idx);
121-
}
122-
123-
/** {@inheritDoc} */
124-
@Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException {
125-
if (qryIdxBytes != null) {
126-
idx = U.unmarshal(marsh, qryIdxBytes, clsLdr);
127-
128-
qryIdxBytes = null;
129-
}
130-
}
131-
132113
/** {@inheritDoc} */
133114
@Override public String toString() {
134115
return S.toString(SchemaIndexCreateOperation.class, this, "parent", super.toString());

0 commit comments

Comments
 (0)