Skip to content
Open
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ private void finish(List<String> code, boolean read, boolean marshallable) {

indent++;

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

indent--;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -232,6 +233,7 @@
import org.apache.ignite.internal.util.distributed.SingleNodeMessage;
import org.apache.ignite.lang.IgniteProductVersion;
import org.apache.ignite.marshaller.Marshaller;
import org.apache.ignite.marshaller.jdk.JdkMarshaller;
import org.apache.ignite.plugin.extensions.communication.Message;
import org.apache.ignite.plugin.extensions.communication.MessageFactory;
import org.apache.ignite.spi.collision.jobstealing.JobStealingRequest;
Expand Down Expand Up @@ -296,23 +298,28 @@ public class CoreMessagesProvider extends AbstractMarshallableMessageFactoryProv
/**
* Default plugin-purposes constructor.
*
* @see #init(Marshaller, ClassLoader)
* @see #init(Marshaller, Marshaller, ClassLoader)
*/
public CoreMessagesProvider() {
// No-op.
}

/**
* Constructor allowing not to call {@link #init(Marshaller, ClassLoader)}.
* Constructor allowing not to call {@link #init(Marshaller, Marshaller, ClassLoader)}.
*
* @param dfltMarsh Schema-less marshaller like {@link JdkMarshaller}.
* @param schemaAwareMarsh Schema-aware marshaller like {@link BinaryMarshaller}.
* @param resolvedClsLdr Resolved (configured) class loader like {@link IgniteConfiguration#setClassLoader(ClassLoader)}.
*/
public CoreMessagesProvider(Marshaller schemaAwareMarsh, ClassLoader resolvedClsLdr) {
init(schemaAwareMarsh, resolvedClsLdr);
public CoreMessagesProvider(Marshaller dfltMarsh, Marshaller schemaAwareMarsh, ClassLoader resolvedClsLdr) {
init(dfltMarsh, 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;

Expand Down Expand Up @@ -532,6 +539,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);
Expand Down Expand Up @@ -649,7 +657,7 @@ private <T extends Message> void withSchema(Class<T> cls) {
register(cls, schemaAwareMarsh, dftlClsLdr);
}

/** Registers message using {@link #schemaAwareMarsh} and {@link #resolvedClsLdr}. */
/** Registers message using {@link #dfltMarsh} and {@link #resolvedClsLdr}. */
private <T extends Message> void withNoSchemaResolvedClassLoader(Class<T> cls) {
register(cls, dfltMarsh, resolvedClsLdr);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1320,14 +1320,18 @@ private void initMessageFactory() throws IgniteCheckedException {

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

compMsgs.add(new CoreMessagesProvider(ctx.marshaller(), U.resolveClassLoader(ctx.config())));
ClassLoader resolvedClsLdr = U.resolveClassLoader(ctx.config());

compMsgs.add(new CoreMessagesProvider(ctx.marshallerContext().jdkMarshaller(), ctx.marshaller(), resolvedClsLdr));

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

if (f != null) {
if (f instanceof AbstractMarshallableMessageFactoryProvider)
((AbstractMarshallableMessageFactoryProvider)f).init(ctx.marshaller(), U.resolveClassLoader(ctx.config()));
if (f instanceof AbstractMarshallableMessageFactoryProvider) {
((AbstractMarshallableMessageFactoryProvider)f).init(ctx.marshallerContext().jdkMarshaller(),
ctx.marshaller(), resolvedClsLdr);
}

compMsgs.add(f);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* 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.io.Serializable;
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.internal.util.typedef.internal.S;
import org.apache.ignite.plugin.extensions.communication.Message;
import org.apache.ignite.plugin.extensions.communication.MessageFactory;

/** Message for {@link QueryIndex}. */
public class QueryIndexMessage implements Serializable, Message {
/** */
private static final long serialVersionUID = 0L;

/** Index name. */
@Order(0)
public String name;

/** */
@GridToStringInclude
@Order(1)
public LinkedHashMap<String, Boolean> fields;

/** */
@Order(2)
QueryIndexType type;

/** */
@Order(3)
int inlineSize;

/** Empty constructor for {@link MessageFactory}. */
public QueryIndexMessage() {
// No-op.
}

/** Copies {@code idx}. */
public QueryIndexMessage(QueryIndex idx) {
name = idx.getName();
fields = idx.getFields();
type = idx.getIndexType();
inlineSize = idx.getInlineSize();
}

/** @return Copy of {@code msg} as {@link QueryIndex}. */
public static QueryIndex queryIndex(QueryIndexMessage msg) {
QueryIndex res = new QueryIndex();

res.setName(msg.name);
res.setFields(msg.fields);
res.setIndexType(msg.type);
res.setInlineSize(msg.inlineSize);

return res;
}

/** {@inheritDoc} */
@Override public String toString() {
return S.toString(QueryIndexMessage.class, this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.apache.ignite.internal.binary.BinaryMarshaller;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.marshaller.Marshaller;
import org.apache.ignite.marshaller.Marshallers;
import org.apache.ignite.marshaller.jdk.JdkMarshaller;
import org.apache.ignite.plugin.extensions.communication.Message;
import org.apache.ignite.plugin.extensions.communication.MessageFactory;
import org.apache.ignite.plugin.extensions.communication.MessageFactoryProvider;
Expand All @@ -36,7 +36,7 @@
*/
public abstract class AbstractMarshallableMessageFactoryProvider implements MessageFactoryProvider {
/** Default schema-less marshaller. */
protected final Marshaller dfltMarsh = Marshallers.jdk();
protected Marshaller dfltMarsh;

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

/**
* @param dfltMarsh Default schema-less marshaller like {@link JdkMarshaller}.
* @param schemaAwareMarsh Schema-aware marshaller like {@link BinaryMarshaller}.
* @param resolvedClsLdr Resolved (configured) class loader like {@link IgniteConfiguration#setClassLoader(ClassLoader)}.
*/
public void init(Marshaller schemaAwareMarsh, ClassLoader resolvedClsLdr) {
public void init(Marshaller dfltMarsh, Marshaller schemaAwareMarsh, ClassLoader resolvedClsLdr) {
this.dfltMarsh = dfltMarsh;
this.schemaAwareMarsh = schemaAwareMarsh;
this.resolvedClsLdr = resolvedClsLdr;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ private void processFailedMessage(UUID nodeId,

break;

case 10910: {
case 10911: {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Vladsz83 @anton-vinogradov , now it looks very ugly that we need to do this. It is necessary to refactor this case block.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use smth. like msgFactory.messageType(msg). Looks like other ticket. Or I could place the message below in the registration list. But I could place it where it should be and make a fix.

GridCacheQueryRequest req = (GridCacheQueryRequest)msg;

GridCacheQueryResponse res = new GridCacheQueryResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,22 @@ public static String indexName(QueryEntity entity, QueryIndex idx) {
* @return Index name.
*/
public static String indexName(String tblName, QueryIndex idx) {
String res = idx.getName();
return indexName(tblName, idx.getName(), idx.getFields());
}

if (res == null) {
/**
* Get index name.
*
* @param tblName Table name.
* @param name Index name.
* @param fields Fields.
* @return Index name.
*/
public static String indexName(String tblName, @Nullable String name, Map<String, Boolean> fields) {
if (name == null) {
StringBuilder idxName = new StringBuilder(tblName + "_");

for (Map.Entry<String, Boolean> field : idx.getFields().entrySet()) {
for (Map.Entry<String, Boolean> field : fields.entrySet()) {
idxName.append(field.getKey());

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

return res;
return name;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,17 @@
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.cache.query.QueryIndexMessage;
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;

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

/** Index. */
@GridToStringInclude
private QueryIndex idx;

/** Serialized form of 'query index'. */
@Order(1)
transient byte[] qryIdxBytes;
QueryIndexMessage idxMsg;

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

/** */
public SchemaIndexCreateOperation() {}
public SchemaIndexCreateOperation() {
// No-op.
}

/**
* Constructor.
Expand All @@ -74,14 +70,14 @@ public SchemaIndexCreateOperation(UUID opId, String cacheName, String schemaName
super(opId, cacheName, schemaName);

this.tblName = tblName;
this.idx = idx;
this.idxMsg = new QueryIndexMessage(idx);
this.ifNotExists = ifNotExists;
this.parallel = parallel;
}

/** {@inheritDoc} */
@Override public String indexName() {
return QueryUtils.indexName(tblName, idx);
return QueryUtils.indexName(tblName, idxMsg.name, idxMsg.fields);
}

/**
Expand All @@ -95,7 +91,7 @@ public String tableName() {
* @return Index params.
*/
public QueryIndex index() {
return idx;
return QueryIndexMessage.queryIndex(idxMsg);
}

/**
Expand All @@ -114,21 +110,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());
Expand Down
Loading
Loading