diff --git a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/message/CalciteContextMarshallableMessage.java b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/message/CalciteContextMarshallableMessage.java index f6ba42de95933..f81fd1709c088 100644 --- a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/message/CalciteContextMarshallableMessage.java +++ b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/message/CalciteContextMarshallableMessage.java @@ -28,7 +28,9 @@ public interface CalciteContextMarshallableMessage extends Message { * * @param ctx Cache shared context. */ - void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException; + default void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { + // No-op. + } /** * Prepares the message before processing. @@ -36,5 +38,7 @@ public interface CalciteContextMarshallableMessage extends Message { * @param ctx Cache shared context. * @param clsLdr Class loader. */ - void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader clsLdr) throws IgniteCheckedException; + default void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader clsLdr) throws IgniteCheckedException { + // No-op. + } } diff --git a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/message/QueryTxEntry.java b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/message/QueryTxEntry.java index 36f2d9dceee84..cad5e8afb75f1 100644 --- a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/message/QueryTxEntry.java +++ b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/message/QueryTxEntry.java @@ -20,15 +20,13 @@ import java.util.Collection; import java.util.Comparator; import java.util.function.Function; -import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.configuration.TransactionConfiguration; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.processors.cache.CacheObject; -import org.apache.ignite.internal.processors.cache.CacheObjectContext; -import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; import org.apache.ignite.internal.processors.query.calcite.exec.ExecutionContext; +import org.apache.ignite.plugin.extensions.communication.CacheIdAware; /** * Class to pass to remote nodes transaction changes. @@ -38,7 +36,7 @@ * @see ExecutionContext#transactionChanges(int, int[], Function, Comparator) * @see QueryStartRequest#queryTransactionEntries() */ -public class QueryTxEntry implements CalciteContextMarshallableMessage { +public class QueryTxEntry implements CalciteContextMarshallableMessage, CacheIdAware { /** Cache id. */ @Order(0) int cacheId; @@ -75,8 +73,8 @@ public QueryTxEntry(int cacheId, KeyCacheObject key, CacheObject val, GridCacheV this.ver = ver; } - /** @return Cache id. */ - public int cacheId() { + /** {@inheritDoc} */ + @Override public int cacheId() { return cacheId; } @@ -94,24 +92,4 @@ public CacheObject value() { public GridCacheVersion version() { return ver; } - - /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - CacheObjectContext coctx = ctx.cacheContext(cacheId).cacheObjectContext(); - - key.prepareMarshal(coctx); - - if (val != null) - val.prepareMarshal(coctx); - } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - CacheObjectContext coctx = ctx.cacheContext(cacheId).cacheObjectContext(); - - key.finishUnmarshal(coctx, ldr); - - if (val != null) - val.finishUnmarshal(coctx, ldr); - } } diff --git a/modules/codegen/src/main/java/org/apache/ignite/internal/MessageSerializerGenerator.java b/modules/codegen/src/main/java/org/apache/ignite/internal/MessageSerializerGenerator.java index 052db3afcdf62..73b92cf256feb 100644 --- a/modules/codegen/src/main/java/org/apache/ignite/internal/MessageSerializerGenerator.java +++ b/modules/codegen/src/main/java/org/apache/ignite/internal/MessageSerializerGenerator.java @@ -28,6 +28,7 @@ import java.util.ArrayList; import java.util.BitSet; import java.util.Collection; +import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -46,12 +47,14 @@ import javax.lang.model.type.PrimitiveType; import javax.lang.model.type.TypeKind; import javax.lang.model.type.TypeMirror; +import javax.lang.model.type.TypeVariable; import javax.lang.model.util.Elements; import javax.tools.Diagnostic; import javax.tools.FileObject; import javax.tools.JavaFileObject; import javax.tools.StandardLocation; import org.apache.ignite.internal.systemview.SystemViewRowAttributeWalkerProcessor; +import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.internal.SB; import org.jetbrains.annotations.Nullable; @@ -74,7 +77,7 @@ public class MessageSerializerGenerator { public static final String NL = System.lineSeparator(); /** */ - private static final String CLS_JAVADOC = "/** " + NL + + private static final String CLS_JAVADOC = "/**" + NL + " * This class is generated automatically." + NL + " *" + NL + " * @see org.apache.ignite.internal.MessageProcessor" + NL + @@ -99,6 +102,9 @@ public class MessageSerializerGenerator { /** Collection of lines for {@code readFrom} method. */ private final List read = new ArrayList<>(); + /** */ + private final List marshall = new ArrayList<>(); + /** Collection of message-specific imports. */ private final Set imports = new TreeSet<>(); @@ -165,10 +171,10 @@ void generate(TypeElement type, List fields) throws Exception { /** Generates full code for a serializer class. */ private String generateSerializerCode(String serClsName) throws IOException { - if (marshallableMessage()) { + if (marshallableMessage()) fields.add("private final Marshaller marshaller;"); - fields.add("private final ClassLoader clsLdr;"); - } + + fields.add("private final ClassLoader clsLdr;"); try (Writer writer = new StringWriter()) { writeClassHeader(writer, env.getElementUtils().getPackageOf(type).toString(), serClsName); @@ -189,9 +195,14 @@ private String generateSerializerCode(String serClsName) throws IOException { writer.write(TAB + "}" + NL); - writer.write("}"); + if (!marshall.isEmpty()) { + writer.write(NL); - writer.write(NL); + for (String p: marshall) + writer.write(p + NL); + } + + writer.write("}"); return writer.toString(); } @@ -199,28 +210,32 @@ private String generateSerializerCode(String serClsName) throws IOException { /** */ private void writeConstructor(Writer writer, String serClsName) throws IOException { - if (!marshallableMessage()) - return; - ++indent; - writer.write(identedLine(METHOD_JAVADOC)); + writer.write(indentedLine(METHOD_JAVADOC)); writer.write(NL); - writer.write(identedLine("public " + serClsName + "(Marshaller marshaller, ClassLoader clsLdr) {")); + + if (marshallableMessage()) + writer.write(indentedLine("public " + serClsName + "(Marshaller marshaller, ClassLoader clsLdr) {")); + else + writer.write(indentedLine("public " + serClsName + "(ClassLoader clsLdr) {")); writer.write(NL); ++indent; - writer.write(identedLine("this.marshaller = marshaller;")); - writer.write(NL); - writer.write(identedLine("this.clsLdr = clsLdr;")); + if (marshallableMessage()) { + writer.write(indentedLine("this.marshaller = marshaller;")); + writer.write(NL); + } + + writer.write(indentedLine("this.clsLdr = clsLdr;")); --indent; writer.write(NL); - writer.write(identedLine("}")); + writer.write(indentedLine("}")); writer.write(NL); --indent; @@ -240,8 +255,318 @@ private void generateMethods(List fields) throws Exception { indent--; - finish(write, false, false); - finish(read, true, marshallableMessage()); + finish(write); + finish(read); + + generateMarshallMethods(fields); + generateUnmarshallMethods(fields); + } + + /** */ + private void generateMarshallMethods(List orderedFields) { + imports.add("org.apache.ignite.IgniteCheckedException"); + imports.add("org.apache.ignite.internal.processors.cache.CacheObjectValueContext"); + imports.add("org.apache.ignite.internal.GridKernalContext"); + imports.add("org.apache.ignite.internal.processors.cache.GridCacheContext"); + + indent = 1; + + marshall.add(indentedLine(METHOD_JAVADOC)); + + marshall.add(indentedLine( + "@Override public void prepareMarshal(" + simpleNameWithGeneric(type) + + " msg, GridKernalContext kctx, GridCacheContext nested) throws IgniteCheckedException {")); + + indent++; + + if (isCacheIdAwareMessage(type)) + marshall.add( + indentedLine("GridCacheContext ctx = nested == null ? kctx.cache().context().cacheContext(msg.cacheId()) : nested;")); + else + marshall.add(indentedLine("GridCacheContext ctx = nested;")); + + if (marshallableMessage()) { + marshall.add(EMPTY); + + marshall.add(indentedLine("msg.prepareMarshal(marshaller);")); + } + + for (VariableElement field : orderedFields) { + List marshalled = marshall(field.asType(), fieldAccessor(field), false); + + if (!marshalled.isEmpty()) { + if (!marshall.get(marshall.size() - 1).equals(EMPTY)) + marshall.add(EMPTY); + + marshall.addAll(marshalled); + } + } + + indent--; + + marshall.add(indentedLine("}")); + } + + /** */ + private void generateUnmarshallMethods(List orderedFields) { + marshall.add(EMPTY); + + indent = 1; + + marshall.add(indentedLine(METHOD_JAVADOC)); + + marshall.add(indentedLine( + "@Override public void finishUnmarshal(" + simpleNameWithGeneric(type) + + " msg, GridKernalContext kctx, GridCacheContext nested) throws IgniteCheckedException {")); + + indent++; + + if (isCacheIdAwareMessage(type)) + marshall.add( + indentedLine("GridCacheContext ctx = nested == null ? kctx.cache().context().cacheContext(msg.cacheId()) : nested;")); + else + marshall.add(indentedLine("GridCacheContext ctx = nested;")); + + for (VariableElement field : orderedFields) { + List unmarshalled = marshall(field.asType(), fieldAccessor(field), true); + + if (!unmarshalled.isEmpty()) { + if (!marshall.get(marshall.size() - 1).equals(EMPTY)) + marshall.add(EMPTY); + + marshall.addAll(unmarshalled); + } + } + + if (marshallableMessage()) { + marshall.add(EMPTY); + + marshall.add(indentedLine("msg.finishUnmarshal(marshaller, clsLdr);")); + } + + indent--; + + marshall.add(indentedLine("}")); + } + + /** */ + private List marshall(TypeMirror t, String accessor, boolean unmarshall) { + if (t.getKind() == TypeKind.ARRAY) { + TypeMirror comp = ((ArrayType)t).getComponentType(); + + if (comp.getKind() == TypeKind.DECLARED) { + List code = new ArrayList<>(); + + imports.add(((QualifiedNameable)((DeclaredType)comp).asElement()).getQualifiedName().toString()); + + code.add(indentedLine("if (%s != null) {", accessor)); + + indent++; + + String el = "e" + indent; + + code.add(indentedLine("for (%s %s : %s) {", ((DeclaredType)comp).asElement().getSimpleName().toString(), el, accessor)); + + indent++; + + List res = marshall(comp, el, unmarshall); + + code.addAll(res); + + indent--; + + code.add(indentedLine("}")); + + indent--; + + code.add(indentedLine("}")); + + if (res.isEmpty()) + return Collections.emptyList(); + else + return code; + } + } + else if (t.getKind() == TypeKind.DECLARED || t.getKind() == TypeKind.TYPEVAR) { + if (isMessage(t)) { + List code = new ArrayList<>(); + + code.add(indentedLine("if (%s != null)", accessor)); + + indent++; + + if (!unmarshall) + code.add(indentedLine( + "kctx.messageFactory().serializer(%s.directType()).prepareMarshal(%s, kctx, ctx);", + accessor, + accessor)); + else + code.add(indentedLine( + "kctx.messageFactory().serializer(%s.directType()).finishUnmarshal(%s, kctx, ctx);", + accessor, + accessor)); + + indent--; + + return code; + } + else if (isCacheObject(t)) { + List code = new ArrayList<>(); + + code.add(indentedLine("if (%s != null)", accessor)); + + indent++; + + if (!unmarshall) + code.add(indentedLine("%s.prepareMarshal(ctx != null ? ctx.cacheObjectContext() : null);", accessor)); + else + code.add(indentedLine("%s.finishUnmarshal(ctx != null ? ctx.cacheObjectContext() : null, clsLdr);", accessor)); + + indent--; + + return code; + } + else if (assignableFrom(erasedType(t), type(Map.class.getName()))) { + List args = ((DeclaredType)t).getTypeArguments(); + + TypeMirror keyType = args.get(0); + TypeMirror valType = args.get(1); + + List code = new ArrayList<>(); + + code.add(indentedLine("if (%s != null) {", accessor)); + + indent++; + + String el = "e" + indent; + + indent++; // Emulating subsequent indent. + List keyRes = marshall(keyType, el, unmarshall); + List valRes = marshall(valType, el, unmarshall); + indent--; + + if (!keyRes.isEmpty() && (keyType.getKind() == TypeKind.DECLARED || keyType.getKind() == TypeKind.TYPEVAR)) { + Element elem = element(keyType); + + imports.add(((QualifiedNameable)(elem)).getQualifiedName().toString()); + imports.add("java.util.Collection"); + + String type = elem.getSimpleName().toString(); + + code.add(indentedLine("for (%s %s : ((Collection)%s.keySet())) {", type, el, type, accessor)); + + indent++; + + code.addAll(keyRes); + + indent--; + + code.add(indentedLine("}")); + } + + if (!valRes.isEmpty() && (valType.getKind() == TypeKind.DECLARED || valType.getKind() == TypeKind.TYPEVAR)) { + Element elem = element(valType); + + imports.add(((QualifiedNameable)(elem)).getQualifiedName().toString()); + imports.add("java.util.Collection"); + + String type = elem.getSimpleName().toString(); + + code.add(indentedLine("for (%s %s : ((Collection)%s.values())) {", type, el, type, accessor)); + + indent++; + + code.addAll(valRes); + + indent--; + + code.add(indentedLine("}")); + } + + indent--; + + code.add(indentedLine("}")); + + if (keyRes.isEmpty() && valRes.isEmpty()) + return Collections.emptyList(); + else + return code; + } + else if (assignableFrom(erasedType(t), type(Collection.class.getName()))) { + List args = ((DeclaredType)t).getTypeArguments(); + + TypeMirror arg = args.get(0); + + if ((arg.getKind() == TypeKind.DECLARED || arg.getKind() == TypeKind.TYPEVAR)) { + List code = new ArrayList<>(); + + Element elem = element(arg); + + imports.add(((QualifiedNameable)(elem)).getQualifiedName().toString()); + imports.add("java.util.Collection"); + + String el = "e" + indent; + + code.add(indentedLine("if (%s != null) {", accessor)); + + indent++; + + String type = elem.getSimpleName().toString(); + + code.add(indentedLine("for (%s %s : (Collection)%s) {", type, el, type, accessor)); + + indent++; + + List res = marshall(arg, el, unmarshall); + + code.addAll(res); + + indent--; + + code.add(indentedLine("}")); + + indent--; + + code.add(indentedLine("}")); + + if (res.isEmpty()) + return Collections.emptyList(); + else + return code; + } + } + } + + return Collections.emptyList(); + } + + /** */ + private boolean isCacheObject(TypeMirror type) { + return assignableFrom(type, type("org.apache.ignite.internal.processors.cache.CacheObject")); + } + + /** */ + private boolean isMessage(TypeMirror type) { + return assignableFrom(type, type(MESSAGE_INTERFACE)); + } + + /** True if {@code te} extends {@code CacheIdAware} and therefore carries its own per-cache {@code cacheId()}. */ + private boolean isCacheIdAwareMessage(TypeElement te) { + return assignableFrom(te.asType(), type("org.apache.ignite.plugin.extensions.communication.CacheIdAware")); + } + + /** */ + private String fieldAccessor(VariableElement field) { + String name = field.getSimpleName().toString(); + + return "msg." + name; + } + + /** */ + private Element element(TypeMirror type) { + return type.getKind() == TypeKind.DECLARED ? + ((DeclaredType)type).asElement() : + ((DeclaredType)((TypeVariable)type).getUpperBound()).asElement(); } /** @@ -262,57 +587,31 @@ private void generateMethods(List fields) throws Exception { private void start(Collection code, boolean write) { indent = 1; - code.add(identedLine(METHOD_JAVADOC)); + code.add(indentedLine(METHOD_JAVADOC)); - code.add(identedLine("@Override public boolean %s(" + type.getSimpleName() + " msg, %s) {", + code.add(indentedLine("@Override public boolean %s(" + simpleNameWithGeneric(type) + " msg, %s) {", write ? "writeTo" : "readFrom", write ? "MessageWriter writer" : "MessageReader reader")); indent++; if (write) { - code.add(identedLine("if (!writer.isHeaderWritten()) {")); + code.add(indentedLine("if (!writer.isHeaderWritten()) {")); indent++; returnFalseIfWriteFailed(code, "writer.writeHeader", "directType()"); - if (write && marshallableMessage()) { - imports.add("org.apache.ignite.IgniteCheckedException"); - imports.add("org.apache.ignite.IgniteException"); - - code.add(EMPTY); - - code.add(identedLine("try {")); - - indent++; - - code.add(identedLine("msg.prepareMarshal(marshaller);")); - - indent--; - - code.add(identedLine("}")); - code.add(identedLine("catch (IgniteCheckedException e) {")); - - indent++; - - code.add(identedLine("throw new IgniteException(\"Failed to marshal object \" + msg.getClass().getSimpleName(), e);")); - - indent--; - - code.add(identedLine("}")); - } - code.add(EMPTY); - code.add(identedLine("writer.onHeaderWritten();")); + code.add(indentedLine("writer.onHeaderWritten();")); indent--; - code.add(identedLine("}")); + code.add(indentedLine("}")); code.add(EMPTY); } - code.add(identedLine("switch (%s.state()) {", write ? "writer" : "reader")); + code.add(indentedLine("switch (%s.state()) {", write ? "writer" : "reader")); } /** @@ -341,14 +640,14 @@ private void processField(VariableElement field, int opt) throws Exception { * @param opt Case option. */ private void writeField(VariableElement field, int opt) throws Exception { - write.add(identedLine("case %d:", opt)); + write.add(indentedLine("case %d:", opt)); indent++; returnFalseIfWriteFailed(field); write.add(EMPTY); - write.add(identedLine("writer.incrementState();")); + write.add(indentedLine("writer.incrementState();")); write.add(EMPTY); indent--; @@ -369,14 +668,14 @@ private void writeField(VariableElement field, int opt) throws Exception { * @param opt Case option. */ private void readField(VariableElement field, int opt) throws Exception { - read.add(identedLine("case %d:", opt)); + read.add(indentedLine("case %d:", opt)); indent++; returnFalseIfReadFailed(field); read.add(EMPTY); - read.add(identedLine("reader.incrementState();")); + read.add(indentedLine("reader.incrementState();")); read.add(EMPTY); indent--; @@ -541,11 +840,11 @@ private String typeNameToFieldName(String typeName) { private void returnFalseIfWriteFailed(Collection code, String accessor, @Nullable String... args) { String argsStr = String.join(", ", args); - code.add(identedLine("if (!%s(msg.%s))", accessor, argsStr)); + code.add(indentedLine("if (!%s(msg.%s))", accessor, argsStr)); indent++; - code.add(identedLine(RETURN_FALSE_STMT)); + code.add(indentedLine(RETURN_FALSE_STMT)); indent--; } @@ -557,15 +856,15 @@ private void returnFalseIfWriteFailed(Collection code, VariableElement f String argsStr = String.join(", ", args); if (type.equals(field.getEnclosingElement())) - code.add(identedLine("if (!%s(msg.%s))", accessor, argsStr)); + code.add(indentedLine("if (!%s(msg.%s))", accessor, argsStr)); else { // Field has to be requested from a super class object. - code.add(identedLine("if (!%s(((%s)msg).%s))", accessor, field.getEnclosingElement().getSimpleName(), argsStr)); + code.add(indentedLine("if (!%s(((%s)msg).%s))", accessor, field.getEnclosingElement().getSimpleName(), argsStr)); } indent++; - code.add(identedLine(RETURN_FALSE_STMT)); + code.add(indentedLine(RETURN_FALSE_STMT)); indent--; } @@ -580,16 +879,16 @@ private void returnFalseIfEnumWriteFailed( String mapperCall, String fieldGetterCall) { if (type.equals(field.getEnclosingElement())) - code.add(identedLine("if (!%s(%s(msg.%s)))", writerCall, mapperCall, fieldGetterCall)); + code.add(indentedLine("if (!%s(%s(msg.%s)))", writerCall, mapperCall, fieldGetterCall)); else { // Field has to be requested from a super class object. - code.add(identedLine("if (!%s(%s(((%s)msg).%s)))", + code.add(indentedLine("if (!%s(%s(((%s)msg).%s)))", writerCall, mapperCall, field.getEnclosingElement().getSimpleName(), fieldGetterCall)); } indent++; - code.add(identedLine(RETURN_FALSE_STMT)); + code.add(indentedLine(RETURN_FALSE_STMT)); indent--; } @@ -886,20 +1185,20 @@ private void returnFalseIfReadFailed(VariableElement field, String mtd, String.. String argsStr = String.join(", ", args); if (type.equals(field.getEnclosingElement())) - read.add(identedLine("msg.%s = %s(%s);", field.getSimpleName().toString(), mtd, argsStr)); + read.add(indentedLine("msg.%s = %s(%s);", field.getSimpleName().toString(), mtd, argsStr)); else { // Field has to be requested from a super class object. - read.add(identedLine("((%s)msg).%s = %s(%s);", + read.add(indentedLine("((%s)msg).%s = %s(%s);", field.getEnclosingElement().getSimpleName(), field.getSimpleName().toString(), mtd, argsStr)); } read.add(EMPTY); - read.add(identedLine("if (!reader.isLastRead())")); + read.add(indentedLine("if (!reader.isLastRead())")); indent++; - read.add(identedLine(RETURN_FALSE_STMT)); + read.add(indentedLine(RETURN_FALSE_STMT)); indent--; } @@ -918,61 +1217,35 @@ private void returnFalseIfEnumReadFailed(VariableElement field, String mapperDec readOp = line("%s(%s, reader.readByte())", mapperDecodeCallStmnt, enumValuesFieldName); if (type.equals(field.getEnclosingElement())) - read.add(identedLine("msg.%s = %s;", field.getSimpleName().toString(), readOp)); + read.add(indentedLine("msg.%s = %s;", field.getSimpleName().toString(), readOp)); else { // Field has to be requested from a super class object. - read.add(identedLine("((%s)msg).%s = %s;", + read.add(indentedLine("((%s)msg).%s = %s;", field.getEnclosingElement().getSimpleName(), field.getSimpleName().toString(), readOp)); } read.add(EMPTY); - read.add(identedLine("if (!reader.isLastRead())")); + read.add(indentedLine("if (!reader.isLastRead())")); indent++; - read.add(identedLine(RETURN_FALSE_STMT)); + read.add(indentedLine(RETURN_FALSE_STMT)); indent--; } /** */ - private void finish(List code, boolean read, boolean marshallable) { + private void finish(List code) { String lastLine = code.get(code.size() - 1); if (EMPTY.equals(lastLine)) code.remove(code.size() - 1); - code.add(identedLine("}")); + code.add(indentedLine("}")); code.add(EMPTY); - if (read && marshallable) { - imports.add("org.apache.ignite.IgniteCheckedException"); - imports.add("org.apache.ignite.IgniteException"); - - code.add(identedLine("try {")); - - indent++; - - code.add(identedLine("msg.finishUnmarshal(marshaller, clsLdr);")); - - indent--; - - code.add(identedLine("}")); - code.add(identedLine("catch (IgniteCheckedException e) {")); - - indent++; - - code.add(identedLine("throw new IgniteException(\"Failed to unmarshal object \" + msg.getClass().getSimpleName(), e);")); - - indent--; - - code.add(identedLine("}")); - - code.add(EMPTY); - } - - code.add(identedLine("return true;")); + code.add(indentedLine("return true;")); } /** @@ -980,7 +1253,7 @@ private void finish(List code, boolean read, boolean marshallable) { * * @return Line with current indent. */ - private String identedLine(String format, Object... args) { + private String indentedLine(String format, Object... args) { SB sb = new SB(); for (int i = 0; i < indent; i++) @@ -1012,9 +1285,9 @@ private void writeClassFields(Writer writer) throws IOException { indent = 1; for (String field: fields) { - writer.write(identedLine(METHOD_JAVADOC)); + writer.write(indentedLine(METHOD_JAVADOC)); writer.write(NL); - writer.write(identedLine(field)); + writer.write(indentedLine(field)); writer.write(NL); } writer.write(NL); @@ -1054,7 +1327,7 @@ private void writeClassHeader(Writer writer, String pkgName, String serClsName) writer.write(CLS_JAVADOC); writer.write(NL); - writer.write("public class " + serClsName + " implements MessageSerializer<" + type.getSimpleName() + "> {" + NL); + writer.write("public class " + serClsName + " implements MessageSerializer<" + simpleNameWithGeneric(type) + "> {" + NL); } /** */ @@ -1150,4 +1423,23 @@ private void checkTypeForCompress(TypeMirror type) { throw new IllegalArgumentException("Compress annotation is used for an unsupported type: " + type); } + + /** @return Simple class name. */ + private String simpleNameWithGeneric(TypeElement te) { + if (F.size(te.getTypeParameters()) == 0) + return te.getSimpleName().toString(); + + StringBuilder generic = new StringBuilder(te.getSimpleName() + "<"); + + for (int i = 0; i < F.size(te.getTypeParameters()); i++) { + if (i > 0) + generic.append(", "); + + generic.append("?"); + } + + generic.append(">"); + + return generic.toString(); + } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridEventConsumeHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/GridEventConsumeHandler.java index 1ac2ce2bc9227..354284e03ed0f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/GridEventConsumeHandler.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/GridEventConsumeHandler.java @@ -563,7 +563,7 @@ void p2pUnmarshal(Marshaller marsh, @Nullable ClassLoader ldr) throws IgniteChec } /** {@inheritDoc} */ - @Override public void prepare(GridDeploymentInfo depInfo) { + @Override public void prepareDeployment(GridDeploymentInfo depInfo) { assert evt instanceof CacheEvent; this.depInfo = depInfo; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java index d62afb99c957b..6e4e609f596dc 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java @@ -1314,7 +1314,7 @@ else if (e instanceof IgniteCheckedException) } /** */ - private void initMessageFactory() throws IgniteCheckedException { + public void initMessageFactory() throws IgniteCheckedException { MessageFactoryProvider[] msgs = ctx.plugins().extensions(MessageFactoryProvider.class); List compMsgs = new ArrayList<>(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/TxEntriesInfo.java b/modules/core/src/main/java/org/apache/ignite/internal/TxEntriesInfo.java index a5a9fcc6bc2f7..25f04b06f2bbb 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/TxEntriesInfo.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/TxEntriesInfo.java @@ -20,7 +20,6 @@ import java.util.Collection; import java.util.HashSet; import java.util.Objects; -import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheMapEntry; import org.apache.ignite.internal.processors.cache.KeyCacheObject; @@ -65,16 +64,6 @@ public TxEntriesInfo() { return; } - try { - for (KeyCacheObject key : keys) - key.finishUnmarshal(cctx.cacheObjectContext(), null); - } - catch (IgniteCheckedException e) { - ctx.cluster().diagnosticLog().error("Failed to unmarshal key: " + e, e); - - sb.append("Failed to unmarshal key: ").append(e).append(U.nl()); - } - sb.append("Cache entries [cacheId=").append(cacheId) .append(", cacheName=").append(cctx.name()).append("]: "); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/CompressedMessageSerializer.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/CompressedMessageSerializer.java index 594aab336e02d..992b798a3bb0c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/CompressedMessageSerializer.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/CompressedMessageSerializer.java @@ -27,6 +27,10 @@ /** Message serializer for compressed message. */ public class CompressedMessageSerializer implements MessageSerializer { + /** */ + public CompressedMessageSerializer(ClassLoader clsLdr) { + } + /** {@inheritDoc} */ @Override public boolean writeTo(CompressedMessage msg, MessageWriter writer) { if (!writer.isHeaderWritten()) { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java index 3acf503561ad8..491203ec6e6a1 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java @@ -128,6 +128,7 @@ import org.apache.ignite.plugin.extensions.communication.MessageFactory; import org.apache.ignite.plugin.extensions.communication.MessageFormatter; import org.apache.ignite.plugin.extensions.communication.MessageReader; +import org.apache.ignite.plugin.extensions.communication.MessageSerializer; import org.apache.ignite.plugin.extensions.communication.MessageWriter; import org.apache.ignite.spi.IgniteSpiException; import org.apache.ignite.spi.communication.CommunicationListener; @@ -465,6 +466,9 @@ public void resetMetrics() { msg.getClass().getName() + ". Most likely GridCommunicationSpi is being used directly, " + "which is illegal - make sure to send messages only via GridProjection API."); } + catch (IgniteCheckedException e) { + throw new IgniteException(e); + } } @Override public void onDisconnected(UUID nodeId) { @@ -1193,10 +1197,14 @@ private void onChannelOpened0(UUID rmtNodeId, GridIoMessage initMsg, Channel cha * @param msg Message bytes. * @param msgC Closure to call when message processing finished. */ - private void onMessage0(UUID nodeId, GridIoMessage msg, IgniteRunnable msgC) { + private void onMessage0(UUID nodeId, GridIoMessage msg, IgniteRunnable msgC) throws IgniteCheckedException { assert nodeId != null; assert msg != null; + MessageSerializer ser = ctx.messageFactory().serializer(msg.directType()); + + ser.finishUnmarshal(msg, ctx, null); + Lock busyLock0 = busyLock.readLock(); busyLock0.lock(); @@ -1929,6 +1937,10 @@ private IgniteInternalFuture openChannel( false ); + MessageSerializer ser = ctx.messageFactory().serializer(ioMsg.directType()); + + ser.prepareMarshal(ioMsg, ctx, null); + try { return ((TcpCommunicationSpi)(CommunicationSpi)getSpi()).openChannel(node, ioMsg); } @@ -1978,6 +1990,10 @@ private void send( GridIoMessage ioMsg = createGridIoMessage(topic, msg, plc, ordered, timeout, skipOnTimeout); + MessageSerializer ser = ctx.messageFactory().serializer(ioMsg.directType()); + + ser.prepareMarshal(ioMsg, ctx, null); + if (locNodeId.equals(node.id())) { assert plc != P2P_POOL; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/plugin/AbstractMarshallableMessageFactoryProvider.java b/modules/core/src/main/java/org/apache/ignite/internal/plugin/AbstractMarshallableMessageFactoryProvider.java index 5ac1f2472997f..39e3dffedc3e3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/plugin/AbstractMarshallableMessageFactoryProvider.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/plugin/AbstractMarshallableMessageFactoryProvider.java @@ -73,7 +73,7 @@ protected static void register(MessageFactory factory, Class serializer = marshallable ? (MessageSerializer)serCls.getConstructor(Marshaller.class, ClassLoader.class).newInstance(marsh, clsLrd) - : (MessageSerializer)serCls.getConstructor().newInstance(); + : (MessageSerializer)serCls.getConstructor(ClassLoader.class).newInstance(clsLrd); } catch (Exception e) { throw new IgniteException("Failed to register message of type " + cls.getSimpleName(), e); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryPredicate.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryPredicate.java index 36312a1591135..d8c8e7083ee62 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryPredicate.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryPredicate.java @@ -17,7 +17,6 @@ package org.apache.ignite.internal.processors.cache; -import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.lang.IgnitePredicate; import org.apache.ignite.plugin.extensions.communication.Message; @@ -25,19 +24,6 @@ * */ public interface CacheEntryPredicate extends IgnitePredicate, Message { - /** - * @param ctx Context. - * @throws IgniteCheckedException If failed. - */ - public void prepareMarshal(GridCacheContext ctx) throws IgniteCheckedException; - - /** - * @param ctx Context. - * @param ldr Class loader. - * @throws IgniteCheckedException If failed. - */ - public void finishUnmarshal(GridCacheContext ctx, ClassLoader ldr) throws IgniteCheckedException; - /** * @param locked Entry locked */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryPredicateAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryPredicateAdapter.java index 0c30dc615aa66..d41a3da341e63 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryPredicateAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheEntryPredicateAdapter.java @@ -18,7 +18,6 @@ package org.apache.ignite.internal.processors.cache; import java.util.Objects; -import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.binary.BinaryObject; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.util.tostring.GridToStringInclude; @@ -118,17 +117,4 @@ public CacheEntryPredicateType type() { throw new IllegalStateException("Unknown cache entry predicate type: " + type); } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheContext ctx, ClassLoader ldr) throws IgniteCheckedException { - if (type == CacheEntryPredicateType.VALUE) - val.finishUnmarshal(ctx.cacheObjectContext(), ldr); - } - - /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheContext ctx) throws IgniteCheckedException { - if (type == CacheEntryPredicateType.VALUE) - val.prepareMarshal(ctx.cacheObjectContext()); - } - } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheInvokeDirectResult.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheInvokeDirectResult.java index 1276c6b63c82c..4490be4c1dfc9 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheInvokeDirectResult.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheInvokeDirectResult.java @@ -19,7 +19,6 @@ import javax.cache.processor.EntryProcessor; import javax.cache.processor.MutableEntry; -import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.managers.communication.ErrorMessage; import org.apache.ignite.internal.util.tostring.GridToStringInclude; @@ -111,19 +110,6 @@ public CacheObject result() { return ErrorMessage.error(errMsg); } - /** - * @param ctx Cache context. - * @throws IgniteCheckedException If failed. - */ - public void prepareMarshal(GridCacheContext ctx) throws IgniteCheckedException { - key.prepareMarshal(ctx.cacheObjectContext()); - - assert unprepareRes == null : "marshalResult() was not called for the result: " + this; - - if (res != null) - res.prepareMarshal(ctx.cacheObjectContext()); - } - /** * Converts the entry processor unprepared result to a cache object instance. * @@ -139,19 +125,6 @@ public void marshalResult(GridCacheContext ctx) { } } - /** - * @param ctx Cache context. - * @param ldr Class loader. - * @throws IgniteCheckedException If failed. - */ - public void finishUnmarshal(GridCacheContext ctx, ClassLoader ldr) throws IgniteCheckedException { - key.finishUnmarshal(ctx.cacheObjectContext(), ldr); - - if (res != null) - res.finishUnmarshal(ctx.cacheObjectContext(), ldr); - } - - /** {@inheritDoc} */ @Override public String toString() { return S.toString(CacheInvokeDirectResult.class, this); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheDeployable.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheDeployable.java index 057ce897bac52..9d8f289bbe1c1 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheDeployable.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheDeployable.java @@ -28,7 +28,7 @@ public interface GridCacheDeployable { * * @param depInfo Deployment information. */ - public void prepare(GridDeploymentInfo depInfo); + public void prepareDeployment(GridDeploymentInfo depInfo); /** * @return Deployment bean. diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheDeploymentManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheDeploymentManager.java index ce2ceaa577771..29abdca600257 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheDeploymentManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheDeploymentManager.java @@ -411,7 +411,7 @@ public void prepare(GridCacheDeployable deployable) throws IgnitePeerToPeerClass checkDeploymentIsCorrect(dep, deployable, true); if (dep != null) - deployable.prepare(dep); + deployable.prepareDeployment(dep); if (log.isDebugEnabled()) log.debug("Prepared grid cache deployable [dep=" + dep + ", deployable=" + deployable + ']'); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryInfo.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryInfo.java index d8d710f62368f..86917aeb48573 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryInfo.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryInfo.java @@ -18,17 +18,19 @@ package org.apache.ignite.internal.processors.cache; import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.MarshallableMessage; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; 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.plugin.extensions.communication.Message; +import org.apache.ignite.marshaller.Marshaller; +import org.apache.ignite.plugin.extensions.communication.CacheIdAware; /** * Entry information that gets passed over wire. */ -public class GridCacheEntryInfo implements Message { +public class GridCacheEntryInfo implements MarshallableMessage, CacheIdAware { /** */ private static final int SIZE_OVERHEAD = 3 * 8 /* reference */ + 4 /* int */ + 2 * 8 /* long */ + 32 /* version */; @@ -63,10 +65,8 @@ public class GridCacheEntryInfo implements Message { /** Deleted flag. */ private boolean deleted; - /** - * @return Cache ID. - */ - public int cacheId() { + /** {@inheritDoc} */ + @Override public int cacheId() { return cacheId; } @@ -175,16 +175,6 @@ public void setDeleted(boolean deleted) { this.deleted = deleted; } - /** - * @param ctx Context. - * @param ldr Loader. - * @throws IgniteCheckedException If failed. - */ - public void unmarshalValue(GridCacheContext ctx, ClassLoader ldr) throws IgniteCheckedException { - if (val != null) - val.finishUnmarshal(ctx.cacheObjectContext(), ldr); - } - /** * @param ctx Cache object context. * @return Marshalled size. @@ -201,26 +191,8 @@ public int marshalledSize(CacheObjectContext ctx) throws IgniteCheckedException return SIZE_OVERHEAD + size; } - /** - * @param ctx Cache context. - * @throws IgniteCheckedException In case of error. - */ - public void marshal(GridCacheContext ctx) throws IgniteCheckedException { - marshal(ctx.cacheObjectContext()); - } - - /** - * @param ctx Cache context. - * @throws IgniteCheckedException In case of error. - */ - public void marshal(CacheObjectContext ctx) throws IgniteCheckedException { - assert key != null; - - key.prepareMarshal(ctx); - - if (val != null) - val.prepareMarshal(ctx); - + /** {@inheritDoc} */ + @Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException { if (expireTime == 0) expireTime = -1; else { @@ -231,30 +203,8 @@ public void marshal(CacheObjectContext ctx) throws IgniteCheckedException { } } - /** - * Unmarshalls entry. - * - * @param ctx Cache context. - * @param clsLdr Class loader. - * @throws IgniteCheckedException If unmarshalling failed. - */ - public void unmarshal(GridCacheContext ctx, ClassLoader clsLdr) throws IgniteCheckedException { - unmarshal(ctx.cacheObjectContext(), clsLdr); - } - - /** - * Unmarshalls entry. - * - * @param ctx Cache context. - * @param clsLdr Class loader. - * @throws IgniteCheckedException If unmarshalling failed. - */ - public void unmarshal(CacheObjectContext ctx, ClassLoader clsLdr) throws IgniteCheckedException { - key.finishUnmarshal(ctx, clsLdr); - - if (val != null) - val.finishUnmarshal(ctx, clsLdr); - + /** {@inheritDoc} */ + @Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException { long remaining = expireTime; expireTime = remaining < 0 ? 0 : U.currentTimeMillis() + remaining; @@ -263,7 +213,7 @@ public void unmarshal(CacheObjectContext ctx, ClassLoader clsLdr) throws IgniteC if (expireTime < 0) expireTime = 0; } - + /** {@inheritDoc} */ @Override public String toString() { return S.toString(GridCacheEntryInfo.class, this); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIdMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIdMessage.java index f0ebb72b7b5b1..1236d67451ac1 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIdMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIdMessage.java @@ -20,20 +20,19 @@ 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.CacheIdAware; /** * Message related to particular cache. */ -public abstract class GridCacheIdMessage extends GridCacheMessage { +public abstract class GridCacheIdMessage extends GridCacheMessage implements CacheIdAware { /** Cache ID. */ @GridToStringInclude @Order(0) public int cacheId; - /** - * @return Cache ID. - */ - public int cacheId() { + /** {@inheritDoc} */ + @Override public int cacheId() { return cacheId; } 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 4dfdb6b35997d..f6fb1ab0d42ef 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 @@ -92,6 +92,7 @@ import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteBiInClosure; import org.apache.ignite.lang.IgniteUuid; +import org.apache.ignite.plugin.extensions.communication.MessageSerializer; import org.apache.ignite.thread.IgniteThread; import org.jetbrains.annotations.Nullable; @@ -316,6 +317,15 @@ else if (desc.receivedFromStartVersion() != null) private void handleMessage(UUID nodeId, GridCacheMessage cacheMsg, byte plc) { MessageHandlers msgHandlers = cacheMsg instanceof GridCacheGroupIdMessage ? grpHandlers : cacheHandlers; + MessageSerializer ser = cctx.kernalContext().messageFactory().serializer(cacheMsg.directType()); + + try { + ser.finishUnmarshal(cacheMsg, cctx.kernalContext(), null); + } + catch (IgniteCheckedException e) { + throw new IgniteException("Failed to unmarshall entry", e); + } + Lock lock = rw.readLock(); lock.lock(); @@ -1095,7 +1105,7 @@ private boolean onSend(GridCacheMessage msg, @Nullable UUID destNodeId) throws I msg.messageId(idGen.incrementAndGet()); if (destNodeId == null || !cctx.localNodeId().equals(destNodeId)) { - msg.prepareMarshal(cctx); + msg.prepareDeployment(cctx); if (msg instanceof GridCacheDeployable && msg.addDeploymentInfo()) cctx.deploy().prepare((GridCacheDeployable)msg); @@ -1551,7 +1561,9 @@ private void unmarshall(UUID nodeId, GridCacheMessage cacheMsg) { log.debug("Set P2P context [senderId=" + nodeId + ", msg=" + cacheMsg + ']'); } - cacheMsg.finishUnmarshal(cctx, cctx.deploy().globalLoader()); + MessageSerializer ser = cctx.kernalContext().messageFactory().serializer(cacheMsg.directType()); + + ser.finishUnmarshal(cacheMsg, cctx.kernalContext(), null); } catch (IgniteCheckedException e) { cacheMsg.onClassError(e); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMessage.java index ec670da2d1cbf..52f7b0a8f2c09 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMessage.java @@ -32,7 +32,6 @@ import org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry; import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.T2; -import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.marshaller.Marshaller; @@ -204,8 +203,8 @@ public void lastAffinityChangedTopologyVersion(AffinityTopologyVersion topVer) { * @param ctx Context. * @throws IgniteCheckedException If failed. */ - protected final void prepareObject(@Nullable Object o, GridCacheContext ctx) throws IgniteCheckedException { - prepareObject(o, ctx.shared()); + protected final void prepareObjectDeployment(@Nullable Object o, GridCacheContext ctx) throws IgniteCheckedException { + prepareObjectDeployment(o, ctx.shared()); } /** @@ -213,14 +212,14 @@ protected final void prepareObject(@Nullable Object o, GridCacheContext ctx) thr * @param ctx Context. * @throws IgniteCheckedException If failed. */ - protected final void prepareObject(@Nullable Object o, GridCacheSharedContext ctx) throws IgniteCheckedException { + protected final void prepareObjectDeployment(@Nullable Object o, GridCacheSharedContext ctx) throws IgniteCheckedException { assert addDepInfo || forceAddDepInfo; if (!skipPrepare && o != null) { GridDeploymentInfo d = ctx.deploy().globalDeploymentInfo(); if (d != null) { - prepare(d); + prepareDeployment(d); // Global deployment has been injected. skipPrepare = true; @@ -233,16 +232,16 @@ protected final void prepareObject(@Nullable Object o, GridCacheSharedContext ct ClassLoader ldr = U.detectClassLoader(cls); if (ldr instanceof GridDeploymentInfo) - prepare((GridDeploymentInfo)ldr); + prepareDeployment((GridDeploymentInfo)ldr); } } } /** * @param depInfo Deployment to set. - * @see GridCacheDeployable#prepare(GridDeploymentInfo) + * @see GridCacheDeployable#prepareDeployment(GridDeploymentInfo) */ - public final void prepare(GridDeploymentInfo depInfo) { + public final void prepareDeployment(GridDeploymentInfo depInfo) { if (depInfo != this.depInfo) { if (this.depInfo != null && depInfo instanceof GridDeployment) // Make sure not to replace remote deployment with local. @@ -269,19 +268,7 @@ public GridDeploymentInfoBean deployInfo() { * @param ctx Cache context. * @throws IgniteCheckedException If failed. */ - public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - // No-op. - } - - /** - * This method is called after the message is deserialized and is responsible for - * unmarshalling state marshalled in {@link #prepareMarshal(GridCacheSharedContext)} method. - * - * @param ctx Context. - * @param ldr Class loader. - * @throws IgniteCheckedException If failed. - */ - public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { + public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { // No-op. } @@ -291,51 +278,34 @@ public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) t * @param cacheObjCtx Cache object context. * @throws IgniteCheckedException If failed. */ - protected final void marshalInfo(GridCacheEntryInfo info, + protected final void prepareInfoDeployment(GridCacheEntryInfo info, GridCacheSharedContext ctx, CacheObjectContext cacheObjCtx ) throws IgniteCheckedException { assert ctx != null; if (info != null) { - info.marshal(cacheObjCtx); - if (addDepInfo) { if (info.key() != null) - prepareObject(info.key().value(cacheObjCtx, false), ctx); + prepareObjectDeployment(info.key().value(cacheObjCtx, false), ctx); CacheObject val = info.value(); if (val != null) { val.finishUnmarshal(cacheObjCtx, ctx.deploy().globalLoader()); - prepareObject(val.value(cacheObjCtx, false), ctx); + prepareObjectDeployment(val.value(cacheObjCtx, false), ctx); } } } } - /** - * @param info Entry to unmarshal. - * @param ctx Context. - * @param ldr Loader. - * @throws IgniteCheckedException If failed. - */ - protected final void unmarshalInfo(GridCacheEntryInfo info, GridCacheContext ctx, - ClassLoader ldr) throws IgniteCheckedException { - assert ldr != null; - assert ctx != null; - - if (info != null) - info.unmarshal(ctx.cacheObjectContext(), ldr); - } - /** * @param infos Entries to marshal. * @param ctx Context. * @throws IgniteCheckedException If failed. */ - protected final void marshalInfos( + protected final void prepareInfosDeployment( Iterable infos, GridCacheSharedContext ctx, CacheObjectContext cacheObjCtx @@ -344,23 +314,7 @@ protected final void marshalInfos( if (infos != null) for (GridCacheEntryInfo e : infos) - marshalInfo(e, ctx, cacheObjCtx); - } - - /** - * @param infos Entries to unmarshal. - * @param ctx Context. - * @param ldr Loader. - * @throws IgniteCheckedException If failed. - */ - protected final void unmarshalInfos(Iterable infos, - GridCacheContext ctx, ClassLoader ldr) throws IgniteCheckedException { - assert ldr != null; - assert ctx != null; - - if (infos != null) - for (GridCacheEntryInfo e : infos) - unmarshalInfo(e, ctx, ldr); + prepareInfoDeployment(e, ctx, cacheObjCtx); } /** @@ -368,29 +322,26 @@ protected final void unmarshalInfos(Iterable infos * @param ctx Context. * @throws IgniteCheckedException If failed. */ - protected final void marshalTx(Iterable txEntries, GridCacheSharedContext ctx) + protected final void prepareTxDeployment(Iterable txEntries, GridCacheSharedContext ctx) throws IgniteCheckedException { assert ctx != null; if (txEntries != null) { - boolean transferExpiry = transferExpiryPolicy(); boolean p2pEnabled = ctx.deploymentEnabled(); for (IgniteTxEntry e : txEntries) { - e.marshal(ctx, transferExpiry); - GridCacheContext cctx = e.context(); if (addDepInfo) { if (e.key() != null) - prepareObject(e.key().value(cctx.cacheObjectContext(), false), ctx); + prepareObjectDeployment(e.key().value(cctx.cacheObjectContext(), false), ctx); if (e.value() != null) - prepareObject(e.value().value(cctx.cacheObjectContext(), false), ctx); + prepareObjectDeployment(e.value().value(cctx.cacheObjectContext(), false), ctx); if (e.entryProcessors() != null) { for (T2, Object[]> entProc : e.entryProcessors()) - prepareObject(entProc.get1(), ctx); + prepareObjectDeployment(entProc.get1(), ctx); } } else if (p2pEnabled && e.entryProcessors() != null) { @@ -398,117 +349,107 @@ else if (p2pEnabled && e.entryProcessors() != null) { forceAddDepInfo = true; for (T2, Object[]> entProc : e.entryProcessors()) - prepareObject(entProc.get1(), ctx); + prepareObjectDeployment(entProc.get1(), ctx); } } } } /** - * @return {@code True} if entries expire policy should be marshalled. - */ - protected boolean transferExpiryPolicy() { - return false; - } - - /** - * @param txEntries Entries to unmarshal. - * @param ctx Context. - * @param ldr Loader. + * @param args Arguments to marshal. + * @param marsh Marshaller. + * @return Marshalled collection. * @throws IgniteCheckedException If failed. */ - protected final void unmarshalTx(Iterable txEntries, - GridCacheSharedContext ctx, - ClassLoader ldr) throws IgniteCheckedException { - assert ldr != null; - assert ctx != null; + @Nullable protected final byte[][] marshallInvokeArguments(@Nullable Object[] args, Marshaller marsh) + throws IgniteCheckedException { - if (txEntries != null) { - for (IgniteTxEntry e : txEntries) { - e.prepareUnmarshal(ctx, topologyVersion(), false); + if (args == null || args.length == 0) + return null; - e.unmarshal(ctx, false, ldr); - } + byte[][] argsBytes = new byte[args.length][]; + + for (int i = 0; i < args.length; i++) { + Object arg = args[i]; + + argsBytes[i] = arg == null ? null : U.marshal(marsh, arg); } + + return argsBytes; } /** * @param args Arguments to marshal. * @param ctx Context. - * @return Marshalled collection. * @throws IgniteCheckedException If failed. */ - @Nullable protected final byte[][] marshalInvokeArguments(@Nullable Object[] args, GridCacheContext ctx) + @Nullable protected final void prepareInvokeArgumentsDeployment(@Nullable Object[] args, GridCacheContext ctx) throws IgniteCheckedException { assert ctx != null; - if (args == null || args.length == 0) - return null; - - byte[][] argsBytes = new byte[args.length][]; + if (args == null) + return; for (int i = 0; i < args.length; i++) { Object arg = args[i]; if (addDepInfo) - prepareObject(arg, ctx.shared()); - - argsBytes[i] = arg == null ? null : CU.marshal(ctx, arg); + prepareObjectDeployment(arg, ctx.shared()); } - - return argsBytes; } - /** * @param byteCol Collection to unmarshal. - * @param ctx Context. + * @param marsh Marshaller. * @param ldr Loader. * @return Unmarshalled collection. * @throws IgniteCheckedException If failed. */ @Nullable protected final Object[] unmarshalInvokeArguments(@Nullable byte[][] byteCol, - GridCacheSharedContext ctx, + Marshaller marsh, ClassLoader ldr) throws IgniteCheckedException { - assert ldr != null; - assert ctx != null; - if (byteCol == null) return null; Object[] args = new Object[byteCol.length]; - Marshaller marsh = ctx.marshaller(); - for (int i = 0; i < byteCol.length; i++) - args[i] = byteCol[i] == null ? null : U.unmarshal(marsh, byteCol[i], U.resolveClassLoader(ldr, ctx.gridConfig())); + args[i] = byteCol[i] == null ? null : U.unmarshal(marsh, byteCol[i], ldr); return args; } /** * @param col Collection to marshal. - * @param ctx Context. + * @param marsh Marshaller. * @return Marshalled collection. * @throws IgniteCheckedException If failed. */ - @Nullable protected List marshalCollection(@Nullable Collection col, - GridCacheContext ctx) throws IgniteCheckedException { - assert ctx != null; - + @Nullable protected List marshallCollection(@Nullable Collection col, Marshaller marsh) throws IgniteCheckedException { if (col == null) return null; List byteCol = new ArrayList<>(col.size()); + for (Object o : col) + byteCol.add(o == null ? null : U.marshal(marsh, o)); + + return byteCol; + } + + /** + * @param col Collection to marshal. + * @param ctx Context. + * @throws IgniteCheckedException If failed. + */ + @Nullable protected void prepareCollectionDeployment(@Nullable Collection col, + GridCacheContext ctx) throws IgniteCheckedException { + assert ctx != null; + for (Object o : col) { if (addDepInfo) - prepareObject(o, ctx.shared()); - - byteCol.add(o == null ? null : CU.marshal(ctx, o)); + prepareObjectDeployment(o, ctx.shared()); } - - return byteCol; } /** @@ -517,7 +458,7 @@ protected final void unmarshalTx(Iterable txEntries, * @throws IgniteCheckedException If failed. */ @SuppressWarnings("ForLoopReplaceableByForEach") - public final void prepareMarshalCacheObjects(@Nullable List col, + public final void prepareCacheObjectsDeployment(@Nullable List col, GridCacheContext ctx) throws IgniteCheckedException { if (col == null) return; @@ -525,7 +466,7 @@ public final void prepareMarshalCacheObjects(@Nullable List col, + protected final void prepareCacheObjectsDeployment(@Nullable Collection col, GridCacheContext ctx) throws IgniteCheckedException { if (col == null) return; for (CacheObject obj : col) { if (obj != null) { - obj.prepareMarshal(ctx.cacheObjectContext()); - if (addDepInfo) - prepareObject(obj.value(ctx.cacheObjectContext(), false), ctx.shared()); + prepareObjectDeployment(obj.value(ctx.cacheObjectContext(), false), ctx.shared()); } } } - /** - * @param col Collection. - * @param ctx Context. - * @param ldr Class loader. - * @throws IgniteCheckedException If failed. - */ - @SuppressWarnings("ForLoopReplaceableByForEach") - public final void finishUnmarshalCacheObjects(@Nullable List col, - GridCacheContext ctx, - ClassLoader ldr - ) throws IgniteCheckedException { - if (col == null) - return; - - int size = col.size(); - - for (int i = 0; i < size; i++) { - CacheObject obj = col.get(i); - - if (obj != null) - obj.finishUnmarshal(ctx.cacheObjectContext(), ldr); - } - } - - /** - * @param col Collection. - * @param ctx Context. - * @param ldr Class loader. - * @throws IgniteCheckedException If failed. - */ - protected final void finishUnmarshalCacheObjects(@Nullable Collection col, - GridCacheContext ctx, - ClassLoader ldr - ) throws IgniteCheckedException { - if (col == null) - return; - - for (CacheObject obj : col) { - if (obj != null) - obj.finishUnmarshal(ctx.cacheObjectContext(), ldr); - } - } - /** * @param byteCol Collection to unmarshal. - * @param ctx Context. + * @param marsh Marshaller. * @param ldr Loader. * @return Unmarshalled collection. * @throws IgniteCheckedException If failed. */ @Nullable protected List unmarshalCollection(@Nullable Collection byteCol, - GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - assert ldr != null; - assert ctx != null; - + Marshaller marsh, ClassLoader ldr) throws IgniteCheckedException { if (byteCol == null) return null; List col = new ArrayList<>(byteCol.size()); - Marshaller marsh = ctx.marshaller(); - for (byte[] bytes : byteCol) - col.add(bytes == null ? null : U.unmarshal(marsh, bytes, U.resolveClassLoader(ldr, ctx.gridConfig()))); + col.add(bytes == null ? null : U.unmarshal(marsh, bytes, ldr)); return col; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheReturn.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheReturn.java index 7c78a10a5cf48..bffb81619672c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheReturn.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheReturn.java @@ -31,13 +31,14 @@ import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.plugin.extensions.communication.CacheIdAware; import org.apache.ignite.plugin.extensions.communication.Message; import org.jetbrains.annotations.Nullable; /** * Return value for cases where both, value and success flag need to be returned. */ -public class GridCacheReturn implements Message { +public class GridCacheReturn implements Message, CacheIdAware { /** Value. */ @GridToStringInclude(sensitive = true) private volatile Object v; @@ -285,10 +286,8 @@ else if (err instanceof UnregisteredBinaryTypeException) } } - /** - * @return Cache ID. - */ - public int cacheId() { + /** {@inheritDoc} */ + @Override public int cacheId() { return cacheId; } @@ -328,22 +327,6 @@ public void marshalResult(GridCacheContext ctx) { } } - /** - * @param ctx Cache context. - * @throws IgniteCheckedException If failed. - */ - public void prepareMarshal(GridCacheContext ctx) throws IgniteCheckedException { - assert !loc; - - if (cacheObj != null) - cacheObj.prepareMarshal(ctx.cacheObjectContext()); - - if (invokeRes && invokeResCol != null) { - for (CacheInvokeDirectResult res : invokeResCol) - res.prepareMarshal(ctx); - } - } - /** * @param ctx Cache context. * @param ldr Class loader. @@ -352,16 +335,10 @@ public void prepareMarshal(GridCacheContext ctx) throws IgniteCheckedException { public void finishUnmarshal(GridCacheContext ctx, ClassLoader ldr) throws IgniteCheckedException { loc = true; - if (cacheObj != null) { - cacheObj.finishUnmarshal(ctx.cacheObjectContext(), ldr); - + if (cacheObj != null) v = ctx.cacheObjectContext().unwrapBinaryIfNeeded(cacheObj, true, false, ldr); - } if (invokeRes && invokeResCol != null) { - for (CacheInvokeDirectResult res : invokeResCol) - res.finishUnmarshal(ctx, ldr); - Map map0 = U.newHashMap(invokeResCol.size()); for (CacheInvokeDirectResult res : invokeResCol) { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheTtlUpdateRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheTtlUpdateRequest.java index c83e732f6181a..d8f00c54b6bfa 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheTtlUpdateRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheTtlUpdateRequest.java @@ -156,26 +156,14 @@ public List nearVersions() { } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); GridCacheContext cctx = ctx.cacheContext(cacheId); - prepareMarshalCacheObjects(keys, cctx); + prepareCacheObjectsDeployment(keys, cctx); - prepareMarshalCacheObjects(nearKeys, cctx); - } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) - throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - - GridCacheContext cctx = ctx.cacheContext(cacheId); - - finishUnmarshalCacheObjects(keys, cctx, ldr); - - finishUnmarshalCacheObjects(nearKeys, cctx, ldr); + prepareCacheObjectsDeployment(nearKeys, cctx); } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockRequest.java index b02d75024fec5..738e65620bed4 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockRequest.java @@ -348,24 +348,14 @@ public long timeout() { /** {@inheritDoc} * @param ctx*/ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); GridCacheContext cctx = ctx.cacheContext(cacheId); - prepareMarshalCacheObjects(keys, cctx); + prepareCacheObjectsDeployment(keys, cctx); } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - - GridCacheContext cctx = ctx.cacheContext(cacheId); - - finishUnmarshalCacheObjects(keys, cctx, ldr); - } - - + /** {@inheritDoc} */ @Override public String toString() { return S.toString(GridDistributedLockRequest.class, this, "keysCnt", retVals.length, diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockResponse.java index cbf10745a7a19..db26cf3901027 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockResponse.java @@ -161,20 +161,12 @@ protected int valuesSize() { /** {@inheritDoc} * @param ctx*/ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); - prepareMarshalCacheObjects(vals, ctx.cacheContext(cacheId)); + prepareCacheObjectsDeployment(vals, ctx.cacheContext(cacheId)); } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - - finishUnmarshalCacheObjects(vals, ctx.cacheContext(cacheId), ldr); - } - - + /** {@inheritDoc} */ @Override public String toString() { return S.toString(GridDistributedLockResponse.class, this, diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxPrepareRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxPrepareRequest.java index bd427bd47b56f..5e6a4242e95ba 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxPrepareRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedTxPrepareRequest.java @@ -25,8 +25,8 @@ import java.util.UUID; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteLogger; +import org.apache.ignite.internal.MarshallableMessage; import org.apache.ignite.internal.Order; -import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx; import org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry; @@ -38,6 +38,7 @@ import org.apache.ignite.internal.util.tostring.GridToStringExclude; import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.marshaller.Marshaller; import org.apache.ignite.transactions.TransactionConcurrency; import org.apache.ignite.transactions.TransactionIsolation; import org.jetbrains.annotations.Nullable; @@ -46,7 +47,7 @@ * Transaction prepare request for optimistic and eventually consistent * transactions. */ -public class GridDistributedTxPrepareRequest extends GridDistributedBaseMessage implements IgniteTxStateAware { +public class GridDistributedTxPrepareRequest extends GridDistributedBaseMessage implements IgniteTxStateAware, MarshallableMessage { /** */ private static final int NEED_RETURN_VALUE_FLAG_MASK = 0x01; @@ -372,54 +373,14 @@ public void applicationAttributes(Map appAttrs) { } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); if (writes != null) - marshalTx(writes, ctx); + prepareTxDeployment(writes, ctx); if (reads != null) - marshalTx(reads, ctx); - - if (dhtVers != null && dhtVerKeys == null) { - for (IgniteTxKey key : dhtVers.keySet()) { - GridCacheContext cctx = ctx.cacheContext(key.cacheId()); - - key.prepareMarshal(cctx); - } - - dhtVerKeys = dhtVers.keySet(); - dhtVerVals = dhtVers.values(); - } - } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - - if (writes != null) - unmarshalTx(writes, ctx, ldr); - - if (reads != null) - unmarshalTx(reads, ctx, ldr); - - if (dhtVerKeys != null && dhtVers == null) { - assert dhtVerVals != null; - assert dhtVerKeys.size() == dhtVerVals.size(); - - Iterator keyIt = dhtVerKeys.iterator(); - Iterator verIt = dhtVerVals.iterator(); - - dhtVers = U.newHashMap(dhtVerKeys.size()); - - while (keyIt.hasNext()) { - IgniteTxKey key = keyIt.next(); - - key.finishUnmarshal(ctx.cacheContext(key.cacheId()), ldr); - - dhtVers.put(key, verIt.next()); - } - } + prepareTxDeployment(reads, ctx); } /** {@inheritDoc} */ @@ -452,6 +413,32 @@ private boolean isFlag(int mask) { return (flags & mask) != 0; } + /** {@inheritDoc} */ + @Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException { + if (dhtVers != null && dhtVerKeys == null) { + dhtVerKeys = dhtVers.keySet(); + dhtVerVals = dhtVers.values(); + } + } + + /** {@inheritDoc} */ + @Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException { + if (dhtVerKeys != null && dhtVers == null) { + assert dhtVerVals != null; + assert dhtVerKeys.size() == dhtVerVals.size(); + + Iterator keyIt = dhtVerKeys.iterator(); + Iterator verIt = dhtVerVals.iterator(); + + dhtVers = U.newHashMap(dhtVerKeys.size()); + + while (keyIt.hasNext()) { + IgniteTxKey key = keyIt.next(); + + dhtVers.put(key, verIt.next()); + } + } + } /** {@inheritDoc} */ @Override public String toString() { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridNearUnlockRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridNearUnlockRequest.java index 7f46f96774850..3d93d9368e3f3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridNearUnlockRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridNearUnlockRequest.java @@ -95,25 +95,17 @@ public void addKey(KeyCacheObject key) { /** {@inheritDoc} * @param ctx*/ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); - prepareMarshalCacheObjects(keys, ctx.cacheContext(cacheId)); - } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - - finishUnmarshalCacheObjects(keys, ctx.cacheContext(cacheId), ldr); + prepareCacheObjectsDeployment(keys, ctx.cacheContext(cacheId)); } /** {@inheritDoc} */ @Override public IgniteLogger messageLogger(GridCacheSharedContext ctx) { return ctx.txLockMessageLogger(); } - - + /** {@inheritDoc} */ @Override public String toString() { return S.toString(GridNearUnlockRequest.class, this, "super", super.toString()); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java index 7277db3ccd698..ec2e09483c0d1 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtCacheAdapter.java @@ -1214,9 +1214,9 @@ protected void processNearSingleGetRequest(final UUID nodeId, final GridNearSing res0 = info; } else if (req.needVersion()) - res0 = new CacheVersionedValue(info.value(), info.version()); + res0 = new CacheVersionedValue(info.value(), info.version(), info.cacheId()); else - res0 = new CacheVersionedValue(info.value(), null); + res0 = new CacheVersionedValue(info.value(), null, info.cacheId()); } res = new GridNearSingleGetResponse( diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockRequest.java index 315997cecd8a6..70afa43649dda 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockRequest.java @@ -21,9 +21,9 @@ import java.util.Map; import java.util.UUID; import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.MarshallableMessage; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; -import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.processors.cache.distributed.GridDistributedLockRequest; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; @@ -32,6 +32,7 @@ import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.lang.IgniteUuid; +import org.apache.ignite.marshaller.Marshaller; import org.apache.ignite.transactions.TransactionIsolation; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -39,7 +40,7 @@ /** * DHT lock request. */ -public class GridDhtLockRequest extends GridDistributedLockRequest { +public class GridDhtLockRequest extends GridDistributedLockRequest implements MarshallableMessage { /** Invalidate reader flags. */ @Order(0) BitSet invalidateEntries; @@ -257,9 +258,7 @@ public long accessTtl() { } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); - + @Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException { if (owned != null && ownedKeys == null) { ownedKeys = new KeyCacheObject[owned.size()]; ownedValues = new GridCacheVersion[ownedKeys.length]; @@ -275,23 +274,18 @@ public long accessTtl() { } /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - + @Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException { if (ownedKeys != null) { owned = new GridLeanMap<>(ownedKeys.length); - for (int i = 0; i < ownedKeys.length; i++) { - ownedKeys[i].finishUnmarshal(ctx.cacheContext(cacheId).cacheObjectContext(), ldr); + for (int i = 0; i < ownedKeys.length; i++) owned.put(ownedKeys[i], ownedValues[i]); - } ownedKeys = null; ownedValues = null; } } - /** {@inheritDoc} */ @Override public String toString() { return S.toString(GridDhtLockRequest.class, this, "super", super.toString()); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockResponse.java index e73f606c827eb..c6528afb1092a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtLockResponse.java @@ -124,24 +124,15 @@ public Collection preloadEntries() { } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); GridCacheContext cctx = ctx.cacheContext(cacheId); if (preloadEntries != null) - marshalInfos(preloadEntries, cctx.shared(), cctx.cacheObjectContext()); + prepareInfosDeployment(preloadEntries, cctx.shared(), cctx.cacheObjectContext()); } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - - if (preloadEntries != null) - unmarshalInfos(preloadEntries, ctx.cacheContext(cacheId), ldr); - } - - + /** {@inheritDoc} */ @Override public String toString() { return S.toString(GridDhtLockResponse.class, this, super.toString()); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishResponse.java index 352281f9b57c8..62c327c8d7ce5 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxFinishResponse.java @@ -17,12 +17,9 @@ package org.apache.ignite.internal.processors.cache.distributed.dht; -import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.managers.communication.ErrorMessage; -import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheReturn; -import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.distributed.GridDistributedTxFinishResponse; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; import org.apache.ignite.internal.util.typedef.internal.S; @@ -118,33 +115,6 @@ public boolean checkCommitted() { return checkCommitted; } - /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); - - if (retVal != null && retVal.cacheId() != 0) { - GridCacheContext cctx = ctx.cacheContext(retVal.cacheId()); - - assert cctx != null : retVal.cacheId(); - - retVal.prepareMarshal(cctx); - } - } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) - throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - - if (retVal != null && retVal.cacheId() != 0) { - GridCacheContext cctx = ctx.cacheContext(retVal.cacheId()); - - assert cctx != null : retVal.cacheId(); - - retVal.finishUnmarshal(cctx, ldr); - } - } - /** * @param retVal Return value. */ @@ -158,8 +128,7 @@ public void returnValue(GridCacheReturn retVal) { public GridCacheReturn returnValue() { return retVal; } - - + /** {@inheritDoc} */ @Override public String toString() { return S.toString(GridDhtTxFinishResponse.class, this, "super", super.toString()); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocalAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocalAdapter.java index af3655f3b2ffb..45ab9b9cfd746 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocalAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocalAdapter.java @@ -496,7 +496,7 @@ private void addMapping( assert state == PREPARING : "Invalid tx state for " + "adding entry [msgId=" + msgId + ", e=" + e + ", tx=" + this + ']'; - e.unmarshal(cctx, false, cctx.deploy().globalLoader()); + e.initializeContext(cctx, false); checkInternal(e.txKey()); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareRequest.java index f8364dca6adb1..2486903e85f77 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareRequest.java @@ -17,7 +17,6 @@ package org.apache.ignite.internal.processors.cache.distributed.dht; -import java.util.ArrayList; import java.util.BitSet; import java.util.Collection; import java.util.Collections; @@ -26,6 +25,7 @@ import java.util.Map; import java.util.UUID; import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.MarshallableMessage; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.GridCacheContext; @@ -39,12 +39,13 @@ import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteUuid; +import org.apache.ignite.marshaller.Marshaller; import org.jetbrains.annotations.Nullable; /** * DHT prepare request. */ -public class GridDhtTxPrepareRequest extends GridDistributedTxPrepareRequest { +public class GridDhtTxPrepareRequest extends GridDistributedTxPrepareRequest implements MarshallableMessage { /** Max order. */ @Order(0) UUID nearNodeId; @@ -320,32 +321,33 @@ public boolean skipCompletedVersion() { * * @param ctx */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); if (owned != null && ownedKeys == null) { - ownedKeys = owned.keySet(); - - ownedVals = owned.values(); - - for (IgniteTxKey key: ownedKeys) { + for (IgniteTxKey key: owned.keySet()) { GridCacheContext cctx = ctx.cacheContext(key.cacheId()); - key.prepareMarshal(cctx); - if (addDepInfo) - prepareObject(key, cctx); + prepareObjectDeployment(key, cctx); } } if (nearWrites != null) - marshalTx(nearWrites, ctx); + prepareTxDeployment(nearWrites, ctx); } /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); + @Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException { + if (owned != null && ownedKeys == null) { + ownedKeys = owned.keySet(); + + ownedVals = owned.values(); + } + } + /** {@inheritDoc} */ + @Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException { if (ownedKeys != null) { assert ownedKeys.size() == ownedVals.size(); @@ -358,40 +360,11 @@ public boolean skipCompletedVersion() { while (keyIter.hasNext()) { IgniteTxKey key = keyIter.next(); - GridCacheContext cacheCtx = ctx.cacheContext(key.cacheId()); - - if (cacheCtx != null) { - key.finishUnmarshal(cacheCtx, ldr); - - owned.put(key, valIter.next()); - } - } - } - - if (nearWrites != null) { - for (Iterator it = nearWrites.iterator(); it.hasNext();) { - IgniteTxEntry e = it.next(); - - GridCacheContext cacheCtx = ctx.cacheContext(e.cacheId()); - - if (cacheCtx == null) { - it.remove(); - - if (nearWritesCacheMissed == null) - nearWritesCacheMissed = new ArrayList<>(); - - nearWritesCacheMissed.add(e.txKey()); - } - else { - e.context(cacheCtx); - - e.unmarshal(ctx, true, ldr); - } + owned.put(key, valIter.next()); } } } - - + /** {@inheritDoc} */ @Override public int partition() { return U.safeAbs(version().hashCode()); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareResponse.java index 921f52790252b..f4ad3faa6bd50 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareResponse.java @@ -21,11 +21,8 @@ import java.util.Collection; import java.util.List; import java.util.Map; -import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.Order; -import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheEntryInfo; -import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.distributed.GridDistributedTxPrepareResponse; import org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; @@ -169,51 +166,6 @@ public void addPreloadEntry(GridCacheEntryInfo info) { preloadEntries.add(info); } - /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); - - if (nearEvicted != null) { - for (IgniteTxKey key : nearEvicted) { - GridCacheContext cctx = ctx.cacheContext(key.cacheId()); - - // Can be null if client near cache was removed, in this case assume do not need prepareMarshal. - if (cctx != null) - key.prepareMarshal(cctx); - } - } - - if (preloadEntries != null) { - for (GridCacheEntryInfo info : preloadEntries) { - GridCacheContext cctx = ctx.cacheContext(info.cacheId()); - - info.marshal(cctx); - } - } - } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - - if (nearEvicted != null) { - for (IgniteTxKey key : nearEvicted) { - GridCacheContext cctx = ctx.cacheContext(key.cacheId()); - - key.finishUnmarshal(cctx, ldr); - } - } - - if (preloadEntries != null) { - for (GridCacheEntryInfo info : preloadEntries) { - GridCacheContext cctx = ctx.cacheContext(info.cacheId()); - - info.unmarshal(cctx, ldr); - } - } - } - - /** {@inheritDoc} */ @Override public String toString() { return S.toString(GridDhtTxPrepareResponse.class, this, diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxRemote.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxRemote.java index e60041e34ed06..3c5ff043e389d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxRemote.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxRemote.java @@ -276,7 +276,7 @@ public UUID nearNodeId() { * @throws IgniteCheckedException If failed. */ public void addWrite(IgniteTxEntry entry, ClassLoader ldr) throws IgniteCheckedException { - entry.unmarshal(cctx, false, ldr); + entry.initializeContext(cctx, false); GridCacheContext cacheCtx = entry.context(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtUnlockRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtUnlockRequest.java index 8c5fc051a69e7..168731d40b353 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtUnlockRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtUnlockRequest.java @@ -71,17 +71,10 @@ public void addNearKey(KeyCacheObject key) } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); - prepareMarshalCacheObjects(nearKeys, ctx.cacheContext(cacheId)); - } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - - finishUnmarshalCacheObjects(nearKeys, ctx.cacheContext(cacheId), ldr); + prepareCacheObjectsDeployment(nearKeys, ctx.cacheContext(cacheId)); } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/TransactionAttributesAwareRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/TransactionAttributesAwareRequest.java index 4cc026c390cda..84d9c76410f9b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/TransactionAttributesAwareRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/TransactionAttributesAwareRequest.java @@ -58,13 +58,8 @@ public Map applicationAttributes() { } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - payload.prepareMarshal(ctx); - } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - payload.finishUnmarshal(ctx, ldr); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + payload.prepareDeployment(ctx); } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/AtomicApplicationAttributesAwareRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/AtomicApplicationAttributesAwareRequest.java index 7c37b474dd2b7..fc6cec6affe0e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/AtomicApplicationAttributesAwareRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/AtomicApplicationAttributesAwareRequest.java @@ -58,13 +58,8 @@ public Map applicationAttributes() { } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - payload.prepareMarshal(ctx); - } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - payload.finishUnmarshal(ctx, ldr); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + payload.prepareDeployment(ctx); } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicNearResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicNearResponse.java index f71e035bdac94..f7944ca52288c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicNearResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicNearResponse.java @@ -18,11 +18,9 @@ package org.apache.ignite.internal.processors.cache.distributed.dht.atomic; import java.util.UUID; -import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.processors.cache.GridCacheIdMessage; import org.apache.ignite.internal.processors.cache.GridCacheReturn; -import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.util.tostring.GridToStringExclude; import org.apache.ignite.internal.util.tostring.GridToStringInclude; @@ -171,22 +169,6 @@ public long futureId() { return false; } - /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); - - if (errs != null) - errs.prepareMarshal(this, ctx.cacheContext(cacheId)); - } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - - if (errs != null) - errs.finishUnmarshal(this, ctx.cacheContext(cacheId), ldr); - } - /** {@inheritDoc} */ @Override public String toString() { StringBuilder flags = new StringBuilder(); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicSingleUpdateRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicSingleUpdateRequest.java index 20aad2f7dec8b..3dbf9d0a58c02 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicSingleUpdateRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicSingleUpdateRequest.java @@ -19,13 +19,10 @@ import java.util.UUID; import javax.cache.processor.EntryProcessor; -import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.CacheObject; -import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheOperation; -import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; import org.apache.ignite.internal.util.tostring.GridToStringInclude; @@ -311,54 +308,6 @@ private void near(boolean near) { return null; } - /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); - - GridCacheContext cctx = ctx.cacheContext(cacheId); - - prepareMarshalObject(key, cctx); - - prepareMarshalObject(val, cctx); - - prepareMarshalObject(prevVal, cctx); - } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - - GridCacheContext cctx = ctx.cacheContext(cacheId); - - finishUnmarshalObject(key, cctx, ldr); - - finishUnmarshalObject(val, cctx, ldr); - - finishUnmarshalObject(prevVal, cctx, ldr); - } - - /** - * @param obj CacheObject to marshal - * @param ctx context - * @throws IgniteCheckedException if error - */ - private void prepareMarshalObject(CacheObject obj, GridCacheContext ctx) throws IgniteCheckedException { - if (obj != null) - obj.prepareMarshal(ctx.cacheObjectContext()); - } - - /** - * @param obj CacheObject un to marshal - * @param ctx context - * @param ldr class loader - * @throws IgniteCheckedException if error - */ - private void finishUnmarshalObject(@Nullable CacheObject obj, GridCacheContext ctx, - ClassLoader ldr) throws IgniteCheckedException { - if (obj != null) - obj.finishUnmarshal(ctx.cacheObjectContext(), ldr); - } - /** * Cleanup values not needed after message was sent. */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateRequest.java index 4d06d1705daaf..b71d3b83367a0 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateRequest.java @@ -23,6 +23,7 @@ import java.util.UUID; import javax.cache.processor.EntryProcessor; import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.MarshallableMessage; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.CacheObject; @@ -36,13 +37,14 @@ import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.marshaller.Marshaller; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** * Lite dht cache backup update request. */ -public class GridDhtAtomicUpdateRequest extends GridDhtAtomicAbstractUpdateRequest { +public class GridDhtAtomicUpdateRequest extends GridDhtAtomicAbstractUpdateRequest implements MarshallableMessage { /** Keys to update. */ @GridToStringInclude @Order(0) @@ -462,20 +464,20 @@ else if (conflictVers != null) } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); GridCacheContext cctx = ctx.cacheContext(cacheId); - prepareMarshalCacheObjects(keys, cctx); + prepareCacheObjectsDeployment(keys, cctx); - prepareMarshalCacheObjects(vals, cctx); + prepareCacheObjectsDeployment(vals, cctx); - prepareMarshalCacheObjects(nearKeys, cctx); + prepareCacheObjectsDeployment(nearKeys, cctx); - prepareMarshalCacheObjects(nearVals, cctx); + prepareCacheObjectsDeployment(nearVals, cctx); - prepareMarshalCacheObjects(prevVals, cctx); + prepareCacheObjectsDeployment(prevVals, cctx); if (forceTransformBackups) { // force addition of deployment info for entry processors if P2P is enabled globally. @@ -483,51 +485,50 @@ else if (conflictVers != null) addDepInfo = true; if (!F.isEmpty(invokeArgs) && invokeArgsBytes == null) - invokeArgsBytes = Arrays.asList(marshalInvokeArguments(invokeArgs, cctx)); + prepareInvokeArgumentsDeployment(invokeArgs, cctx); if (entryProcessorsBytes == null) - entryProcessorsBytes = marshalCollection(entryProcessors, cctx); + prepareCollectionDeployment(entryProcessors, cctx); if (nearEntryProcessorsBytes == null) - nearEntryProcessorsBytes = marshalCollection(nearEntryProcessors, cctx); + prepareCollectionDeployment(nearEntryProcessors, cctx); } } /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - - GridCacheContext cctx = ctx.cacheContext(cacheId); - - finishUnmarshalCacheObjects(keys, cctx, ldr); - - finishUnmarshalCacheObjects(vals, cctx, ldr); + @Override protected void cleanup() { + nearVals = null; + prevVals = null; + } - finishUnmarshalCacheObjects(nearKeys, cctx, ldr); + /** {@inheritDoc} */ + @Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException { + if (forceTransformBackups) { + if (!F.isEmpty(invokeArgs) && invokeArgsBytes == null) + invokeArgsBytes = Arrays.asList(marshallInvokeArguments(invokeArgs, marsh)); - finishUnmarshalCacheObjects(nearVals, cctx, ldr); + if (entryProcessorsBytes == null) + entryProcessorsBytes = marshallCollection(entryProcessors, marsh); - finishUnmarshalCacheObjects(prevVals, cctx, ldr); + if (nearEntryProcessorsBytes == null) + nearEntryProcessorsBytes = marshallCollection(nearEntryProcessors, marsh); + } + } + /** {@inheritDoc} */ + @Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException { if (forceTransformBackups) { if (entryProcessors == null) - entryProcessors = unmarshalCollection(entryProcessorsBytes, ctx, ldr); + entryProcessors = unmarshalCollection(entryProcessorsBytes, marsh, clsLdr); if (invokeArgsBytes != null && invokeArgs == null) - invokeArgs = unmarshalInvokeArguments(invokeArgsBytes.toArray(new byte[invokeArgsBytes.size()][]), ctx, ldr); + invokeArgs = unmarshalInvokeArguments(invokeArgsBytes.toArray(new byte[invokeArgsBytes.size()][]), marsh, clsLdr); if (nearEntryProcessors == null) - nearEntryProcessors = unmarshalCollection(nearEntryProcessorsBytes, ctx, ldr); + nearEntryProcessors = unmarshalCollection(nearEntryProcessorsBytes, marsh, clsLdr); } } - /** {@inheritDoc} */ - @Override protected void cleanup() { - nearVals = null; - prevVals = null; - } - - /** {@inheritDoc} */ @Override public String toString() { return S.toString(GridDhtAtomicUpdateRequest.class, this, "super", super.toString()); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateResponse.java index a63354bc634fa..861717cb9147e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicUpdateResponse.java @@ -119,30 +119,14 @@ public void nearEvicted(List nearEvicted) { } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); GridCacheContext cctx = ctx.cacheContext(cacheId); // Can be null if client near cache was removed, in this case assume do not need prepareMarshal. - if (cctx != null) { - prepareMarshalCacheObjects(nearEvicted, cctx); - - if (errs != null) - errs.prepareMarshal(this, cctx); - } - } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - - GridCacheContext cctx = ctx.cacheContext(cacheId); - - finishUnmarshalCacheObjects(nearEvicted, cctx, ldr); - - if (errs != null) - errs.finishUnmarshal(this, cctx, ldr); + if (cctx != null) + prepareCacheObjectsDeployment(nearEvicted, cctx); } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicFullUpdateRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicFullUpdateRequest.java index 62fcf3966d916..567c4e328ef6b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicFullUpdateRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicFullUpdateRequest.java @@ -25,6 +25,7 @@ import javax.cache.processor.EntryProcessor; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.cache.CacheWriteSynchronizationMode; +import org.apache.ignite.internal.MarshallableMessage; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.CacheEntryPredicate; @@ -41,6 +42,7 @@ import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.marshaller.Marshaller; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -51,7 +53,7 @@ /** * Lite DHT cache update request sent from near node to primary node. */ -public class GridNearAtomicFullUpdateRequest extends GridNearAtomicAbstractUpdateRequest { +public class GridNearAtomicFullUpdateRequest extends GridNearAtomicAbstractUpdateRequest implements MarshallableMessage { /** Keys to update. */ @Order(0) @GridToStringInclude @@ -328,30 +330,15 @@ else if (conflictVers != null) } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); GridCacheContext cctx = ctx.cacheContext(cacheId); - if (expiryPlc != null && expiryPlcBytes == null) - expiryPlcBytes = CU.marshal(cctx, new IgniteExternalizableExpiryPolicy(expiryPlc)); - - prepareMarshalCacheObjects(keys, cctx); - - if (filter != null) { - boolean hasFilter = false; + prepareCacheObjectsDeployment(keys, cctx); - for (CacheEntryPredicate p : filter) { - if (p != null) { - hasFilter = true; - - p.prepareMarshal(cctx); - } - } - - if (!hasFilter) - filter = null; - } + if (filter != null && filter.length == 0) + filter = null; if (operation() == TRANSFORM) { // force addition of deployment info for entry processors if P2P is enabled globally. @@ -359,42 +346,13 @@ else if (conflictVers != null) addDepInfo = true; if (entryProcessorsBytes == null) - entryProcessorsBytes = marshalCollection(entryProcessors, cctx); + prepareCollectionDeployment(entryProcessors, cctx); if (!F.isEmpty(invokeArgs) && invokeArgsBytes == null) - invokeArgsBytes = Arrays.asList(marshalInvokeArguments(invokeArgs, cctx)); + prepareInvokeArgumentsDeployment(invokeArgs, cctx); } else - prepareMarshalCacheObjects(vals, cctx); - } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - - GridCacheContext cctx = ctx.cacheContext(cacheId); - - if (expiryPlcBytes != null && expiryPlc == null) - expiryPlc = U.unmarshal(ctx, expiryPlcBytes, U.resolveClassLoader(ldr, ctx.gridConfig())); - - finishUnmarshalCacheObjects(keys, cctx, ldr); - - if (filter != null) { - for (CacheEntryPredicate p : filter) { - if (p != null) - p.finishUnmarshal(cctx, ldr); - } - } - - if (operation() == TRANSFORM) { - if (entryProcessors == null) - entryProcessors = unmarshalCollection(entryProcessorsBytes, ctx, ldr); - - if (invokeArgsBytes != null && invokeArgs == null) - invokeArgs = unmarshalInvokeArguments(invokeArgsBytes.toArray(new byte[invokeArgsBytes.size()][]), ctx, ldr); - } - else - finishUnmarshalCacheObjects(vals, cctx, ldr); + prepareCacheObjectsDeployment(vals, cctx); } /** {@inheritDoc} */ @@ -416,6 +374,33 @@ else if (conflictVers != null) keys = null; } + /** {@inheritDoc} */ + @Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException { + if (expiryPlc != null && expiryPlcBytes == null) + expiryPlcBytes = U.marshal(marsh, new IgniteExternalizableExpiryPolicy(expiryPlc)); + + if (operation() == TRANSFORM) { + if (entryProcessorsBytes == null) + entryProcessorsBytes = marshallCollection(entryProcessors, marsh); + + if (!F.isEmpty(invokeArgs) && invokeArgsBytes == null) + invokeArgsBytes = Arrays.asList(marshallInvokeArguments(invokeArgs, marsh)); + } + } + + /** {@inheritDoc} */ + @Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException { + if (expiryPlcBytes != null && expiryPlc == null) + expiryPlc = U.unmarshal(marsh, expiryPlcBytes, clsLdr); + + if (operation() == TRANSFORM) { + if (entryProcessors == null) + entryProcessors = unmarshalCollection(entryProcessorsBytes, marsh, clsLdr); + + if (invokeArgsBytes != null && invokeArgs == null) + invokeArgs = unmarshalInvokeArguments(invokeArgsBytes.toArray(new byte[invokeArgsBytes.size()][]), marsh, clsLdr); + } + } /** {@inheritDoc} */ @Override public String toString() { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateFilterRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateFilterRequest.java index 7b072491d4f89..ef55deb9f50c3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateFilterRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateFilterRequest.java @@ -21,20 +21,20 @@ import java.util.UUID; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.cache.CacheWriteSynchronizationMode; +import org.apache.ignite.internal.MarshallableMessage; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.CacheEntryPredicate; -import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheOperation; -import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.marshaller.Marshaller; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** * */ -public class GridNearAtomicSingleUpdateFilterRequest extends GridNearAtomicSingleUpdateRequest { +public class GridNearAtomicSingleUpdateFilterRequest extends GridNearAtomicSingleUpdateRequest implements MarshallableMessage { /** Filter. */ @Order(0) CacheEntryPredicate[] filter; @@ -92,42 +92,16 @@ public GridNearAtomicSingleUpdateFilterRequest() { } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); - - GridCacheContext cctx = ctx.cacheContext(cacheId); - - if (filter != null) { - boolean hasFilter = false; - - for (CacheEntryPredicate p : filter) { - if (p != null) { - hasFilter = true; - - p.prepareMarshal(cctx); - } - } - - if (!hasFilter) - filter = null; - } + @Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException { + if (filter != null && filter.length == 0) + filter = null; } /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - - if (filter != null) { - GridCacheContext cctx = ctx.cacheContext(cacheId); + @Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException { - for (CacheEntryPredicate p : filter) { - if (p != null) - p.finishUnmarshal(cctx, ldr); - } - } } - /** {@inheritDoc} */ @Override public String toString() { return S.toString(GridNearAtomicSingleUpdateFilterRequest.class, this, "filter", Arrays.toString(filter), diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateInvokeRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateInvokeRequest.java index 2b2e44f5e7ea7..59f825a30359d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateInvokeRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateInvokeRequest.java @@ -24,6 +24,7 @@ import javax.cache.processor.EntryProcessor; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.cache.CacheWriteSynchronizationMode; +import org.apache.ignite.internal.MarshallableMessage; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.CacheObject; @@ -33,9 +34,9 @@ import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; import org.apache.ignite.internal.util.typedef.F; -import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.marshaller.Marshaller; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -44,7 +45,7 @@ /** * */ -public class GridNearAtomicSingleUpdateInvokeRequest extends GridNearAtomicSingleUpdateRequest { +public class GridNearAtomicSingleUpdateInvokeRequest extends GridNearAtomicSingleUpdateRequest implements MarshallableMessage { /** Optional arguments for entry processor. */ private @Nullable Object[] invokeArgs; @@ -160,8 +161,8 @@ public GridNearAtomicSingleUpdateInvokeRequest() { } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); GridCacheContext cctx = ctx.cacheContext(cacheId); @@ -171,34 +172,38 @@ public GridNearAtomicSingleUpdateInvokeRequest() { if (entryProc != null && entryProcBytes == null) { if (addDepInfo) - prepareObject(entryProc, cctx); - - entryProcBytes = CU.marshal(cctx, entryProc); + prepareObjectDeployment(entryProc, cctx); } if (!F.isEmpty(invokeArgs) && invokeArgsBytes == null) - invokeArgsBytes = Arrays.asList(marshalInvokeArguments(invokeArgs, cctx)); + prepareInvokeArgumentsDeployment(invokeArgs, cctx); } /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); + @Override public void cleanup(boolean clearKey) { + super.cleanup(clearKey); - if (entryProcBytes != null && entryProc == null) - entryProc = U.unmarshal(ctx, entryProcBytes, U.resolveClassLoader(ldr, ctx.gridConfig())); + entryProc = null; + } - if (invokeArgsBytes != null && invokeArgs == null) - invokeArgs = unmarshalInvokeArguments(invokeArgsBytes.toArray(new byte[invokeArgsBytes.size()][]), ctx, ldr); + /** {@inheritDoc} */ + @Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException { + if (entryProc != null && entryProcBytes == null) + entryProcBytes = U.marshal(marsh, entryProc); + + if (!F.isEmpty(invokeArgs) && invokeArgsBytes == null) + invokeArgsBytes = Arrays.asList(marshallInvokeArguments(invokeArgs, marsh)); } /** {@inheritDoc} */ - @Override public void cleanup(boolean clearKey) { - super.cleanup(clearKey); + @Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException { + if (entryProcBytes != null && entryProc == null) + entryProc = U.unmarshal(marsh, entryProcBytes, clsLdr); - entryProc = null; + if (invokeArgsBytes != null && invokeArgs == null) + invokeArgs = unmarshalInvokeArguments(invokeArgsBytes.toArray(new byte[invokeArgsBytes.size()][]), marsh, clsLdr); } - /** {@inheritDoc} */ @Override public String toString() { return S.toString(GridNearAtomicSingleUpdateRequest.class, this, super.toString()); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateRequest.java index 25b31b062c7c3..ca62244d75d8c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicSingleUpdateRequest.java @@ -217,27 +217,15 @@ public GridNearAtomicSingleUpdateRequest() { } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); GridCacheContext cctx = ctx.cacheContext(cacheId); - prepareMarshalCacheObject(key, cctx); + prepareCacheObjectDeployment(key, cctx); if (val != null) - prepareMarshalCacheObject(val, cctx); - } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - - GridCacheContext cctx = ctx.cacheContext(cacheId); - - key.finishUnmarshal(cctx.cacheObjectContext(), ldr); - - if (val != null) - val.finishUnmarshal(cctx.cacheObjectContext(), ldr); + prepareCacheObjectDeployment(val, cctx); } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateResponse.java index a1103fb308d55..270acaceacf77 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicUpdateResponse.java @@ -339,35 +339,13 @@ synchronized void addFailedKeys(Collection keys, Throwable e) { /** {@inheritDoc} * @param ctx*/ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); GridCacheContext cctx = ctx.cacheContext(cacheId); - if (errs != null) - errs.prepareMarshal(this, cctx); - if (nearUpdates != null) - prepareMarshalCacheObjects(nearUpdates.nearValues(), cctx); - - if (ret != null) - ret.prepareMarshal(cctx); - } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - - GridCacheContext cctx = ctx.cacheContext(cacheId); - - if (errs != null) - errs.finishUnmarshal(this, cctx, ldr); - - if (nearUpdates != null) - finishUnmarshalCacheObjects(nearUpdates.nearValues(), cctx, ldr); - - if (ret != null) - ret.finishUnmarshal(cctx, ldr); + prepareCacheObjectsDeployment(nearUpdates.nearValues(), cctx); } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/UpdateErrors.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/UpdateErrors.java index 0e42f82082251..820b5d7b4d17a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/UpdateErrors.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/UpdateErrors.java @@ -23,8 +23,6 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.managers.communication.ErrorMessage; -import org.apache.ignite.internal.processors.cache.GridCacheContext; -import org.apache.ignite.internal.processors.cache.GridCacheMessage; import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.internal.S; @@ -115,17 +113,6 @@ void addFailedKeys(Collection keys, Throwable e) { errMsg.error().addSuppressed(e); } - /** */ - void prepareMarshal(GridCacheMessage msg, GridCacheContext cctx) throws IgniteCheckedException { - msg.prepareMarshalCacheObjects(failedKeys, cctx); - } - - /** */ - void finishUnmarshal(GridCacheMessage msg, GridCacheContext cctx, ClassLoader ldr) throws IgniteCheckedException { - msg.finishUnmarshalCacheObjects(failedKeys, cctx, ldr); - } - - /** {@inheritDoc} */ @Override public String toString() { return S.toString(UpdateErrors.class, this); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysRequest.java index 898ad4478f086..37d0c42732970 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysRequest.java @@ -114,21 +114,12 @@ public Collection keys() { } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); GridCacheContext cctx = ctx.cacheContext(cacheId); - prepareMarshalCacheObjects(keys, cctx); - } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - - GridCacheContext cctx = ctx.cacheContext(cacheId); - - finishUnmarshalCacheObjects(keys, cctx, ldr); + prepareCacheObjectsDeployment(keys, cctx); } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysResponse.java index cafcb5fa3e364..519dbd680a9b6 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysResponse.java @@ -132,41 +132,20 @@ public void addInfo(GridCacheEntryInfo info) { } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); GridCacheContext cctx = ctx.cacheContext(cacheId); if (missedKeys != null) - prepareMarshalCacheObjects(missedKeys, cctx); - - if (infos != null) { - for (GridCacheEntryInfo info : infos) - info.marshal(cctx.cacheObjectContext()); - } - } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - - GridCacheContext cctx = ctx.cacheContext(cacheId); - - if (missedKeys != null) - finishUnmarshalCacheObjects(missedKeys, cctx, ldr); - - if (infos != null) { - for (GridCacheEntryInfo info : infos) - info.unmarshal(cctx.cacheObjectContext(), ldr); - } + prepareCacheObjectsDeployment(missedKeys, cctx); } /** {@inheritDoc} */ @Override public boolean addDeploymentInfo() { return addDepInfo; } - - + /** {@inheritDoc} */ @Override public String toString() { return S.toString(GridDhtForceKeysResponse.class, this, super.toString()); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplyMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplyMessage.java index a800ab4d1f7a8..212474a532247 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplyMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionSupplyMessage.java @@ -27,7 +27,6 @@ import org.apache.ignite.internal.Order; import org.apache.ignite.internal.managers.communication.ErrorMessage; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; -import org.apache.ignite.internal.processors.cache.CacheGroupContext; import org.apache.ignite.internal.processors.cache.CacheObjectContext; import org.apache.ignite.internal.processors.cache.GridCacheDeployable; import org.apache.ignite.internal.processors.cache.GridCacheEntryInfo; @@ -215,7 +214,7 @@ void addEntry0(int p, boolean historical, GridCacheEntryInfo info, GridCacheShar assert info.value() != null || historical : info; // Need to call this method to initialize info properly. - marshalInfo(info, ctx, cacheObjCtx); + prepareInfoDeployment(info, ctx, cacheObjCtx); msgSize += info.marshalledSize(cacheObjCtx); @@ -230,21 +229,6 @@ void addEntry0(int p, boolean historical, GridCacheEntryInfo info, GridCacheShar infoCol.add(info); } - /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - - CacheGroupContext grp = ctx.cache().cacheGroup(grpId); - - if (grp == null) - return; - - for (List entries : getInfosSafe().values()) { - for (int i = 0; i < entries.size(); i++) - entries.get(i).unmarshal(grp.cacheObjectContext(), ldr); - } - } - /** {@inheritDoc} */ @Override public boolean addDeploymentInfo() { return addDepInfo; @@ -256,8 +240,7 @@ void addEntry0(int p, boolean historical, GridCacheEntryInfo info, GridCacheShar public int size() { return getInfosSafe().size(); } - - + /** {@inheritDoc} */ @Override public String toString() { return S.toString(GridDhtPartitionSupplyMessage.class, this, diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java index 59d3df1e45657..e731ae0241f88 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsExchangeFuture.java @@ -3853,7 +3853,7 @@ else if (exchCtx.events().hasServerLeft()) else if (forceAffReassignment) msg.idealAffinityDiff(idealAffDiff); - msg.prepareMarshal(cctx); + msg.prepareDeployment(cctx); timeBag.finishGlobalStage("Full message preparing"); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsFullMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsFullMessage.java index f8fc363a829dd..d2f183c739f12 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsFullMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsFullMessage.java @@ -393,7 +393,13 @@ public void rebalanced(boolean rebalanced) { if (!F.isEmpty(parts) && locParts == null) locParts = copyPartitionsMap(parts); - errMsgs = errs == null ? null : F.viewReadOnly(errs, ErrorMessage::new); + if (errs != null) { + errMsgs = new HashMap<>(); + + for (Map.Entry entry : errs.entrySet()) { + errMsgs.put(entry.getKey(), new ErrorMessage(entry.getValue())); + } + } } /** diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsSingleMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsSingleMessage.java index a4a28d2eed3c1..c2685d3e2bb04 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsSingleMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtPartitionsSingleMessage.java @@ -21,12 +21,9 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; -import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.Compress; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.managers.communication.ErrorMessage; -import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; -import org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.F; @@ -289,33 +286,7 @@ public long exchangeStartTime() { public void exchangeStartTime(long exchangeStartTime) { this.exchangeStartTime = exchangeStartTime; } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - - if (dupPartsData != null) { - assert parts != null; - - for (Map.Entry e : dupPartsData.entrySet()) { - GridDhtPartitionMap map1 = parts.get(e.getKey()); - - assert map1 != null : e.getKey(); - assert F.isEmpty(map1.map()); - assert !map1.hasMovingPartitions(); - - GridDhtPartitionMap map2 = parts.get(e.getValue()); - - assert map2 != null : e.getValue(); - assert map2.map() != null; - - for (Map.Entry e0 : map2.map().entrySet()) - map1.put(e0.getKey(), e0.getValue()); - } - } - } - - + /** {@inheritDoc} */ @Override public String toString() { return S.toString(GridDhtPartitionsSingleMessage.class, this, super.toString()); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/CacheVersionedValue.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/CacheVersionedValue.java index af5d90f84d2a2..1cd8b6456b037 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/CacheVersionedValue.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/CacheVersionedValue.java @@ -17,20 +17,18 @@ package org.apache.ignite.internal.processors.cache.distributed.near; -import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.processors.cache.CacheObject; -import org.apache.ignite.internal.processors.cache.CacheObjectContext; -import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.plugin.extensions.communication.CacheIdAware; import org.apache.ignite.plugin.extensions.communication.Message; /** * Cache object and version. */ -public class CacheVersionedValue implements Message { +public class CacheVersionedValue implements Message, CacheIdAware { /** Value. */ @Order(0) @GridToStringInclude @@ -40,6 +38,10 @@ public class CacheVersionedValue implements Message { @Order(1) @GridToStringInclude GridCacheVersion ver; + + /** */ + @Order(2) + int cacheId; /** */ public CacheVersionedValue() { @@ -50,9 +52,10 @@ public CacheVersionedValue() { * @param val Cache value. * @param ver Cache version. */ - public CacheVersionedValue(CacheObject val, GridCacheVersion ver) { + public CacheVersionedValue(CacheObject val, GridCacheVersion ver, int cacheId) { this.val = val; this.ver = ver; + this.cacheId = cacheId; } /** @@ -69,34 +72,14 @@ public CacheObject value() { return val; } - /** - * This method is called before the whole message is sent - * and is responsible for pre-marshalling state. - * - * @param ctx Cache object context. - * @throws IgniteCheckedException If failed. - */ - public void prepareMarshal(CacheObjectContext ctx) throws IgniteCheckedException { - if (val != null) - val.prepareMarshal(ctx); - } - - /** - * This method is called after the whole message is received - * and is responsible for unmarshalling state. - * - * @param ctx Context. - * @param ldr Class loader. - * @throws IgniteCheckedException If failed. - */ - public void finishUnmarshal(GridCacheContext ctx, ClassLoader ldr) throws IgniteCheckedException { - if (val != null) - val.finishUnmarshal(ctx.cacheObjectContext(), ldr); - } - /** {@inheritDoc} */ @Override public String toString() { return S.toString(CacheVersionedValue.class, this); } + + /** {@inheritDoc} */ + @Override public int cacheId() { + return cacheId; + } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java index a8df9c74253c6..75ef1509bc4af 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetFuture.java @@ -628,8 +628,6 @@ private Map loadEntries( for (GridCacheEntryInfo info : infos) { try { - info.unmarshalValue(cctx, cctx.deploy().globalLoader()); - // Entries available locally in DHT should not be loaded into near cache for reading. if (!cctx.affinity().keyLocalNode(info.key(), cctx.affinity().affinityTopologyVersion())) { GridNearCacheEntry entry = savedEntries.get(info.key()); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetRequest.java index 74ad48394405d..30278a6227412 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetRequest.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Map; import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.MarshallableMessage; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.GridCacheContext; @@ -37,14 +38,14 @@ import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteUuid; +import org.apache.ignite.marshaller.Marshaller; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** * Get request. Responsible for obtaining entry from primary node. 'Near' means 'Initiating node' here, not 'Near Cache'. */ -public class GridNearGetRequest extends GridCacheIdMessage implements GridCacheDeployable, - GridCacheVersionable { +public class GridNearGetRequest extends GridCacheIdMessage implements GridCacheDeployable, GridCacheVersionable, MarshallableMessage { /** */ private static final int READ_THROUGH_FLAG_MASK = 0x01; @@ -284,8 +285,8 @@ public long accessTtl() { * @param ctx Cache context. * @throws IgniteCheckedException If failed. */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); assert ctx != null; assert !F.isEmpty(keys); @@ -293,21 +294,21 @@ public long accessTtl() { GridCacheContext cctx = ctx.cacheContext(cacheId); - prepareMarshalCacheObjects(keys, cctx); + prepareCacheObjectsDeployment(keys, cctx); } - /** - * @param ctx Context. - * @param ldr Loader. - * @throws IgniteCheckedException If failed. - */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - - GridCacheContext cctx = ctx.cacheContext(cacheId); + /** {@inheritDoc} */ + @Override public boolean addDeploymentInfo() { + return addDepInfo; + } - finishUnmarshalCacheObjects(keys, cctx, ldr); + /** {@inheritDoc} */ + @Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException { + // No-op. + } + /** {@inheritDoc} */ + @Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException { assert !F.isEmpty(keys); assert readersFlags == null || keys.size() == readersFlags.size(); @@ -324,12 +325,6 @@ public long accessTtl() { } } - /** {@inheritDoc} */ - @Override public boolean addDeploymentInfo() { - return addDepInfo; - } - - /** {@inheritDoc} */ @Override public String toString() { return S.toString(GridNearGetRequest.class, this); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetResponse.java index 56f0aa1ca803d..c8a8c84b6b148 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearGetResponse.java @@ -19,15 +19,12 @@ import java.util.Collection; import java.util.Collections; -import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.managers.communication.ErrorMessage; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; -import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheDeployable; import org.apache.ignite.internal.processors.cache.GridCacheEntryInfo; import org.apache.ignite.internal.processors.cache.GridCacheIdMessage; -import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; import org.apache.ignite.internal.processors.cache.version.GridCacheVersionable; import org.apache.ignite.internal.util.GridLeanSet; @@ -173,31 +170,6 @@ public void error(@Nullable Throwable err) { errMsg = new ErrorMessage(err); } - /** {@inheritDoc} - * @param ctx*/ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); - - GridCacheContext cctx = ctx.cacheContext(cacheId); - - if (entries != null) { - for (GridCacheEntryInfo info : entries) - info.marshal(cctx); - } - } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - - GridCacheContext cctx = ctx.cacheContext(cacheId()); - - if (entries != null) { - for (GridCacheEntryInfo info : entries) - info.unmarshal(cctx, ldr); - } - } - /** {@inheritDoc} */ @Override public boolean addDeploymentInfo() { return addDepInfo; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetRequest.java index 07ca1355fc0f0..8350d8b61819d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetRequest.java @@ -250,25 +250,14 @@ public boolean recovery() { } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); assert key != null; GridCacheContext cctx = ctx.cacheContext(cacheId); - prepareMarshalCacheObject(key, cctx); - } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - - assert key != null; - - GridCacheContext cctx = ctx.cacheContext(cacheId); - - key.finishUnmarshal(cctx.cacheObjectContext(), ldr); + prepareCacheObjectDeployment(key, cctx); } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetResponse.java index 73f72ec4c0247..9225b42c07138 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearSingleGetResponse.java @@ -24,7 +24,6 @@ import org.apache.ignite.internal.processors.cache.CacheObject; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheDeployable; -import org.apache.ignite.internal.processors.cache.GridCacheEntryInfo; import org.apache.ignite.internal.processors.cache.GridCacheIdMessage; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.util.typedef.internal.S; @@ -145,34 +144,14 @@ public long futureId() { } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); if (res != null) { GridCacheContext cctx = ctx.cacheContext(cacheId); if (res instanceof CacheObject) - prepareMarshalCacheObject((CacheObject)res, cctx); - else if (res instanceof CacheVersionedValue) - ((CacheVersionedValue)res).prepareMarshal(cctx.cacheObjectContext()); - else if (res instanceof GridCacheEntryInfo) - ((GridCacheEntryInfo)res).marshal(cctx); - } - } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - - if (res != null) { - GridCacheContext cctx = ctx.cacheContext(cacheId()); - - if (res instanceof CacheObject) - ((CacheObject)res).finishUnmarshal(cctx.cacheObjectContext(), ldr); - else if (res instanceof CacheVersionedValue) - ((CacheVersionedValue)res).finishUnmarshal(cctx, ldr); - else if (res instanceof GridCacheEntryInfo) - ((GridCacheEntryInfo)res).unmarshal(cctx, ldr); + prepareCacheObjectDeployment((CacheObject)res, cctx); } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareRequest.java index 05b7f6ef918a1..a9ada7e55545a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareRequest.java @@ -265,11 +265,6 @@ private Collection cloneEntries(Collection c) { return cp; } - /** {@inheritDoc} */ - @Override protected boolean transferExpiryPolicy() { - return true; - } - /** * Sets flag mask. * diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareResponse.java index 646335209b86e..ea06d7b0e24d9 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxPrepareResponse.java @@ -23,12 +23,11 @@ import java.util.Iterator; import java.util.Map; import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.MarshallableMessage; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.CacheObject; -import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheReturn; -import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.processors.cache.distributed.GridDistributedTxPrepareResponse; import org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; @@ -37,12 +36,13 @@ import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteUuid; +import org.apache.ignite.marshaller.Marshaller; import org.jetbrains.annotations.Nullable; /** * Near cache prepare response. */ -public class GridNearTxPrepareResponse extends GridDistributedTxPrepareResponse { +public class GridNearTxPrepareResponse extends GridDistributedTxPrepareResponse implements MarshallableMessage { /** Versions that are less than lock version ({@link #version()}). */ @GridToStringInclude @Order(0) @@ -196,7 +196,7 @@ public void addOwnedValue(IgniteTxKey key, GridCacheVersion ver, CacheObject val if (ownedVals == null) ownedVals = new HashMap<>(); - CacheVersionedValue oVal = new CacheVersionedValue(val, ver); + CacheVersionedValue oVal = new CacheVersionedValue(val, ver, key.cacheId()); ownedVals.put(key, oVal); } @@ -236,54 +236,16 @@ public boolean hasOwnedValue(IgniteTxKey key) { } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); - - // There are separate collections for keys and values of the 'ownedVals' map, because IgniteTxKey - // can not be inserted directly in a map as a key during invocation of MessageReader#read. - // The IgniteTxKey's hash code calculation will fail due to delegation of calculation - // to KeyCacheObjectImpl#hashCode, which in turn fails with assertion error if KeyCacheObjectImpl#val - // has not initialized yet in KeyCacheObjectImpl#finishUnmarshal. + @Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException { if (ownedVals != null && ownedValKeys == null) { ownedValKeys = ownedVals.keySet(); ownedValVals = ownedVals.values(); - - for (Map.Entry entry : ownedVals.entrySet()) { - GridCacheContext cacheCtx = ctx.cacheContext(entry.getKey().cacheId()); - - entry.getKey().prepareMarshal(cacheCtx); - - entry.getValue().prepareMarshal(cacheCtx.cacheObjectContext()); - } - } - - if (retVal != null && retVal.cacheId() != 0) { - GridCacheContext cctx = ctx.cacheContext(retVal.cacheId()); - - assert cctx != null : retVal.cacheId(); - - retVal.prepareMarshal(cctx); - } - - if (filterFailedKeys != null) { - for (IgniteTxKey key : filterFailedKeys) { - GridCacheContext cctx = ctx.cacheContext(key.cacheId()); - - key.prepareMarshal(cctx); - } } } /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - - // There are separate collections for keys and values of the 'ownedVals' map, because IgniteTxKey - // can not be inserted directly in a map as a key during invocation of MessageReader#read. - // The IgniteTxKey's hash code calculation will fail due to delegation of calculation - // to KeyCacheObjectImpl#hashCode, which in turn fails with assertion error if KeyCacheObjectImpl#val - // has not initialized yet in KeyCacheObjectImpl#finishUnmarshal. + @Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException { if (ownedValKeys != null && ownedVals == null) { ownedVals = U.newHashMap(ownedValKeys.size()); @@ -296,36 +258,13 @@ public boolean hasOwnedValue(IgniteTxKey key) { while (keyIter.hasNext()) { IgniteTxKey key = keyIter.next(); - GridCacheContext cctx = ctx.cacheContext(key.cacheId()); - CacheVersionedValue val = valIter.next(); - key.finishUnmarshal(cctx, ldr); - - val.finishUnmarshal(cctx, ldr); - ownedVals.put(key, val); } } - - if (retVal != null && retVal.cacheId() != 0) { - GridCacheContext cctx = ctx.cacheContext(retVal.cacheId()); - - assert cctx != null : retVal.cacheId(); - - retVal.finishUnmarshal(cctx, ldr); - } - - if (filterFailedKeys != null) { - for (IgniteTxKey key : filterFailedKeys) { - GridCacheContext cctx = ctx.cacheContext(key.cacheId()); - - key.finishUnmarshal(cctx, ldr); - } - } } - - + /** {@inheritDoc} */ @Override public String toString() { return S.toString(GridNearTxPrepareResponse.class, this, "super", super.toString()); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxRemote.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxRemote.java index 936033d8b3838..6186de9446623 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxRemote.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxRemote.java @@ -126,7 +126,7 @@ public GridNearTxRemote( if (writeEntries != null) { for (IgniteTxEntry entry : writeEntries) { - entry.unmarshal(ctx, true, ldr); + entry.initializeContext(ctx, true); addEntry(entry); } @@ -203,7 +203,7 @@ public Collection evicted() { */ public void addEntries(ClassLoader ldr, Iterable entries) throws IgniteCheckedException { for (IgniteTxEntry entry : entries) { - entry.unmarshal(cctx, true, ldr); + entry.initializeContext(cctx, true); addEntry(entry); } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IncrementalSnapshotAwareMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IncrementalSnapshotAwareMessage.java index 5a0824c9a5d41..abac24c67ceaf 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IncrementalSnapshotAwareMessage.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IncrementalSnapshotAwareMessage.java @@ -82,16 +82,10 @@ public long snapshotTopologyVersion() { } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - payload.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + payload.prepareDeployment(ctx); } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - payload.finishUnmarshal(ctx, ldr); - } - - + /** {@inheritDoc} */ @Override public boolean addDeploymentInfo() { return false; diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IncrementalSnapshotVerifyResult.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IncrementalSnapshotVerifyResult.java index 641e123ffff69..b6614c8535c38 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IncrementalSnapshotVerifyResult.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IncrementalSnapshotVerifyResult.java @@ -17,6 +17,7 @@ package org.apache.ignite.internal.processors.cache.persistence.snapshot; +import java.util.ArrayList; import java.util.Collection; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.managers.communication.ErrorMessage; @@ -24,7 +25,6 @@ import org.apache.ignite.internal.processors.cache.verify.PartitionHashRecord; import org.apache.ignite.internal.processors.cache.verify.TransactionsHashRecord; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; -import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.plugin.extensions.communication.Message; import org.apache.ignite.plugin.extensions.communication.MessageFactory; @@ -64,7 +64,14 @@ public IncrementalSnapshotVerifyResult() { this.txHashRes = txHashRes; this.partHashRes = partHashRes; this.partiallyCommittedTxs = partiallyCommittedTxs; - this.exceptions = exceptions == null ? null : F.viewReadOnly(exceptions, ErrorMessage::new); + + if (exceptions != null) { + this.exceptions = new ArrayList<>(); + + for (Throwable th : exceptions) { + this.exceptions.add(new ErrorMessage(th)); + } + } } /** */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryRequest.java index 84813c40420c9..8a892468f786b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryRequest.java @@ -19,9 +19,9 @@ import java.util.Collection; import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.MarshallableMessage; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; -import org.apache.ignite.internal.processors.cache.CacheObjectContext; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheDeployable; import org.apache.ignite.internal.processors.cache.GridCacheIdMessage; @@ -29,7 +29,6 @@ import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.F; -import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgniteBiPredicate; @@ -45,7 +44,7 @@ /** * Query request. */ -public class GridCacheQueryRequest extends GridCacheIdMessage implements GridCacheDeployable { +public class GridCacheQueryRequest extends GridCacheIdMessage implements GridCacheDeployable, MarshallableMessage { /** */ private static final int FLAG_DATA_PAGE_SCAN_DFLT = 0b00; @@ -407,82 +406,36 @@ private static byte setDataPageScanEnabled(int flags, Boolean enabled) { } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); GridCacheContext cctx = ctx.cacheContext(cacheId); if (keyValFilter != null && keyValFilterBytes == null) { if (addDepInfo) - prepareObject(keyValFilter, cctx); - - keyValFilterBytes = CU.marshal(cctx, keyValFilter); + prepareObjectDeployment(keyValFilter, cctx); } if (rdc != null && rdcBytes == null) { if (addDepInfo) - prepareObject(rdc, cctx); - - rdcBytes = CU.marshal(cctx, rdc); + prepareObjectDeployment(rdc, cctx); } if (trans != null && transBytes == null) { if (addDepInfo) - prepareObject(trans, cctx); - - transBytes = CU.marshal(cctx, trans); + prepareObjectDeployment(trans, cctx); } if (!F.isEmpty(args) && argsBytes == null) { if (addDepInfo) { for (Object arg : args) - prepareObject(arg, cctx); + prepareObjectDeployment(arg, cctx); } - - argsBytes = CU.marshal(cctx, args); } if (idxQryDesc != null && idxQryDescBytes == null) { if (addDepInfo) - prepareObject(idxQryDesc, cctx); - - idxQryDescBytes = CU.marshal(cctx, idxQryDesc); - } - - if (!F.isEmpty(skipKeys)) { - for (KeyCacheObject k : skipKeys) - k.prepareMarshal(cctx.cacheObjectContext()); - } - } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - - Marshaller mrsh = ctx.marshaller(); - - ClassLoader clsLdr = U.resolveClassLoader(ldr, ctx.gridConfig()); - - if (keyValFilterBytes != null && keyValFilter == null) - keyValFilter = U.unmarshal(mrsh, keyValFilterBytes, clsLdr); - - if (rdcBytes != null && rdc == null) - rdc = U.unmarshal(mrsh, rdcBytes, ldr); - - if (transBytes != null && trans == null) - trans = U.unmarshal(mrsh, transBytes, clsLdr); - - if (argsBytes != null && args == null) - args = U.unmarshal(mrsh, argsBytes, clsLdr); - - if (idxQryDescBytes != null && idxQryDesc == null) - idxQryDesc = U.unmarshal(mrsh, idxQryDescBytes, clsLdr); - - if (!F.isEmpty(skipKeys)) { - CacheObjectContext objCtx = ctx.cacheObjectContext(cacheId); - - for (KeyCacheObject k : skipKeys) - k.finishUnmarshal(objCtx, ldr); + prepareObjectDeployment(idxQryDesc, cctx); } } @@ -659,6 +612,41 @@ public Collection skipKeys() { return part; } + /** {@inheritDoc} */ + @Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException { + if (keyValFilter != null && keyValFilterBytes == null) + keyValFilterBytes = U.marshal(marsh, keyValFilter); + + if (rdc != null && rdcBytes == null) + rdcBytes = U.marshal(marsh, rdc); + + if (trans != null && transBytes == null) + transBytes = U.marshal(marsh, trans); + + if (!F.isEmpty(args) && argsBytes == null) + argsBytes = U.marshal(marsh, args); + + if (idxQryDesc != null && idxQryDescBytes == null) + idxQryDescBytes = U.marshal(marsh, idxQryDesc); + } + + /** {@inheritDoc} */ + @Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException { + if (keyValFilterBytes != null && keyValFilter == null) + keyValFilter = U.unmarshal(marsh, keyValFilterBytes, clsLdr); + + if (rdcBytes != null && rdc == null) + rdc = U.unmarshal(marsh, rdcBytes, clsLdr); + + if (transBytes != null && trans == null) + trans = U.unmarshal(marsh, transBytes, clsLdr); + + if (argsBytes != null && args == null) + args = U.unmarshal(marsh, argsBytes, clsLdr); + + if (idxQryDescBytes != null && idxQryDesc == null) + idxQryDesc = U.unmarshal(marsh, idxQryDescBytes, clsLdr); + } /** {@inheritDoc} */ @Override public String toString() { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryResponse.java index 6b295f2561182..ee030ce661855 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheQueryResponse.java @@ -17,30 +17,26 @@ package org.apache.ignite.internal.processors.cache.query; -import java.util.ArrayList; import java.util.Collection; -import java.util.List; import java.util.Map; import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.MarshallableMessage; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.cache.query.index.IndexQueryResultMeta; import org.apache.ignite.internal.managers.communication.ErrorMessage; -import org.apache.ignite.internal.processors.cache.CacheObjectContext; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheDeployable; import org.apache.ignite.internal.processors.cache.GridCacheIdMessage; import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; -import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.internal.S; -import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.marshaller.Marshaller; import org.jetbrains.annotations.Nullable; /** * Page of cache query response. */ -public class GridCacheQueryResponse extends GridCacheIdMessage implements GridCacheDeployable { +public class GridCacheQueryResponse extends GridCacheIdMessage implements GridCacheDeployable, MarshallableMessage { /** */ @Order(0) boolean finished; @@ -105,77 +101,26 @@ public GridCacheQueryResponse(int cacheId, long reqId, Throwable err, boolean ad /** {@inheritDoc} * @param ctx*/ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); + @Override public void prepareDeployment(GridCacheSharedContext ctx) throws IgniteCheckedException { + super.prepareDeployment(ctx); GridCacheContext cctx = ctx.cacheContext(cacheId); if (dataBytes == null && data != null) - dataBytes = marshalCollection(data, cctx); + prepareCollectionDeployment(data, cctx); if (addDepInfo && !F.isEmpty(data)) { for (Object o : data) { if (o instanceof Map.Entry) { Map.Entry e = (Map.Entry)o; - prepareObject(e.getKey(), cctx); - prepareObject(e.getValue(), cctx); + prepareObjectDeployment(e.getKey(), cctx); + prepareObjectDeployment(e.getValue(), cctx); } } } } - /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - - if (data == null) - data = unmarshalCollection0(dataBytes, ctx, ldr); - } - - /** - * @param byteCol Collection to unmarshal. - * @param ctx Context. - * @param ldr Loader. - * @return Unmarshalled collection. - * @throws IgniteCheckedException If failed. - */ - @Nullable protected List unmarshalCollection0(@Nullable Collection byteCol, - GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - assert ldr != null; - assert ctx != null; - - if (byteCol == null) - return null; - - List col = new ArrayList<>(byteCol.size()); - - Marshaller marsh = ctx.marshaller(); - - ClassLoader ldr0 = U.resolveClassLoader(ldr, ctx.gridConfig()); - - CacheObjectContext cacheObjCtx = null; - - for (byte[] bytes : byteCol) { - Object obj = bytes == null ? null : marsh.unmarshal(bytes, ldr0); - - if (obj instanceof Map.Entry) { - Object key = ((Map.Entry)obj).getKey(); - - if (key instanceof KeyCacheObject) { - if (cacheObjCtx == null) - cacheObjCtx = ctx.cacheContext(cacheId).cacheObjectContext(); - - ((KeyCacheObject)key).finishUnmarshal(cacheObjCtx, ldr0); - } - } - - col.add((T)obj); - } - - return col; - } - /** {@inheritDoc} */ @Override public boolean addDeploymentInfo() { return addDepInfo; @@ -233,6 +178,17 @@ public boolean fields() { return fields; } + /** {@inheritDoc} */ + @Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException { + if (data != null) + dataBytes = marshallCollection(data, marsh); + } + + /** {@inheritDoc} */ + @Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException { + if (dataBytes != null) + data = unmarshalCollection(dataBytes, marsh, clsLdr); + } /** {@inheritDoc} */ @Override public String toString() { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEntry.java index 130dcec622821..2cd35df578da5 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEntry.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryEntry.java @@ -18,25 +18,23 @@ package org.apache.ignite.internal.processors.cache.query.continuous; import javax.cache.event.EventType; -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.internal.MarshallableMessage; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.managers.deployment.GridDeploymentInfo; import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.CacheObject; -import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheDeployable; import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.util.tostring.GridToStringExclude; import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.internal.S; -import org.apache.ignite.marshaller.Marshaller; +import org.apache.ignite.plugin.extensions.communication.CacheIdAware; +import org.apache.ignite.plugin.extensions.communication.Message; import org.jetbrains.annotations.Nullable; /** * Continuous query entry. */ -public class CacheContinuousQueryEntry implements GridCacheDeployable, MarshallableMessage { +public class CacheContinuousQueryEntry implements GridCacheDeployable, Message, CacheIdAware { /** */ private static final byte BACKUP_ENTRY = 0b0001; @@ -56,27 +54,18 @@ public class CacheContinuousQueryEntry implements GridCacheDeployable, Marshalla /** Key. */ @GridToStringInclude - KeyCacheObject key; - - /** */ @Order(2) - byte[] keyBytes; + KeyCacheObject key; /** New value. */ @GridToStringInclude - CacheObject newVal; - - /** */ @Order(3) - byte[] newValBytes; + CacheObject newVal; /** Old value. */ @GridToStringInclude - CacheObject oldVal; - - /** */ @Order(4) - byte[] oldValBytes; + CacheObject oldVal; /** Cache name. */ @Order(5) @@ -194,10 +183,8 @@ public byte flags() { return topVer; } - /** - * @return Cache ID. - */ - int cacheId() { + /** {@inheritDoc} */ + @Override public int cacheId() { return cacheId; } @@ -235,6 +222,9 @@ void markBackup() { void markFiltered() { flags |= FILTERED_ENTRY; depInfo = null; + key = null; + newVal = null; + oldVal = null; } /** @@ -295,39 +285,6 @@ boolean isKeepBinary() { return (flags & KEEP_BINARY) != 0; } - /** - * @param cctx Cache context. - * @throws IgniteCheckedException In case of error. - */ - void prepareMarshal(GridCacheContext cctx) throws IgniteCheckedException { - if (key != null) - key.prepareMarshal(cctx.cacheObjectContext()); - - if (newVal != null) - newVal.prepareMarshal(cctx.cacheObjectContext()); - - if (oldVal != null) - oldVal.prepareMarshal(cctx.cacheObjectContext()); - } - - /** - * @param cctx Cache context. - * @param ldr Class loader. - * @throws IgniteCheckedException In case of error. - */ - void unmarshal(GridCacheContext cctx, @Nullable ClassLoader ldr) throws IgniteCheckedException { - if (!isFiltered()) { - if (key != null) - key.finishUnmarshal(cctx.cacheObjectContext(), ldr); - - if (newVal != null) - newVal.finishUnmarshal(cctx.cacheObjectContext(), ldr); - - if (oldVal != null) - oldVal.finishUnmarshal(cctx.cacheObjectContext(), ldr); - } - } - /** * @return Key. */ @@ -350,7 +307,7 @@ CacheObject oldValue() { } /** {@inheritDoc} */ - @Override public void prepare(GridDeploymentInfo depInfo) { + @Override public void prepareDeployment(GridDeploymentInfo depInfo) { this.depInfo = depInfo; } @@ -358,36 +315,9 @@ CacheObject oldValue() { @Override public GridDeploymentInfo deployInfo() { return depInfo; } - - + /** {@inheritDoc} */ @Override public String toString() { return S.toString(CacheContinuousQueryEntry.class, this); } - - /** {@inheritDoc} */ - @Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException { - if (!isFiltered()) { - if (key != null) - keyBytes = marsh.marshal(key); - - if (newVal != null) - newValBytes = marsh.marshal(newVal); - - if (oldVal != null) - oldValBytes = marsh.marshal(oldVal); - } - } - - /** {@inheritDoc} */ - @Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException { - if (keyBytes != null) - key = marsh.unmarshal(keyBytes, clsLdr); - - if (newValBytes != null) - newVal = marsh.unmarshal(newValBytes, clsLdr); - - if (oldValBytes != null) - oldVal = marsh.unmarshal(oldValBytes, clsLdr); - } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java index 200a40cb796d1..68f05b1dea04c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryHandler.java @@ -928,13 +928,8 @@ protected CacheEntryEventFilter getEventFilter0() { */ private void prepareEntry(GridCacheContext cctx, UUID nodeId, CacheContinuousQueryEntry entry) throws IgniteCheckedException { - if (cctx.kernalContext().config().isPeerClassLoadingEnabled() && cctx.discovery().node(nodeId) != null) { - entry.prepareMarshal(cctx); - + if (cctx.kernalContext().config().isPeerClassLoadingEnabled() && cctx.discovery().node(nodeId) != null) cctx.deploy().prepare(entry); - } - else - entry.prepareMarshal(cctx); } /** @@ -1072,8 +1067,6 @@ private void notifyCallback0(UUID nodeId, } } - e.unmarshal(cctx, ldr); - Collection> evts = handleEvent(ctx, e); if (evts != null && !evts.isEmpty()) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java index c4f024b2d25b0..9ed05e2484dba 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxEntry.java @@ -25,13 +25,12 @@ import javax.cache.processor.EntryProcessor; import org.apache.ignite.IgniteCache; import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.MarshallableMessage; import org.apache.ignite.internal.Order; -import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion; import org.apache.ignite.internal.processors.cache.CacheEntryPredicate; import org.apache.ignite.internal.processors.cache.CacheInvalidStateException; import org.apache.ignite.internal.processors.cache.CacheInvokeEntry; import org.apache.ignite.internal.processors.cache.CacheObject; -import org.apache.ignite.internal.processors.cache.CacheObjectValueContext; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheEntryEx; import org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException; @@ -47,7 +46,8 @@ import org.apache.ignite.internal.util.typedef.T2; import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.U; -import org.apache.ignite.plugin.extensions.communication.Message; +import org.apache.ignite.marshaller.Marshaller; +import org.apache.ignite.plugin.extensions.communication.CacheIdAware; import org.apache.ignite.thread.IgniteThread; import org.jetbrains.annotations.Nullable; @@ -59,7 +59,7 @@ * {@link #equals(Object)} method, as transaction entries should use referential * equality. */ -public class IgniteTxEntry implements GridPeerDeployAware, Message { +public class IgniteTxEntry implements GridPeerDeployAware, MarshallableMessage, CacheIdAware { /** */ private static final long serialVersionUID = 0L; @@ -588,7 +588,7 @@ public KeyCacheObject key() { /** * @return Cache ID. */ - public int cacheId() { + @Override public int cacheId() { return cacheId; } @@ -1021,59 +1021,45 @@ public void filtersSet(boolean filtersSet) { this.filtersSet = filtersSet; } - /** - * @param ctx Context. - * @param transferExpiry {@code True} if expire policy should be marshalled. - * @throws IgniteCheckedException If failed. - */ - public void marshal(GridCacheSharedContext ctx, boolean transferExpiry) throws IgniteCheckedException { - if (filters != null) { - for (CacheEntryPredicate p : filters) { - if (p != null) - p.prepareMarshal(this.ctx); - } - } - + /** {@inheritDoc} */ + @Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException { // Do not serialize filters if they are null. if (transformClosBytes == null && entryProcessorsCol != null) - transformClosBytes = CU.marshal(this.ctx, entryProcessorsCol); + transformClosBytes = U.marshal(marsh, entryProcessorsCol); - if (transferExpiry) - transferExpiryPlc = expiryPlc != null && expiryPlc != this.ctx.expiry(); - - key.prepareMarshal(context().cacheObjectContext()); - - val.marshal(context()); + transferExpiryPlc = expiryPlc != null && expiryPlc != ctx.expiry(); if (transferExpiryPlc) { if (expiryPlcBytes == null) - expiryPlcBytes = CU.marshal(this.ctx, new IgniteExternalizableExpiryPolicy(expiryPlc)); + expiryPlcBytes = U.marshal(marsh, new IgniteExternalizableExpiryPolicy(expiryPlc)); } else expiryPlcBytes = null; + } + + /** {@inheritDoc} */ + @Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException { + // Unmarshal transform closure anyway if it exists. + if (transformClosBytes != null && entryProcessorsCol == null) + entryProcessorsCol = U.unmarshal(marsh, transformClosBytes, clsLdr); + + if (filters == null) + filters = CU.empty0(); - if (oldVal != null) - oldVal.marshal(context()); + if (expiryPlcBytes != null && expiryPlc == null) + expiryPlc = U.unmarshal(marsh, expiryPlcBytes, clsLdr); } /** - * Prepares this entry to unmarshall. In particular, this method initialize a cache context. - * * @param ctx Cache context. - * @param topVer Topology version that is used to validate a cache context. - * If this parameter is {@code null} then validation will be skipped. * @param near Near flag. * @throws IgniteCheckedException If un-marshalling failed. */ - public void prepareUnmarshal( - GridCacheSharedContext ctx, - AffinityTopologyVersion topVer, - boolean near - ) throws IgniteCheckedException { + public void initializeContext(GridCacheSharedContext ctx, boolean near) throws IgniteCheckedException { if (this.ctx == null) { GridCacheContext cacheCtx = ctx.cacheContext(cacheId); - if (cacheCtx == null || (topVer != null && topVer.before(cacheCtx.startTopologyVersion()))) + if (cacheCtx == null) throw new CacheInvalidStateException( "Failed to perform cache operation (cache is stopped), cacheId=" + cacheId); @@ -1086,53 +1072,6 @@ else if (!cacheCtx.isNear() && near) } } - /** - * Unmarshalls entry. - * - * @param ctx Cache context. - * @param near Near flag. - * @param clsLdr Class loader. - * @throws IgniteCheckedException If un-marshalling failed. - */ - public void unmarshal( - GridCacheSharedContext ctx, - boolean near, - ClassLoader clsLdr - ) throws IgniteCheckedException { - - if (this.ctx == null) - prepareUnmarshal(ctx, null, near); - - CacheObjectValueContext coctx = this.ctx.cacheObjectContext(); - - if (coctx == null) - throw new CacheInvalidStateException( - "Failed to perform cache operation (cache is stopped), cacheId=" + cacheId); - - // Unmarshal transform closure anyway if it exists. - if (transformClosBytes != null && entryProcessorsCol == null) - entryProcessorsCol = U.unmarshal(ctx, transformClosBytes, U.resolveClassLoader(clsLdr, ctx.gridConfig())); - - if (filters == null) - filters = CU.empty0(); - else { - for (CacheEntryPredicate p : filters) { - if (p != null) - p.finishUnmarshal(this.ctx, clsLdr); - } - } - - key.finishUnmarshal(coctx, clsLdr); - - val.unmarshal(coctx, clsLdr); - - if (expiryPlcBytes != null && expiryPlc == null) - expiryPlc = U.unmarshal(ctx, expiryPlcBytes, U.resolveClassLoader(clsLdr, ctx.gridConfig())); - - if (hasOldValue()) - oldVal.unmarshal(coctx, clsLdr); - } - /** * @param expiryPlc Expiry policy. */ diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxHandler.java index 392f37d32b060..df2a4467a97ee 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxHandler.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxHandler.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.UUID; @@ -377,7 +378,7 @@ private IgniteTxEntry unmarshal(@Nullable Collection entries) thr IgniteTxEntry firstEntry = null; for (IgniteTxEntry e : entries) { - e.unmarshal(ctx, false, ctx.deploy().globalLoader()); + e.initializeContext(ctx, false); if (firstEntry == null) firstEntry = e; @@ -1211,7 +1212,26 @@ private void processDhtTxPrepareRequest(final UUID nodeId, final GridDhtTxPrepar if (nearTx != null) res.nearEvicted(nearTx.evicted()); - List writesCacheMissed = req.nearWritesCacheMissed(); + List writesCacheMissed = new ArrayList<>(); + + Collection writes = req.nearWrites(); + + for (Iterator it = writes.iterator(); it.hasNext();) { + IgniteTxEntry e = it.next(); + + GridCacheContext cacheCtx = ctx.cacheContext(e.cacheId()); + + if (cacheCtx == null) { + it.remove(); + + writesCacheMissed.add(e.txKey()); + } + else { + e.context(cacheCtx); + + e.initializeContext(ctx, true); + } + } if (writesCacheMissed != null) { Collection evicted0 = res.nearEvicted(); @@ -1745,6 +1765,8 @@ private void sendReply(UUID nodeId, GridDhtTxFinishRequest req, boolean committe int idx = 0; for (IgniteTxEntry entry : req.writes()) { + entry.initializeContext(ctx, false); + GridCacheContext cacheCtx = entry.context(); int part = cacheCtx.affinity().partition(entry.key()); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxKey.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxKey.java index b50bc340c3ba1..4ca6c017bf40e 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxKey.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxKey.java @@ -17,19 +17,18 @@ package org.apache.ignite.internal.processors.cache.transactions; -import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.Order; -import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.KeyCacheObject; import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.plugin.extensions.communication.CacheIdAware; import org.apache.ignite.plugin.extensions.communication.Message; /** * Cache transaction key. This wrapper is needed because same keys may be enlisted in the same transaction * for multiple caches. */ -public class IgniteTxKey implements Message { +public class IgniteTxKey implements Message, CacheIdAware { /** Key. */ @Order(0) @GridToStringInclude(sensitive = true) @@ -65,29 +64,10 @@ public KeyCacheObject key() { /** * @return Cache ID. */ - public int cacheId() { + @Override public int cacheId() { return cacheId; } - /** - * @param ctx Context. - * @throws IgniteCheckedException If failed. - */ - public void prepareMarshal(GridCacheContext ctx) throws IgniteCheckedException { - key.prepareMarshal(ctx.cacheObjectContext()); - } - - /** - * @param ctx Context. - * @param ldr Class loader. - * @throws IgniteCheckedException If failed. - */ - public void finishUnmarshal(GridCacheContext ctx, ClassLoader ldr) throws IgniteCheckedException { - assert key != null; - - key.finishUnmarshal(ctx.cacheObjectContext(), ldr); - } - /** {@inheritDoc} */ @Override public boolean equals(Object o) { if (this == o) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java index cd2704daf9007..92d8b80a27acd 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTxManager.java @@ -114,6 +114,7 @@ import org.apache.ignite.lang.IgniteFuture; import org.apache.ignite.lang.IgniteOutClosure; import org.apache.ignite.lang.IgniteReducer; +import org.apache.ignite.plugin.extensions.communication.MessageSerializer; import org.apache.ignite.spi.systemview.view.TransactionView; import org.apache.ignite.transactions.TransactionConcurrency; import org.apache.ignite.transactions.TransactionIsolation; @@ -2431,7 +2432,7 @@ void txLocksInfo(UUID nodeId, TxDeadlockFuture fut, Set txKeys) { try { if (!cctx.localNodeId().equals(nodeId)) - req.prepareMarshal(cctx); + req.prepareDeployment(cctx); cctx.gridIO().sendToGridTopic(node, TOPIC_TX, req, SYSTEM_POOL); } @@ -3361,7 +3362,7 @@ private class DeadlockDetectionListener implements GridMessageListener { try { if (!cctx.localNodeId().equals(nodeId)) - res.prepareMarshal(cctx); + res.prepareDeployment(cctx); cctx.gridIO().sendToGridTopic(nodeId, TOPIC_TX, res, SYSTEM_POOL); } @@ -3446,7 +3447,9 @@ private void unmarshall(UUID nodeId, GridCacheMessage cacheMsg) { return; try { - cacheMsg.finishUnmarshal(cctx, cctx.deploy().globalLoader()); + MessageSerializer ser = cctx.kernalContext().messageFactory().serializer(cacheMsg.directType()); + + ser.finishUnmarshal(cacheMsg, cctx.kernalContext(), null); } catch (IgniteCheckedException e) { cacheMsg.onClassError(e); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxEntryValueHolder.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxEntryValueHolder.java index 98e5830cb3b46..425e4d88cdfeb 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxEntryValueHolder.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxEntryValueHolder.java @@ -17,11 +17,8 @@ package org.apache.ignite.internal.processors.cache.transactions; -import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.processors.cache.CacheObject; -import org.apache.ignite.internal.processors.cache.CacheObjectValueContext; -import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheOperation; import org.apache.ignite.internal.util.tostring.GridToStringExclude; import org.apache.ignite.internal.util.tostring.GridToStringInclude; @@ -119,25 +116,6 @@ public boolean hasReadValue() { return hasReadVal; } - /** - * @param ctx Cache context. - * @throws IgniteCheckedException If marshaling failed. - */ - public void marshal(GridCacheContext ctx) throws IgniteCheckedException { - if (hasWriteVal && val != null) - val.prepareMarshal(ctx.cacheObjectContext()); - } - - /** - * @param ctx Cache context. - * @param ldr Class loader. - * @throws IgniteCheckedException If unmarshalling failed. - */ - public void unmarshal(CacheObjectValueContext ctx, ClassLoader ldr) throws IgniteCheckedException { - if (hasWriteVal && val != null) - val.finishUnmarshal(ctx, ldr); - } - /** {@inheritDoc} */ @Override public String toString() { return S.toString(TxEntryValueHolder.class, this); diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxLocksRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxLocksRequest.java index 4db908333d72b..588219de8bef6 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxLocksRequest.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxLocksRequest.java @@ -20,19 +20,20 @@ import java.util.Collection; import java.util.Set; import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.MarshallableMessage; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.processors.cache.GridCacheMessage; -import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.util.tostring.GridToStringExclude; import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.internal.A; import org.apache.ignite.internal.util.typedef.internal.S; import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.marshaller.Marshaller; /** * Transactions lock list request. */ -public class TxLocksRequest extends GridCacheMessage { +public class TxLocksRequest extends GridCacheMessage implements MarshallableMessage { /** Future ID. */ @Order(0) long futId; @@ -89,33 +90,20 @@ public Collection txKeys() { } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); - + @Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException { txKeysArr = new IgniteTxKey[txKeys.size()]; int i = 0; - for (IgniteTxKey key : txKeys) { - key.prepareMarshal(ctx.cacheContext(key.cacheId())); - + for (IgniteTxKey key : txKeys) txKeysArr[i++] = key; - } } /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - super.finishUnmarshal(ctx, ldr); - + @Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException { txKeys = U.newHashSet(txKeysArr.length); - for (IgniteTxKey key : txKeysArr) { - key.finishUnmarshal(ctx.cacheContext(key.cacheId()), ldr); - + for (IgniteTxKey key : txKeysArr) txKeys.add(key); - } - - txKeysArr = null; } - } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxLocksResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxLocksResponse.java index 8ebbcbddbd031..e517c7c5c522a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxLocksResponse.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxLocksResponse.java @@ -24,18 +24,19 @@ import java.util.Map; import java.util.Set; import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.MarshallableMessage; import org.apache.ignite.internal.Order; import org.apache.ignite.internal.processors.cache.GridCacheMessage; -import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; import org.apache.ignite.internal.util.tostring.GridToStringExclude; 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; /** * Transactions lock list response. */ -public class TxLocksResponse extends GridCacheMessage { +public class TxLocksResponse extends GridCacheMessage implements MarshallableMessage { /** Future ID. */ @Order(0) long futId; @@ -137,9 +138,7 @@ public void addKey(IgniteTxKey key) { } /** {@inheritDoc} */ - @Override public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException { - super.prepareMarshal(ctx); - + @Override public void prepareMarshal(Marshaller marsh) throws IgniteCheckedException { if (nearTxKeyLocks != null && !nearTxKeyLocks.isEmpty()) { int len = nearTxKeyLocks.size(); @@ -151,8 +150,6 @@ public void addKey(IgniteTxKey key) { for (Map.Entry> entry : nearTxKeyLocks.entrySet()) { IgniteTxKey key = entry.getKey(); - key.prepareMarshal(ctx.cacheContext(key.cacheId())); - nearTxKeysArr[i] = key; locksArr[i] = entry.getValue(); @@ -165,47 +162,31 @@ public void addKey(IgniteTxKey key) { int i = 0; - for (IgniteTxKey key : txKeys) { - key.prepareMarshal(ctx.cacheContext(key.cacheId())); - + for (IgniteTxKey key : txKeys) txKeysArr[i++] = key; - } } } /** {@inheritDoc} */ - @Override public void finishUnmarshal(GridCacheSharedContext ctx, ClassLoader ldr) throws IgniteCheckedException { - try { - super.finishUnmarshal(ctx, ldr); - - if (nearTxKeysArr != null) { - for (int i = 0; i < nearTxKeysArr.length; i++) { - IgniteTxKey txKey = nearTxKeysArr[i]; - - txKey.key().finishUnmarshal(ctx.cacheObjectContext(txKey.cacheId()), ldr); + @Override public void finishUnmarshal(Marshaller marsh, ClassLoader clsLdr) throws IgniteCheckedException { + if (nearTxKeysArr != null) { + for (int i = 0; i < nearTxKeysArr.length; i++) { + IgniteTxKey txKey = nearTxKeysArr[i]; - txLocks().put(txKey, locksArr[i]); - } - - nearTxKeysArr = null; - locksArr = null; + txLocks().put(txKey, locksArr[i]); } - if (txKeysArr != null) { - txKeys = U.newHashSet(txKeysArr.length); + nearTxKeysArr = null; + locksArr = null; + } - for (IgniteTxKey txKey : txKeysArr) { - txKey.key().finishUnmarshal(ctx.cacheObjectContext(txKey.cacheId()), ldr); + if (txKeysArr != null) { + txKeys = U.newHashSet(txKeysArr.length); - txKeys.add(txKey); - } + for (IgniteTxKey txKey : txKeysArr) + txKeys.add(txKey); - txKeysArr = null; - } - } - catch (Exception e) { - throw new IgniteCheckedException(e); + txKeysArr = null; } } - } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/service/ServiceSingleNodeDeploymentResult.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/ServiceSingleNodeDeploymentResult.java index 10ceefb8284aa..cefe1ae00f9f6 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/service/ServiceSingleNodeDeploymentResult.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/ServiceSingleNodeDeploymentResult.java @@ -18,6 +18,7 @@ package org.apache.ignite.internal.processors.service; import java.io.Serializable; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import org.apache.ignite.internal.Order; @@ -76,8 +77,14 @@ public Collection errors() { * @param errors Exceptions. */ public void errors(@Nullable Collection errors) { - if (!F.isEmpty(errors)) - this.errors = F.viewReadOnly(errors, ErrorMessage::new); + if (errors == null) + return; + + this.errors = new ArrayList<>(); + + for (Throwable th : errors) { + this.errors.add(new ErrorMessage(th)); + } } /** {@inheritDoc} */ diff --git a/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/CacheIdAware.java b/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/CacheIdAware.java new file mode 100644 index 0000000000000..3233d054dd2d8 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/CacheIdAware.java @@ -0,0 +1,25 @@ +/* + * 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.plugin.extensions.communication; +/** */ +public interface CacheIdAware { + /** + * @return Cache ID. + */ + public int cacheId(); +} diff --git a/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageSerializer.java b/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageSerializer.java index 90df0601693c3..47202e3b13b25 100644 --- a/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageSerializer.java +++ b/modules/core/src/main/java/org/apache/ignite/plugin/extensions/communication/MessageSerializer.java @@ -17,9 +17,11 @@ package org.apache.ignite.plugin.extensions.communication; -/** - * Interface for message serialization logic. - */ +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.GridKernalContext; +import org.apache.ignite.internal.processors.cache.GridCacheContext; + +/** Message serialization logic. */ public interface MessageSerializer { /** * Writes this message to provided byte buffer. @@ -38,4 +40,28 @@ public interface MessageSerializer { * @return Whether message was fully read. */ public boolean readFrom(M msg, MessageReader reader); + + /** + * Marshalls cache-object fields on the user thread. + * + * @param msg Message instance. + * @param kctx Kernal context. + * @param nested Nested context. + * @throws IgniteCheckedException If marshalling fails. + */ + public default void prepareMarshal(M msg, GridKernalContext kctx, GridCacheContext nested) throws IgniteCheckedException { + // No-op by default. + } + + /** + * Unmarshalls cache-object fields on the user thread. + * + * @param msg Message instance. + * @param kctx Kernal context. + * @param nested Nested context. + * @throws IgniteCheckedException If unmarshalling fails. + */ + public default void finishUnmarshal(M msg, GridKernalContext kctx, GridCacheContext nested) throws IgniteCheckedException { + // No-op by default. + } } diff --git a/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/internal/GridNioServerWrapper.java b/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/internal/GridNioServerWrapper.java index df7935c6c2f41..beba50cc4695f 100644 --- a/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/internal/GridNioServerWrapper.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/internal/GridNioServerWrapper.java @@ -826,7 +826,7 @@ public GridNioServer resetNioServer() throws IgniteCheckedException { @Override public MessageSerializer serializer(short type) { // Enable sending wait message for a communication peer while context isn't initialized. if (impl == null && type == CoreMessagesProvider.HANDSHAKE_WAIT_MSG_TYPE) - return new HandshakeWaitMessageSerializer(); + return new HandshakeWaitMessageSerializer(U.gridClassLoader()); return get().serializer(type); } diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryIoSession.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryIoSession.java index b8fc471493069..9389b0b991bfc 100644 --- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryIoSession.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoveryIoSession.java @@ -32,6 +32,7 @@ import javax.net.ssl.SSLSocket; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteException; +import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.direct.DirectMessageReader; import org.apache.ignite.internal.direct.DirectMessageWriter; import org.apache.ignite.internal.managers.communication.UnknownMessageException; @@ -145,7 +146,7 @@ void writeMessage(TcpDiscoveryAbstractMessage msg) throws IgniteCheckedException * @return Deserialized message instance. * @throws IgniteCheckedException If deserialization fails. */ - T readMessage() throws IgniteCheckedException, IOException { + T readMessage() throws IgniteCheckedException, IOException { try { byte b0 = (byte)in.read(); byte b1 = (byte)in.read(); @@ -197,6 +198,8 @@ T readMessage() throws IgniteCheckedException, IOException { } while (!finished); + msgSer.finishUnmarshal(msg, ((IgniteEx)spi.ignite()).context(), null); + return (T)msg; } catch (Exception e) { @@ -238,9 +241,11 @@ public Socket socket() { * @param out Output stream to write serialized message. * @throws IOException If serialization fails. */ - void serializeMessage(Message m, OutputStream out) throws IOException { + void serializeMessage(Message m, OutputStream out) throws IOException, IgniteCheckedException { MessageSerializer msgSer = spi.messageFactory().serializer(m.directType()); + msgSer.prepareMarshal(m, ((IgniteEx)spi.ignite()).context(), null); + msgWriter.reset(); msgWriter.setBuffer(msgBuf); diff --git a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java index 6e14dfa8f272f..db7eeb89c509c 100644 --- a/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java +++ b/modules/core/src/main/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySpi.java @@ -72,6 +72,7 @@ import org.apache.ignite.lang.IgniteProductVersion; import org.apache.ignite.lang.IgniteUuid; import org.apache.ignite.marshaller.Marshaller; +import org.apache.ignite.plugin.extensions.communication.Message; import org.apache.ignite.plugin.extensions.communication.MessageFactory; import org.apache.ignite.resources.IgniteInstanceResource; import org.apache.ignite.resources.LoggerResource; @@ -1815,7 +1816,7 @@ protected void writeToSocket( * @throws IOException If IO failed or read timed out. * @throws IgniteCheckedException If unmarshalling failed. */ - protected T readMessage(TcpDiscoveryIoSession ses, long timeout) throws IOException, IgniteCheckedException { + protected T readMessage(TcpDiscoveryIoSession ses, long timeout) throws IOException, IgniteCheckedException { Socket sock = ses.socket(); assert sock != null; @@ -1825,7 +1826,9 @@ protected T readMessage(TcpDiscoveryIoSession ses, long timeout) throws IOEx try { sock.setSoTimeout((int)timeout); - return ses.readMessage(); + T msg = ses.readMessage(); + + return msg; } catch (IOException | IgniteCheckedException e) { if (X.hasCause(e, SocketTimeoutException.class)) diff --git a/modules/core/src/test/java/org/apache/ignite/internal/codegen/MessageProcessorTest.java b/modules/core/src/test/java/org/apache/ignite/internal/codegen/MessageProcessorTest.java index e1e2e38dbbf5c..89fd3aae12c15 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/codegen/MessageProcessorTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/codegen/MessageProcessorTest.java @@ -340,6 +340,36 @@ public void testCompressedMessageExplicitUsageFails() { assertThat(compilation).hadErrorContaining(errMsg); } + /** Collection-of-entries encoding of a {@code Map}: generator recurses into each entry's KCO. */ + @Test + public void testKeyCacheObjectInCollectionOfEntries() { + Compilation compilation = compile("KeyCacheObjectEntryMsg.java", "TestKeyCacheObjectCollectionMessage.java"); + + assertThat(compilation).succeeded(); + + assertEquals(2, compilation.generatedSourceFiles().size()); + + assertThat(compilation) + .generatedSourceFile("org.apache.ignite.internal.KeyCacheObjectEntryMsgSerializer") + .hasSourceEquivalentTo(javaFile("KeyCacheObjectEntryMsgSerializer.java")); + + assertThat(compilation) + .generatedSourceFile("org.apache.ignite.internal.TestKeyCacheObjectCollectionMessageSerializer") + .hasSourceEquivalentTo(javaFile("TestKeyCacheObjectCollectionMessageSerializer.java")); + } + +/** {@code @Order Map}: generator walks keys/values via {@code keySet()/values()}. */ + @Test + public void testMapWithKeyCacheObjectAndMessageValue() { + Compilation compilation = compile("TestMapKeyCacheObjectMessage.java"); + + assertThat(compilation).succeeded(); + + assertThat(compilation) + .generatedSourceFile("org.apache.ignite.internal.TestMapKeyCacheObjectMessageSerializer") + .hasSourceEquivalentTo(javaFile("TestMapKeyCacheObjectMessageSerializer.java")); + } + /** * Negative test that verifies the compilation failed if the Compress annotation is used for unsupported types. */ diff --git a/modules/core/src/test/java/org/apache/ignite/internal/direct/DirectMarshallingMessagesTest.java b/modules/core/src/test/java/org/apache/ignite/internal/direct/DirectMarshallingMessagesTest.java index ea37b6abe4545..77cf4814eaea8 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/direct/DirectMarshallingMessagesTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/direct/DirectMarshallingMessagesTest.java @@ -50,7 +50,7 @@ public class DirectMarshallingMessagesTest extends GridCommonAbstractTest { factory -> factory.register( TestNestedContainersMessage.TYPE, TestNestedContainersMessage::new, - new TestNestedContainersMessageSerializer() + new TestNestedContainersMessageSerializer(U.gridClassLoader()) ) }); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/GridCommunicationSendMessageSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/GridCommunicationSendMessageSelfTest.java index 90d9027ad7b67..2b325359e90c6 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/GridCommunicationSendMessageSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/GridCommunicationSendMessageSelfTest.java @@ -20,6 +20,7 @@ import java.util.UUID; import java.util.concurrent.CountDownLatch; import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.plugin.AbstractTestPluginProvider; import org.apache.ignite.plugin.ExtensionRegistry; import org.apache.ignite.plugin.PluginContext; @@ -151,8 +152,9 @@ public static class TestPluginProvider extends AbstractTestPluginProvider { @Override public void initExtensions(PluginContext ctx, ExtensionRegistry registry) { registry.registerExtension(MessageFactoryProvider.class, new MessageFactoryProvider() { @Override public void registerAll(MessageFactory factory) { - factory.register(DIRECT_TYPE, TestValidByteIdMessage::new, new TestValidByteIdMessageSerializer()); - factory.register(DIRECT_TYPE_OVER_BYTE, TestOverByteIdMessage::new, new TestOverByteIdMessageSerializer()); + factory.register(DIRECT_TYPE, TestValidByteIdMessage::new, new TestValidByteIdMessageSerializer(U.gridClassLoader())); + factory.register(DIRECT_TYPE_OVER_BYTE, + TestOverByteIdMessage::new, new TestOverByteIdMessageSerializer(U.gridClassLoader())); } }); } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/IgniteMessageFactoryImplTest.java b/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/IgniteMessageFactoryImplTest.java index 838474c82c7d1..b89beeec8b82c 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/IgniteMessageFactoryImplTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/IgniteMessageFactoryImplTest.java @@ -19,6 +19,7 @@ import org.apache.ignite.IgniteException; import org.apache.ignite.internal.CoreMessagesProvider; +import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.plugin.extensions.communication.Message; import org.apache.ignite.plugin.extensions.communication.MessageFactory; import org.apache.ignite.plugin.extensions.communication.MessageFactoryProvider; @@ -107,8 +108,8 @@ public void testRegisterTheSameType() { private static class TestMessageFactoryPovider implements MessageFactoryProvider { /** {@inheritDoc} */ @Override public void registerAll(MessageFactory factory) { - factory.register(TEST_MSG_1_TYPE, TestMessage1::new, new TestMessage1Serializer()); - factory.register(TEST_MSG_42_TYPE, TestMessage42::new, new TestMessage42Serializer()); + factory.register(TEST_MSG_1_TYPE, TestMessage1::new, new TestMessage1Serializer(U.gridClassLoader())); + factory.register(TEST_MSG_42_TYPE, TestMessage42::new, new TestMessage42Serializer(U.gridClassLoader())); } } @@ -118,7 +119,7 @@ private static class TestMessageFactoryPovider implements MessageFactoryProvider private static class TestMessageFactoryPoviderWithTheSameDirectType implements MessageFactoryProvider { /** {@inheritDoc} */ @Override public void registerAll(MessageFactory factory) { - factory.register(TEST_MSG_1_TYPE, TestMessage1::new, new TestMessage1Serializer()); + factory.register(TEST_MSG_1_TYPE, TestMessage1::new, new TestMessage1Serializer(U.gridClassLoader())); } } @@ -128,7 +129,7 @@ private static class TestMessageFactoryPoviderWithTheSameDirectType implements M private static class TestMessageFactory implements MessageFactoryProvider { /** {@inheritDoc} */ @Override public void registerAll(MessageFactory factory) { - factory.register(TEST_MSG_2_TYPE, TestMessage2::new, new TestMessage2Serializer()); + factory.register(TEST_MSG_2_TYPE, TestMessage2::new, new TestMessage2Serializer(U.gridClassLoader())); } } } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/MessageDirectTypeIdConflictTest.java b/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/MessageDirectTypeIdConflictTest.java index f540a08293d02..744f5dc2e9a5a 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/MessageDirectTypeIdConflictTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/managers/communication/MessageDirectTypeIdConflictTest.java @@ -20,6 +20,7 @@ import java.util.concurrent.Callable; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.plugin.AbstractTestPluginProvider; import org.apache.ignite.plugin.ExtensionRegistry; import org.apache.ignite.plugin.PluginContext; @@ -81,7 +82,8 @@ public static class TestPluginProvider extends AbstractTestPluginProvider { @Override public void initExtensions(PluginContext ctx, ExtensionRegistry registry) { registry.registerExtension(MessageFactoryProvider.class, new MessageFactoryProvider() { @Override public void registerAll(MessageFactory factory) { - factory.register(DIRECT_TYPE, DuplicateDirectTypeIdMessage::new, new DuplicateDirectTypeIdMessageSerializer()); + factory.register(DIRECT_TYPE, + DuplicateDirectTypeIdMessage::new, new DuplicateDirectTypeIdMessageSerializer(U.gridClassLoader())); } }); } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheIoManagerRetryTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheIoManagerRetryTest.java index 0ab5cd5382219..39d54e07d8831 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheIoManagerRetryTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheIoManagerRetryTest.java @@ -27,6 +27,7 @@ import org.apache.ignite.cluster.ClusterNode; import org.apache.ignite.internal.GridKernalContext; import org.apache.ignite.internal.GridTopic; +import org.apache.ignite.internal.IgniteKernal; import org.apache.ignite.internal.managers.communication.GridIoManager; import org.apache.ignite.internal.managers.deployment.GridDeploymentManager; import org.apache.ignite.internal.managers.discovery.GridDiscoveryManager; @@ -128,6 +129,8 @@ private void doTest(Function action) throws Except cacheIoMgr.start(cctx); + ((IgniteKernal)cacheIoMgr.context().kernalContext().grid()).initMessageFactory(); + return cacheIoMgr; } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IncrementalSnapshotTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IncrementalSnapshotTest.java index 6224135de075f..1028299f7bf91 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IncrementalSnapshotTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IncrementalSnapshotTest.java @@ -23,6 +23,7 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.function.UnaryOperator; import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteException; import org.apache.ignite.cache.QueryEntity; import org.apache.ignite.cluster.ClusterState; @@ -51,6 +52,7 @@ import static org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.RESTORE_CACHE_GROUP_SNAPSHOT_PREPARE; import static org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.RESTORE_CACHE_GROUP_SNAPSHOT_START; import static org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType.RESTORE_INCREMENTAL_SNAPSHOT_START; +import static org.apache.ignite.marshaller.Marshallers.jdk; import static org.apache.ignite.testframework.GridTestUtils.assertThrows; import static org.apache.ignite.testframework.GridTestUtils.assertThrowsWithCause; import static org.apache.ignite.testframework.GridTestUtils.waitForCondition; @@ -426,8 +428,18 @@ public void testStagesFail() throws Exception { DistributedProcess.DistributedProcessType stage = failStage.get(); - if (stage != null && stage.ordinal() == singleMsg.type()) - GridTestUtils.setFieldValue(singleMsg, "errMsg", new ErrorMessage(new IgniteException("Test exception."))); + if (stage != null && stage.ordinal() == singleMsg.type()) { + ErrorMessage em = new ErrorMessage(new IgniteException("Test exception.")); + + try { + em.prepareMarshal(jdk()); + } + catch (IgniteCheckedException e) { + throw new RuntimeException(e); + } + + GridTestUtils.setFieldValue(singleMsg, "errMsg", em); + } } return false; diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/IgniteCacheContinuousQueryImmutableEntryTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/IgniteCacheContinuousQueryImmutableEntryTest.java index a41490c0e405f..285ddb2362bb2 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/IgniteCacheContinuousQueryImmutableEntryTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/query/continuous/IgniteCacheContinuousQueryImmutableEntryTest.java @@ -182,11 +182,11 @@ public void testCacheContinuousQueryEntrySerialization() { // Key and value shouldn't be serialized in case an event is filtered. assertNull(e1.key()); - assertNotNull(e0.key()); + assertNull(e0.key()); assertNull(e1.oldValue()); - assertNotNull(e0.oldValue()); + assertNull(e0.oldValue()); assertNull(e1.newValue()); - assertNotNull(e0.newValue()); + assertNull(e0.newValue()); } /** @@ -207,7 +207,7 @@ private static class CacheEventFilter implements CacheEntryEventFilter evt) { evts.add(evt); - return false; + return true; } } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxDeadlockDetectionMessageMarshallingTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxDeadlockDetectionMessageMarshallingTest.java index a6d6375c1ed87..e6f32de834b40 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxDeadlockDetectionMessageMarshallingTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxDeadlockDetectionMessageMarshallingTest.java @@ -65,7 +65,7 @@ public void testMessageUnmarshallWithoutCacheContext() throws Exception { @Override public void onMessage(UUID nodeId, Object msg, byte plc) { if (msg instanceof TxLocksResponse) { try { - ((TxLocksResponse)msg).finishUnmarshal(clientCtx, clientCtx.deploy().globalLoader()); + ((TxLocksResponse)msg).finishUnmarshal(clientCtx.marshaller(), clientCtx.deploy().globalLoader()); res.set(true); } @@ -86,7 +86,7 @@ public void testMessageUnmarshallWithoutCacheContext() throws Exception { TxLocksResponse msg = new TxLocksResponse(); msg.addKey(cctx.txKey(key)); - msg.prepareMarshal(cctx.shared()); + msg.prepareDeployment(cctx.shared()); ((IgniteKernal)ignite).context().cache().context().gridIO().sendToCustomTopic( ((IgniteKernal)client).localNode(), TOPIC, msg, GridIoPolicy.PUBLIC_POOL); diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerImplSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerImplSelfTest.java index 625f290d1c6fc..ddb5a7f0cc985 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerImplSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/datastreamer/DataStreamerImplSelfTest.java @@ -32,6 +32,7 @@ import javax.cache.CacheException; import org.apache.ignite.Ignite; import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteDataStreamer; import org.apache.ignite.IgniteException; import org.apache.ignite.IgniteLogger; @@ -51,6 +52,7 @@ import org.apache.ignite.lang.IgniteFuture; import org.apache.ignite.lang.IgniteInClosure; import org.apache.ignite.plugin.extensions.communication.Message; +import org.apache.ignite.plugin.extensions.communication.MessageSerializer; import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi; import org.apache.ignite.stream.StreamReceiver; import org.apache.ignite.testframework.GridTestUtils; @@ -713,6 +715,15 @@ private static class StaleTopologyCommunicationSpi extends TcpCommunicationSpi { ioMsg.skipOnTimeout() ); + MessageSerializer msgSer = ((IgniteEx)ignite).context().messageFactory().serializer(msg.directType()); + + try { + msgSer.prepareMarshal(msg, ((IgniteEx)ignite).context(), null); + } + catch (IgniteCheckedException e) { + throw new RuntimeException(e); + } + needStaleTop = false; } } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/nio/IgniteExceptionInNioWorkerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/nio/IgniteExceptionInNioWorkerSelfTest.java index bceb60e4f6375..0f46c4715f857 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/util/nio/IgniteExceptionInNioWorkerSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/util/nio/IgniteExceptionInNioWorkerSelfTest.java @@ -18,11 +18,19 @@ package org.apache.ignite.internal.util.nio; import java.util.UUID; +import org.apache.ignite.IgniteException; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.GridTopic; import org.apache.ignite.internal.IgniteDiagnosticRequest; import org.apache.ignite.internal.IgniteKernal; +import org.apache.ignite.plugin.AbstractTestPluginProvider; +import org.apache.ignite.plugin.ExtensionRegistry; +import org.apache.ignite.plugin.PluginContext; +import org.apache.ignite.plugin.extensions.communication.MessageFactoryProvider; +import org.apache.ignite.plugin.extensions.communication.MessageReader; +import org.apache.ignite.plugin.extensions.communication.MessageSerializer; +import org.apache.ignite.plugin.extensions.communication.MessageWriter; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; import org.junit.Test; @@ -43,6 +51,8 @@ public class IgniteExceptionInNioWorkerSelfTest extends GridCommonAbstractTest { cfg.setCacheConfiguration(ccfg); + cfg.setPluginProviders(new BrokenMessageProvider()); + return cfg; } @@ -73,19 +83,50 @@ public void testBrokenMessage() throws Exception { * */ private static class BrokenMessage extends IgniteDiagnosticRequest { + // No-op. + } + + /** */ + private static class BrokenMessageSerializer implements MessageSerializer { /** */ private boolean fail = true; - /** {@inheritDoc} */ - @Override public short directType() { + /** */ + @Override public boolean writeTo(BrokenMessage msg, MessageWriter writer) { + if (!writer.isHeaderWritten()) { + if (!writer.writeHeader(msg.directType())) + return false; + + writer.onHeaderWritten(); + } + if (fail) { fail = false; - return (byte)242; + throw new IgniteException("Broken message"); } - // IgniteDiagnosticRequest as an example. - return 13003; + return true; + } + + /** */ + @Override public boolean readFrom(BrokenMessage msg, MessageReader reader) { + return true; + } + } + + /** */ + public static class BrokenMessageProvider extends AbstractTestPluginProvider { + /** {@inheritDoc} */ + @Override public String name() { + return getClass().getName(); + } + + /** {@inheritDoc} */ + @Override public void initExtensions(PluginContext ctx, ExtensionRegistry registry) { + registry.registerExtension(MessageFactoryProvider.class, (factory) -> + factory.register(-42, BrokenMessage::new, new BrokenMessageSerializer()) + ); } } } diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/nio/TcpCommunicationSpiSslVolatilePayloadTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/nio/TcpCommunicationSpiSslVolatilePayloadTest.java index 9be2ee3156092..e0259a5ee4040 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/util/nio/TcpCommunicationSpiSslVolatilePayloadTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/util/nio/TcpCommunicationSpiSslVolatilePayloadTest.java @@ -96,7 +96,8 @@ public class TcpCommunicationSpiSslVolatilePayloadTest extends GridAbstractCommu /** {@inheritDoc} */ @Override protected MessageFactoryProvider customMessageFactory() { return f -> f.register( - TestVolatilePayloadMessage.DIRECT_TYPE, TestVolatilePayloadMessage::new, new TestVolatilePayloadMessageSerializer() + TestVolatilePayloadMessage.DIRECT_TYPE, + TestVolatilePayloadMessage::new, new TestVolatilePayloadMessageSerializer(U.gridClassLoader()) ); } diff --git a/modules/core/src/test/java/org/apache/ignite/p2p/ClassLoadingProblemExceptionTest.java b/modules/core/src/test/java/org/apache/ignite/p2p/ClassLoadingProblemExceptionTest.java index 44a39859e05b7..3c4853ca04efe 100644 --- a/modules/core/src/test/java/org/apache/ignite/p2p/ClassLoadingProblemExceptionTest.java +++ b/modules/core/src/test/java/org/apache/ignite/p2p/ClassLoadingProblemExceptionTest.java @@ -197,7 +197,7 @@ private class TestCommunicationSpi extends TcpCommunicationSpi { GridCacheQueryRequest qryReq = (GridCacheQueryRequest)m; if (qryReq.deployInfo() != null) { - qryReq.prepare( + qryReq.prepareDeployment( new GridDeploymentInfoBean( IgniteUuid.fromUuid(UUID.randomUUID()), qryReq.deployInfo().userVersion(), diff --git a/modules/core/src/test/java/org/apache/ignite/spi/communication/GridCacheMessageSelfTest.java b/modules/core/src/test/java/org/apache/ignite/spi/communication/GridCacheMessageSelfTest.java index 5357052713835..ecb8a67eb653e 100644 --- a/modules/core/src/test/java/org/apache/ignite/spi/communication/GridCacheMessageSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/spi/communication/GridCacheMessageSelfTest.java @@ -34,6 +34,7 @@ import org.apache.ignite.internal.managers.communication.GridMessageListener; import org.apache.ignite.internal.processors.cache.GridCacheMessage; import org.apache.ignite.internal.util.typedef.CI2; +import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.plugin.AbstractTestPluginProvider; import org.apache.ignite.plugin.ExtensionRegistry; import org.apache.ignite.plugin.PluginContext; @@ -231,11 +232,11 @@ public static class TestPluginProvider extends AbstractTestPluginProvider { /** {@inheritDoc} */ @Override public void initExtensions(PluginContext ctx, ExtensionRegistry registry) { registry.registerExtension(MessageFactoryProvider.class, factory -> { - factory.register(TestMessage.DIRECT_TYPE, TestMessage::new, new TestMessageSerializer()); - factory.register(GridTestMessage.DIRECT_TYPE, GridTestMessage::new, new GridTestMessageSerializer()); - factory.register(TestMessage1.DIRECT_TYPE, TestMessage1::new, new TestMessage1Serializer()); - factory.register(TestMessage2.DIRECT_TYPE, TestMessage2::new, new TestMessage2Serializer()); - factory.register(TestBadMessage.DIRECT_TYPE, TestBadMessage::new, new TestBadMessageSerializer()); + factory.register(TestMessage.DIRECT_TYPE, TestMessage::new, new TestMessageSerializer(U.gridClassLoader())); + factory.register(GridTestMessage.DIRECT_TYPE, GridTestMessage::new, new GridTestMessageSerializer(U.gridClassLoader())); + factory.register(TestMessage1.DIRECT_TYPE, TestMessage1::new, new TestMessage1Serializer(U.gridClassLoader())); + factory.register(TestMessage2.DIRECT_TYPE, TestMessage2::new, new TestMessage2Serializer(U.gridClassLoader())); + factory.register(TestBadMessage.DIRECT_TYPE, TestBadMessage::new, new TestBadMessageSerializer(U.gridClassLoader())); }); } } diff --git a/modules/core/src/test/java/org/apache/ignite/spi/communication/GridTestMessage.java b/modules/core/src/test/java/org/apache/ignite/spi/communication/GridTestMessage.java index 83a6ea91775b7..21c115a4e019d 100644 --- a/modules/core/src/test/java/org/apache/ignite/spi/communication/GridTestMessage.java +++ b/modules/core/src/test/java/org/apache/ignite/spi/communication/GridTestMessage.java @@ -20,6 +20,7 @@ import java.util.Objects; import java.util.UUID; import org.apache.ignite.internal.Order; +import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.plugin.extensions.communication.Message; import org.apache.ignite.plugin.extensions.communication.MessageFactoryProvider; @@ -32,7 +33,7 @@ public class GridTestMessage implements Message { /** */ public static final MessageFactoryProvider GRID_TEST_MESSAGE_FACTORY = f -> f.register( - GridTestMessage.DIRECT_TYPE, GridTestMessage::new, new GridTestMessageSerializer()); + GridTestMessage.DIRECT_TYPE, GridTestMessage::new, new GridTestMessageSerializer(U.gridClassLoader())); /** */ @Order(0) diff --git a/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpiSkipMessageSendTest.java b/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpiSkipMessageSendTest.java index aeba1e4d7c136..a9ea6d824db20 100644 --- a/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpiSkipMessageSendTest.java +++ b/modules/core/src/test/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpiSkipMessageSendTest.java @@ -278,7 +278,7 @@ class CustomDiscoverySpi extends TcpDiscoverySpi { private final CountDownLatch netDisabledLatch = new CountDownLatch(1); /** {@inheritDoc} */ - @Override protected T readMessage(TcpDiscoveryIoSession ses, + @Override protected T readMessage(TcpDiscoveryIoSession ses, long timeout) throws IOException, IgniteCheckedException { if (netDisabled) { U.sleep(timeout); diff --git a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/DiscoveryDeserializationExceptionTest.java b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/DiscoveryDeserializationExceptionTest.java index cfe047d58e75d..10aeab8dab0d4 100644 --- a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/DiscoveryDeserializationExceptionTest.java +++ b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/DiscoveryDeserializationExceptionTest.java @@ -25,6 +25,7 @@ import org.apache.ignite.failure.FailureContext; import org.apache.ignite.failure.FailureType; import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.plugin.AbstractTestPluginProvider; import org.apache.ignite.plugin.ExtensionRegistry; import org.apache.ignite.plugin.PluginContext; @@ -138,7 +139,7 @@ public static class NotRegisteredMessageProvider extends AbstractTestPluginProvi /** {@inheritDoc} */ @Override public void initExtensions(PluginContext ctx, ExtensionRegistry registry) { registry.registerExtension(MessageFactoryProvider.class, (factory) -> - factory.register(MSG_DIRECT_TYPE, NotRegisteredMessage::new, new NotRegisteredMessageSerializer()) + factory.register(MSG_DIRECT_TYPE, NotRegisteredMessage::new, new NotRegisteredMessageSerializer(U.gridClassLoader())) ); } } diff --git a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/DiscoveryUnmarshalVulnerabilityTest.java b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/DiscoveryUnmarshalVulnerabilityTest.java index 830e9aa27e4c5..9cf44281893f3 100644 --- a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/DiscoveryUnmarshalVulnerabilityTest.java +++ b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/DiscoveryUnmarshalVulnerabilityTest.java @@ -26,10 +26,13 @@ import java.net.Socket; import java.nio.ByteBuffer; import java.util.concurrent.atomic.AtomicBoolean; +import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.CoreMessagesProvider; +import org.apache.ignite.internal.GridKernalContext; import org.apache.ignite.internal.direct.DirectMessageWriter; import org.apache.ignite.internal.plugin.AbstractMarshallableMessageFactoryProvider; +import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.util.IgniteUtils; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.marshaller.Marshallers; @@ -48,6 +51,7 @@ import static org.apache.ignite.IgniteSystemProperties.IGNITE_ENABLE_OBJECT_INPUT_FILTER_AUTOCONFIGURATION; import static org.apache.ignite.IgniteSystemProperties.IGNITE_MARSHALLER_BLACKLIST; import static org.apache.ignite.IgniteSystemProperties.IGNITE_MARSHALLER_WHITELIST; +import static org.apache.ignite.marshaller.Marshallers.jdk; import static org.apache.ignite.testframework.GridTestUtils.loadSerializer; /** @@ -60,6 +64,9 @@ public class DiscoveryUnmarshalVulnerabilityTest extends GridCommonAbstractTest /** */ private LogListener lsnr; + + /** */ + private MessageSerializer serializer; /** {@inheritDoc} */ @Override protected void beforeTest() throws Exception { @@ -82,10 +89,12 @@ public class DiscoveryUnmarshalVulnerabilityTest extends GridCommonAbstractTest @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { MessageFactoryProvider msgFactoryProvider = new AbstractMarshallableMessageFactoryProvider() { @Override public void registerAll(MessageFactory factory) { + serializer = new MessageSerializerWrapper(this); + factory.register( CoreMessagesProvider.MAX_MESSAGE_ID + 1, ExploitMessage::new, - new MessageSerializerWrapper(this)); + serializer); } }; @@ -214,7 +223,7 @@ private void attack(byte[] data) throws IOException { } /** */ - private byte[] serializedMessage() { + private byte[] serializedMessage() throws IgniteCheckedException { ByteBuffer buf = ByteBuffer.allocate(4096); MessageFactory msgFactory = ((TcpDiscoverySpi)grid().configuration().getDiscoverySpi()).messageFactory(); @@ -222,7 +231,11 @@ private byte[] serializedMessage() { DirectMessageWriter writer = new DirectMessageWriter(msgFactory); writer.setBuffer(buf); - writer.writeMessage(new ExploitMessage(new Exploit())); + ExploitMessage msg = new ExploitMessage(new Exploit()); + + serializer.prepareMarshal(msg, grid().context(), null); + + writer.writeMessage(msg); return buf.flip().compact().array(); } @@ -267,6 +280,12 @@ private MessageSerializerWrapper(AbstractMarshallableMessageFactoryProvider prov return serde.readFrom(msg, reader); } + /** {@inheritDoc} */ + @Override public void prepareMarshal(ExploitMessage msg, GridKernalContext kctx, + GridCacheContext nested) throws IgniteCheckedException { + msg.prepareMarshal(jdk()); + } + /** */ private void initIfNecessary() { if (init.get() && init.compareAndSet(true, false)) diff --git a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpClientDiscoverySpiFailureTimeoutSelfTest.java b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpClientDiscoverySpiFailureTimeoutSelfTest.java index 10645f5fc25d6..49ba4f269821d 100644 --- a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpClientDiscoverySpiFailureTimeoutSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpClientDiscoverySpiFailureTimeoutSelfTest.java @@ -36,6 +36,7 @@ import org.apache.ignite.internal.util.typedef.X; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.lang.IgnitePredicate; +import org.apache.ignite.plugin.extensions.communication.Message; import org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode; import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; import org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage; @@ -516,7 +517,7 @@ private static class TestTcpDiscoverySpi2 extends TcpDiscoverySpi { } /** {@inheritDoc} */ - @Override protected T readMessage(TcpDiscoveryIoSession ses, long timeout) + @Override protected T readMessage(TcpDiscoveryIoSession ses, long timeout) throws IOException, IgniteCheckedException { long currTimeout = getLocalNode().isClient() ? clientFailureDetectionTimeout() : failureDetectionTimeout(); diff --git a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySslSecuredUnsecuredTest.java b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySslSecuredUnsecuredTest.java index dcf9931ef9236..79b6962db51e6 100644 --- a/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySslSecuredUnsecuredTest.java +++ b/modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySslSecuredUnsecuredTest.java @@ -23,6 +23,7 @@ import javax.net.ssl.SSLException; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.plugin.extensions.communication.Message; import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder; import org.apache.ignite.testframework.GridTestUtils; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; @@ -174,7 +175,7 @@ private FailDiscoverySpi(final boolean plain) { } /** {@inheritDoc} */ - @Override protected T readMessage(final TcpDiscoveryIoSession ses, + @Override protected T readMessage(final TcpDiscoveryIoSession ses, final long timeout) throws IOException, IgniteCheckedException { if (cnt-- > 0) { if (plain) diff --git a/modules/core/src/test/resources/codegen/KeyCacheObjectEntryMsg.java b/modules/core/src/test/resources/codegen/KeyCacheObjectEntryMsg.java new file mode 100644 index 0000000000000..80d23d2e6ad09 --- /dev/null +++ b/modules/core/src/test/resources/codegen/KeyCacheObjectEntryMsg.java @@ -0,0 +1,35 @@ +/* + * 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; + +import org.apache.ignite.internal.processors.cache.KeyCacheObject; +import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; +import org.apache.ignite.plugin.extensions.communication.Message; + +/** APT fixture: entry Message for {@link TestKeyCacheObjectCollectionMessage}. */ +public class KeyCacheObjectEntryMsg implements Message { + @Order(0) + KeyCacheObject key; + + @Order(1) + GridCacheVersion val; + + public short directType() { + return 0; + } +} diff --git a/modules/core/src/test/resources/codegen/KeyCacheObjectEntryMsgSerializer.java b/modules/core/src/test/resources/codegen/KeyCacheObjectEntryMsgSerializer.java new file mode 100644 index 0000000000000..59e90a33c9ade --- /dev/null +++ b/modules/core/src/test/resources/codegen/KeyCacheObjectEntryMsgSerializer.java @@ -0,0 +1,95 @@ +/* + * 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; + +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.KeyCacheObjectEntryMsg; +import org.apache.ignite.internal.processors.cache.CacheObjectValueContext; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.internal.processors.cache.version.GridCacheVersionSerializer; +import org.apache.ignite.plugin.extensions.communication.MessageReader; +import org.apache.ignite.plugin.extensions.communication.MessageSerializer; +import org.apache.ignite.plugin.extensions.communication.MessageWriter; + +/** + * This class is generated automatically. + * + * @see org.apache.ignite.internal.MessageProcessor + */ +public class KeyCacheObjectEntryMsgSerializer implements MessageSerializer { + /** */ + private final static GridCacheVersionSerializer GRID_CACHE_VERSION_SER = new GridCacheVersionSerializer(); + + /** */ + @Override public boolean writeTo(KeyCacheObjectEntryMsg msg, MessageWriter writer) { + if (!writer.isHeaderWritten()) { + if (!writer.writeHeader(msg.directType())) + return false; + + writer.onHeaderWritten(); + } + + switch (writer.state()) { + case 0: + if (!writer.writeKeyCacheObject(msg.key)) + return false; + + writer.incrementState(); + + case 1: + if (!writer.writeMessage(msg.val)) + return false; + + writer.incrementState(); + } + + return true; + } + + /** */ + @Override public boolean readFrom(KeyCacheObjectEntryMsg msg, MessageReader reader) { + switch (reader.state()) { + case 0: + msg.key = reader.readKeyCacheObject(); + + if (!reader.isLastRead()) + return false; + + reader.incrementState(); + + case 1: + msg.val = reader.readMessage(); + + if (!reader.isLastRead()) + return false; + + reader.incrementState(); + } + + return true; + } + + /** */ + @Override public void prepareMarshalCacheObjects(KeyCacheObjectEntryMsg msg, CacheObjectValueContext ctx, GridCacheSharedContext sharedCtx) throws IgniteCheckedException { + if (msg.key != null) + msg.key.prepareMarshal(ctx); + + if (msg.val != null) + GRID_CACHE_VERSION_SER.prepareMarshalCacheObjects(msg.val, ctx, sharedCtx); + } +} \ No newline at end of file diff --git a/modules/core/src/test/resources/codegen/TestCollectionsMessageSerializer.java b/modules/core/src/test/resources/codegen/TestCollectionsMessageSerializer.java index 329f334337488..496d5c889d7e1 100644 --- a/modules/core/src/test/resources/codegen/TestCollectionsMessageSerializer.java +++ b/modules/core/src/test/resources/codegen/TestCollectionsMessageSerializer.java @@ -17,7 +17,12 @@ package org.apache.ignite.internal; +import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.TestCollectionsMessage; +import org.apache.ignite.internal.processors.cache.CacheObjectValueContext; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; +import org.apache.ignite.internal.processors.cache.version.GridCacheVersionSerializer; import org.apache.ignite.plugin.extensions.communication.MessageCollectionItemType; import org.apache.ignite.plugin.extensions.communication.MessageCollectionType; import org.apache.ignite.plugin.extensions.communication.MessageItemType; @@ -32,55 +37,57 @@ */ public class TestCollectionsMessageSerializer implements MessageSerializer { /** */ - private final static MessageCollectionType affTopVersionListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.AFFINITY_TOPOLOGY_VERSION), false); + private final static GridCacheVersionSerializer GRID_CACHE_VERSION_SER = new GridCacheVersionSerializer(); /** */ - private final static MessageCollectionType bitSetListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.BIT_SET), false); + private static final MessageCollectionType affTopVersionListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.AFFINITY_TOPOLOGY_VERSION), false); /** */ - private final static MessageCollectionType bitSetSetCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.BIT_SET), true); + private static final MessageCollectionType bitSetListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.BIT_SET), false); /** */ - private final static MessageCollectionType booleanArrayListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.BOOLEAN_ARR), false); + private static final MessageCollectionType bitSetSetCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.BIT_SET), true); /** */ - private final static MessageCollectionType boxedBooleanListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.BOOLEAN), false); + private static final MessageCollectionType booleanArrayListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.BOOLEAN_ARR), false); /** */ - private final static MessageCollectionType boxedByteListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.BYTE), false); + private static final MessageCollectionType boxedBooleanListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.BOOLEAN), false); /** */ - private final static MessageCollectionType boxedCharListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.CHAR), false); + private static final MessageCollectionType boxedByteListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.BYTE), false); /** */ - private final static MessageCollectionType boxedDoubleListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.DOUBLE), false); + private static final MessageCollectionType boxedCharListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.CHAR), false); /** */ - private final static MessageCollectionType boxedFloatListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.FLOAT), false); + private static final MessageCollectionType boxedDoubleListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.DOUBLE), false); /** */ - private final static MessageCollectionType boxedIntListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.INT), false); + private static final MessageCollectionType boxedFloatListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.FLOAT), false); /** */ - private final static MessageCollectionType boxedIntegerSetCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.INT), true); + private static final MessageCollectionType boxedIntListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.INT), false); /** */ - private final static MessageCollectionType boxedLongListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.LONG), false); + private static final MessageCollectionType boxedIntegerSetCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.INT), true); /** */ - private final static MessageCollectionType boxedShortListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.SHORT), false); + private static final MessageCollectionType boxedLongListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.LONG), false); /** */ - private final static MessageCollectionType byteArrayListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.BYTE_ARR), false); + private static final MessageCollectionType boxedShortListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.SHORT), false); /** */ - private final static MessageCollectionType charArrayListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.CHAR_ARR), false); + private static final MessageCollectionType byteArrayListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.BYTE_ARR), false); /** */ - private final static MessageCollectionType doubleArrayListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.DOUBLE_ARR), false); + private static final MessageCollectionType charArrayListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.CHAR_ARR), false); /** */ - private final static MessageCollectionType floatArrayListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.FLOAT_ARR), false); + private static final MessageCollectionType doubleArrayListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.DOUBLE_ARR), false); /** */ - private final static MessageCollectionType gridLongListListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.GRID_LONG_LIST), false); + private static final MessageCollectionType floatArrayListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.FLOAT_ARR), false); /** */ - private final static MessageCollectionType igniteUuidListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.IGNITE_UUID), false); + private static final MessageCollectionType gridLongListListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.GRID_LONG_LIST), false); /** */ - private final static MessageCollectionType intArrayListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.INT_ARR), false); + private static final MessageCollectionType igniteUuidListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.IGNITE_UUID), false); /** */ - private final static MessageCollectionType longArrayListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.LONG_ARR), false); + private static final MessageCollectionType intArrayListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.INT_ARR), false); /** */ - private final static MessageCollectionType messageListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.MSG), false); + private static final MessageCollectionType longArrayListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.LONG_ARR), false); /** */ - private final static MessageCollectionType shortArrayListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.SHORT_ARR), false); + private static final MessageCollectionType messageListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.MSG), false); /** */ - private final static MessageCollectionType stringListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.STRING), false); + private static final MessageCollectionType shortArrayListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.SHORT_ARR), false); /** */ - private final static MessageCollectionType uuidListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.UUID), false); + private static final MessageCollectionType stringListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.STRING), false); + /** */ + private static final MessageCollectionType uuidListCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.UUID), false); /** */ @Override public boolean writeTo(TestCollectionsMessage msg, MessageWriter writer) { @@ -452,4 +459,14 @@ public class TestCollectionsMessageSerializer implements MessageSerializer} field. */ +public class TestKeyCacheObjectCollectionMessage implements Message { + @Order(0) + Collection entries; + + @Order(1) + KeyCacheObjectEntryMsg[] entriesArr; + + public short directType() { + return 1; + } +} diff --git a/modules/core/src/test/resources/codegen/TestKeyCacheObjectCollectionMessageSerializer.java b/modules/core/src/test/resources/codegen/TestKeyCacheObjectCollectionMessageSerializer.java new file mode 100644 index 0000000000000..70510b79eee0c --- /dev/null +++ b/modules/core/src/test/resources/codegen/TestKeyCacheObjectCollectionMessageSerializer.java @@ -0,0 +1,112 @@ +/* + * 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; + +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.KeyCacheObjectEntryMsg; +import org.apache.ignite.internal.KeyCacheObjectEntryMsgSerializer; +import org.apache.ignite.internal.TestKeyCacheObjectCollectionMessage; +import org.apache.ignite.internal.processors.cache.CacheObjectValueContext; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.plugin.extensions.communication.MessageArrayType; +import org.apache.ignite.plugin.extensions.communication.MessageCollectionItemType; +import org.apache.ignite.plugin.extensions.communication.MessageCollectionType; +import org.apache.ignite.plugin.extensions.communication.MessageItemType; +import org.apache.ignite.plugin.extensions.communication.MessageReader; +import org.apache.ignite.plugin.extensions.communication.MessageSerializer; +import org.apache.ignite.plugin.extensions.communication.MessageWriter; + +/** + * This class is generated automatically. + * + * @see org.apache.ignite.internal.MessageProcessor + */ +public class TestKeyCacheObjectCollectionMessageSerializer implements MessageSerializer { + /** */ + private final static KeyCacheObjectEntryMsgSerializer KEY_CACHE_OBJECT_ENTRY_MSG_SER = new KeyCacheObjectEntryMsgSerializer(); + /** */ + private static final MessageArrayType entriesArrCollDesc = new MessageArrayType(new MessageItemType(MessageCollectionItemType.MSG), KeyCacheObjectEntryMsg.class); + /** */ + private static final MessageCollectionType entriesCollDesc = new MessageCollectionType(new MessageItemType(MessageCollectionItemType.MSG), false); + + /** */ + @Override public boolean writeTo(TestKeyCacheObjectCollectionMessage msg, MessageWriter writer) { + if (!writer.isHeaderWritten()) { + if (!writer.writeHeader(msg.directType())) + return false; + + writer.onHeaderWritten(); + } + + switch (writer.state()) { + case 0: + if (!writer.writeCollection(msg.entries, entriesCollDesc)) + return false; + + writer.incrementState(); + + case 1: + if (!writer.writeObjectArray(msg.entriesArr, entriesArrCollDesc)) + return false; + + writer.incrementState(); + } + + return true; + } + + /** */ + @Override public boolean readFrom(TestKeyCacheObjectCollectionMessage msg, MessageReader reader) { + switch (reader.state()) { + case 0: + msg.entries = reader.readCollection(entriesCollDesc); + + if (!reader.isLastRead()) + return false; + + reader.incrementState(); + + case 1: + msg.entriesArr = reader.readObjectArray(entriesArrCollDesc); + + if (!reader.isLastRead()) + return false; + + reader.incrementState(); + } + + return true; + } + + /** */ + @Override public void prepareMarshalCacheObjects(TestKeyCacheObjectCollectionMessage msg, CacheObjectValueContext ctx, GridCacheSharedContext sharedCtx) throws IgniteCheckedException { + if (msg.entries != null) { + for (KeyCacheObjectEntryMsg e : msg.entries) { + if (e != null) + KEY_CACHE_OBJECT_ENTRY_MSG_SER.prepareMarshalCacheObjects(e, ctx, sharedCtx); + } + } + + if (msg.entriesArr != null) { + for (KeyCacheObjectEntryMsg e : msg.entriesArr) { + if (e != null) + KEY_CACHE_OBJECT_ENTRY_MSG_SER.prepareMarshalCacheObjects(e, ctx, sharedCtx); + } + } + } +} diff --git a/modules/core/src/test/resources/codegen/TestMapKeyCacheObjectMessage.java b/modules/core/src/test/resources/codegen/TestMapKeyCacheObjectMessage.java new file mode 100644 index 0000000000000..1956319cef672 --- /dev/null +++ b/modules/core/src/test/resources/codegen/TestMapKeyCacheObjectMessage.java @@ -0,0 +1,33 @@ +/* + * 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; + +import java.util.Map; +import org.apache.ignite.internal.processors.cache.KeyCacheObject; +import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; +import org.apache.ignite.plugin.extensions.communication.Message; + +/** APT fixture: {@code @Order Map} is safe — deferred {@code HashMap} assembly. */ +public class TestMapKeyCacheObjectMessage implements Message { + @Order(0) + Map entries; + + public short directType() { + return 0; + } +} diff --git a/modules/core/src/test/resources/codegen/TestMapKeyCacheObjectMessageSerializer.java b/modules/core/src/test/resources/codegen/TestMapKeyCacheObjectMessageSerializer.java new file mode 100644 index 0000000000000..c7217c0dba9e3 --- /dev/null +++ b/modules/core/src/test/resources/codegen/TestMapKeyCacheObjectMessageSerializer.java @@ -0,0 +1,94 @@ +/* + * 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; + +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.TestMapKeyCacheObjectMessage; +import org.apache.ignite.internal.processors.cache.CacheObjectValueContext; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.internal.processors.cache.KeyCacheObject; +import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; +import org.apache.ignite.internal.processors.cache.version.GridCacheVersionSerializer; +import org.apache.ignite.plugin.extensions.communication.MessageCollectionItemType; +import org.apache.ignite.plugin.extensions.communication.MessageItemType; +import org.apache.ignite.plugin.extensions.communication.MessageMapType; +import org.apache.ignite.plugin.extensions.communication.MessageReader; +import org.apache.ignite.plugin.extensions.communication.MessageSerializer; +import org.apache.ignite.plugin.extensions.communication.MessageWriter; + +/** + * This class is generated automatically. + * + * @see org.apache.ignite.internal.MessageProcessor + */ +public class TestMapKeyCacheObjectMessageSerializer implements MessageSerializer { + /** */ + private final static GridCacheVersionSerializer GRID_CACHE_VERSION_SER = new GridCacheVersionSerializer(); + /** */ + private static final MessageMapType entriesCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.KEY_CACHE_OBJECT), new MessageItemType(MessageCollectionItemType.MSG), false); + + /** */ + @Override public boolean writeTo(TestMapKeyCacheObjectMessage msg, MessageWriter writer) { + if (!writer.isHeaderWritten()) { + if (!writer.writeHeader(msg.directType())) + return false; + + writer.onHeaderWritten(); + } + + switch (writer.state()) { + case 0: + if (!writer.writeMap(msg.entries, entriesCollDesc)) + return false; + + writer.incrementState(); + } + + return true; + } + + /** */ + @Override public boolean readFrom(TestMapKeyCacheObjectMessage msg, MessageReader reader) { + switch (reader.state()) { + case 0: + msg.entries = reader.readMap(entriesCollDesc); + + if (!reader.isLastRead()) + return false; + + reader.incrementState(); + } + + return true; + } + + /** */ + @Override public void prepareMarshalCacheObjects(TestMapKeyCacheObjectMessage msg, CacheObjectValueContext ctx, GridCacheSharedContext sharedCtx) throws IgniteCheckedException { + if (msg.entries != null) { + for (KeyCacheObject k : msg.entries.keySet()) { + if (k != null) + k.prepareMarshal(ctx); + } + + for (GridCacheVersion v : msg.entries.values()) { + if (v != null) + GRID_CACHE_VERSION_SER.prepareMarshalCacheObjects(v, ctx, sharedCtx); + } + } + } +} \ No newline at end of file diff --git a/modules/core/src/test/resources/codegen/TestMapMessageSerializer.java b/modules/core/src/test/resources/codegen/TestMapMessageSerializer.java index b2e66053653df..d210abbc82ba8 100644 --- a/modules/core/src/test/resources/codegen/TestMapMessageSerializer.java +++ b/modules/core/src/test/resources/codegen/TestMapMessageSerializer.java @@ -17,7 +17,12 @@ package org.apache.ignite.internal; +import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.internal.TestMapMessage; +import org.apache.ignite.internal.processors.cache.CacheObjectValueContext; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; +import org.apache.ignite.internal.processors.cache.version.GridCacheVersionSerializer; import org.apache.ignite.plugin.extensions.communication.MessageCollectionItemType; import org.apache.ignite.plugin.extensions.communication.MessageCollectionType; import org.apache.ignite.plugin.extensions.communication.MessageItemType; @@ -33,55 +38,57 @@ */ public class TestMapMessageSerializer implements MessageSerializer { /** */ - private final static MessageMapType affTopVersionIgniteUuidMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.AFFINITY_TOPOLOGY_VERSION), new MessageItemType(MessageCollectionItemType.IGNITE_UUID), false); + private final static GridCacheVersionSerializer GRID_CACHE_VERSION_SER = new GridCacheVersionSerializer(); /** */ - private final static MessageMapType bitSetUuidMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.BIT_SET), new MessageItemType(MessageCollectionItemType.UUID), false); + private static final MessageMapType affTopVersionIgniteUuidMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.AFFINITY_TOPOLOGY_VERSION), new MessageItemType(MessageCollectionItemType.IGNITE_UUID), false); /** */ - private final static MessageMapType booleanArrayBoxedLongMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.BOOLEAN_ARR), new MessageItemType(MessageCollectionItemType.LONG), false); + private static final MessageMapType bitSetUuidMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.BIT_SET), new MessageItemType(MessageCollectionItemType.UUID), false); /** */ - private final static MessageMapType boxedBooleanAffTopVersionMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.BOOLEAN), new MessageItemType(MessageCollectionItemType.AFFINITY_TOPOLOGY_VERSION), false); + private static final MessageMapType booleanArrayBoxedLongMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.BOOLEAN_ARR), new MessageItemType(MessageCollectionItemType.LONG), false); /** */ - private final static MessageMapType boxedByteBoxedBooleanMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.BYTE), new MessageItemType(MessageCollectionItemType.BOOLEAN), false); + private static final MessageMapType boxedBooleanAffTopVersionMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.BOOLEAN), new MessageItemType(MessageCollectionItemType.AFFINITY_TOPOLOGY_VERSION), false); /** */ - private final static MessageMapType boxedCharBoxedLongMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.CHAR), new MessageItemType(MessageCollectionItemType.LONG), false); + private static final MessageMapType boxedByteBoxedBooleanMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.BYTE), new MessageItemType(MessageCollectionItemType.BOOLEAN), false); /** */ - private final static MessageMapType boxedDoubleBoxedFloatMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.DOUBLE), new MessageItemType(MessageCollectionItemType.FLOAT), false); + private static final MessageMapType boxedCharBoxedLongMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.CHAR), new MessageItemType(MessageCollectionItemType.LONG), false); /** */ - private final static MessageMapType boxedFloatBoxedCharMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.FLOAT), new MessageItemType(MessageCollectionItemType.CHAR), false); + private static final MessageMapType boxedDoubleBoxedFloatMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.DOUBLE), new MessageItemType(MessageCollectionItemType.FLOAT), false); /** */ - private final static MessageMapType boxedIntBoxedShortMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.INT), new MessageItemType(MessageCollectionItemType.SHORT), false); + private static final MessageMapType boxedFloatBoxedCharMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.FLOAT), new MessageItemType(MessageCollectionItemType.CHAR), false); /** */ - private final static MessageMapType boxedLongBoxedIntMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.LONG), new MessageItemType(MessageCollectionItemType.INT), false); + private static final MessageMapType boxedIntBoxedShortMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.INT), new MessageItemType(MessageCollectionItemType.SHORT), false); /** */ - private final static MessageMapType boxedShortBoxedByteMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.SHORT), new MessageItemType(MessageCollectionItemType.BYTE), false); + private static final MessageMapType boxedLongBoxedIntMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.LONG), new MessageItemType(MessageCollectionItemType.INT), false); /** */ - private final static MessageMapType byteArrayBooleanArrayMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.BYTE_ARR), new MessageItemType(MessageCollectionItemType.BOOLEAN_ARR), false); + private static final MessageMapType boxedShortBoxedByteMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.SHORT), new MessageItemType(MessageCollectionItemType.BYTE), false); /** */ - private final static MessageMapType charArrayLongArrayMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.CHAR_ARR), new MessageItemType(MessageCollectionItemType.LONG_ARR), false); + private static final MessageMapType byteArrayBooleanArrayMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.BYTE_ARR), new MessageItemType(MessageCollectionItemType.BOOLEAN_ARR), false); /** */ - private final static MessageMapType doubleArrayFloatArrayMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.DOUBLE_ARR), new MessageItemType(MessageCollectionItemType.FLOAT_ARR), false); + private static final MessageMapType charArrayLongArrayMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.CHAR_ARR), new MessageItemType(MessageCollectionItemType.LONG_ARR), false); /** */ - private final static MessageMapType floatArrayCharArrayMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.FLOAT_ARR), new MessageItemType(MessageCollectionItemType.CHAR_ARR), false); + private static final MessageMapType doubleArrayFloatArrayMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.DOUBLE_ARR), new MessageItemType(MessageCollectionItemType.FLOAT_ARR), false); /** */ - private final static MessageMapType gridLongListIntegerMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.GRID_LONG_LIST), new MessageItemType(MessageCollectionItemType.INT), false); + private static final MessageMapType floatArrayCharArrayMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.FLOAT_ARR), new MessageItemType(MessageCollectionItemType.CHAR_ARR), false); /** */ - private final static MessageMapType gridlistDoubleMapUuidMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.GRID_LONG_LIST), new MessageMapType(new MessageItemType(MessageCollectionItemType.UUID), new MessageCollectionType(new MessageItemType(MessageCollectionItemType.DOUBLE), false), false), false); + private static final MessageMapType gridLongListIntegerMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.GRID_LONG_LIST), new MessageItemType(MessageCollectionItemType.INT), false); /** */ - private final static MessageMapType igniteUuidBitSetMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.IGNITE_UUID), new MessageItemType(MessageCollectionItemType.BIT_SET), false); + private static final MessageMapType gridlistDoubleMapUuidMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.GRID_LONG_LIST), new MessageMapType(new MessageItemType(MessageCollectionItemType.UUID), new MessageCollectionType(new MessageItemType(MessageCollectionItemType.DOUBLE), false), false), false); /** */ - private final static MessageMapType intArrayShortArrayMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.INT_ARR), new MessageItemType(MessageCollectionItemType.SHORT_ARR), false); + private static final MessageMapType igniteUuidBitSetMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.IGNITE_UUID), new MessageItemType(MessageCollectionItemType.BIT_SET), false); /** */ - private final static MessageMapType integerGridLongListMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.INT), new MessageItemType(MessageCollectionItemType.GRID_LONG_LIST), false); + private static final MessageMapType intArrayShortArrayMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.INT_ARR), new MessageItemType(MessageCollectionItemType.SHORT_ARR), false); /** */ - private final static MessageMapType longArrayIntArrayMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.LONG_ARR), new MessageItemType(MessageCollectionItemType.INT_ARR), false); + private static final MessageMapType integerGridLongListMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.INT), new MessageItemType(MessageCollectionItemType.GRID_LONG_LIST), false); /** */ - private final static MessageMapType messageBoxedDoubleMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.MSG), new MessageItemType(MessageCollectionItemType.DOUBLE), false); + private static final MessageMapType longArrayIntArrayMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.LONG_ARR), new MessageItemType(MessageCollectionItemType.INT_ARR), false); /** */ - private final static MessageMapType shortArrayByteArrayMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.SHORT_ARR), new MessageItemType(MessageCollectionItemType.BYTE_ARR), false); + private static final MessageMapType messageBoxedDoubleMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.MSG), new MessageItemType(MessageCollectionItemType.DOUBLE), false); /** */ - private final static MessageMapType stringDoubleArrayMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.STRING), new MessageItemType(MessageCollectionItemType.DOUBLE_ARR), false); + private static final MessageMapType shortArrayByteArrayMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.SHORT_ARR), new MessageItemType(MessageCollectionItemType.BYTE_ARR), false); /** */ - private final static MessageMapType uuidStringMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.UUID), new MessageItemType(MessageCollectionItemType.STRING), false); + private static final MessageMapType stringDoubleArrayMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.STRING), new MessageItemType(MessageCollectionItemType.DOUBLE_ARR), false); + /** */ + private static final MessageMapType uuidStringMapCollDesc = new MessageMapType(new MessageItemType(MessageCollectionItemType.UUID), new MessageItemType(MessageCollectionItemType.STRING), false); /** */ @Override public boolean writeTo(TestMapMessage msg, MessageWriter writer) { @@ -453,4 +460,14 @@ public class TestMapMessageSerializer implements MessageSerializer { /** */ - private final static MessageArrayType intMatrixCollDesc = new MessageArrayType(new MessageItemType(MessageCollectionItemType.INT_ARR), int[].class); + private final static GridCacheVersionSerializer GRID_CACHE_VERSION_SER = new GridCacheVersionSerializer(); /** */ - private final static MessageArrayType strArrCollDesc = new MessageArrayType(new MessageItemType(MessageCollectionItemType.STRING), String.class); + private static final MessageArrayType intMatrixCollDesc = new MessageArrayType(new MessageItemType(MessageCollectionItemType.INT_ARR), int[].class); /** */ - private final static MessageArrayType verArrCollDesc = new MessageArrayType(new MessageItemType(MessageCollectionItemType.MSG), GridCacheVersion.class); + private static final MessageArrayType strArrCollDesc = new MessageArrayType(new MessageItemType(MessageCollectionItemType.STRING), String.class); + /** */ + private static final MessageArrayType verArrCollDesc = new MessageArrayType(new MessageItemType(MessageCollectionItemType.MSG), GridCacheVersion.class); /** */ @Override public boolean writeTo(TestMessage msg, MessageWriter writer) { @@ -269,4 +275,23 @@ public class TestMessageSerializer implements MessageSerializer { return true; } + + /** */ + @Override public void prepareMarshalCacheObjects(TestMessage msg, CacheObjectValueContext ctx, GridCacheSharedContext sharedCtx) throws IgniteCheckedException { + if (msg.ver != null) + GRID_CACHE_VERSION_SER.prepareMarshalCacheObjects(msg.ver, ctx, sharedCtx); + + if (msg.verArr != null) { + for (GridCacheVersion e : msg.verArr) { + if (e != null) + GRID_CACHE_VERSION_SER.prepareMarshalCacheObjects(e, ctx, sharedCtx); + } + } + + if (msg.keyCacheObject != null) + msg.keyCacheObject.prepareMarshal(ctx); + + if (msg.cacheObject != null) + msg.cacheObject.prepareMarshal(ctx); + } } \ No newline at end of file diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2ValueMessageFactory.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2ValueMessageFactory.java index b26089afd70fe..c22e32703714f 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2ValueMessageFactory.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/twostep/msg/GridH2ValueMessageFactory.java @@ -26,6 +26,7 @@ import org.apache.ignite.internal.processors.query.h2.QueryTable; import org.apache.ignite.internal.processors.query.h2.QueryTableSerializer; import org.apache.ignite.internal.processors.query.h2.opt.GridH2ValueCacheObject; +import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.plugin.extensions.communication.Message; import org.apache.ignite.plugin.extensions.communication.MessageFactory; import org.apache.ignite.plugin.extensions.communication.MessageFactoryProvider; @@ -37,34 +38,34 @@ public class GridH2ValueMessageFactory implements MessageFactoryProvider { /** {@inheritDoc} */ @Override public void registerAll(MessageFactory factory) { - factory.register(-4, () -> GridH2Null.INSTANCE, new GridH2NullSerializer()); - factory.register(-5, GridH2Boolean::new, new GridH2BooleanSerializer()); - factory.register(-6, GridH2Byte::new, new GridH2ByteSerializer()); - factory.register(-7, GridH2Short::new, new GridH2ShortSerializer()); - factory.register(-8, GridH2Integer::new, new GridH2IntegerSerializer()); - factory.register(-9, GridH2Long::new, new GridH2LongSerializer()); - factory.register(-10, GridH2Decimal::new, new GridH2DecimalSerializer()); - factory.register(-11, GridH2Double::new, new GridH2DoubleSerializer()); - factory.register(-12, GridH2Float::new, new GridH2FloatSerializer()); - factory.register(-13, GridH2Time::new, new GridH2TimeSerializer()); - factory.register(-14, GridH2Date::new, new GridH2DateSerializer()); - factory.register(-15, GridH2Timestamp::new, new GridH2TimestampSerializer()); - factory.register(-16, GridH2Bytes::new, new GridH2BytesSerializer()); - factory.register(-17, GridH2String::new, new GridH2StringSerializer()); - factory.register(-18, GridH2Array::new, new GridH2ArraySerializer()); - factory.register(-19, GridH2JavaObject::new, new GridH2JavaObjectSerializer()); - factory.register(-20, GridH2Uuid::new, new GridH2UuidSerializer()); - factory.register(-21, GridH2Geometry::new, new GridH2GeometrySerializer()); - factory.register(-22, GridH2CacheObject::new, new GridH2CacheObjectSerializer()); - factory.register(-30, GridH2IndexRangeRequest::new, new GridH2IndexRangeRequestSerializer()); - factory.register(-31, GridH2IndexRangeResponse::new, new GridH2IndexRangeResponseSerializer()); - factory.register(-32, GridH2RowMessage::new, new GridH2RowMessageSerializer()); - factory.register(-33, GridH2QueryRequest::new, new GridH2QueryRequestSerializer()); - factory.register(-34, GridH2RowRange::new, new GridH2RowRangeSerializer()); - factory.register(-35, GridH2RowRangeBounds::new, new GridH2RowRangeBoundsSerializer()); - factory.register(-54, QueryTable::new, new QueryTableSerializer()); - factory.register(-55, GridH2DmlRequest::new, new GridH2DmlRequestSerializer()); - factory.register(-56, GridH2DmlResponse::new, new GridH2DmlResponseSerializer()); + factory.register(-4, () -> GridH2Null.INSTANCE, new GridH2NullSerializer(U.gridClassLoader())); + factory.register(-5, GridH2Boolean::new, new GridH2BooleanSerializer(U.gridClassLoader())); + factory.register(-6, GridH2Byte::new, new GridH2ByteSerializer(U.gridClassLoader())); + factory.register(-7, GridH2Short::new, new GridH2ShortSerializer(U.gridClassLoader())); + factory.register(-8, GridH2Integer::new, new GridH2IntegerSerializer(U.gridClassLoader())); + factory.register(-9, GridH2Long::new, new GridH2LongSerializer(U.gridClassLoader())); + factory.register(-10, GridH2Decimal::new, new GridH2DecimalSerializer(U.gridClassLoader())); + factory.register(-11, GridH2Double::new, new GridH2DoubleSerializer(U.gridClassLoader())); + factory.register(-12, GridH2Float::new, new GridH2FloatSerializer(U.gridClassLoader())); + factory.register(-13, GridH2Time::new, new GridH2TimeSerializer(U.gridClassLoader())); + factory.register(-14, GridH2Date::new, new GridH2DateSerializer(U.gridClassLoader())); + factory.register(-15, GridH2Timestamp::new, new GridH2TimestampSerializer(U.gridClassLoader())); + factory.register(-16, GridH2Bytes::new, new GridH2BytesSerializer(U.gridClassLoader())); + factory.register(-17, GridH2String::new, new GridH2StringSerializer(U.gridClassLoader())); + factory.register(-18, GridH2Array::new, new GridH2ArraySerializer(U.gridClassLoader())); + factory.register(-19, GridH2JavaObject::new, new GridH2JavaObjectSerializer(U.gridClassLoader())); + factory.register(-20, GridH2Uuid::new, new GridH2UuidSerializer(U.gridClassLoader())); + factory.register(-21, GridH2Geometry::new, new GridH2GeometrySerializer(U.gridClassLoader())); + factory.register(-22, GridH2CacheObject::new, new GridH2CacheObjectSerializer(U.gridClassLoader())); + factory.register(-30, GridH2IndexRangeRequest::new, new GridH2IndexRangeRequestSerializer(U.gridClassLoader())); + factory.register(-31, GridH2IndexRangeResponse::new, new GridH2IndexRangeResponseSerializer(U.gridClassLoader())); + factory.register(-32, GridH2RowMessage::new, new GridH2RowMessageSerializer(U.gridClassLoader())); + factory.register(-33, GridH2QueryRequest::new, new GridH2QueryRequestSerializer(U.gridClassLoader())); + factory.register(-34, GridH2RowRange::new, new GridH2RowRangeSerializer(U.gridClassLoader())); + factory.register(-35, GridH2RowRangeBounds::new, new GridH2RowRangeBoundsSerializer(U.gridClassLoader())); + factory.register(-54, QueryTable::new, new QueryTableSerializer(U.gridClassLoader())); + factory.register(-55, GridH2DmlRequest::new, new GridH2DmlRequestSerializer(U.gridClassLoader())); + factory.register(-56, GridH2DmlResponse::new, new GridH2DmlResponseSerializer(U.gridClassLoader())); } /** diff --git a/modules/zookeeper/src/main/java/org/apache/ignite/spi/discovery/zk/internal/DiscoveryMessageParser.java b/modules/zookeeper/src/main/java/org/apache/ignite/spi/discovery/zk/internal/DiscoveryMessageParser.java index d29a73f7039f4..efba2098bddb9 100644 --- a/modules/zookeeper/src/main/java/org/apache/ignite/spi/discovery/zk/internal/DiscoveryMessageParser.java +++ b/modules/zookeeper/src/main/java/org/apache/ignite/spi/discovery/zk/internal/DiscoveryMessageParser.java @@ -25,12 +25,15 @@ import java.nio.ByteBuffer; import java.util.zip.DeflaterOutputStream; import java.util.zip.InflaterInputStream; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.direct.DirectMessageReader; import org.apache.ignite.internal.direct.DirectMessageWriter; import org.apache.ignite.plugin.extensions.communication.Message; import org.apache.ignite.plugin.extensions.communication.MessageFactory; import org.apache.ignite.plugin.extensions.communication.MessageSerializer; import org.apache.ignite.spi.IgniteSpiException; +import org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi; import static org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi.makeMessageType; @@ -45,8 +48,12 @@ public class DiscoveryMessageParser { private final MessageFactory msgFactory; /** */ - public DiscoveryMessageParser(MessageFactory msgFactory) { + private final ZookeeperDiscoverySpi spi; + + /** */ + public DiscoveryMessageParser(MessageFactory msgFactory, ZookeeperDiscoverySpi spi) { this.msgFactory = msgFactory; + this.spi = spi; } /** Marshals discovery message to bytes array. */ @@ -85,6 +92,13 @@ private void serializeMessage(Message m, OutputStream out) throws IOException { MessageSerializer msgSer = msgFactory.serializer(m.directType()); + try { + msgSer.prepareMarshal(m, ((IgniteEx)spi.ignite()).context(), null); + } + catch (IgniteCheckedException e) { + throw new IgniteSpiException("Failed to marshal joining node data", e); + } + boolean finished; do { diff --git a/modules/zookeeper/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZkMessageFactory.java b/modules/zookeeper/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZkMessageFactory.java index 39d89b32af878..393ea9f8e5a89 100644 --- a/modules/zookeeper/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZkMessageFactory.java +++ b/modules/zookeeper/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZkMessageFactory.java @@ -17,6 +17,7 @@ package org.apache.ignite.spi.discovery.zk.internal; +import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.plugin.extensions.communication.MessageFactory; import org.apache.ignite.plugin.extensions.communication.MessageFactoryProvider; @@ -24,9 +25,11 @@ public class ZkMessageFactory implements MessageFactoryProvider { /** {@inheritDoc} */ @Override public void registerAll(MessageFactory factory) { - factory.register(400, ZkCommunicationErrorResolveFinishMessage::new, new ZkCommunicationErrorResolveFinishMessageSerializer()); - factory.register(401, ZkCommunicationErrorResolveStartMessage::new, new ZkCommunicationErrorResolveStartMessageSerializer()); - factory.register(402, ZkForceNodeFailMessage::new, new ZkForceNodeFailMessageSerializer()); - factory.register(403, ZkNoServersMessage::new, new ZkNoServersMessageSerializer()); + factory.register(400, + ZkCommunicationErrorResolveFinishMessage::new, new ZkCommunicationErrorResolveFinishMessageSerializer(U.gridClassLoader())); + factory.register(401, + ZkCommunicationErrorResolveStartMessage::new, new ZkCommunicationErrorResolveStartMessageSerializer(U.gridClassLoader())); + factory.register(402, ZkForceNodeFailMessage::new, new ZkForceNodeFailMessageSerializer(U.gridClassLoader())); + factory.register(403, ZkNoServersMessage::new, new ZkNoServersMessageSerializer(U.gridClassLoader())); } } diff --git a/modules/zookeeper/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoveryImpl.java b/modules/zookeeper/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoveryImpl.java index 0d0531d1a9a2c..96d29f66b9c15 100644 --- a/modules/zookeeper/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoveryImpl.java +++ b/modules/zookeeper/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoveryImpl.java @@ -270,7 +270,7 @@ public ZookeeperDiscoveryImpl( this.stats = stats; - msgParser = new DiscoveryMessageParser(msgFactory); + msgParser = new DiscoveryMessageParser(msgFactory, spi); } /**