You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by pt...@apache.org on 2025/01/13 13:46:00 UTC
(ignite-3) 01/02: IGNITE-24059 Reuse compute serialization in client and embedded APIs (#5017)
This is an automated email from the ASF dual-hosted git repository.
ptupitsyn pushed a commit to branch ignite-3.0
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
commit 45ab4fc3cc7650892e125bae1897869149e0c453
Author: Pavel Tupitsyn <pt...@apache.org>
AuthorDate: Mon Jan 13 11:29:47 2025 +0200
IGNITE-24059 Reuse compute serialization in client and embedded APIs (#5017)
* Extract common logic to `SharedComputeUtils`, reuse in client and embedded APIs
* Always use `ComputeJobDataHolder` to pass argument and result data around internally
* Before that we used internal message serialization for args and results in some cases, resulting in inconsistent behavior
* Now we have a clear boundary where the serialization happens
* Local execution also performs serialization - to be fixed in IGNITE-24183
(cherry picked from commit a57ee5f9e6e4407d36f4cb2f32e123b4148aa562)
---
.../client/proto/ClientComputeJobPacker.java | 110 +--------
.../client/proto/ClientComputeJobUnpacker.java | 103 +-------
.../internal/compute/ComputeJobDataHolder.java | 0
.../internal/compute/ComputeJobDataType.java | 0
.../ignite/internal/compute/JobStateImpl.java | 0
.../internal/compute/JobTaskStatusMapper.java | 0
.../internal/compute/PojoConversionException.java | 0
.../ignite/internal/compute/PojoConverter.java | 0
.../internal/compute/SharedComputeUtils.java | 261 +++++++++++++++++++++
.../ignite/internal/compute/TaskStateImpl.java | 0
.../proto/ClientComputeJobPackerUnpackerTest.java | 10 +-
.../ClientComputeExecuteColocatedRequest.java | 7 +-
.../compute/ClientComputeExecuteRequest.java | 11 +-
.../apache/ignite/client/fakes/FakeCompute.java | 77 ++++--
modules/compute/build.gradle | 1 +
.../ignite/internal/compute/ItComputeBaseTest.java | 38 +--
.../internal/compute/ItComputeTestClient.java | 31 ---
.../internal/compute/ItComputeTestEmbedded.java | 62 +++--
.../internal/compute/ItComputeTestStandalone.java | 6 +-
.../compute/{ConcatJob.java => ToStringJob.java} | 12 +-
.../ignite/internal/compute/ComputeComponent.java | 35 +--
.../internal/compute/ComputeComponentImpl.java | 40 ++--
.../internal/compute/ComputeJobFailover.java | 20 +-
.../ignite/internal/compute/ComputeUtils.java | 213 +----------------
.../internal/compute/DelegatingJobExecution.java | 30 +--
.../ignite/internal/compute/ExecutionManager.java | 16 +-
.../ignite/internal/compute/IgniteComputeImpl.java | 49 ++--
.../internal/compute/IgniteComputeInternal.java | 10 +-
.../apache/ignite/internal/compute/JobStarter.java | 6 +-
.../internal/compute/RemoteExecutionContext.java | 22 +-
.../compute/ResultUnmarshallingJobExecution.java | 16 +-
.../internal/compute/executor/ComputeExecutor.java | 6 +-
.../compute/executor/ComputeExecutorImpl.java | 31 ++-
.../compute/executor/JobExecutionInternal.java | 7 +-
.../internal/compute/message/ExecuteRequest.java | 3 +-
.../compute/message/JobResultResponse.java | 3 +-
.../compute/messaging/ComputeMessaging.java | 18 +-
.../internal/compute/ComputeComponentImplTest.java | 60 +++--
.../internal/compute/IgniteComputeImplTest.java | 30 +--
.../compute/executor/ComputeExecutorTest.java | 51 ++--
.../client/ItThinClientComputeMarshallingTest.java | 4 +-
...tThinClientComputeTypeCheckMarshallingTest.java | 10 +-
.../ItThinClientPojoComputeMarshallingTest.java | 6 +-
.../app/compute/ItEmbeddedMarshallingTest.java | 13 +-
44 files changed, 654 insertions(+), 774 deletions(-)
diff --git a/modules/client-common/src/main/java/org/apache/ignite/internal/client/proto/ClientComputeJobPacker.java b/modules/client-common/src/main/java/org/apache/ignite/internal/client/proto/ClientComputeJobPacker.java
index 4ea19494f5..d877c80899 100644
--- a/modules/client-common/src/main/java/org/apache/ignite/internal/client/proto/ClientComputeJobPacker.java
+++ b/modules/client-common/src/main/java/org/apache/ignite/internal/client/proto/ClientComputeJobPacker.java
@@ -17,34 +17,13 @@
package org.apache.ignite.internal.client.proto;
-import static org.apache.ignite.internal.compute.ComputeJobDataType.MARSHALLED_CUSTOM;
-import static org.apache.ignite.internal.compute.ComputeJobDataType.NATIVE;
-import static org.apache.ignite.internal.compute.ComputeJobDataType.POJO;
-import static org.apache.ignite.internal.compute.ComputeJobDataType.TUPLE;
-import static org.apache.ignite.internal.compute.ComputeJobDataType.TUPLE_COLLECTION;
-import static org.apache.ignite.internal.compute.PojoConverter.toTuple;
-
-import java.nio.ByteBuffer;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Set;
-import java.util.stream.Collectors;
-import org.apache.ignite.internal.binarytuple.BinaryTupleBuilder;
-import org.apache.ignite.internal.binarytuple.inlineschema.TupleWithSchemaMarshalling;
import org.apache.ignite.internal.compute.ComputeJobDataHolder;
-import org.apache.ignite.internal.compute.PojoConversionException;
+import org.apache.ignite.internal.compute.SharedComputeUtils;
import org.apache.ignite.marshalling.Marshaller;
-import org.apache.ignite.marshalling.MarshallingException;
-import org.apache.ignite.sql.ColumnType;
-import org.apache.ignite.table.Tuple;
import org.jetbrains.annotations.Nullable;
/** Packs job arguments and results. */
public final class ClientComputeJobPacker {
- private static final Set<Class<?>> NATIVE_TYPES = Arrays.stream(ColumnType.values())
- .map(ColumnType::javaClass)
- .collect(Collectors.toUnmodifiableSet());
-
/**
* Packs compute job argument. If the marshaller is provided, it will be used to marshal the argument. If the marshaller is not provided
* and the argument is a native column type or a tuple, it will be packed accordingly.
@@ -68,92 +47,21 @@ public final class ClientComputeJobPacker {
* @param <T> Result type.
*/
public static <T> void packJobResult(@Nullable T res, @Nullable Marshaller<T, byte[]> marshaller, ClientMessagePacker packer) {
- if (res instanceof ComputeJobDataHolder) {
- ComputeJobDataHolder resultDataHolder = (ComputeJobDataHolder) res;
- packer.packInt(resultDataHolder.type().id());
- packer.packBinary(resultDataHolder.data());
- } else {
- pack(res, marshaller, packer);
- }
+ pack(res, marshaller, packer);
}
/** Packs object in the format: | typeId | value |. */
private static <T> void pack(@Nullable T obj, @Nullable Marshaller<T, byte[]> marshaller, ClientMessagePacker packer) {
- if (obj == null) {
- packer.packNil();
- return;
- }
-
- if (marshaller != null) {
- packer.packInt(MARSHALLED_CUSTOM.id());
- byte[] marshalled = marshaller.marshal(obj);
-
- if (marshalled == null) {
- packer.packNil();
- return;
- }
-
- packer.packBinary(marshalled);
- return;
- }
-
- if (obj instanceof Tuple) {
- packer.packInt(TUPLE.id());
-
- packTuple((Tuple) obj, packer);
- return;
- }
-
- if (obj instanceof Collection) {
- Collection<?> col = (Collection<?>) obj;
-
- packer.packInt(TUPLE_COLLECTION.id());
+ ComputeJobDataHolder holder = obj instanceof ComputeJobDataHolder
+ ? (ComputeJobDataHolder) obj
+ : SharedComputeUtils.marshalArgOrResult(obj, marshaller);
- // Pack entire collection into a single binary blob.
- BinaryTupleBuilder tupleBuilder = new BinaryTupleBuilder(col.size());
-
- for (Object el : col) {
- if (el == null) {
- tupleBuilder.appendNull();
- continue;
- }
-
- if (!(el instanceof Tuple)) {
- throw new MarshallingException("Can't pack collection: expected Tuple, but got " + el.getClass(), null);
- }
-
- tupleBuilder.appendBytes(TupleWithSchemaMarshalling.marshal((Tuple) el));
- }
-
- ByteBuffer binTupleBytes = tupleBuilder.build();
- packer.packBinaryHeader(Integer.BYTES + binTupleBytes.remaining());
- packer.writeIntRawLittleEndian(col.size());
- packer.writePayload(binTupleBytes);
-
- return;
- }
-
- if (isNativeType(obj.getClass())) {
- packer.packInt(NATIVE.id());
-
- packer.packObjectAsBinaryTuple(obj);
+ if (holder == null) {
+ packer.packNil();
return;
}
- try {
- packer.packInt(POJO.id());
-
- packTuple(toTuple(obj), packer);
- } catch (PojoConversionException e) {
- throw new MarshallingException("Can't pack object: " + obj, e);
- }
- }
-
- private static boolean isNativeType(Class<?> clazz) {
- return NATIVE_TYPES.contains(clazz);
- }
-
- private static void packTuple(Tuple tuple, ClientMessagePacker packer) {
- packer.packBinary(TupleWithSchemaMarshalling.marshal(tuple));
+ packer.packInt(holder.type().id());
+ packer.packBinary(holder.data());
}
}
diff --git a/modules/client-common/src/main/java/org/apache/ignite/internal/client/proto/ClientComputeJobUnpacker.java b/modules/client-common/src/main/java/org/apache/ignite/internal/client/proto/ClientComputeJobUnpacker.java
index a7c7856441..ed2c2ef732 100644
--- a/modules/client-common/src/main/java/org/apache/ignite/internal/client/proto/ClientComputeJobUnpacker.java
+++ b/modules/client-common/src/main/java/org/apache/ignite/internal/client/proto/ClientComputeJobUnpacker.java
@@ -17,22 +17,11 @@
package org.apache.ignite.internal.client.proto;
-import static org.apache.ignite.internal.compute.PojoConverter.fromTuple;
-import static org.apache.ignite.marshalling.Marshaller.tryUnmarshalOrCast;
-
-import java.lang.reflect.InvocationTargetException;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.ignite.internal.binarytuple.BinaryTupleReader;
-import org.apache.ignite.internal.binarytuple.inlineschema.TupleWithSchemaMarshalling;
import org.apache.ignite.internal.compute.ComputeJobDataHolder;
import org.apache.ignite.internal.compute.ComputeJobDataType;
-import org.apache.ignite.internal.compute.PojoConversionException;
+import org.apache.ignite.internal.compute.SharedComputeUtils;
import org.apache.ignite.marshalling.Marshaller;
import org.apache.ignite.marshalling.UnmarshallingException;
-import org.apache.ignite.table.Tuple;
import org.jetbrains.annotations.Nullable;
/** Unpacks job results. */
@@ -52,97 +41,13 @@ public final class ClientComputeJobUnpacker {
@Nullable Marshaller<?, byte[]> marshaller,
@Nullable Class<?> resultClass
) {
- if (unpacker.tryUnpackNil()) {
- return null;
- }
-
- // Underlying byte array expected to be in the following format: | typeId | value |.
- int typeId = unpacker.unpackInt();
- ComputeJobDataType type = ComputeJobDataType.fromId(typeId);
- if (type == null) {
- throw new UnmarshallingException("Unsupported compute job type id: " + typeId);
- }
-
- switch (type) {
- case NATIVE:
- if (marshaller != null) {
- throw new UnmarshallingException(
- "Can not unpack object because the marshaller is provided but the object was packed without marshaller."
- );
- }
-
- return unpacker.unpackObjectFromBinaryTuple();
-
- case TUPLE:
- return TupleWithSchemaMarshalling.unmarshal(unpacker.readBinary());
+ ComputeJobDataHolder holder = unpackJobArgumentWithoutMarshaller(unpacker);
- case MARSHALLED_CUSTOM:
- if (marshaller == null) {
- throw new UnmarshallingException(
- "Can not unpack object because the marshaller is not provided but the object was packed with marshaller."
- );
- }
- return tryUnmarshalOrCast(marshaller, unpacker.readBinary());
-
- case POJO:
- if (resultClass == null) {
- throw new UnmarshallingException(
- "Can not unpack object because the pojo class is not provided but the object was packed as pojo. "
- + "Provide Job result type in JobDescriptor.resultClass."
- );
- }
- return unpackPojo(unpacker, resultClass);
-
- case TUPLE_COLLECTION: {
- // TODO: IGNITE-24059 Deduplicate with ComputeUtils.
- ByteBuffer collectionBuf = unpacker.readBinaryUnsafe().order(ByteOrder.LITTLE_ENDIAN);
- int count = collectionBuf.getInt();
- BinaryTupleReader reader = new BinaryTupleReader(count, collectionBuf.slice().order(ByteOrder.LITTLE_ENDIAN));
-
- List<Tuple> res = new ArrayList<>(count);
- for (int i = 0; i < count; i++) {
- ByteBuffer elementBytes = reader.bytesValueAsBuffer(i);
-
- if (elementBytes == null) {
- res.add(null);
- continue;
- }
-
- res.add(TupleWithSchemaMarshalling.unmarshal(elementBytes));
- }
-
- return res;
- }
-
- default:
- throw new UnmarshallingException("Unsupported compute job type: " + type);
- }
- }
-
- private static Object unpackPojo(ClientMessageUnpacker unpacker, Class<?> pojoClass) {
- try {
- Object obj = pojoClass.getConstructor().newInstance();
-
- fromTuple(obj, TupleWithSchemaMarshalling.unmarshal(unpacker.readBinary()));
-
- return obj;
- } catch (NoSuchMethodException e) {
- throw new UnmarshallingException("Class " + pojoClass.getName() + " doesn't have public default constructor. "
- + "Add the default constructor or provide Marshaller for " + pojoClass.getName() + " in JobDescriptor.resultMarshaller",
- e);
- } catch (InvocationTargetException e) {
- throw new UnmarshallingException("Constructor has thrown an exception", e);
- } catch (InstantiationException e) {
- throw new UnmarshallingException("Can't instantiate an object of class " + pojoClass.getName(), e);
- } catch (IllegalAccessException e) {
- throw new UnmarshallingException("Constructor is inaccessible", e);
- } catch (PojoConversionException e) {
- throw new UnmarshallingException("Can't unpack object", e);
- }
+ return SharedComputeUtils.unmarshalArgOrResult(holder, marshaller, resultClass);
}
/** Unpacks compute job argument without marshaller. */
- public static @Nullable Object unpackJobArgumentWithoutMarshaller(ClientMessageUnpacker unpacker) {
+ public static @Nullable ComputeJobDataHolder unpackJobArgumentWithoutMarshaller(ClientMessageUnpacker unpacker) {
if (unpacker.tryUnpackNil()) {
return null;
}
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/compute/ComputeJobDataHolder.java b/modules/client-common/src/main/java/org/apache/ignite/internal/compute/ComputeJobDataHolder.java
similarity index 100%
rename from modules/core/src/main/java/org/apache/ignite/internal/compute/ComputeJobDataHolder.java
rename to modules/client-common/src/main/java/org/apache/ignite/internal/compute/ComputeJobDataHolder.java
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/compute/ComputeJobDataType.java b/modules/client-common/src/main/java/org/apache/ignite/internal/compute/ComputeJobDataType.java
similarity index 100%
rename from modules/core/src/main/java/org/apache/ignite/internal/compute/ComputeJobDataType.java
rename to modules/client-common/src/main/java/org/apache/ignite/internal/compute/ComputeJobDataType.java
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/compute/JobStateImpl.java b/modules/client-common/src/main/java/org/apache/ignite/internal/compute/JobStateImpl.java
similarity index 100%
rename from modules/core/src/main/java/org/apache/ignite/internal/compute/JobStateImpl.java
rename to modules/client-common/src/main/java/org/apache/ignite/internal/compute/JobStateImpl.java
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/compute/JobTaskStatusMapper.java b/modules/client-common/src/main/java/org/apache/ignite/internal/compute/JobTaskStatusMapper.java
similarity index 100%
rename from modules/core/src/main/java/org/apache/ignite/internal/compute/JobTaskStatusMapper.java
rename to modules/client-common/src/main/java/org/apache/ignite/internal/compute/JobTaskStatusMapper.java
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/compute/PojoConversionException.java b/modules/client-common/src/main/java/org/apache/ignite/internal/compute/PojoConversionException.java
similarity index 100%
rename from modules/core/src/main/java/org/apache/ignite/internal/compute/PojoConversionException.java
rename to modules/client-common/src/main/java/org/apache/ignite/internal/compute/PojoConversionException.java
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/compute/PojoConverter.java b/modules/client-common/src/main/java/org/apache/ignite/internal/compute/PojoConverter.java
similarity index 100%
rename from modules/core/src/main/java/org/apache/ignite/internal/compute/PojoConverter.java
rename to modules/client-common/src/main/java/org/apache/ignite/internal/compute/PojoConverter.java
diff --git a/modules/client-common/src/main/java/org/apache/ignite/internal/compute/SharedComputeUtils.java b/modules/client-common/src/main/java/org/apache/ignite/internal/compute/SharedComputeUtils.java
new file mode 100644
index 0000000000..1f5d857355
--- /dev/null
+++ b/modules/client-common/src/main/java/org/apache/ignite/internal/compute/SharedComputeUtils.java
@@ -0,0 +1,261 @@
+/*
+ * 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.compute;
+
+import static org.apache.ignite.internal.compute.ComputeJobDataType.MARSHALLED_CUSTOM;
+import static org.apache.ignite.internal.compute.ComputeJobDataType.NATIVE;
+import static org.apache.ignite.internal.compute.ComputeJobDataType.POJO;
+import static org.apache.ignite.internal.compute.ComputeJobDataType.TUPLE;
+import static org.apache.ignite.internal.compute.ComputeJobDataType.TUPLE_COLLECTION;
+import static org.apache.ignite.internal.compute.PojoConverter.fromTuple;
+import static org.apache.ignite.internal.compute.PojoConverter.toTuple;
+import static org.apache.ignite.lang.ErrorGroups.Compute.MARSHALLING_TYPE_MISMATCH_ERR;
+
+import java.lang.reflect.InvocationTargetException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.apache.ignite.compute.ComputeException;
+import org.apache.ignite.internal.binarytuple.BinaryTupleBuilder;
+import org.apache.ignite.internal.binarytuple.BinaryTupleReader;
+import org.apache.ignite.internal.binarytuple.inlineschema.TupleWithSchemaMarshalling;
+import org.apache.ignite.internal.client.proto.ClientBinaryTupleUtils;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.marshalling.Marshaller;
+import org.apache.ignite.marshalling.MarshallingException;
+import org.apache.ignite.marshalling.UnmarshallingException;
+import org.apache.ignite.sql.ColumnType;
+import org.apache.ignite.table.Tuple;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Compute serialization utils shared between client and embedded APIs.
+ */
+public class SharedComputeUtils {
+ private static final Set<Class<?>> NATIVE_TYPES = Arrays.stream(ColumnType.values())
+ .map(ColumnType::javaClass)
+ .collect(Collectors.toUnmodifiableSet());
+
+ /**
+ * Marshals the job result using either provided marshaller if not {@code null} or depending on the type of the result either as a
+ * {@link Tuple}, a native type (see {@link ColumnType}) or a POJO. Wraps the marshalled data with the data type in the
+ * {@link ComputeJobDataHolder} to be unmarshalled on the client.
+ *
+ * @param obj Compute job result.
+ * @param marshaller Optional result marshaller.
+ *
+ * @return Data holder.
+ */
+ @Nullable
+ public static <T> ComputeJobDataHolder marshalArgOrResult(@Nullable T obj, @Nullable Marshaller<T, byte[]> marshaller) {
+ if (obj == null) {
+ return null;
+ }
+
+ if (marshaller != null) {
+ byte[] data = marshaller.marshal(obj);
+ if (data == null) {
+ return null;
+ }
+ return new ComputeJobDataHolder(MARSHALLED_CUSTOM, data);
+ }
+
+ if (obj instanceof Tuple) {
+ Tuple tuple = (Tuple) obj;
+ return new ComputeJobDataHolder(TUPLE, TupleWithSchemaMarshalling.marshal(tuple));
+ }
+
+ if (obj instanceof Collection) {
+ Collection<?> col = (Collection<?>) obj;
+
+ // Pack entire collection into a single binary blob, starting with the number of elements (4 bytes, little-endian).
+ BinaryTupleBuilder tupleBuilder = SharedComputeUtils.writeTupleCollection(col);
+
+ ByteBuffer binTupleBytes = tupleBuilder.build();
+
+ byte[] resArr = new byte[Integer.BYTES + binTupleBytes.remaining()];
+ ByteBuffer resBuf = ByteBuffer.wrap(resArr).order(ByteOrder.LITTLE_ENDIAN);
+ resBuf.putInt(col.size());
+ resBuf.put(binTupleBytes);
+
+ return new ComputeJobDataHolder(TUPLE_COLLECTION, resArr);
+ }
+
+
+ if (isNativeType(obj.getClass())) {
+ // Builder with inline schema.
+ // Value is represented by 3 tuple elements: type, scale, value.
+ var builder = new BinaryTupleBuilder(3, 3, false);
+ ClientBinaryTupleUtils.appendObject(builder, obj);
+ return new ComputeJobDataHolder(NATIVE, IgniteUtils.byteBufferToByteArray(builder.build()));
+ }
+
+ try {
+ // TODO https://issues.apache.org/jira/browse/IGNITE-23320
+ Tuple tuple = toTuple(obj);
+ return new ComputeJobDataHolder(POJO, TupleWithSchemaMarshalling.marshal(tuple));
+ } catch (PojoConversionException e) {
+ throw new MarshallingException("Can't pack object: " + obj, e);
+ }
+ }
+
+ /**
+ * Unmarshals the job argument or result.
+ *
+ * @param holder Data holder.
+ * @param marshaller Optional marshaller.
+ * @param resultClass Optional result class.
+ * @param <T> Type of the object.
+ * @return Unmarshalled object.
+ */
+ public static <T> @Nullable T unmarshalArgOrResult(
+ @Nullable ComputeJobDataHolder holder,
+ @Nullable Marshaller<?, byte[]> marshaller,
+ @Nullable Class<?> resultClass) {
+ if (holder == null) {
+ return null;
+ }
+
+ ComputeJobDataType type = holder.type();
+ if (type != MARSHALLED_CUSTOM && marshaller != null) {
+ throw new ComputeException(
+ MARSHALLING_TYPE_MISMATCH_ERR,
+ "Marshaller is defined on the server, but the argument was not marshalled on the client. "
+ + "If you want to use default marshalling strategy, "
+ + "then you should not define your marshaller in the job. "
+ + "If you would like to use your own marshaller, then double-check "
+ + "that both of them are defined in the client and in the server."
+ );
+ }
+
+ switch (type) {
+ case NATIVE: {
+ var reader = new BinaryTupleReader(3, holder.data());
+ return (T) ClientBinaryTupleUtils.readObject(reader, 0);
+ }
+
+ case TUPLE:
+ // TODO https://issues.apache.org/jira/browse/IGNITE-23320
+ return (T) TupleWithSchemaMarshalling.unmarshal(holder.data());
+
+ case POJO:
+ if (resultClass == null) {
+ throw new ComputeException(
+ MARSHALLING_TYPE_MISMATCH_ERR,
+ "JobDescriptor.resultClass is not defined, but the job result is packed as a POJO");
+ }
+
+ Tuple tuple = TupleWithSchemaMarshalling.unmarshal(holder.data());
+
+ return resultClass == Tuple.class
+ ? (T) tuple
+ : (T) unmarshalPojo(resultClass, tuple);
+
+ case MARSHALLED_CUSTOM:
+ if (marshaller == null) {
+ throw new ComputeException(MARSHALLING_TYPE_MISMATCH_ERR, "Marshaller should be defined on the client");
+ }
+ try {
+ return (T) marshaller.unmarshal(holder.data());
+ } catch (Exception ex) {
+ throw new ComputeException(MARSHALLING_TYPE_MISMATCH_ERR, "Exception in user-defined marshaller", ex);
+ }
+
+ case TUPLE_COLLECTION:
+ return (T) readTupleCollection(ByteBuffer.wrap(holder.data()).order(ByteOrder.LITTLE_ENDIAN));
+
+ default:
+ throw new ComputeException(MARSHALLING_TYPE_MISMATCH_ERR, "Unexpected job argument type: " + type);
+ }
+ }
+
+ /**
+ * Unmarshals a POJO from the tuple.
+ *
+ * @param pojoType POJO type.
+ * @param input Tuple.
+ * @return Unmarshalled POJO.
+ */
+ public static Object unmarshalPojo(Class<?> pojoType, Tuple input) {
+ try {
+ Object obj = pojoType.getConstructor().newInstance();
+
+ fromTuple(obj, input);
+
+ return obj;
+ } catch (NoSuchMethodException e) {
+ throw new UnmarshallingException("Class " + pojoType.getName() + " doesn't have public default constructor. "
+ + "Add the constructor or define argument marshaller in the compute job.", e);
+ } catch (InvocationTargetException e) {
+ throw new UnmarshallingException("Constructor has thrown an exception", e);
+ } catch (InstantiationException e) {
+ throw new UnmarshallingException("Can't instantiate an object of class " + pojoType.getName(), e);
+ } catch (IllegalAccessException e) {
+ throw new UnmarshallingException("Constructor is inaccessible", e);
+ } catch (PojoConversionException e) {
+ throw new UnmarshallingException("Can't unpack object", e);
+ }
+ }
+
+ private static boolean isNativeType(Class<?> clazz) {
+ return NATIVE_TYPES.contains(clazz);
+ }
+
+ private static BinaryTupleBuilder writeTupleCollection(Collection<?> col) {
+ BinaryTupleBuilder builder = new BinaryTupleBuilder(col.size());
+
+ for (Object el : col) {
+ if (el == null) {
+ builder.appendNull();
+ continue;
+ }
+
+ if (!(el instanceof Tuple)) {
+ throw new MarshallingException("Can't pack collection: expected Tuple, but got " + el.getClass(), null);
+ }
+
+ builder.appendBytes(TupleWithSchemaMarshalling.marshal((Tuple) el));
+ }
+
+ return builder;
+ }
+
+ private static List<Tuple> readTupleCollection(ByteBuffer collectionBuf) {
+ int count = collectionBuf.getInt();
+ BinaryTupleReader reader = new BinaryTupleReader(count, collectionBuf.slice().order(ByteOrder.LITTLE_ENDIAN));
+
+ List<Tuple> res = new ArrayList<>(count);
+ for (int i = 0; i < count; i++) {
+ ByteBuffer elementBytes = reader.bytesValueAsBuffer(i);
+
+ if (elementBytes == null) {
+ res.add(null);
+ continue;
+ }
+
+ res.add(TupleWithSchemaMarshalling.unmarshal(elementBytes));
+ }
+
+ return res;
+ }
+}
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/compute/TaskStateImpl.java b/modules/client-common/src/main/java/org/apache/ignite/internal/compute/TaskStateImpl.java
similarity index 100%
rename from modules/core/src/main/java/org/apache/ignite/internal/compute/TaskStateImpl.java
rename to modules/client-common/src/main/java/org/apache/ignite/internal/compute/TaskStateImpl.java
diff --git a/modules/client-common/src/test/java/org/apache/ignite/internal/client/proto/ClientComputeJobPackerUnpackerTest.java b/modules/client-common/src/test/java/org/apache/ignite/internal/client/proto/ClientComputeJobPackerUnpackerTest.java
index d93c62dafa..aabf9ff303 100644
--- a/modules/client-common/src/test/java/org/apache/ignite/internal/client/proto/ClientComputeJobPackerUnpackerTest.java
+++ b/modules/client-common/src/test/java/org/apache/ignite/internal/client/proto/ClientComputeJobPackerUnpackerTest.java
@@ -44,13 +44,13 @@ import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Stream;
+import org.apache.ignite.compute.ComputeException;
import org.apache.ignite.internal.client.proto.pojo.Pojo;
import org.apache.ignite.internal.client.proto.pojo.StaticFieldPojo;
import org.apache.ignite.internal.compute.ComputeJobDataHolder;
import org.apache.ignite.internal.compute.ComputeJobDataType;
import org.apache.ignite.marshalling.Marshaller;
import org.apache.ignite.marshalling.MarshallingException;
-import org.apache.ignite.marshalling.UnmarshallingException;
import org.apache.ignite.table.Tuple;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@@ -207,9 +207,9 @@ class ClientComputeJobPackerUnpackerTest {
try (var messageUnpacker = messageUnpacker(data)) {
// Then the exception is thrown because it is not allowed unpack the marshalled object without marshaller.
assertThrows(
- UnmarshallingException.class,
+ ComputeException.class,
() -> unpackJobResult(messageUnpacker, null, null),
- "Can not unpack object because the marshaller is not provided but the object was packed with marshaller."
+ "Marshaller should be defined on the client"
);
}
}
@@ -228,9 +228,9 @@ class ClientComputeJobPackerUnpackerTest {
try (var messageUnpacker = messageUnpacker(data)) {
// Then the exception is thrown because it is not allowed to define the marshaller only for the result.
assertThrows(
- UnmarshallingException.class,
+ ComputeException.class,
() -> unpackJobResult(messageUnpacker, new TestStringMarshaller(), null),
- "Can not unpack object because the marshaller is provided but the object was packed without marshaller."
+ "Marshaller is defined on the server, but the argument was not marshalled on the client"
);
}
}
diff --git a/modules/client-handler/src/main/java/org/apache/ignite/client/handler/requests/compute/ClientComputeExecuteColocatedRequest.java b/modules/client-handler/src/main/java/org/apache/ignite/client/handler/requests/compute/ClientComputeExecuteColocatedRequest.java
index f468889bf1..caeba69cfd 100644
--- a/modules/client-handler/src/main/java/org/apache/ignite/client/handler/requests/compute/ClientComputeExecuteColocatedRequest.java
+++ b/modules/client-handler/src/main/java/org/apache/ignite/client/handler/requests/compute/ClientComputeExecuteColocatedRequest.java
@@ -30,6 +30,7 @@ import org.apache.ignite.compute.JobExecutionOptions;
import org.apache.ignite.deployment.DeploymentUnit;
import org.apache.ignite.internal.client.proto.ClientMessagePacker;
import org.apache.ignite.internal.client.proto.ClientMessageUnpacker;
+import org.apache.ignite.internal.compute.ComputeJobDataHolder;
import org.apache.ignite.internal.compute.IgniteComputeInternal;
import org.apache.ignite.internal.network.ClusterService;
import org.apache.ignite.table.IgniteTables;
@@ -59,11 +60,11 @@ public class ClientComputeExecuteColocatedRequest {
List<DeploymentUnit> deploymentUnits = in.unpackDeploymentUnits();
String jobClassName = in.unpackString();
JobExecutionOptions options = JobExecutionOptions.builder().priority(in.unpackInt()).maxRetries(in.unpackInt()).build();
- Object args = unpackJobArgumentWithoutMarshaller(in);
+ ComputeJobDataHolder args = unpackJobArgumentWithoutMarshaller(in);
out.packInt(table.schemaView().lastKnownSchemaVersion());
- CompletableFuture<JobExecution<Object>> jobExecutionFut = compute.submitColocatedInternal(
+ CompletableFuture<JobExecution<ComputeJobDataHolder>> jobExecutionFut = compute.submitColocatedInternal(
table,
keyTuple,
deploymentUnits,
@@ -72,7 +73,7 @@ public class ClientComputeExecuteColocatedRequest {
null,
args);
- var jobExecution = compute.wrapJobExecutionFuture(jobExecutionFut);
+ JobExecution<ComputeJobDataHolder> jobExecution = compute.wrapJobExecutionFuture(jobExecutionFut);
sendResultAndState(jobExecution, notificationSender);
diff --git a/modules/client-handler/src/main/java/org/apache/ignite/client/handler/requests/compute/ClientComputeExecuteRequest.java b/modules/client-handler/src/main/java/org/apache/ignite/client/handler/requests/compute/ClientComputeExecuteRequest.java
index bf6a621a95..8342398fba 100644
--- a/modules/client-handler/src/main/java/org/apache/ignite/client/handler/requests/compute/ClientComputeExecuteRequest.java
+++ b/modules/client-handler/src/main/java/org/apache/ignite/client/handler/requests/compute/ClientComputeExecuteRequest.java
@@ -32,6 +32,7 @@ import org.apache.ignite.deployment.DeploymentUnit;
import org.apache.ignite.internal.client.proto.ClientComputeJobPacker;
import org.apache.ignite.internal.client.proto.ClientMessagePacker;
import org.apache.ignite.internal.client.proto.ClientMessageUnpacker;
+import org.apache.ignite.internal.compute.ComputeJobDataHolder;
import org.apache.ignite.internal.compute.IgniteComputeInternal;
import org.apache.ignite.internal.compute.MarshallerProvider;
import org.apache.ignite.internal.network.ClusterService;
@@ -65,9 +66,9 @@ public class ClientComputeExecuteRequest {
List<DeploymentUnit> deploymentUnits = in.unpackDeploymentUnits();
String jobClassName = in.unpackString();
JobExecutionOptions options = JobExecutionOptions.builder().priority(in.unpackInt()).maxRetries(in.unpackInt()).build();
- Object arg = unpackJobArgumentWithoutMarshaller(in);
+ ComputeJobDataHolder arg = unpackJobArgumentWithoutMarshaller(in);
- JobExecution<Object> execution = compute.executeAsyncWithFailover(
+ JobExecution<ComputeJobDataHolder> execution = compute.executeAsyncWithFailover(
candidates, deploymentUnits, jobClassName, options, null, arg
);
sendResultAndState(execution, notificationSender);
@@ -102,8 +103,8 @@ public class ClientComputeExecuteRequest {
return nodes;
}
- static CompletableFuture<Object> sendResultAndState(
- JobExecution<Object> execution,
+ static CompletableFuture<ComputeJobDataHolder> sendResultAndState(
+ JobExecution<ComputeJobDataHolder> execution,
NotificationSender notificationSender
) {
return execution.resultAsync().whenComplete((val, err) ->
@@ -115,7 +116,7 @@ public class ClientComputeExecuteRequest {
}, err)));
}
- private static <T> @Nullable Marshaller<T, byte[]> extractMarshaller(JobExecution<T> e) {
+ private static <T> @Nullable Marshaller<T, byte[]> extractMarshaller(JobExecution<ComputeJobDataHolder> e) {
if (e instanceof MarshallerProvider) {
return ((MarshallerProvider<T>) e).resultMarshaller();
}
diff --git a/modules/client/src/test/java/org/apache/ignite/client/fakes/FakeCompute.java b/modules/client/src/test/java/org/apache/ignite/client/fakes/FakeCompute.java
index 91e5c05578..39b9cbeeed 100644
--- a/modules/client/src/test/java/org/apache/ignite/client/fakes/FakeCompute.java
+++ b/modules/client/src/test/java/org/apache/ignite/client/fakes/FakeCompute.java
@@ -54,11 +54,13 @@ import org.apache.ignite.compute.TaskDescriptor;
import org.apache.ignite.compute.TaskState;
import org.apache.ignite.compute.task.TaskExecution;
import org.apache.ignite.deployment.DeploymentUnit;
+import org.apache.ignite.internal.compute.ComputeJobDataHolder;
import org.apache.ignite.internal.compute.ComputeUtils;
import org.apache.ignite.internal.compute.IgniteComputeInternal;
import org.apache.ignite.internal.compute.JobExecutionContextImpl;
import org.apache.ignite.internal.compute.JobStateImpl;
import org.apache.ignite.internal.compute.MarshallerProvider;
+import org.apache.ignite.internal.compute.SharedComputeUtils;
import org.apache.ignite.internal.compute.TaskStateImpl;
import org.apache.ignite.internal.compute.loader.JobClassLoader;
import org.apache.ignite.internal.table.TableViewInternal;
@@ -94,16 +96,16 @@ public class FakeCompute implements IgniteComputeInternal {
}
@Override
- public <R> JobExecution<R> executeAsyncWithFailover(
+ public JobExecution<ComputeJobDataHolder> executeAsyncWithFailover(
Set<ClusterNode> nodes,
List<DeploymentUnit> units,
String jobClassName,
JobExecutionOptions options,
@Nullable CancellationToken cancellationToken,
- Object args) {
+ @Nullable ComputeJobDataHolder args) {
if (Objects.equals(jobClassName, GET_UNITS)) {
String unitString = units.stream().map(DeploymentUnit::render).collect(Collectors.joining(","));
- return completedExecution((R) unitString);
+ return completedExecution(unitString);
}
try {
@@ -119,39 +121,75 @@ public class FakeCompute implements IgniteComputeInternal {
if (jobClassName.startsWith("org.apache.ignite")) {
JobClassLoader jobClassLoader = new JobClassLoader(List.of(), new URL[]{}, this.getClass().getClassLoader());
- Class<ComputeJob<Object, R>> jobClass = ComputeUtils.jobClass(jobClassLoader, jobClassName);
- ComputeJob<Object, R> job = ComputeUtils.instantiateJob(jobClass);
- CompletableFuture<R> jobFut = job.executeAsync(
- new JobExecutionContextImpl(ignite, new AtomicBoolean(), this.getClass().getClassLoader()), args);
+ Class<ComputeJob<Object, Object>> jobClass = ComputeUtils.jobClass(jobClassLoader, jobClassName);
+ ComputeJob<Object, Object> job = ComputeUtils.instantiateJob(jobClass);
+ CompletableFuture<Object> jobFut = job.executeAsync(
+ new JobExecutionContextImpl(ignite, new AtomicBoolean(), this.getClass().getClassLoader()),
+ SharedComputeUtils.unmarshalArgOrResult(args, null, null));
return jobExecution(jobFut != null ? jobFut : nullCompletedFuture());
}
var future0 = future;
- return jobExecution(future0 != null ? future0 : completedFuture((R) nodeName));
+ return jobExecution(future0 != null ? future0 : completedFuture(SharedComputeUtils.marshalArgOrResult(nodeName, null)));
}
/** {@inheritDoc} */
@Override
- public <R> CompletableFuture<JobExecution<R>> submitColocatedInternal(
+ public CompletableFuture<JobExecution<ComputeJobDataHolder>> submitColocatedInternal(
TableViewInternal table,
Tuple key,
List<DeploymentUnit> units,
String jobClassName,
JobExecutionOptions options,
@Nullable CancellationToken cancellationToken,
- Object args
+ ComputeJobDataHolder args
) {
- return completedFuture(jobExecution(future != null ? future : completedFuture((R) nodeName)));
+ return completedFuture(jobExecution(future != null
+ ? future
+ : completedFuture(SharedComputeUtils.marshalArgOrResult(nodeName, null))));
}
- private <T, R> JobExecution<R> submit(JobTarget target, JobDescriptor<T, R> descriptor, @Nullable CancellationToken cancellationToken,
+ private <T, R> JobExecution<R> submit(
+ JobTarget target,
+ JobDescriptor<T, R> descriptor,
+ @Nullable CancellationToken cancellationToken,
@Nullable T args) {
if (target instanceof AnyNodeJobTarget) {
Set<ClusterNode> nodes = ((AnyNodeJobTarget) target).nodes();
- return executeAsyncWithFailover(
- nodes, descriptor.units(), descriptor.jobClassName(), descriptor.options(), cancellationToken, args
+
+ JobExecution<ComputeJobDataHolder> internalExecution = executeAsyncWithFailover(
+ nodes,
+ descriptor.units(),
+ descriptor.jobClassName(),
+ descriptor.options(),
+ cancellationToken,
+ SharedComputeUtils.marshalArgOrResult(args, null)
);
+
+ return new JobExecution<>() {
+ @Override
+ public CompletableFuture<R> resultAsync() {
+ return internalExecution.resultAsync()
+ .thenApply(r -> SharedComputeUtils.unmarshalArgOrResult(
+ r, descriptor.resultMarshaller(), descriptor.resultClass()));
+ }
+
+ @Override
+ public CompletableFuture<@Nullable JobState> stateAsync() {
+ return internalExecution.stateAsync();
+ }
+
+ @Override
+ public CompletableFuture<@Nullable Boolean> cancelAsync() {
+ return internalExecution.cancelAsync();
+ }
+
+ @Override
+ public CompletableFuture<@Nullable Boolean> changePriorityAsync(int newPriority) {
+ return internalExecution.cancelAsync();
+ }
+ };
} else if (target instanceof ColocatedJobTarget) {
return jobExecution(future != null ? future : completedFuture((R) nodeName));
} else {
@@ -201,11 +239,11 @@ public class FakeCompute implements IgniteComputeInternal {
return sync(executeMapReduceAsync(taskDescriptor, cancellationToken, arg));
}
- private <R> JobExecution<R> completedExecution(R result) {
- return jobExecution(completedFuture(result));
+ private <R> JobExecution<ComputeJobDataHolder> completedExecution(R result) {
+ return jobExecution(completedFuture(SharedComputeUtils.marshalArgOrResult(result, null)));
}
- private <R> JobExecution<R> jobExecution(CompletableFuture<R> result) {
+ private <R> JobExecution<ComputeJobDataHolder> jobExecution(CompletableFuture<R> result) {
UUID jobId = UUID.randomUUID();
JobState state = JobStateImpl.builder()
@@ -221,7 +259,10 @@ public class FakeCompute implements IgniteComputeInternal {
JobState newState = JobStateImpl.toBuilder(state).status(status).finishTime(Instant.now()).build();
jobStates.put(jobId, newState);
});
- return new FakeJobExecution<>(result, jobId);
+
+ return new FakeJobExecution<>(result.thenApply(r -> r instanceof ComputeJobDataHolder
+ ? (ComputeJobDataHolder) r
+ : SharedComputeUtils.marshalArgOrResult(r, null)), jobId);
}
private class FakeJobExecution<R> implements JobExecution<R>, MarshallerProvider<R> {
diff --git a/modules/compute/build.gradle b/modules/compute/build.gradle
index a32ad834fd..6a9b873a16 100644
--- a/modules/compute/build.gradle
+++ b/modules/compute/build.gradle
@@ -63,6 +63,7 @@ dependencies {
integrationTestImplementation project(':ignite-catalog')
integrationTestImplementation project(':ignite-client')
integrationTestImplementation project(':ignite-system-view-api')
+ integrationTestImplementation project(':ignite-client-common')
integrationTestImplementation testFixtures(project(':ignite-core'))
integrationTestImplementation testFixtures(project(':ignite-runner'))
}
diff --git a/modules/compute/src/integrationTest/java/org/apache/ignite/internal/compute/ItComputeBaseTest.java b/modules/compute/src/integrationTest/java/org/apache/ignite/internal/compute/ItComputeBaseTest.java
index 2a88dbe753..3736855d09 100644
--- a/modules/compute/src/integrationTest/java/org/apache/ignite/internal/compute/ItComputeBaseTest.java
+++ b/modules/compute/src/integrationTest/java/org/apache/ignite/internal/compute/ItComputeBaseTest.java
@@ -157,10 +157,10 @@ public abstract class ItComputeBaseTest extends ClusterPerClassIntegrationTest {
String result = compute().execute(
JobTarget.node(clusterNode(entryNode)),
- JobDescriptor.builder(concatJobClass()).units(units()).build(),
- new Object[]{"a", 42});
+ JobDescriptor.builder(toStringJobClass()).units(units()).build(),
+ 42);
- assertThat(result, is("a42"));
+ assertThat(result, is("42"));
}
@Test
@@ -169,10 +169,10 @@ public abstract class ItComputeBaseTest extends ClusterPerClassIntegrationTest {
JobExecution<String> execution = compute().submit(
JobTarget.node(clusterNode(entryNode)),
- JobDescriptor.builder(concatJobClass()).units(units()).build(),
- new Object[] {"a", 42});
+ JobDescriptor.builder(toStringJobClass()).units(units()).build(),
+ 42);
- assertThat(execution.resultAsync(), willBe("a42"));
+ assertThat(execution.resultAsync(), willBe("42"));
assertThat(execution.stateAsync(), willBe(jobStateWithStatus(COMPLETED)));
assertThat(execution.cancelAsync(), willBe(false));
}
@@ -181,20 +181,20 @@ public abstract class ItComputeBaseTest extends ClusterPerClassIntegrationTest {
void executesJobOnRemoteNodes() {
String result = compute().execute(
JobTarget.anyNode(clusterNode(node(1)), clusterNode(node(2))),
- JobDescriptor.builder(concatJobClass()).units(units()).build(),
- new Object[]{"a", 42});
+ JobDescriptor.builder(toStringJobClass()).units(units()).build(),
+ 42);
- assertThat(result, is("a42"));
+ assertThat(result, is("42"));
}
@Test
void executesJobOnRemoteNodesAsync() {
JobExecution<String> execution = compute().submit(
JobTarget.anyNode(clusterNode(node(1)), clusterNode(node(2))),
- JobDescriptor.builder(concatJobClass()).units(units()).build(),
- new Object[]{"a", 42});
+ JobDescriptor.builder(toStringJobClass()).units(units()).build(),
+ 42);
- assertThat(execution.resultAsync(), willBe("a42"));
+ assertThat(execution.resultAsync(), willBe("42"));
assertThat(execution.stateAsync(), willBe(jobStateWithStatus(COMPLETED)));
assertThat(execution.cancelAsync(), willBe(false));
}
@@ -290,14 +290,14 @@ public abstract class ItComputeBaseTest extends ClusterPerClassIntegrationTest {
Map<ClusterNode, JobExecution<String>> results = compute().submitBroadcast(
Set.of(clusterNode(entryNode), clusterNode(node(1)), clusterNode(node(2))),
- JobDescriptor.builder(concatJobClass()).units(units()).build(),
- new Object[] {"a", 42});
+ JobDescriptor.builder(toStringJobClass()).units(units()).build(),
+ 42);
assertThat(results, is(aMapWithSize(3)));
for (int i = 0; i < 3; i++) {
ClusterNode node = clusterNode(node(i));
JobExecution<String> execution = results.get(node);
- assertThat(execution.resultAsync(), willBe("a42"));
+ assertThat(execution.resultAsync(), willBe("42"));
assertThat(execution.stateAsync(), willBe(jobStateWithStatus(COMPLETED)));
assertThat(execution.cancelAsync(), willBe(false));
}
@@ -691,12 +691,12 @@ public abstract class ItComputeBaseTest extends ClusterPerClassIntegrationTest {
).map(Arguments::of);
}
- static String concatJobClassName() {
- return ConcatJob.class.getName();
+ static String toStringJobClassName() {
+ return ToStringJob.class.getName();
}
- private static Class<ConcatJob> concatJobClass() {
- return ConcatJob.class;
+ private static Class<ToStringJob> toStringJobClass() {
+ return ToStringJob.class;
}
private static String getNodeNameJobClassName() {
diff --git a/modules/compute/src/integrationTest/java/org/apache/ignite/internal/compute/ItComputeTestClient.java b/modules/compute/src/integrationTest/java/org/apache/ignite/internal/compute/ItComputeTestClient.java
index a3ab1a64f3..83b8a25bb4 100644
--- a/modules/compute/src/integrationTest/java/org/apache/ignite/internal/compute/ItComputeTestClient.java
+++ b/modules/compute/src/integrationTest/java/org/apache/ignite/internal/compute/ItComputeTestClient.java
@@ -23,7 +23,6 @@ import org.apache.ignite.client.IgniteClient;
import org.apache.ignite.compute.IgniteCompute;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Disabled;
/**
* Integration tests for Compute functionality using thin client API.
@@ -55,34 +54,4 @@ public class ItComputeTestClient extends ItComputeTestEmbedded {
void cancelsNotCancellableJob(boolean local) {
// No-op. Embedded-specific.
}
-
- @Override
- @Disabled("IGNITE-24059 Compute argument serialization is inconsistent in embedded and thin client")
- void executesJobLocally() {
- super.executesJobLocally();
- }
-
- @Override
- @Disabled("IGNITE-24059 Compute argument serialization is inconsistent in embedded and thin client")
- void executesJobLocallyAsync() {
- super.executesJobLocallyAsync();
- }
-
- @Override
- @Disabled("IGNITE-24059 Compute argument serialization is inconsistent in embedded and thin client")
- void broadcastsJobWithArgumentsAsync() {
- super.broadcastsJobWithArgumentsAsync();
- }
-
- @Override
- @Disabled("IGNITE-24059 Compute argument serialization is inconsistent in embedded and thin client")
- void executesJobOnRemoteNodes() {
- super.executesJobOnRemoteNodes();
- }
-
- @Override
- @Disabled("IGNITE-24059 Compute argument serialization is inconsistent in embedded and thin client")
- void executesJobOnRemoteNodesAsync() {
- super.executesJobOnRemoteNodesAsync();
- }
}
diff --git a/modules/compute/src/integrationTest/java/org/apache/ignite/internal/compute/ItComputeTestEmbedded.java b/modules/compute/src/integrationTest/java/org/apache/ignite/internal/compute/ItComputeTestEmbedded.java
index 99b01ad130..b10c1b945c 100644
--- a/modules/compute/src/integrationTest/java/org/apache/ignite/internal/compute/ItComputeTestEmbedded.java
+++ b/modules/compute/src/integrationTest/java/org/apache/ignite/internal/compute/ItComputeTestEmbedded.java
@@ -63,6 +63,7 @@ import org.apache.ignite.lang.IgniteException;
import org.apache.ignite.network.ClusterNode;
import org.apache.ignite.table.KeyValueView;
import org.apache.ignite.table.Table;
+import org.jetbrains.annotations.Nullable;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
@@ -71,32 +72,34 @@ import org.junit.jupiter.params.provider.MethodSource;
/**
* Integration tests for Compute functionality in embedded Ignite mode.
*/
-@SuppressWarnings({"NewClassNamingConvention"})
+@SuppressWarnings("NewClassNamingConvention")
class ItComputeTestEmbedded extends ItComputeBaseTest {
-
@Override
protected List<DeploymentUnit> units() {
return List.of();
}
+ @SuppressWarnings("AssignmentToStaticFieldFromInstanceMethod")
@Test
void changeJobPriorityLocally() {
Ignite entryNode = node(0);
JobTarget jobTarget = JobTarget.node(clusterNode(entryNode));
CountDownLatch countDownLatch = new CountDownLatch(1);
- JobDescriptor<CountDownLatch, String> job = JobDescriptor.builder(WaitLatchJob.class).units(units()).build();
+ WaitLatchJob.latches = new CountDownLatch[]{countDownLatch, new CountDownLatch(1)};
+
+ JobDescriptor<Integer, Void> job = JobDescriptor.builder(WaitLatchJob.class).units(units()).build();
// Start 1 task in executor with 1 thread
- JobExecution<String> execution1 = entryNode.compute().submit(jobTarget, job, countDownLatch);
+ JobExecution<Void> execution1 = entryNode.compute().submit(jobTarget, job, 0);
await().until(execution1::stateAsync, willBe(jobStateWithStatus(EXECUTING)));
// Start one more task
- JobExecution<String> execution2 = entryNode.compute().submit(jobTarget, job, new CountDownLatch(1));
+ JobExecution<Void> execution2 = entryNode.compute().submit(jobTarget, job, 1);
await().until(execution2::stateAsync, willBe(jobStateWithStatus(QUEUED)));
// Start third task
- JobExecution<String> execution3 = entryNode.compute().submit(jobTarget, job, countDownLatch);
+ JobExecution<Void> execution3 = entryNode.compute().submit(jobTarget, job, 0);
await().until(execution3::stateAsync, willBe(jobStateWithStatus(QUEUED)));
// Task 2 and 3 are not completed, in queued state
@@ -120,32 +123,37 @@ class ItComputeTestEmbedded extends ItComputeBaseTest {
assertThat(execution2.cancelAsync(), willBe(true));
}
+ @SuppressWarnings("AssignmentToStaticFieldFromInstanceMethod")
@Test
void executesJobLocallyWithOptions() {
Ignite entryNode = node(0);
JobTarget jobTarget = JobTarget.node(clusterNode(entryNode));
CountDownLatch countDownLatch = new CountDownLatch(1);
- JobDescriptor<CountDownLatch, String> job = JobDescriptor.builder(WaitLatchJob.class).units(units()).build();
+ WaitLatchJob.latches = new CountDownLatch[]{countDownLatch, new CountDownLatch(1)};
+
+ JobDescriptor<Integer, Void> job = JobDescriptor.builder(WaitLatchJob.class).units(units()).build();
// Start 1 task in executor with 1 thread
- JobExecution<String> execution1 = entryNode.compute().submit(jobTarget, job, countDownLatch);
+ JobExecution<Void> execution1 = entryNode.compute().submit(jobTarget, job, 0);
await().until(execution1::stateAsync, willBe(jobStateWithStatus(EXECUTING)));
// Start one more task
- JobExecution<String> execution2 = entryNode.compute().submit(jobTarget, job, new CountDownLatch(1));
+ JobExecution<Void> execution2 = entryNode.compute().submit(jobTarget, job, 1);
await().until(execution2::stateAsync, willBe(jobStateWithStatus(QUEUED)));
// Start third task it should be before task2 in the queue due to higher priority in options
JobExecutionOptions options = JobExecutionOptions.builder().priority(1).maxRetries(2).build();
- JobExecution<String> execution3 = entryNode.compute().submit(
+ WaitLatchThrowExceptionOnFirstExecutionJob.latch = countDownLatch;
+
+ JobExecution<Void> execution3 = entryNode.compute().submit(
jobTarget,
JobDescriptor.builder(WaitLatchThrowExceptionOnFirstExecutionJob.class)
.units(units())
.options(options)
.build(),
- countDownLatch);
+ null);
await().until(execution3::stateAsync, willBe(jobStateWithStatus(QUEUED)));
// Task 1 and 2 are not competed, in queue state
@@ -172,30 +180,34 @@ class ItComputeTestEmbedded extends ItComputeBaseTest {
assertThat(execution2.cancelAsync(), willBe(true));
}
+ @SuppressWarnings("AssignmentToStaticFieldFromInstanceMethod")
@Test
void shouldNotConvertIgniteException() {
Ignite entryNode = node(0);
IgniteException exception = new IgniteException(INTERNAL_ERR, "Test exception");
+ CustomFailingJob.th = exception;
IgniteException ex = assertThrows(IgniteException.class, () -> entryNode.compute().execute(
JobTarget.node(clusterNode(entryNode)),
JobDescriptor.builder(CustomFailingJob.class).units(units()).build(),
- exception));
+ null));
assertPublicException(ex, exception.code(), exception.getMessage());
}
+ @SuppressWarnings("AssignmentToStaticFieldFromInstanceMethod")
@Test
void shouldNotConvertIgniteCheckedException() {
Ignite entryNode = node(0);
IgniteCheckedException exception = new IgniteCheckedException(INTERNAL_ERR, "Test exception");
+ CustomFailingJob.th = exception;
IgniteCheckedException ex = assertThrows(IgniteCheckedException.class, () -> entryNode.compute().execute(
JobTarget.node(clusterNode(entryNode)),
JobDescriptor.builder(CustomFailingJob.class).units(units()).build(),
- exception));
+ null));
assertPublicCheckedException(ex, exception.code(), exception.getMessage());
}
@@ -209,15 +221,18 @@ class ItComputeTestEmbedded extends ItComputeBaseTest {
);
}
+ @SuppressWarnings("AssignmentToStaticFieldFromInstanceMethod")
@ParameterizedTest
@MethodSource("privateExceptions")
void shouldConvertToComputeException(Throwable throwable) {
Ignite entryNode = node(0);
+ CustomFailingJob.th = throwable;
+
IgniteException ex = assertThrows(IgniteException.class, () -> entryNode.compute().execute(
JobTarget.node(clusterNode(entryNode)),
JobDescriptor.builder(CustomFailingJob.class).units(units()).build(),
- throwable));
+ null));
assertComputeException(ex, throwable);
}
@@ -284,18 +299,22 @@ class ItComputeTestEmbedded extends ItComputeBaseTest {
return IntStream.range(0, initialNodes()).mapToObj(Arguments::of);
}
- private static class CustomFailingJob implements ComputeJob<Throwable, String> {
+ private static class CustomFailingJob implements ComputeJob<Void, Void> {
+ static Throwable th;
+
@Override
- public CompletableFuture<String> executeAsync(JobExecutionContext context, Throwable th) {
+ public CompletableFuture<Void> executeAsync(JobExecutionContext context, Void arg) {
throw ExceptionUtils.sneakyThrow(th);
}
}
- private static class WaitLatchJob implements ComputeJob<CountDownLatch, String> {
+ private static class WaitLatchJob implements ComputeJob<Integer, Void> {
+ private static CountDownLatch[] latches;
+
@Override
- public CompletableFuture<String> executeAsync(JobExecutionContext context, CountDownLatch latch) {
+ public @Nullable CompletableFuture<Void> executeAsync(JobExecutionContext context, Integer latchId) {
try {
- latch.await();
+ latches[latchId].await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
@@ -303,11 +322,12 @@ class ItComputeTestEmbedded extends ItComputeBaseTest {
}
}
- private static class WaitLatchThrowExceptionOnFirstExecutionJob implements ComputeJob<CountDownLatch, String> {
+ private static class WaitLatchThrowExceptionOnFirstExecutionJob implements ComputeJob<Void, Void> {
+ private static CountDownLatch latch;
static final AtomicInteger counter = new AtomicInteger(0);
@Override
- public CompletableFuture<String> executeAsync(JobExecutionContext context, CountDownLatch latch) {
+ public @Nullable CompletableFuture<Void> executeAsync(JobExecutionContext context, Void arg) {
try {
latch.await();
if (counter.incrementAndGet() == 1) {
diff --git a/modules/compute/src/integrationTest/java/org/apache/ignite/internal/compute/ItComputeTestStandalone.java b/modules/compute/src/integrationTest/java/org/apache/ignite/internal/compute/ItComputeTestStandalone.java
index 5620c49db5..8159eb7b74 100644
--- a/modules/compute/src/integrationTest/java/org/apache/ignite/internal/compute/ItComputeTestStandalone.java
+++ b/modules/compute/src/integrationTest/java/org/apache/ignite/internal/compute/ItComputeTestStandalone.java
@@ -88,15 +88,15 @@ class ItComputeTestStandalone extends ItComputeBaseTest {
List<DeploymentUnit> nonExistingUnits = List.of(new DeploymentUnit("non-existing", "1.0.0"));
CompletableFuture<String> result = entryNode.compute().executeAsync(
JobTarget.node(clusterNode(entryNode)),
- JobDescriptor.<Object[], String>builder(concatJobClassName()).units(nonExistingUnits).build(),
- new Object[]{"a", 42});
+ JobDescriptor.<Object[], String>builder(toStringJobClassName()).units(nonExistingUnits).build(),
+ null);
CompletionException ex0 = assertThrows(CompletionException.class, result::join);
assertComputeException(
ex0,
ClassNotFoundException.class,
- "org.apache.ignite.internal.compute.ConcatJob. Deployment unit non-existing:1.0.0 doesn't exist"
+ "org.apache.ignite.internal.compute.ToStringJob. Deployment unit non-existing:1.0.0 doesn't exist"
);
}
diff --git a/modules/compute/src/jobs/java/org/apache/ignite/internal/compute/ConcatJob.java b/modules/compute/src/jobs/java/org/apache/ignite/internal/compute/ToStringJob.java
similarity index 75%
rename from modules/compute/src/jobs/java/org/apache/ignite/internal/compute/ConcatJob.java
rename to modules/compute/src/jobs/java/org/apache/ignite/internal/compute/ToStringJob.java
index 9cf96f4745..de38ccace8 100644
--- a/modules/compute/src/jobs/java/org/apache/ignite/internal/compute/ConcatJob.java
+++ b/modules/compute/src/jobs/java/org/apache/ignite/internal/compute/ToStringJob.java
@@ -19,19 +19,15 @@ package org.apache.ignite.internal.compute;
import static java.util.concurrent.CompletableFuture.completedFuture;
-import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
-import java.util.stream.Collectors;
import org.apache.ignite.compute.ComputeJob;
import org.apache.ignite.compute.JobExecutionContext;
-/** Compute job that concatenates the string representation of its arguments. */
-public class ConcatJob implements ComputeJob<Object[], String> {
+/** Compute job that returns the string representation of its argument. */
+public class ToStringJob implements ComputeJob<Object, String> {
@Override
- public CompletableFuture<String> executeAsync(JobExecutionContext context, Object... input) {
- return completedFuture(Arrays.stream(input)
- .map(Object::toString)
- .collect(Collectors.joining()));
+ public CompletableFuture<String> executeAsync(JobExecutionContext context, Object input) {
+ return completedFuture(input == null ? null : input.toString());
}
}
diff --git a/modules/compute/src/main/java/org/apache/ignite/internal/compute/ComputeComponent.java b/modules/compute/src/main/java/org/apache/ignite/internal/compute/ComputeComponent.java
index ad320d9529..60ba436efe 100644
--- a/modules/compute/src/main/java/org/apache/ignite/internal/compute/ComputeComponent.java
+++ b/modules/compute/src/main/java/org/apache/ignite/internal/compute/ComputeComponent.java
@@ -44,37 +44,16 @@ public interface ComputeComponent extends IgniteComponent {
* @param jobClassName Name of the job class.
* @param cancellationToken Cancellation token or {@code null}.
* @param arg Job args.
- * @param <R> Job result type.
* @return Job execution object.
*/
- <T, R> JobExecution<R> executeLocally(
+ JobExecution<ComputeJobDataHolder> executeLocally(
ExecutionOptions options,
List<DeploymentUnit> units,
String jobClassName,
@Nullable CancellationToken cancellationToken,
- @Nullable T arg
+ @Nullable ComputeJobDataHolder arg
);
- /**
- * Executes a job of the given class on the current node.
- *
- *
- * @param options Job execution options.
- * @param units Deployment units which will be loaded for execution.
- * @param jobClassName Name of the job class.
- * @param arg Job args.
- * @param <R> Job result type.
- * @return Job execution object.
- */
- default <T, R> JobExecution<R> executeLocally(
- ExecutionOptions options,
- List<DeploymentUnit> units,
- String jobClassName,
- @Nullable T arg
- ) {
- return executeLocally(options, units, jobClassName, null, arg);
- }
-
/**
* Executes a job of the given class on a remote node.
*
@@ -84,16 +63,15 @@ public interface ComputeComponent extends IgniteComponent {
* @param jobClassName Name of the job class.
* @param cancellationToken Cancellation token or {@code null}.
* @param arg Job args.
- * @param <R> Job result type.
* @return Job execution object.
*/
- <T, R> JobExecution<R> executeRemotely(
+ JobExecution<ComputeJobDataHolder> executeRemotely(
ExecutionOptions options,
ClusterNode remoteNode,
List<DeploymentUnit> units,
String jobClassName,
@Nullable CancellationToken cancellationToken,
- T arg
+ @Nullable ComputeJobDataHolder arg
);
/**
@@ -107,17 +85,16 @@ public interface ComputeComponent extends IgniteComponent {
* @param jobClassName Name of the job class.
* @param cancellationToken Cancellation token or {@code null}.
* @param arg Job args.
- * @param <R> Job result type.
* @return Job execution object.
*/
- <T, R> JobExecution<R> executeRemotelyWithFailover(
+ JobExecution<ComputeJobDataHolder> executeRemotelyWithFailover(
ClusterNode remoteNode,
NextWorkerSelector nextWorkerSelector,
List<DeploymentUnit> units,
String jobClassName,
ExecutionOptions options,
@Nullable CancellationToken cancellationToken,
- @Nullable T arg
+ @Nullable ComputeJobDataHolder arg
);
/**
diff --git a/modules/compute/src/main/java/org/apache/ignite/internal/compute/ComputeComponentImpl.java b/modules/compute/src/main/java/org/apache/ignite/internal/compute/ComputeComponentImpl.java
index c68056c66e..f2c613d4a1 100644
--- a/modules/compute/src/main/java/org/apache/ignite/internal/compute/ComputeComponentImpl.java
+++ b/modules/compute/src/main/java/org/apache/ignite/internal/compute/ComputeComponentImpl.java
@@ -122,15 +122,15 @@ public class ComputeComponentImpl implements ComputeComponent, SystemViewProvide
/** {@inheritDoc} */
@Override
- public <I, R> JobExecution<R> executeLocally(
+ public JobExecution<ComputeJobDataHolder> executeLocally(
ExecutionOptions options,
List<DeploymentUnit> units,
String jobClassName,
@Nullable CancellationToken cancellationToken,
- I arg
+ @Nullable ComputeJobDataHolder arg
) {
if (!busyLock.enterBusy()) {
- return new DelegatingJobExecution<>(
+ return new DelegatingJobExecution(
failedFuture(new IgniteInternalException(NODE_STOPPING_ERR, new NodeStoppingException()))
);
}
@@ -138,10 +138,10 @@ public class ComputeComponentImpl implements ComputeComponent, SystemViewProvide
try {
CompletableFuture<JobContext> classLoaderFut = jobContextManager.acquireClassLoader(units);
- CompletableFuture<JobExecutionInternal<R>> future =
+ CompletableFuture<JobExecutionInternal<ComputeJobDataHolder>> future =
mapClassLoaderExceptions(classLoaderFut, jobClassName)
.thenApply(context -> {
- JobExecutionInternal<R> execution = execJob(context, options, jobClassName, arg);
+ JobExecutionInternal<ComputeJobDataHolder> execution = execJob(context, options, jobClassName, arg);
execution.resultAsync().whenComplete((result, e) -> context.close());
inFlightFutures.registerFuture(execution.resultAsync());
return execution;
@@ -150,7 +150,7 @@ public class ComputeComponentImpl implements ComputeComponent, SystemViewProvide
inFlightFutures.registerFuture(future);
inFlightFutures.registerFuture(classLoaderFut);
- JobExecution<R> result = new DelegatingJobExecution<>(future);
+ JobExecution<ComputeJobDataHolder> result = new DelegatingJobExecution(future);
if (cancellationToken != null) {
CancelHandleHelper.addCancelAction(cancellationToken, classLoaderFut);
@@ -191,6 +191,7 @@ public class ComputeComponentImpl implements ComputeComponent, SystemViewProvide
inFlightFutures.registerFuture(taskFuture);
DelegatingTaskExecution<I, M, T, R> result = new DelegatingTaskExecution<>(taskFuture);
+
result.idAsync().thenAccept(jobId -> executionManager.addExecution(jobId, new TaskToJobExecutionWrapper<>(result)));
return result;
} finally {
@@ -200,28 +201,30 @@ public class ComputeComponentImpl implements ComputeComponent, SystemViewProvide
/** {@inheritDoc} */
@Override
- public <T, R> JobExecution<R> executeRemotely(
+ public JobExecution<ComputeJobDataHolder> executeRemotely(
ExecutionOptions options,
ClusterNode remoteNode,
List<DeploymentUnit> units,
String jobClassName,
@Nullable CancellationToken cancellationToken,
- T arg
+ @Nullable ComputeJobDataHolder arg
) {
if (!busyLock.enterBusy()) {
- return new DelegatingJobExecution<>(
+ return new DelegatingJobExecution(
failedFuture(new IgniteInternalException(NODE_STOPPING_ERR, new NodeStoppingException()))
);
}
try {
CompletableFuture<UUID> jobIdFuture = messaging.remoteExecuteRequestAsync(options, remoteNode, units, jobClassName, arg);
- CompletableFuture<R> resultFuture = jobIdFuture.thenCompose(jobId -> messaging.remoteJobResultRequestAsync(remoteNode, jobId));
+ CompletableFuture<ComputeJobDataHolder> resultFuture = jobIdFuture.thenCompose(
+ jobId -> messaging.remoteJobResultRequestAsync(remoteNode, jobId));
inFlightFutures.registerFuture(jobIdFuture);
inFlightFutures.registerFuture(resultFuture);
- JobExecution<R> result = new RemoteJobExecution<>(remoteNode, jobIdFuture, resultFuture, inFlightFutures, messaging);
+ JobExecution<ComputeJobDataHolder> result = new RemoteJobExecution<>(
+ remoteNode, jobIdFuture, resultFuture, inFlightFutures, messaging);
if (cancellationToken != null) {
CancelHandleHelper.addCancelAction(cancellationToken, result::cancelAsync, result.resultAsync());
@@ -235,16 +238,16 @@ public class ComputeComponentImpl implements ComputeComponent, SystemViewProvide
}
@Override
- public <T, R> JobExecution<R> executeRemotelyWithFailover(
+ public JobExecution<ComputeJobDataHolder> executeRemotelyWithFailover(
ClusterNode remoteNode,
NextWorkerSelector nextWorkerSelector,
List<DeploymentUnit> units,
String jobClassName,
ExecutionOptions options,
@Nullable CancellationToken cancellationToken,
- @Nullable T arg
+ @Nullable ComputeJobDataHolder arg
) {
- JobExecution<R> result = (JobExecution<R>) new ComputeJobFailover<>(
+ JobExecution<ComputeJobDataHolder> result = new ComputeJobFailover(
this, logicalTopologyService, topologyService,
remoteNode, nextWorkerSelector, failoverExecutor, units,
jobClassName, options, cancellationToken, arg
@@ -293,7 +296,8 @@ public class ComputeComponentImpl implements ComputeComponent, SystemViewProvide
@Override
public CompletableFuture<Void> startAsync(ComponentContext componentContext) {
executor.start();
- messaging.start(this::executeLocally);
+ messaging.start((options, units, jobClassName, arg) ->
+ executeLocally(options, units, jobClassName, null, arg));
executionManager.start();
computeViewProvider.init(executionManager);
@@ -320,7 +324,11 @@ public class ComputeComponentImpl implements ComputeComponent, SystemViewProvide
}
- private <T, R> JobExecutionInternal<R> execJob(JobContext context, ExecutionOptions options, String jobClassName, T arg) {
+ private JobExecutionInternal<ComputeJobDataHolder> execJob(
+ JobContext context,
+ ExecutionOptions options,
+ String jobClassName,
+ @Nullable ComputeJobDataHolder arg) {
try {
return executor.executeJob(options, jobClass(context.classLoader(), jobClassName), context.classLoader(), arg);
} catch (Throwable e) {
diff --git a/modules/compute/src/main/java/org/apache/ignite/internal/compute/ComputeJobFailover.java b/modules/compute/src/main/java/org/apache/ignite/internal/compute/ComputeJobFailover.java
index ae531a1ee0..87f3678973 100644
--- a/modules/compute/src/main/java/org/apache/ignite/internal/compute/ComputeJobFailover.java
+++ b/modules/compute/src/main/java/org/apache/ignite/internal/compute/ComputeJobFailover.java
@@ -43,10 +43,8 @@ import org.jetbrains.annotations.Nullable;
* <p>If you want to execute a job on node1 and use node2 and node3 as failover candidates,
* then you should create an instance of this class with workerNode = node1, failoverCandidates = [node2, node3] as arguments and call
* {@link #failSafeExecute()}.
- *
- * @param <R> the type of the result of the job.
*/
-class ComputeJobFailover<R> {
+class ComputeJobFailover {
private static final IgniteLogger LOG = Loggers.forClass(ComputeJobFailover.class);
/**
@@ -84,7 +82,7 @@ class ComputeJobFailover<R> {
/**
* Context of the called job. Captures deployment units, jobClassName and arguments.
*/
- private final RemoteExecutionContext<?, R> jobContext;
+ private final RemoteExecutionContext jobContext;
/** Cancellation token. */
@Nullable private final CancellationToken cancellationToken;
@@ -102,7 +100,7 @@ class ComputeJobFailover<R> {
* @param jobClassName the name of the job class.
* @param executionOptions execution options like priority or max retries.
* @param cancellationToken Cancellation token or {@code null}.
- * @param args the arguments of the job.
+ * @param arg the arguments of the job.
*/
ComputeJobFailover(
ComputeComponent computeComponent,
@@ -115,14 +113,14 @@ class ComputeJobFailover<R> {
String jobClassName,
ExecutionOptions executionOptions,
@Nullable CancellationToken cancellationToken,
- Object args
+ @Nullable ComputeJobDataHolder arg
) {
this.computeComponent = computeComponent;
this.runningWorkerNode = new AtomicReference<>(workerNode);
this.logicalTopologyService = logicalTopologyService;
this.topologyService = topologyService;
this.nextWorkerSelector = nextWorkerSelector;
- this.jobContext = new RemoteExecutionContext<>(units, jobClassName, executionOptions, args);
+ this.jobContext = new RemoteExecutionContext(units, jobClassName, executionOptions, arg);
this.executor = executor;
this.cancellationToken = cancellationToken;
}
@@ -132,8 +130,8 @@ class ComputeJobFailover<R> {
*
* @return JobExecution with the result of the job and the status of the job.
*/
- JobExecution<R> failSafeExecute() {
- JobExecution<R> jobExecution = launchJobOn(runningWorkerNode.get());
+ JobExecution<ComputeJobDataHolder> failSafeExecute() {
+ JobExecution<ComputeJobDataHolder> jobExecution = launchJobOn(runningWorkerNode.get());
jobContext.initJobExecution(new FailSafeJobExecution<>(jobExecution));
LogicalTopologyEventListener nodeLeftEventListener = new OnNodeLeft();
@@ -143,7 +141,7 @@ class ComputeJobFailover<R> {
return jobContext.failSafeJobExecution();
}
- private JobExecution<R> launchJobOn(ClusterNode runningWorkerNode) {
+ private JobExecution<ComputeJobDataHolder> launchJobOn(ClusterNode runningWorkerNode) {
if (runningWorkerNode.name().equals(topologyService.localMember().name())) {
return computeComponent.executeLocally(
jobContext.executionOptions(), jobContext.units(), jobContext.jobClassName(), cancellationToken,
@@ -191,7 +189,7 @@ class ComputeJobFailover<R> {
LOG.info("Restarting the job {} on node {}.", jobContext.jobClassName(), nextWorker.name());
runningWorkerNode.set(nextWorker);
- JobExecution<R> jobExecution = launchJobOn(runningWorkerNode.get());
+ JobExecution<ComputeJobDataHolder> jobExecution = launchJobOn(runningWorkerNode.get());
jobContext.updateJobExecution(jobExecution);
});
}
diff --git a/modules/compute/src/main/java/org/apache/ignite/internal/compute/ComputeUtils.java b/modules/compute/src/main/java/org/apache/ignite/internal/compute/ComputeUtils.java
index 3f0664d1a7..33864c6f1d 100644
--- a/modules/compute/src/main/java/org/apache/ignite/internal/compute/ComputeUtils.java
+++ b/modules/compute/src/main/java/org/apache/ignite/internal/compute/ComputeUtils.java
@@ -19,28 +19,15 @@ package org.apache.ignite.internal.compute;
import static java.util.concurrent.CompletableFuture.completedFuture;
import static java.util.concurrent.CompletableFuture.failedFuture;
-import static org.apache.ignite.internal.compute.ComputeJobDataType.MARSHALLED_CUSTOM;
-import static org.apache.ignite.internal.compute.ComputeJobDataType.NATIVE;
-import static org.apache.ignite.internal.compute.ComputeJobDataType.POJO;
-import static org.apache.ignite.internal.compute.ComputeJobDataType.TUPLE;
-import static org.apache.ignite.internal.compute.ComputeJobDataType.TUPLE_COLLECTION;
-import static org.apache.ignite.internal.compute.PojoConverter.fromTuple;
-import static org.apache.ignite.internal.compute.PojoConverter.toTuple;
import static org.apache.ignite.internal.util.ExceptionUtils.unwrapCause;
import static org.apache.ignite.lang.ErrorGroups.Compute.CLASS_INITIALIZATION_ERR;
import static org.apache.ignite.lang.ErrorGroups.Compute.COMPUTE_JOB_FAILED_ERR;
import static org.apache.ignite.lang.ErrorGroups.Compute.MARSHALLING_TYPE_MISMATCH_ERR;
import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
import java.util.List;
-import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
@@ -53,10 +40,6 @@ import org.apache.ignite.compute.task.MapReduceTask;
import org.apache.ignite.compute.task.TaskExecutionContext;
import org.apache.ignite.deployment.DeploymentUnit;
import org.apache.ignite.deployment.version.Version;
-import org.apache.ignite.internal.binarytuple.BinaryTupleBuilder;
-import org.apache.ignite.internal.binarytuple.BinaryTupleReader;
-import org.apache.ignite.internal.binarytuple.inlineschema.TupleWithSchemaMarshalling;
-import org.apache.ignite.internal.client.proto.ClientBinaryTupleUtils;
import org.apache.ignite.internal.compute.loader.JobClassLoader;
import org.apache.ignite.internal.compute.message.DeploymentUnitMsg;
import org.apache.ignite.internal.compute.message.ExecuteResponse;
@@ -65,13 +48,9 @@ import org.apache.ignite.internal.compute.message.JobChangePriorityResponse;
import org.apache.ignite.internal.compute.message.JobResultResponse;
import org.apache.ignite.internal.compute.message.JobStateResponse;
import org.apache.ignite.internal.compute.message.JobStatesResponse;
-import org.apache.ignite.internal.util.IgniteUtils;
import org.apache.ignite.lang.IgniteCheckedException;
import org.apache.ignite.lang.IgniteException;
import org.apache.ignite.marshalling.Marshaller;
-import org.apache.ignite.marshalling.MarshallingException;
-import org.apache.ignite.marshalling.UnmarshallingException;
-import org.apache.ignite.sql.ColumnType;
import org.apache.ignite.table.DataStreamerReceiver;
import org.apache.ignite.table.Tuple;
import org.jetbrains.annotations.Nullable;
@@ -82,10 +61,6 @@ import org.jetbrains.annotations.Nullable;
public class ComputeUtils {
private static final ComputeMessagesFactory MESSAGES_FACTORY = new ComputeMessagesFactory();
- private static final Set<Class<?>> NATIVE_TYPES = Arrays.stream(ColumnType.values())
- .map(ColumnType::javaClass)
- .collect(Collectors.toUnmodifiableSet());
-
/**
* Instantiate compute job via provided class loader by provided job class.
*
@@ -255,16 +230,15 @@ public class ComputeUtils {
* Extract Compute job result from execute response.
*
* @param jobResultResponse Job execution result message response.
- * @param <R> Compute job return type.
* @return Completable future with result.
*/
- public static <R> CompletableFuture<R> resultFromJobResultResponse(JobResultResponse jobResultResponse) {
+ public static CompletableFuture<ComputeJobDataHolder> resultFromJobResultResponse(JobResultResponse jobResultResponse) {
Throwable throwable = jobResultResponse.throwable();
if (throwable != null) {
return failedFuture(throwable);
}
- return completedFuture((R) jobResultResponse.result());
+ return completedFuture(jobResultResponse.result());
}
/**
@@ -388,14 +362,14 @@ public class ComputeUtils {
}
if (input instanceof ComputeJobDataHolder) {
- return unmarshalArgumentFromDataHolder(marshaller, (ComputeJobDataHolder) input, pojoType);
+ return SharedComputeUtils.unmarshalArgOrResult((ComputeJobDataHolder) input, marshaller, pojoType);
}
if (marshaller == null) {
if (input instanceof Tuple) {
// If input was marshalled as Tuple and argument type is not tuple then it's a pojo.
if (pojoType != null && pojoType != Tuple.class) {
- return (T) unmarshalPojo(pojoType, (Tuple) input);
+ return (T) SharedComputeUtils.unmarshalPojo(pojoType, (Tuple) input);
}
}
return (T) input;
@@ -419,185 +393,6 @@ public class ComputeUtils {
);
}
- /**
- * Unmarshals the input from the {@link ComputeJobDataHolder} using provided marshaller if input was marshalled on the client. If the
- * input was marshalled as a {@link Tuple} or POJO, then, if provided pojo type is not {@code null} and not a {@link Tuple}, unmarshals
- * the input as a pojo using the provided pojo type, otherwise unmarshals it as a {@link Tuple}.
- *
- * @param marshaller Optional marshaller to unmarshal the input.
- * @param argumentHolder Argument holder.
- * @param pojoType Pojo type to use when unmarshalling as a pojo.
- * @param <T> Result type.
- * @return Unmarshalled object.
- */
- private static <T> @Nullable T unmarshalArgumentFromDataHolder(
- @Nullable Marshaller<T, byte[]> marshaller,
- ComputeJobDataHolder argumentHolder,
- @Nullable Class<?> pojoType
- ) {
- ComputeJobDataType type = argumentHolder.type();
- if (type != MARSHALLED_CUSTOM && marshaller != null) {
- throw new ComputeException(
- MARSHALLING_TYPE_MISMATCH_ERR,
- "Marshaller is defined on the server, but the argument was not marshalled on the client. "
- + "If you want to use default marshalling strategy, "
- + "then you should not define your marshaller in the job. "
- + "If you would like to use your own marshaller, then double-check "
- + "that both of them are defined in the client and in the server."
- );
- }
- switch (type) {
- case NATIVE: {
- var reader = new BinaryTupleReader(3, argumentHolder.data());
- return (T) ClientBinaryTupleUtils.readObject(reader, 0);
- }
-
- case TUPLE: // Fallthrough TODO https://issues.apache.org/jira/browse/IGNITE-23320
- case POJO:
- Tuple tuple = TupleWithSchemaMarshalling.unmarshal(argumentHolder.data());
- if (pojoType != null && pojoType != Tuple.class) {
- return (T) unmarshalPojo(pojoType, tuple);
- }
- return (T) tuple;
-
- case MARSHALLED_CUSTOM:
- if (marshaller == null) {
- throw new ComputeException(MARSHALLING_TYPE_MISMATCH_ERR, "Marshaller should be defined on the client");
- }
- try {
- return marshaller.unmarshal(argumentHolder.data());
- } catch (Exception ex) {
- throw new ComputeException(MARSHALLING_TYPE_MISMATCH_ERR, "Exception in user-defined marshaller", ex);
- }
-
- case TUPLE_COLLECTION: {
- // TODO: IGNITE-24059 Deduplicate with ClientComputeJobUnpacker.
- ByteBuffer collectionBuf = ByteBuffer.wrap(argumentHolder.data()).order(ByteOrder.LITTLE_ENDIAN);
- int count = collectionBuf.getInt();
- BinaryTupleReader reader = new BinaryTupleReader(count, collectionBuf.slice().order(ByteOrder.LITTLE_ENDIAN));
-
- List<Tuple> res = new ArrayList<>(count);
- for (int i = 0; i < count; i++) {
- ByteBuffer elementBytes = reader.bytesValueAsBuffer(i);
-
- if (elementBytes == null) {
- res.add(null);
- continue;
- }
-
- res.add(TupleWithSchemaMarshalling.unmarshal(elementBytes));
- }
-
- return (T) res;
- }
-
- default:
- throw new ComputeException(MARSHALLING_TYPE_MISMATCH_ERR, "Unexpected job argument type: " + type);
- }
- }
-
- private static Object unmarshalPojo(Class<?> pojoType, Tuple input) {
- try {
- Object obj = pojoType.getConstructor().newInstance();
-
- fromTuple(obj, input);
-
- return obj;
- } catch (NoSuchMethodException e) {
- throw new UnmarshallingException("Class " + pojoType.getName() + " doesn't have public default constructor. "
- + "Add the constructor or define argument marshaller in the compute job.", e);
- } catch (InvocationTargetException e) {
- throw new UnmarshallingException("Constructor has thrown an exception", e);
- } catch (InstantiationException e) {
- throw new UnmarshallingException("Can't instantiate an object of class " + pojoType.getName(), e);
- } catch (IllegalAccessException e) {
- throw new UnmarshallingException("Constructor is inaccessible", e);
- } catch (PojoConversionException e) {
- throw new UnmarshallingException("Can't unpack object", e);
- }
- }
-
- /**
- * Marshals the job result using either provided marshaller if not {@code null} or depending on the type of the result either as a
- * {@link Tuple}, a native type (see {@link ColumnType}) or a POJO. Wraps the marshalled data with the data type in the
- * {@link ComputeJobDataHolder} to be unmarshalled on the client.
- *
- * @param result Compute job result.
- * @param marshaller Optional result marshaller.
- *
- * @return Data holder.
- */
- @Nullable
- static ComputeJobDataHolder marshalAndWrapResult(Object result, @Nullable Marshaller<Object, byte[]> marshaller) {
- if (result == null) {
- return null;
- }
-
- if (marshaller != null) {
- byte[] data = marshaller.marshal(result);
- if (data == null) {
- return null;
- }
- return new ComputeJobDataHolder(MARSHALLED_CUSTOM, data);
- }
-
- if (result instanceof Tuple) {
- Tuple tuple = (Tuple) result;
- return new ComputeJobDataHolder(TUPLE, TupleWithSchemaMarshalling.marshal(tuple));
- }
-
- if (result instanceof Collection) {
- // TODO: IGNITE-24059 Deduplicate with ClientComputeJobPacker.
- Collection<?> col = (Collection<?>) result;
-
- // Pack entire collection into a single binary blob.
- BinaryTupleBuilder tupleBuilder = new BinaryTupleBuilder(col.size());
-
- for (Object el : col) {
- if (el == null) {
- tupleBuilder.appendNull();
- continue;
- }
-
- if (!(el instanceof Tuple)) {
- throw new MarshallingException("Can't pack collection: expected Tuple, but got " + el.getClass(), null);
- }
-
- tupleBuilder.appendBytes(TupleWithSchemaMarshalling.marshal((Tuple) el));
- }
-
- ByteBuffer binTupleBytes = tupleBuilder.build();
-
- byte[] resArr = new byte[Integer.BYTES + binTupleBytes.remaining()];
- ByteBuffer resBuf = ByteBuffer.wrap(resArr).order(ByteOrder.LITTLE_ENDIAN);
- resBuf.putInt(col.size());
- resBuf.put(binTupleBytes);
-
- return new ComputeJobDataHolder(TUPLE_COLLECTION, resArr);
- }
-
-
- if (isNativeType(result.getClass())) {
- // Builder with inline schema.
- // Value is represented by 3 tuple elements: type, scale, value.
- var builder = new BinaryTupleBuilder(3, 3, false);
- ClientBinaryTupleUtils.appendObject(builder, result);
- return new ComputeJobDataHolder(NATIVE, IgniteUtils.byteBufferToByteArray(builder.build()));
- }
-
- try {
- // TODO https://issues.apache.org/jira/browse/IGNITE-23320
- Tuple tuple = toTuple(result);
- return new ComputeJobDataHolder(POJO, TupleWithSchemaMarshalling.marshal(tuple));
- } catch (PojoConversionException e) {
- throw new MarshallingException("Can't pack object", e);
- }
- }
-
- private static boolean isNativeType(Class<?> clazz) {
- return NATIVE_TYPES.contains(clazz);
- }
-
/**
* Finds the second argument type of the {@link ComputeJob#executeAsync(JobExecutionContext, T)} method in the provided job class.
*
diff --git a/modules/compute/src/main/java/org/apache/ignite/internal/compute/DelegatingJobExecution.java b/modules/compute/src/main/java/org/apache/ignite/internal/compute/DelegatingJobExecution.java
index de376d8be2..00c4d18cd6 100644
--- a/modules/compute/src/main/java/org/apache/ignite/internal/compute/DelegatingJobExecution.java
+++ b/modules/compute/src/main/java/org/apache/ignite/internal/compute/DelegatingJobExecution.java
@@ -18,27 +18,23 @@
package org.apache.ignite.internal.compute;
import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.ExecutionException;
import org.apache.ignite.compute.JobExecution;
import org.apache.ignite.compute.JobState;
import org.apache.ignite.internal.compute.executor.JobExecutionInternal;
-import org.apache.ignite.marshalling.Marshaller;
import org.jetbrains.annotations.Nullable;
/**
* Delegates {@link JobExecution} to the future of {@link JobExecutionInternal}.
- *
- * @param <R> Result type.
*/
-class DelegatingJobExecution<R> implements JobExecution<R>, MarshallerProvider<R> {
- private final CompletableFuture<JobExecutionInternal<R>> delegate;
+class DelegatingJobExecution implements JobExecution<ComputeJobDataHolder> {
+ private final CompletableFuture<JobExecutionInternal<ComputeJobDataHolder>> delegate;
- DelegatingJobExecution(CompletableFuture<JobExecutionInternal<R>> delegate) {
+ DelegatingJobExecution(CompletableFuture<JobExecutionInternal<ComputeJobDataHolder>> delegate) {
this.delegate = delegate;
}
@Override
- public CompletableFuture<R> resultAsync() {
+ public CompletableFuture<ComputeJobDataHolder> resultAsync() {
return delegate.thenCompose(JobExecutionInternal::resultAsync);
}
@@ -56,22 +52,4 @@ class DelegatingJobExecution<R> implements JobExecution<R>, MarshallerProvider<R
public CompletableFuture<@Nullable Boolean> changePriorityAsync(int newPriority) {
return delegate.thenApply(jobExecutionInternal -> jobExecutionInternal.changePriority(newPriority));
}
-
- @Override
- public @Nullable Marshaller<R, byte[]> resultMarshaller() {
- try {
- return delegate.thenApply(JobExecutionInternal::resultMarshaller).get();
- } catch (InterruptedException | ExecutionException e) {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- public boolean marshalResult() {
- try {
- return delegate.thenApply(JobExecutionInternal::marshalResult).get();
- } catch (InterruptedException | ExecutionException e) {
- throw new RuntimeException(e);
- }
- }
}
diff --git a/modules/compute/src/main/java/org/apache/ignite/internal/compute/ExecutionManager.java b/modules/compute/src/main/java/org/apache/ignite/internal/compute/ExecutionManager.java
index cf4101a675..9287a7b7aa 100644
--- a/modules/compute/src/main/java/org/apache/ignite/internal/compute/ExecutionManager.java
+++ b/modules/compute/src/main/java/org/apache/ignite/internal/compute/ExecutionManager.java
@@ -36,7 +36,6 @@ import org.apache.ignite.compute.JobState;
import org.apache.ignite.internal.compute.configuration.ComputeConfiguration;
import org.apache.ignite.internal.compute.messaging.RemoteJobExecution;
import org.apache.ignite.internal.network.TopologyService;
-import org.apache.ignite.marshalling.Marshaller;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
@@ -93,22 +92,9 @@ public class ExecutionManager {
public CompletableFuture<?> resultAsync(UUID jobId) {
JobExecution<?> execution = executions.get(jobId);
if (execution != null) {
- if (execution instanceof MarshallerProvider) {
- MarshallerProvider provider = (MarshallerProvider) execution;
- Marshaller<Object, byte[]> marshaller = provider.resultMarshaller();
-
- // If result needs to be marshalled, then job execution request came from the client and we need to marshal the result and
- // return the wrapper object back to the client handler node so it can pass the binary data directly back to client.
- if (provider.marshalResult()) {
- return execution.resultAsync().thenApply(result -> ComputeUtils.marshalAndWrapResult(result, marshaller));
- }
-
- if (marshaller != null) {
- return execution.resultAsync().thenApply(marshaller::marshal);
- }
- }
return execution.resultAsync();
}
+
return failedFuture(new ComputeException(RESULT_NOT_FOUND_ERR, "Job result not found for the job with ID: " + jobId));
}
diff --git a/modules/compute/src/main/java/org/apache/ignite/internal/compute/IgniteComputeImpl.java b/modules/compute/src/main/java/org/apache/ignite/internal/compute/IgniteComputeImpl.java
index ddc4b5b40c..04e7daca29 100644
--- a/modules/compute/src/main/java/org/apache/ignite/internal/compute/IgniteComputeImpl.java
+++ b/modules/compute/src/main/java/org/apache/ignite/internal/compute/IgniteComputeImpl.java
@@ -24,7 +24,6 @@ import static org.apache.ignite.internal.lang.IgniteExceptionMapperUtil.mapToPub
import static org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture;
import static org.apache.ignite.internal.util.ExceptionUtils.unwrapCause;
import static org.apache.ignite.lang.ErrorGroups.Compute.COMPUTE_JOB_FAILED_ERR;
-import static org.apache.ignite.marshalling.Marshaller.tryMarshalOrCast;
import java.util.Collection;
import java.util.HashSet;
@@ -126,9 +125,10 @@ public class IgniteComputeImpl implements IgniteComputeInternal, StreamerReceive
return new ResultUnmarshallingJobExecution<>(
executeAsyncWithFailover(
nodes, descriptor.units(), descriptor.jobClassName(), descriptor.options(), cancellationToken,
- tryMarshalOrCast(argumentMarshaller, args)
+ SharedComputeUtils.marshalArgOrResult(args, argumentMarshaller)
),
- resultMarshaller
+ resultMarshaller,
+ descriptor.resultClass()
);
}
@@ -138,7 +138,7 @@ public class IgniteComputeImpl implements IgniteComputeInternal, StreamerReceive
String tableName = colocatedTarget.tableName();
Object key = colocatedTarget.key();
- CompletableFuture<JobExecution<R>> jobFut;
+ CompletableFuture<JobExecution<ComputeJobDataHolder>> jobFut;
if (mapper != null) {
jobFut = requiredTable(tableName)
.thenCompose(table -> primaryReplicaForPartitionByMappedKey(table, key, mapper)
@@ -148,7 +148,7 @@ public class IgniteComputeImpl implements IgniteComputeInternal, StreamerReceive
descriptor.units(),
descriptor.jobClassName(),
descriptor.options(), cancellationToken,
- tryMarshalOrCast(argumentMarshaller, args)
+ SharedComputeUtils.marshalArgOrResult(args, argumentMarshaller)
)));
} else {
@@ -160,11 +160,11 @@ public class IgniteComputeImpl implements IgniteComputeInternal, StreamerReceive
descriptor.jobClassName(),
descriptor.options(),
cancellationToken,
- tryMarshalOrCast(argumentMarshaller, args)))
- .thenApply(job -> (JobExecution<R>) job);
+ SharedComputeUtils.marshalArgOrResult(args, argumentMarshaller)));
}
- return new ResultUnmarshallingJobExecution<>(new JobExecutionFutureWrapper<>(jobFut), resultMarshaller);
+ return new ResultUnmarshallingJobExecution<>(
+ new JobExecutionFutureWrapper<>(jobFut), resultMarshaller, descriptor.resultClass());
}
throw new IllegalArgumentException("Unsupported job target: " + target);
@@ -188,13 +188,13 @@ public class IgniteComputeImpl implements IgniteComputeInternal, StreamerReceive
}
@Override
- public <R> JobExecution<R> executeAsyncWithFailover(
+ public JobExecution<ComputeJobDataHolder> executeAsyncWithFailover(
Set<ClusterNode> nodes,
List<DeploymentUnit> units,
String jobClassName,
JobExecutionOptions options,
@Nullable CancellationToken cancellationToken,
- @Nullable Object arg
+ @Nullable ComputeJobDataHolder arg
) {
Set<ClusterNode> candidates = new HashSet<>();
for (ClusterNode node : nodes) {
@@ -235,14 +235,14 @@ public class IgniteComputeImpl implements IgniteComputeInternal, StreamerReceive
return iterator.next();
}
- private <T, R> JobExecution<R> executeOnOneNodeWithFailover(
+ private JobExecution<ComputeJobDataHolder> executeOnOneNodeWithFailover(
ClusterNode targetNode,
NextWorkerSelector nextWorkerSelector,
List<DeploymentUnit> units,
String jobClassName,
JobExecutionOptions jobExecutionOptions,
@Nullable CancellationToken cancellationToken,
- @Nullable T arg
+ @Nullable ComputeJobDataHolder arg
) {
ExecutionOptions options = ExecutionOptions.from(jobExecutionOptions);
@@ -276,14 +276,14 @@ public class IgniteComputeImpl implements IgniteComputeInternal, StreamerReceive
}
@Override
- public <R> CompletableFuture<JobExecution<R>> submitColocatedInternal(
+ public CompletableFuture<JobExecution<ComputeJobDataHolder>> submitColocatedInternal(
TableViewInternal table,
Tuple key,
List<DeploymentUnit> units,
String jobClassName,
JobExecutionOptions options,
@Nullable CancellationToken cancellationToken,
- @Nullable Object arg) {
+ @Nullable ComputeJobDataHolder arg) {
return primaryReplicaForPartitionByTupleKey(table, key)
.thenApply(primaryNode -> executeOnOneNodeWithFailover(
primaryNode,
@@ -340,6 +340,7 @@ public class IgniteComputeImpl implements IgniteComputeInternal, StreamerReceive
Marshaller<T, byte[]> argumentMarshaller = descriptor.argumentMarshaller();
Marshaller<R, byte[]> resultMarshaller = descriptor.resultMarshaller();
+ ComputeJobDataHolder argHolder = SharedComputeUtils.marshalArgOrResult(args, argumentMarshaller);
return nodes.stream()
.collect(toUnmodifiableMap(identity(),
@@ -349,13 +350,19 @@ public class IgniteComputeImpl implements IgniteComputeInternal, StreamerReceive
if (topologyService.getByConsistentId(node.name()) == null) {
return new FailedExecution<>(new NodeNotFoundException(Set.of(node.name())));
}
+
return new ResultUnmarshallingJobExecution<>(
new JobExecutionWrapper<>(
executeOnOneNodeWithFailover(
- node, CompletableFutures::nullCompletedFuture,
- descriptor.units(), descriptor.jobClassName(),
- descriptor.options(), null, tryMarshalOrCast(argumentMarshaller, args))),
- resultMarshaller);
+ node,
+ CompletableFutures::nullCompletedFuture,
+ descriptor.units(),
+ descriptor.jobClassName(),
+ descriptor.options(),
+ null,
+ argHolder)),
+ resultMarshaller,
+ descriptor.resultClass());
}));
}
@@ -429,13 +436,13 @@ public class IgniteComputeImpl implements IgniteComputeInternal, StreamerReceive
@Override
public CompletableFuture<byte[]> runReceiverAsync(byte[] payload, ClusterNode node, List<DeploymentUnit> deploymentUnits) {
// Use Compute to execute receiver on the target node with failover, class loading, scheduling.
- JobExecution<byte[]> jobExecution = executeAsyncWithFailover(
+ JobExecution<ComputeJobDataHolder> jobExecution = executeAsyncWithFailover(
Set.of(node),
deploymentUnits,
StreamerReceiverJob.class.getName(),
JobExecutionOptions.DEFAULT,
null,
- payload);
+ SharedComputeUtils.marshalArgOrResult(payload, null));
return jobExecution.resultAsync()
.handle((res, err) -> {
@@ -450,7 +457,7 @@ public class IgniteComputeImpl implements IgniteComputeInternal, StreamerReceive
ExceptionUtils.sneakyThrow(err);
}
- return res;
+ return SharedComputeUtils.unmarshalArgOrResult(res, null, null);
});
}
diff --git a/modules/compute/src/main/java/org/apache/ignite/internal/compute/IgniteComputeInternal.java b/modules/compute/src/main/java/org/apache/ignite/internal/compute/IgniteComputeInternal.java
index 90835bc4f4..db3453e2db 100644
--- a/modules/compute/src/main/java/org/apache/ignite/internal/compute/IgniteComputeInternal.java
+++ b/modules/compute/src/main/java/org/apache/ignite/internal/compute/IgniteComputeInternal.java
@@ -42,7 +42,6 @@ public interface IgniteComputeInternal extends IgniteCompute {
* Executes a {@link ComputeJob} of the given class on a single node. If the node leaves the cluster, it will be restarted on one of the
* candidate nodes.
*
- * @param <R> Job result type.
* @param nodes Candidate nodes; In case target node left the cluster, the job will be restarted on one of them.
* @param units Deployment units. Can be empty.
* @param jobClassName Name of the job class to execute.
@@ -51,13 +50,13 @@ public interface IgniteComputeInternal extends IgniteCompute {
* @param payload Arguments of the job.
* @return CompletableFuture Job result.
*/
- <R> JobExecution<R> executeAsyncWithFailover(
+ JobExecution<ComputeJobDataHolder> executeAsyncWithFailover(
Set<ClusterNode> nodes,
List<DeploymentUnit> units,
String jobClassName,
JobExecutionOptions options,
@Nullable CancellationToken cancellationToken,
- @Nullable Object payload
+ @Nullable ComputeJobDataHolder payload
);
/**
@@ -71,17 +70,16 @@ public interface IgniteComputeInternal extends IgniteCompute {
* @param options job execution options (priority, max retries).
* @param cancellationToken Cancellation token or {@code null}.
* @param payload Arguments of the job.
- * @param <R> Job result type.
* @return Job execution object.
*/
- <R> CompletableFuture<JobExecution<R>> submitColocatedInternal(
+ CompletableFuture<JobExecution<ComputeJobDataHolder>> submitColocatedInternal(
TableViewInternal table,
Tuple key,
List<DeploymentUnit> units,
String jobClassName,
JobExecutionOptions options,
@Nullable CancellationToken cancellationToken,
- Object payload);
+ @Nullable ComputeJobDataHolder payload);
/**
* Wraps the given future into a job execution object.
diff --git a/modules/compute/src/main/java/org/apache/ignite/internal/compute/JobStarter.java b/modules/compute/src/main/java/org/apache/ignite/internal/compute/JobStarter.java
index 941a4ad263..a561d0ea8d 100644
--- a/modules/compute/src/main/java/org/apache/ignite/internal/compute/JobStarter.java
+++ b/modules/compute/src/main/java/org/apache/ignite/internal/compute/JobStarter.java
@@ -20,6 +20,7 @@ package org.apache.ignite.internal.compute;
import java.util.List;
import org.apache.ignite.compute.JobExecution;
import org.apache.ignite.deployment.DeploymentUnit;
+import org.jetbrains.annotations.Nullable;
/**
* Compute job starter interface.
@@ -32,13 +33,12 @@ public interface JobStarter {
* @param units Deployment units. Can be empty.
* @param jobClassName Name of the job class to execute.
* @param args Arguments of the job.
- * @param <R> Job result type.
* @return CompletableFuture Job result.
*/
- <R> JobExecution<R> start(
+ JobExecution<ComputeJobDataHolder> start(
ExecutionOptions options,
List<DeploymentUnit> units,
String jobClassName,
- Object args
+ @Nullable ComputeJobDataHolder args
);
}
diff --git a/modules/compute/src/main/java/org/apache/ignite/internal/compute/RemoteExecutionContext.java b/modules/compute/src/main/java/org/apache/ignite/internal/compute/RemoteExecutionContext.java
index 4aefcfc303..bab48411d4 100644
--- a/modules/compute/src/main/java/org/apache/ignite/internal/compute/RemoteExecutionContext.java
+++ b/modules/compute/src/main/java/org/apache/ignite/internal/compute/RemoteExecutionContext.java
@@ -25,23 +25,19 @@ import org.apache.ignite.deployment.DeploymentUnit;
/**
* Captures the context of a remote job execution. Also provides methods to access the job execution object
* that is returned to the user. The access is thread safe.
- *
- * @param <T> type of the input of the job.
- * @param <R> type of the result of the job.
*/
-class RemoteExecutionContext<T, R> {
-
+class RemoteExecutionContext {
private final ExecutionOptions executionOptions;
private final List<DeploymentUnit> units;
private final String jobClassName;
- private final T arg;
+ private final ComputeJobDataHolder arg;
- private final AtomicReference<FailSafeJobExecution<R>> jobExecution;
+ private final AtomicReference<FailSafeJobExecution<ComputeJobDataHolder>> jobExecution;
- RemoteExecutionContext(List<DeploymentUnit> units, String jobClassName, ExecutionOptions executionOptions, T arg) {
+ RemoteExecutionContext(List<DeploymentUnit> units, String jobClassName, ExecutionOptions executionOptions, ComputeJobDataHolder arg) {
this.executionOptions = executionOptions;
this.units = units;
this.jobClassName = jobClassName;
@@ -54,7 +50,7 @@ class RemoteExecutionContext<T, R> {
*
* @param jobExecution the instance of job execution that should be returned to the client.
*/
- void initJobExecution(FailSafeJobExecution<R> jobExecution) {
+ void initJobExecution(FailSafeJobExecution<ComputeJobDataHolder> jobExecution) {
if (!this.jobExecution.compareAndSet(null, jobExecution)) {
throw new IllegalStateException("Job execution is already initialized.");
}
@@ -65,8 +61,8 @@ class RemoteExecutionContext<T, R> {
*
* @return fail-safe job execution object.
*/
- FailSafeJobExecution<R> failSafeJobExecution() {
- FailSafeJobExecution<R> jobExecution = this.jobExecution.get();
+ FailSafeJobExecution<ComputeJobDataHolder> failSafeJobExecution() {
+ FailSafeJobExecution<ComputeJobDataHolder> jobExecution = this.jobExecution.get();
if (jobExecution == null) {
throw new IllegalStateException("Job execution is not initialized. Call initJobExecution() first.");
}
@@ -80,7 +76,7 @@ class RemoteExecutionContext<T, R> {
*
* @param jobExecution the new job execution object (supposed to be a restarted job but in another worker node).
*/
- void updateJobExecution(JobExecution<R> jobExecution) {
+ void updateJobExecution(JobExecution<ComputeJobDataHolder> jobExecution) {
failSafeJobExecution().updateJobExecution(jobExecution);
}
@@ -96,7 +92,7 @@ class RemoteExecutionContext<T, R> {
return jobClassName;
}
- T arg() {
+ ComputeJobDataHolder arg() {
return arg;
}
}
diff --git a/modules/compute/src/main/java/org/apache/ignite/internal/compute/ResultUnmarshallingJobExecution.java b/modules/compute/src/main/java/org/apache/ignite/internal/compute/ResultUnmarshallingJobExecution.java
index b6145258a0..54f8099b9c 100644
--- a/modules/compute/src/main/java/org/apache/ignite/internal/compute/ResultUnmarshallingJobExecution.java
+++ b/modules/compute/src/main/java/org/apache/ignite/internal/compute/ResultUnmarshallingJobExecution.java
@@ -17,8 +17,6 @@
package org.apache.ignite.internal.compute;
-import static org.apache.ignite.marshalling.Marshaller.tryUnmarshalOrCast;
-
import java.util.concurrent.CompletableFuture;
import org.apache.ignite.compute.JobExecution;
import org.apache.ignite.compute.JobState;
@@ -31,17 +29,23 @@ import org.jetbrains.annotations.Nullable;
* @param <R> Result type.
*/
class ResultUnmarshallingJobExecution<R> implements JobExecution<R> {
- private final JobExecution<R> delegate;
- private final Marshaller<R, byte[]> resultUnmarshaller;
+ private final JobExecution<ComputeJobDataHolder> delegate;
+ private final @Nullable Marshaller<R, byte[]> resultUnmarshaller;
+ private final @Nullable Class<R> resultClass;
- ResultUnmarshallingJobExecution(JobExecution<R> delegate, @Nullable Marshaller<R, byte[]> resultUnmarshaller) {
+ ResultUnmarshallingJobExecution(
+ JobExecution<ComputeJobDataHolder> delegate,
+ @Nullable Marshaller<R, byte[]> resultUnmarshaller,
+ @Nullable Class<R> resultClass) {
this.delegate = delegate;
this.resultUnmarshaller = resultUnmarshaller;
+ this.resultClass = resultClass;
}
@Override
public CompletableFuture<R> resultAsync() {
- return delegate.resultAsync().thenApply(r -> tryUnmarshalOrCast(resultUnmarshaller, r));
+ return delegate.resultAsync().thenApply(
+ r -> SharedComputeUtils.unmarshalArgOrResult(r, resultUnmarshaller, resultClass));
}
@Override
diff --git a/modules/compute/src/main/java/org/apache/ignite/internal/compute/executor/ComputeExecutor.java b/modules/compute/src/main/java/org/apache/ignite/internal/compute/executor/ComputeExecutor.java
index 9588ccaa60..08632bf191 100644
--- a/modules/compute/src/main/java/org/apache/ignite/internal/compute/executor/ComputeExecutor.java
+++ b/modules/compute/src/main/java/org/apache/ignite/internal/compute/executor/ComputeExecutor.java
@@ -19,20 +19,22 @@ package org.apache.ignite.internal.compute.executor;
import org.apache.ignite.compute.ComputeJob;
import org.apache.ignite.compute.task.MapReduceTask;
+import org.apache.ignite.internal.compute.ComputeJobDataHolder;
import org.apache.ignite.internal.compute.ExecutionOptions;
import org.apache.ignite.internal.compute.loader.JobClassLoader;
import org.apache.ignite.internal.compute.task.JobSubmitter;
import org.apache.ignite.internal.compute.task.TaskExecutionInternal;
+import org.jetbrains.annotations.Nullable;
/**
* Executor of Compute jobs.
*/
public interface ComputeExecutor {
- <T, R> JobExecutionInternal<R> executeJob(
+ <T, R> JobExecutionInternal<ComputeJobDataHolder> executeJob(
ExecutionOptions options,
Class<? extends ComputeJob<T, R>> jobClass,
JobClassLoader classLoader,
- T input);
+ @Nullable ComputeJobDataHolder input);
<I, M, T, R> TaskExecutionInternal<I, M, T, R> executeTask(
JobSubmitter<M, T> jobSubmitter,
diff --git a/modules/compute/src/main/java/org/apache/ignite/internal/compute/executor/ComputeExecutorImpl.java b/modules/compute/src/main/java/org/apache/ignite/internal/compute/executor/ComputeExecutorImpl.java
index d696f2d2b7..06e99b80a5 100644
--- a/modules/compute/src/main/java/org/apache/ignite/internal/compute/executor/ComputeExecutorImpl.java
+++ b/modules/compute/src/main/java/org/apache/ignite/internal/compute/executor/ComputeExecutorImpl.java
@@ -34,6 +34,7 @@ import org.apache.ignite.internal.compute.ComputeJobDataHolder;
import org.apache.ignite.internal.compute.ComputeUtils;
import org.apache.ignite.internal.compute.ExecutionOptions;
import org.apache.ignite.internal.compute.JobExecutionContextImpl;
+import org.apache.ignite.internal.compute.SharedComputeUtils;
import org.apache.ignite.internal.compute.configuration.ComputeConfiguration;
import org.apache.ignite.internal.compute.loader.JobClassLoader;
import org.apache.ignite.internal.compute.queue.PriorityQueueExecutor;
@@ -80,11 +81,11 @@ public class ComputeExecutorImpl implements ComputeExecutor {
}
@Override
- public <T, R> JobExecutionInternal<R> executeJob(
+ public <T, R> JobExecutionInternal<ComputeJobDataHolder> executeJob(
ExecutionOptions options,
Class<? extends ComputeJob<T, R>> jobClass,
JobClassLoader classLoader,
- T input
+ ComputeJobDataHolder input
) {
assert executorService != null;
@@ -94,27 +95,31 @@ public class ComputeExecutorImpl implements ComputeExecutor {
Marshaller<T, byte[]> inputMarshaller = jobInstance.inputMarshaller();
Marshaller<R, byte[]> resultMarshaller = jobInstance.resultMarshaller();
- // If input is of this type, this means that the request came from the thin client and packing the result to the byte array will be
- // needed in any case. In order to minimize conversion, marshal the result here.
- boolean marshalResult = input instanceof ComputeJobDataHolder;
-
- QueueExecution<R> execution = executorService.submit(
- unmarshalExecMarshal(input, jobClass, jobInstance, context, inputMarshaller),
+ QueueExecution<ComputeJobDataHolder> execution = executorService.submit(
+ unmarshalExecMarshal(input, jobClass, jobInstance, context, inputMarshaller, resultMarshaller),
options.priority(),
options.maxRetries()
);
- return new JobExecutionInternal<>(execution, isInterrupted, resultMarshaller, marshalResult);
+ return new JobExecutionInternal<>(execution, isInterrupted, null, false);
}
- private static <T, R> Callable<CompletableFuture<R>> unmarshalExecMarshal(
- T input,
+ private static <T, R> Callable<CompletableFuture<ComputeJobDataHolder>> unmarshalExecMarshal(
+ ComputeJobDataHolder input,
Class<? extends ComputeJob<T, R>> jobClass,
ComputeJob<T, R> jobInstance,
JobExecutionContext context,
- @Nullable Marshaller<T, byte[]> inputMarshaller
+ @Nullable Marshaller<T, byte[]> inputMarshaller,
+ @Nullable Marshaller<R, byte[]> resultMarshaller
) {
- return () -> jobInstance.executeAsync(context, unmarshalOrNotIfNull(inputMarshaller, input, getJobExecuteArgumentType(jobClass)));
+ return () -> {
+ CompletableFuture<R> userJobFut = jobInstance.executeAsync(
+ context, unmarshalOrNotIfNull(inputMarshaller, input, getJobExecuteArgumentType(jobClass)));
+
+ return userJobFut == null
+ ? null
+ : userJobFut.thenApply(r -> SharedComputeUtils.marshalArgOrResult(r, resultMarshaller));
+ };
}
@Override
diff --git a/modules/compute/src/main/java/org/apache/ignite/internal/compute/executor/JobExecutionInternal.java b/modules/compute/src/main/java/org/apache/ignite/internal/compute/executor/JobExecutionInternal.java
index 093e11b062..84953fcd84 100644
--- a/modules/compute/src/main/java/org/apache/ignite/internal/compute/executor/JobExecutionInternal.java
+++ b/modules/compute/src/main/java/org/apache/ignite/internal/compute/executor/JobExecutionInternal.java
@@ -20,6 +20,7 @@ package org.apache.ignite.internal.compute.executor;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.ignite.compute.JobState;
+import org.apache.ignite.internal.compute.ComputeJobDataHolder;
import org.apache.ignite.internal.compute.MarshallerProvider;
import org.apache.ignite.internal.compute.queue.QueueExecution;
import org.apache.ignite.marshalling.Marshaller;
@@ -31,7 +32,7 @@ import org.jetbrains.annotations.Nullable;
* @param <R> Job result type.
*/
public class JobExecutionInternal<R> implements MarshallerProvider<R> {
- private final QueueExecution<R> execution;
+ private final QueueExecution<ComputeJobDataHolder> execution;
private final AtomicBoolean isInterrupted;
@@ -48,7 +49,7 @@ public class JobExecutionInternal<R> implements MarshallerProvider<R> {
* @param marshalResult Flag indicating whether the marshalling of the result will be needed.
*/
JobExecutionInternal(
- QueueExecution<R> execution,
+ QueueExecution<ComputeJobDataHolder> execution,
AtomicBoolean isInterrupted,
@Nullable Marshaller<R, byte[]> marshaller,
boolean marshalResult
@@ -59,7 +60,7 @@ public class JobExecutionInternal<R> implements MarshallerProvider<R> {
this.marshalResult = marshalResult;
}
- public CompletableFuture<R> resultAsync() {
+ public CompletableFuture<ComputeJobDataHolder> resultAsync() {
return execution.resultAsync();
}
diff --git a/modules/compute/src/main/java/org/apache/ignite/internal/compute/message/ExecuteRequest.java b/modules/compute/src/main/java/org/apache/ignite/internal/compute/message/ExecuteRequest.java
index e82dcfcdb7..f367e73a82 100644
--- a/modules/compute/src/main/java/org/apache/ignite/internal/compute/message/ExecuteRequest.java
+++ b/modules/compute/src/main/java/org/apache/ignite/internal/compute/message/ExecuteRequest.java
@@ -20,6 +20,7 @@ package org.apache.ignite.internal.compute.message;
import java.util.List;
import java.util.Set;
import org.apache.ignite.compute.JobDescriptor;
+import org.apache.ignite.internal.compute.ComputeJobDataHolder;
import org.apache.ignite.internal.compute.ComputeMessageTypes;
import org.apache.ignite.internal.compute.ExecutionOptions;
import org.apache.ignite.internal.network.NetworkMessage;
@@ -61,5 +62,5 @@ public interface ExecuteRequest extends NetworkMessage {
*/
@Marshallable
@Nullable
- Object input();
+ ComputeJobDataHolder input();
}
diff --git a/modules/compute/src/main/java/org/apache/ignite/internal/compute/message/JobResultResponse.java b/modules/compute/src/main/java/org/apache/ignite/internal/compute/message/JobResultResponse.java
index afed9e3f38..d9b54ce367 100644
--- a/modules/compute/src/main/java/org/apache/ignite/internal/compute/message/JobResultResponse.java
+++ b/modules/compute/src/main/java/org/apache/ignite/internal/compute/message/JobResultResponse.java
@@ -17,6 +17,7 @@
package org.apache.ignite.internal.compute.message;
+import org.apache.ignite.internal.compute.ComputeJobDataHolder;
import org.apache.ignite.internal.compute.ComputeMessageTypes;
import org.apache.ignite.internal.network.NetworkMessage;
import org.apache.ignite.internal.network.annotations.Marshallable;
@@ -35,7 +36,7 @@ public interface JobResultResponse extends NetworkMessage {
*/
@Nullable
@Marshallable
- Object result();
+ ComputeJobDataHolder result();
/**
* Returns a {@link Throwable} that was thrown during job execution ({@code null} if the execution was successful).
diff --git a/modules/compute/src/main/java/org/apache/ignite/internal/compute/messaging/ComputeMessaging.java b/modules/compute/src/main/java/org/apache/ignite/internal/compute/messaging/ComputeMessaging.java
index f5269021c7..8b87c38600 100644
--- a/modules/compute/src/main/java/org/apache/ignite/internal/compute/messaging/ComputeMessaging.java
+++ b/modules/compute/src/main/java/org/apache/ignite/internal/compute/messaging/ComputeMessaging.java
@@ -43,6 +43,7 @@ import org.apache.ignite.compute.ComputeException;
import org.apache.ignite.compute.JobExecution;
import org.apache.ignite.compute.JobState;
import org.apache.ignite.deployment.DeploymentUnit;
+import org.apache.ignite.internal.compute.ComputeJobDataHolder;
import org.apache.ignite.internal.compute.ComputeMessageTypes;
import org.apache.ignite.internal.compute.ComputeMessagesFactory;
import org.apache.ignite.internal.compute.ComputeUtils;
@@ -174,12 +175,12 @@ public class ComputeMessaging {
* @param input Arguments of the job.
* @return Job id future that will be completed when the job is submitted on the remote node.
*/
- public <T> CompletableFuture<UUID> remoteExecuteRequestAsync(
+ public CompletableFuture<UUID> remoteExecuteRequestAsync(
ExecutionOptions options,
ClusterNode remoteNode,
List<DeploymentUnit> units,
String jobClassName,
- T input
+ ComputeJobDataHolder input
) {
List<DeploymentUnitMsg> deploymentUnitMsgs = units.stream()
.map(ComputeUtils::toDeploymentUnitMsg)
@@ -199,7 +200,7 @@ public class ComputeMessaging {
private void processExecuteRequest(JobStarter starter, ExecuteRequest request, ClusterNode sender, long correlationId) {
List<DeploymentUnit> units = toDeploymentUnit(request.deploymentUnits());
- JobExecution<Object> execution = starter.start(
+ JobExecution<ComputeJobDataHolder> execution = starter.start(
request.executeOptions(), units, request.jobClassName(), request.input()
);
execution.idAsync().whenComplete((jobId, err) -> sendExecuteResponse(jobId, err, sender, correlationId));
@@ -219,10 +220,9 @@ public class ComputeMessaging {
*
* @param remoteNode The job will be executed on this node.
* @param jobId Job id.
- * @param <R> Job result type
* @return Job result.
*/
- public <R> CompletableFuture<R> remoteJobResultRequestAsync(ClusterNode remoteNode, UUID jobId) {
+ public CompletableFuture<ComputeJobDataHolder> remoteJobResultRequestAsync(ClusterNode remoteNode, UUID jobId) {
JobResultRequest jobResultRequest = messagesFactory.jobResultRequest()
.jobId(jobId)
.build();
@@ -233,10 +233,14 @@ public class ComputeMessaging {
private void processJobResultRequest(JobResultRequest request, ClusterNode sender, long correlationId) {
executionManager.resultAsync(request.jobId())
- .whenComplete((result, err) -> sendJobResultResponse(result, err, sender, correlationId));
+ .whenComplete((result, err) -> sendJobResultResponse((ComputeJobDataHolder) result, err, sender, correlationId));
}
- private void sendJobResultResponse(@Nullable Object result, @Nullable Throwable ex, ClusterNode sender, long correlationId) {
+ private void sendJobResultResponse(
+ @Nullable ComputeJobDataHolder result,
+ @Nullable Throwable ex,
+ ClusterNode sender,
+ long correlationId) {
JobResultResponse jobResultResponse = messagesFactory.jobResultResponse()
.result(result)
.throwable(ex)
diff --git a/modules/compute/src/test/java/org/apache/ignite/internal/compute/ComputeComponentImplTest.java b/modules/compute/src/test/java/org/apache/ignite/internal/compute/ComputeComponentImplTest.java
index 707e36336f..08bbe54d85 100644
--- a/modules/compute/src/test/java/org/apache/ignite/internal/compute/ComputeComponentImplTest.java
+++ b/modules/compute/src/test/java/org/apache/ignite/internal/compute/ComputeComponentImplTest.java
@@ -189,9 +189,10 @@ class ComputeComponentImplTest extends BaseIgniteAbstractTest {
@Test
void executesLocally() {
- JobExecution<String> execution = computeComponent.executeLocally(DEFAULT, List.of(), SimpleJob.class.getName(), null, "");
+ JobExecution<ComputeJobDataHolder> execution = computeComponent.executeLocally(
+ DEFAULT, List.of(), SimpleJob.class.getName(), null, SharedComputeUtils.marshalArgOrResult("", null));
- assertThat(execution.resultAsync(), willBe("jobResponse"));
+ assertThat(unwrapResult(execution), willBe("jobResponse"));
assertThat(execution.stateAsync(), willBe(jobStateWithStatus(COMPLETED)));
assertThat(execution.cancelAsync(), willBe(false));
assertThat(execution.changePriorityAsync(1), willBe(false));
@@ -208,8 +209,8 @@ class ComputeComponentImplTest extends BaseIgniteAbstractTest {
CancelHandle cancelHandle = CancelHandle.create();
- JobExecution<String> execution = computeComponent.executeLocally(DEFAULT, List.of(), SimpleJob.class.getName(),
- cancelHandle.token(), "");
+ JobExecution<ComputeJobDataHolder> execution = computeComponent.executeLocally(DEFAULT, List.of(), SimpleJob.class.getName(),
+ cancelHandle.token(), SharedComputeUtils.marshalArgOrResult("", null));
assertFalse(infiniteFuture.isDone());
assertFalse(execution.resultAsync().isDone());
@@ -224,7 +225,8 @@ class ComputeComponentImplTest extends BaseIgniteAbstractTest {
@Test
void getsStateAndCancelsLocally() {
- JobExecution<String> execution = computeComponent.executeLocally(DEFAULT, List.of(), LongJob.class.getName(), null, null);
+ JobExecution<ComputeJobDataHolder> execution = computeComponent.executeLocally(
+ DEFAULT, List.of(), LongJob.class.getName(), null, null);
await().until(execution::stateAsync, willBe(jobStateWithStatus(EXECUTING)));
@@ -237,10 +239,12 @@ class ComputeComponentImplTest extends BaseIgniteAbstractTest {
@Test
void stateCancelAndChangePriorityTriesLocalNodeFirst() {
- JobExecution<String> runningExecution = computeComponent.executeLocally(DEFAULT, List.of(), LongJob.class.getName(), null, null);
+ JobExecution<ComputeJobDataHolder> runningExecution = computeComponent.executeLocally(
+ DEFAULT, List.of(), LongJob.class.getName(), null, null);
await().until(runningExecution::stateAsync, willBe(jobStateWithStatus(EXECUTING)));
- JobExecution<String> queuedExecution = computeComponent.executeLocally(DEFAULT, List.of(), LongJob.class.getName(), null, null);
+ JobExecution<ComputeJobDataHolder> queuedExecution = computeComponent.executeLocally(
+ DEFAULT, List.of(), LongJob.class.getName(), null, null);
await().until(queuedExecution::stateAsync, willBe(jobStateWithStatus(QUEUED)));
UUID jobId = queuedExecution.idAsync().join();
@@ -278,13 +282,13 @@ class ComputeComponentImplTest extends BaseIgniteAbstractTest {
respondWithJobStateResponseWhenJobStateRequestIsSent(jobId, COMPLETED);
respondWithJobCancelResponseWhenJobCancelRequestIsSent(jobId, false);
- JobExecution<String> execution = computeComponent.executeRemotely(
- DEFAULT, remoteNode, List.of(), SimpleJob.class.getName(), null, "a"
+ JobExecution<ComputeJobDataHolder> execution = computeComponent.executeRemotely(
+ DEFAULT, remoteNode, List.of(), SimpleJob.class.getName(), null, SharedComputeUtils.marshalArgOrResult("a", null)
);
- assertThat(execution.resultAsync(), willBe("remoteResponse"));
+ assertThat(unwrapResult(execution), willBe("remoteResponse"));
// Verify that second invocation of resultAsync will not result in the network communication (i.e. the result is cached locally)
- assertThat(execution.resultAsync(), willBe("remoteResponse"));
+ assertThat(unwrapResult(execution), willBe("remoteResponse"));
assertThat(execution.stateAsync(), willBe(jobStateWithStatus(COMPLETED)));
assertThat(execution.cancelAsync(), willBe(false));
@@ -303,11 +307,11 @@ class ComputeComponentImplTest extends BaseIgniteAbstractTest {
respondWithJobStateResponseWhenJobStateRequestIsSent(jobId, EXECUTING);
respondWithJobCancelResponseWhenJobCancelRequestIsSent(jobId, true);
- JobExecution<String> execution = computeComponent.executeRemotely(DEFAULT, remoteNode, List.of(), LongJob.class.getName(), null,
- null);
+ JobExecution<ComputeJobDataHolder> execution = computeComponent.executeRemotely(
+ DEFAULT, remoteNode, List.of(), LongJob.class.getName(), null, null);
assertThat(execution.stateAsync(), willBe(jobStateWithStatus(EXECUTING)));
- assertThat(execution.resultAsync(), willBe("remoteResponse"));
+ assertThat(unwrapResult(execution), willBe("remoteResponse"));
assertThat(execution.cancelAsync(), willBe(true));
assertThatExecuteRequestWasSent(LongJob.class.getName(), null);
@@ -322,8 +326,8 @@ class ComputeComponentImplTest extends BaseIgniteAbstractTest {
respondWithExecuteResponseWhenExecuteRequestIsSent(jobId);
respondWithJobChangePriorityResponseWhenJobChangePriorityRequestIsSent(jobId);
- JobExecution<String> execution = computeComponent.executeRemotely(DEFAULT, remoteNode, List.of(), LongJob.class.getName(), null,
- null);
+ JobExecution<ComputeJobDataHolder> execution = computeComponent.executeRemotely(
+ DEFAULT, remoteNode, List.of(), LongJob.class.getName(), null, null);
assertThat(execution.changePriorityAsync(1), willBe(true));
@@ -340,7 +344,7 @@ class ComputeComponentImplTest extends BaseIgniteAbstractTest {
private void respondWithJobResultResponseWhenJobResultRequestIsSent(UUID jobId) {
JobResultResponse jobResultResponse = new ComputeMessagesFactory().jobResultResponse()
- .result("remoteResponse")
+ .result(SharedComputeUtils.marshalArgOrResult("remoteResponse", null))
.build();
when(messagingService.invoke(anyString(), argThat(msg -> jobResultRequestWithJobId(msg, jobId)), anyLong()))
.thenReturn(completedFuture(jobResultResponse));
@@ -406,7 +410,7 @@ class ComputeComponentImplTest extends BaseIgniteAbstractTest {
ExecuteRequest capturedRequest = invokeAndCaptureRequest(ExecuteRequest.class);
assertThat(capturedRequest.jobClassName(), is(jobClassName));
- assertThat(capturedRequest.input(), is(equalTo(args)));
+ assertThat(SharedComputeUtils.unmarshalArgOrResult(capturedRequest.input(), null, null), is(equalTo(args)));
}
private void assertThatJobResultRequestWasSent(UUID jobId) {
@@ -461,7 +465,7 @@ class ComputeComponentImplTest extends BaseIgniteAbstractTest {
.executeOptions(DEFAULT)
.deploymentUnits(List.of())
.jobClassName(SimpleJob.class.getName())
- .input("")
+ .input(SharedComputeUtils.marshalArgOrResult("", null))
.build();
ExecuteResponse executeResponse = sendRequestAndCaptureResponse(executeRequest, testNode, 123L);
@@ -474,7 +478,7 @@ class ComputeComponentImplTest extends BaseIgniteAbstractTest {
.build();
JobResultResponse jobResultResponse = sendRequestAndCaptureResponse(jobResultRequest, testNode, 456L);
- assertThat(jobResultResponse.result(), is("jobResponse"));
+ assertThat(SharedComputeUtils.unmarshalArgOrResult(jobResultResponse.result(), null, null), is("jobResponse"));
assertThat(jobResultResponse.throwable(), is(nullValue()));
}
@@ -528,7 +532,7 @@ class ComputeComponentImplTest extends BaseIgniteAbstractTest {
.executeOptions(DEFAULT)
.deploymentUnits(List.of())
.jobClassName(SimpleJob.class.getName())
- .input(new Object[]{"a", 42})
+ .input(SharedComputeUtils.marshalArgOrResult(42, null))
.build();
ExecuteResponse response = sendRequestAndCaptureResponse(request, testNode, 123L);
@@ -712,14 +716,20 @@ class ComputeComponentImplTest extends BaseIgniteAbstractTest {
}
private CompletableFuture<String> executeLocally(List<DeploymentUnit> units, String jobClassName, String args) {
- return computeComponent.<String, String>executeLocally(DEFAULT, units, jobClassName, null, args).resultAsync();
+ return computeComponent.<String, String>executeLocally(
+ DEFAULT, units, jobClassName, null, SharedComputeUtils.marshalArgOrResult(args, null))
+ .resultAsync()
+ .thenApply(r -> SharedComputeUtils.unmarshalArgOrResult(r, null, null));
}
private CompletableFuture<String> executeRemotely(
String jobClassName,
String args
) {
- return computeComponent.<String, String>executeRemotely(DEFAULT, remoteNode, List.of(), jobClassName, null, args).resultAsync();
+ return computeComponent.<String, String>executeRemotely(
+ DEFAULT, remoteNode, List.of(), jobClassName, null, SharedComputeUtils.marshalArgOrResult(args, null))
+ .resultAsync()
+ .thenApply(r -> SharedComputeUtils.unmarshalArgOrResult(r, null, null));
}
private CompletableFuture<String> executeRemotely(
@@ -728,6 +738,10 @@ class ComputeComponentImplTest extends BaseIgniteAbstractTest {
return executeRemotely(jobClassName, null);
}
+ private static CompletableFuture<Object> unwrapResult(JobExecution<ComputeJobDataHolder> execution) {
+ return execution.resultAsync().thenApply(r -> SharedComputeUtils.unmarshalArgOrResult(r, null, null));
+ }
+
private static class SimpleJob implements ComputeJob<String, String> {
/** {@inheritDoc} */
@Override
diff --git a/modules/compute/src/test/java/org/apache/ignite/internal/compute/IgniteComputeImplTest.java b/modules/compute/src/test/java/org/apache/ignite/internal/compute/IgniteComputeImplTest.java
index debd9da238..88de0e19ee 100644
--- a/modules/compute/src/test/java/org/apache/ignite/internal/compute/IgniteComputeImplTest.java
+++ b/modules/compute/src/test/java/org/apache/ignite/internal/compute/IgniteComputeImplTest.java
@@ -119,11 +119,11 @@ class IgniteComputeImplTest extends BaseIgniteAbstractTest {
compute.executeAsync(
JobTarget.node(localNode),
JobDescriptor.builder(JOB_CLASS_NAME).units(testDeploymentUnits).build(),
- "a"),
+ null),
willBe("jobResponse")
);
- verify(computeComponent).executeLocally(ExecutionOptions.DEFAULT, testDeploymentUnits, JOB_CLASS_NAME, null, "a");
+ verify(computeComponent).executeLocally(ExecutionOptions.DEFAULT, testDeploymentUnits, JOB_CLASS_NAME, null, null);
}
@Test
@@ -137,7 +137,7 @@ class IgniteComputeImplTest extends BaseIgniteAbstractTest {
JobTarget.node(localNode),
JobDescriptor.builder(JOB_CLASS_NAME).units(testDeploymentUnits).build(),
cancelHandle.token(),
- "a"),
+ null),
willBe("jobResponse")
);
@@ -157,11 +157,11 @@ class IgniteComputeImplTest extends BaseIgniteAbstractTest {
compute.executeAsync(
JobTarget.node(newNode),
JobDescriptor.builder(JOB_CLASS_NAME).units(testDeploymentUnits).build(),
- "a"),
+ null),
willBe("jobResponse")
);
- verify(computeComponent).executeLocally(ExecutionOptions.DEFAULT, testDeploymentUnits, JOB_CLASS_NAME, null, "a");
+ verify(computeComponent).executeLocally(ExecutionOptions.DEFAULT, testDeploymentUnits, JOB_CLASS_NAME, null, null);
}
@Test
@@ -189,11 +189,11 @@ class IgniteComputeImplTest extends BaseIgniteAbstractTest {
compute.executeAsync(
JobTarget.node(localNode),
JobDescriptor.builder(JOB_CLASS_NAME).units(testDeploymentUnits).options(options).build(),
- "a"),
+ null),
willBe("jobResponse")
);
- verify(computeComponent).executeLocally(expectedOptions, testDeploymentUnits, JOB_CLASS_NAME, null, "a");
+ verify(computeComponent).executeLocally(expectedOptions, testDeploymentUnits, JOB_CLASS_NAME, null, null);
}
@Test
@@ -250,7 +250,7 @@ class IgniteComputeImplTest extends BaseIgniteAbstractTest {
CompletableFuture<Map<ClusterNode, String>> future = compute.executeBroadcastAsync(
Set.of(localNode, remoteNode), JobDescriptor.<String, String>builder(JOB_CLASS_NAME).units(testDeploymentUnits).build(),
- "a"
+ null
);
assertThat(future, willBe(aMapWithSize(2)));
@@ -268,24 +268,24 @@ class IgniteComputeImplTest extends BaseIgniteAbstractTest {
}
private void respondWhenExecutingSimpleJobLocally(ExecutionOptions executionOptions) {
- when(computeComponent.executeLocally(executionOptions, testDeploymentUnits, JOB_CLASS_NAME, null, "a"))
- .thenReturn(completedExecution("jobResponse"));
+ when(computeComponent.executeLocally(executionOptions, testDeploymentUnits, JOB_CLASS_NAME, null, null))
+ .thenReturn(completedExecution(SharedComputeUtils.marshalArgOrResult("jobResponse", null)));
}
private void respondWhenExecutingSimpleJobLocally(ExecutionOptions executionOptions, CancellationToken token) {
- when(computeComponent.executeLocally(executionOptions, testDeploymentUnits, JOB_CLASS_NAME, token, "a"))
- .thenReturn(completedExecution("jobResponse"));
+ when(computeComponent.executeLocally(executionOptions, testDeploymentUnits, JOB_CLASS_NAME, token, null))
+ .thenReturn(completedExecution(SharedComputeUtils.marshalArgOrResult("jobResponse", null)));
}
private void respondWhenExecutingSimpleJobRemotely(ExecutionOptions options) {
when(computeComponent.executeRemotelyWithFailover(
- eq(remoteNode), any(), eq(testDeploymentUnits), eq(JOB_CLASS_NAME), eq(options), isNull(), eq("a")
- )).thenReturn(completedExecution("remoteResponse"));
+ eq(remoteNode), any(), eq(testDeploymentUnits), eq(JOB_CLASS_NAME), eq(options), isNull(), any()
+ )).thenReturn(completedExecution(SharedComputeUtils.marshalArgOrResult("remoteResponse", null)));
}
private void verifyExecuteRemotelyWithFailover(ExecutionOptions options) {
verify(computeComponent).executeRemotelyWithFailover(
- eq(remoteNode), any(), eq(testDeploymentUnits), eq(JOB_CLASS_NAME), eq(options), isNull(), eq("a")
+ eq(remoteNode), any(), eq(testDeploymentUnits), eq(JOB_CLASS_NAME), eq(options), isNull(), any()
);
}
diff --git a/modules/compute/src/test/java/org/apache/ignite/internal/compute/executor/ComputeExecutorTest.java b/modules/compute/src/test/java/org/apache/ignite/internal/compute/executor/ComputeExecutorTest.java
index 33c9e46e15..2aac571326 100644
--- a/modules/compute/src/test/java/org/apache/ignite/internal/compute/executor/ComputeExecutorTest.java
+++ b/modules/compute/src/test/java/org/apache/ignite/internal/compute/executor/ComputeExecutorTest.java
@@ -44,6 +44,7 @@ import org.apache.ignite.compute.task.MapReduceJob;
import org.apache.ignite.compute.task.MapReduceTask;
import org.apache.ignite.compute.task.TaskExecutionContext;
import org.apache.ignite.internal.compute.ExecutionOptions;
+import org.apache.ignite.internal.compute.SharedComputeUtils;
import org.apache.ignite.internal.compute.configuration.ComputeConfiguration;
import org.apache.ignite.internal.compute.state.InMemoryComputeStateMachine;
import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension;
@@ -143,62 +144,60 @@ class ComputeExecutorTest extends BaseIgniteAbstractTest {
@Test
void retryJobFail() {
- AtomicInteger runTimes = new AtomicInteger();
-
int maxRetries = 5;
+ RetryJobFail.runTimes.set(0);
JobExecutionInternal<?> execution = computeExecutor.executeJob(
ExecutionOptions.builder().maxRetries(maxRetries).build(),
RetryJobFail.class,
null,
- new Object[]{runTimes}
+ null
);
await().until(execution::state, jobStateWithStatus(FAILED));
- assertThat(runTimes.get(), is(maxRetries + 1));
+ assertThat(RetryJobFail.runTimes.get(), is(maxRetries + 1));
}
- private static class RetryJobFail implements ComputeJob<Object[], Integer> {
+ private static class RetryJobFail implements ComputeJob<Object, Integer> {
+ static final AtomicInteger runTimes = new AtomicInteger();
@Override
- public CompletableFuture<Integer> executeAsync(JobExecutionContext context, Object... args) {
- AtomicInteger runTimes = (AtomicInteger) args[0];
+ public CompletableFuture<Integer> executeAsync(JobExecutionContext context, Object args) {
runTimes.incrementAndGet();
+
throw new RuntimeException();
}
}
@Test
void retryJobSuccess() {
- AtomicInteger runTimes = new AtomicInteger();
-
int maxRetries = 5;
+ RetryJobSuccess.runTimes.set(0);
JobExecutionInternal<?> execution = computeExecutor.executeJob(
ExecutionOptions.builder().maxRetries(maxRetries).build(),
RetryJobSuccess.class,
null,
- new Object[]{
- runTimes,
- maxRetries
- }
+ SharedComputeUtils.marshalArgOrResult(maxRetries, null)
);
await().until(execution::state, jobStateWithStatus(COMPLETED));
- assertThat(runTimes.get(), is(maxRetries + 1));
+ assertThat(RetryJobSuccess.runTimes.get(), is(maxRetries + 1));
}
- private static class RetryJobSuccess implements ComputeJob<Object[], Integer> {
+ private static class RetryJobSuccess implements ComputeJob<Integer, Integer> {
+ static final AtomicInteger runTimes = new AtomicInteger();
@Override
- public CompletableFuture<Integer> executeAsync(JobExecutionContext context, Object... args) {
- AtomicInteger runTimes = (AtomicInteger) args[0];
- int maxRetries = (int) args[1];
+ public CompletableFuture<Integer> executeAsync(JobExecutionContext context, Integer args) {
+ int maxRetries = args;
+
if (runTimes.incrementAndGet() <= maxRetries) {
throw new RuntimeException();
}
+
return completedFuture(0);
}
@@ -206,34 +205,34 @@ class ComputeExecutorTest extends BaseIgniteAbstractTest {
@Test
void runJobOnce() {
- AtomicInteger runTimes = new AtomicInteger();
-
int maxRetries = 5;
+ JobSuccess.runTimes.set(0);
JobExecutionInternal<?> execution = computeExecutor.executeJob(
ExecutionOptions.builder().maxRetries(maxRetries).build(),
JobSuccess.class,
null,
- runTimes
+ null
);
await().until(execution::state, jobStateWithStatus(COMPLETED));
- assertThat(execution.resultAsync(), willBe(1));
- assertThat(runTimes.get(), is(1));
+ assertThat(execution.resultAsync().thenApply(h -> SharedComputeUtils.unmarshalArgOrResult(h, null, null)), willBe(1));
+ assertThat(JobSuccess.runTimes.get(), is(1));
}
- private static class JobSuccess implements ComputeJob<AtomicInteger, Integer> {
+ private static class JobSuccess implements ComputeJob<Object, Integer> {
+ static final AtomicInteger runTimes = new AtomicInteger();
@Override
- public CompletableFuture<Integer> executeAsync(JobExecutionContext context, AtomicInteger runTimes) {
+ public CompletableFuture<Integer> executeAsync(JobExecutionContext context, Object arg) {
return completedFuture(runTimes.incrementAndGet());
}
}
@Test
void findJobArgumentType() {
- assertThat(getJobExecuteArgumentType(JobSuccess.class), is(AtomicInteger.class));
+ assertThat(getJobExecuteArgumentType(RetryJobSuccess.class), is(Integer.class));
}
private static class Task implements MapReduceTask<String, String, String, String> {
diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItThinClientComputeMarshallingTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItThinClientComputeMarshallingTest.java
index c6294801ec..41836de82b 100644
--- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItThinClientComputeMarshallingTest.java
+++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItThinClientComputeMarshallingTest.java
@@ -318,7 +318,9 @@ public class ItThinClientComputeMarshallingTest extends ItAbstractThinClientTest
+ ":marshalledOnClient"
+ ":unmarshalledOnServer" // Job argument unmarshalled on the target node
+ ":processedOnServer" // Job processed on the target node
- // Job result is not marshalled because it's a local execution
+ // TODO IGNITE-24183 Avoid job argument and result marshalling on local execution
+ + ":marshalledOnServer"
+ + ":unmarshalledOnClient"
+ ":listMarshalledOnServer" // Reduce job result marshalled on the client handler node
+ ":listUnmarshalledOnClient", // Reduce job result unmarshalled on the client
"Input_1"
diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItThinClientComputeTypeCheckMarshallingTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItThinClientComputeTypeCheckMarshallingTest.java
index ed7124fe3b..2c504d64bc 100644
--- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItThinClientComputeTypeCheckMarshallingTest.java
+++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItThinClientComputeTypeCheckMarshallingTest.java
@@ -20,6 +20,7 @@ package org.apache.ignite.internal.runner.app.client;
import static java.util.concurrent.CompletableFuture.completedFuture;
import static org.apache.ignite.compute.JobStatus.COMPLETED;
import static org.apache.ignite.compute.JobStatus.FAILED;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.assertThrowsWithCause;
import static org.apache.ignite.internal.testframework.matchers.CompletableFutureExceptionMatcher.willThrow;
import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willBe;
import static org.apache.ignite.internal.testframework.matchers.JobStateMatcher.jobStateWithStatus;
@@ -42,7 +43,6 @@ import org.apache.ignite.internal.runner.app.Jobs.ResultMarshallingJob;
import org.apache.ignite.lang.ErrorGroups.Compute;
import org.apache.ignite.marshalling.ByteArrayMarshaller;
import org.apache.ignite.marshalling.Marshaller;
-import org.apache.ignite.marshalling.UnmarshallingException;
import org.apache.ignite.marshalling.UnsupportedObjectTypeMarshallingException;
import org.jetbrains.annotations.Nullable;
import org.junit.jupiter.api.Test;
@@ -77,7 +77,7 @@ public class ItThinClientComputeTypeCheckMarshallingTest extends ItAbstractThinC
);
await().until(result::stateAsync, willBe(jobStateWithStatus(COMPLETED)));
- assertThat(result.resultAsync(), willThrow(UnmarshallingException.class));
+ assertThat(result.resultAsync(), willThrow(ComputeException.class));
}
@Test
@@ -111,11 +111,9 @@ public class ItThinClientComputeTypeCheckMarshallingTest extends ItAbstractThinC
);
await().until(result::stateAsync, willBe(jobStateWithStatus(COMPLETED)));
+
// The job has completed successfully, but result was not unmarshaled
- assertThat(result.resultAsync(), willBe(instanceOf(byte[].class)));
- assertThrows(ClassCastException.class, () -> {
- Integer i = result.resultAsync().join();
- });
+ assertThrowsWithCause(() -> result.resultAsync().join(), ClassCastException.class);
}
static class ArgumentTypeCheckingmarshallingJob implements ComputeJob<String, String> {
diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItThinClientPojoComputeMarshallingTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItThinClientPojoComputeMarshallingTest.java
index 344f9770d2..3b389e0025 100644
--- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItThinClientPojoComputeMarshallingTest.java
+++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItThinClientPojoComputeMarshallingTest.java
@@ -24,6 +24,7 @@ import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.compute.ComputeException;
import org.apache.ignite.compute.JobDescriptor;
import org.apache.ignite.compute.JobDescriptor.Builder;
import org.apache.ignite.compute.JobTarget;
@@ -35,7 +36,6 @@ import org.apache.ignite.internal.runner.app.Jobs.PojoArgNativeResult;
import org.apache.ignite.internal.runner.app.Jobs.PojoJob;
import org.apache.ignite.internal.runner.app.Jobs.PojoResult;
import org.apache.ignite.internal.runner.app.Jobs.TwoStringPojo;
-import org.apache.ignite.marshalling.UnmarshallingException;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -137,13 +137,13 @@ public class ItThinClientPojoComputeMarshallingTest extends ClusterPerClassInteg
// When run job with custom marshaller for pojo argument and result.
assertThrows(
- UnmarshallingException.class,
+ ComputeException.class,
() -> client.compute().execute(
JobTarget.node(targetNode),
JobDescriptor.builder(PojoJob.class).build(),
new PojoArg().setIntValue(2).setStrValue("1")
),
- "Can not unpack object because the pojo class is not provided but the object was packed as pojo."
+ "JobDescriptor.resultClass is not defined, but the job result is packed as a POJO"
);
}
diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/compute/ItEmbeddedMarshallingTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/compute/ItEmbeddedMarshallingTest.java
index 9d1ece5c46..090c426a5a 100644
--- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/compute/ItEmbeddedMarshallingTest.java
+++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/compute/ItEmbeddedMarshallingTest.java
@@ -103,7 +103,7 @@ public class ItEmbeddedMarshallingTest extends ItAbstractThinClientTest {
var embeddedCompute = node.compute();
PojoResult result = embeddedCompute.execute(
JobTarget.node(targetNode),
- JobDescriptor.builder(PojoJob.class).build(),
+ JobDescriptor.builder(PojoJob.class).resultClass(PojoResult.class).build(),
new PojoArg().setIntValue(2).setStrValue("1")
);
@@ -122,7 +122,7 @@ public class ItEmbeddedMarshallingTest extends ItAbstractThinClientTest {
var embeddedCompute = node.compute();
PojoResult result = embeddedCompute.execute(
JobTarget.node(targetNode),
- JobDescriptor.builder(PojoJob.class).build(),
+ JobDescriptor.builder(PojoJob.class).resultClass(PojoResult.class).build(),
new PojoArg().setIntValue(2).setStrValue("1")
);
@@ -145,7 +145,8 @@ public class ItEmbeddedMarshallingTest extends ItAbstractThinClientTest {
"Input"
);
- assertEquals("Input:marshalledOnClient:unmarshalledOnServer:processedOnServer", result);
+ // TODO IGNITE-24183 Avoid job argument and result marshalling on local execution
+ assertEquals("Input:marshalledOnClient:unmarshalledOnServer:processedOnServer:marshalledOnServer:unmarshalledOnClient", result);
}
@Test
@@ -164,9 +165,10 @@ public class ItEmbeddedMarshallingTest extends ItAbstractThinClientTest {
);
// Then.
+ // TODO IGNITE-24183 Avoid job argument and result marshalling on local execution
Map<ClusterNode, String> resultExpected = Map.of(
// todo: "https://issues.apache.org/jira/browse/IGNITE-23024"
- node(0), "Input:marshalledOnClient:unmarshalledOnServer:processedOnServer",
+ node(0), "Input:marshalledOnClient:unmarshalledOnServer:processedOnServer:marshalledOnServer:unmarshalledOnClient",
node(1), "Input:marshalledOnClient:unmarshalledOnServer:processedOnServer:marshalledOnServer:unmarshalledOnClient"
);
@@ -191,9 +193,10 @@ public class ItEmbeddedMarshallingTest extends ItAbstractThinClientTest {
);
// Then.
+ // TODO IGNITE-24183 Avoid job argument and result marshalling on local execution
Map<ClusterNode, String> resultExpected = Map.of(
// todo: "https://issues.apache.org/jira/browse/IGNITE-23024"
- node(0), "Input:marshalledOnClient:unmarshalledOnServer:processedOnServer",
+ node(0), "Input:marshalledOnClient:unmarshalledOnServer:processedOnServer:marshalledOnServer:unmarshalledOnClient",
node(1), "Input:marshalledOnClient:unmarshalledOnServer:processedOnServer:marshalledOnServer:unmarshalledOnClient"
);