You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "ptupitsyn (via GitHub)" <gi...@apache.org> on 2024/06/14 05:50:04 UTC

[PR] IGNITE-20645 Make ComputeJob.execute asynchronous [ignite-3]

ptupitsyn opened a new pull request, #3920:
URL: https://github.com/apache/ignite-3/pull/3920

   (no comment)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20645 Make ComputeJob.execute asynchronous [ignite-3]

Posted by "ptupitsyn (via GitHub)" <gi...@apache.org>.
ptupitsyn commented on code in PR #3920:
URL: https://github.com/apache/ignite-3/pull/3920#discussion_r1642826742


##########
modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItThinClientComputeTest.java:
##########
@@ -737,39 +745,47 @@ private List<ClusterNode> sortedNodes() {
 
     private static class NodeNameJob implements ComputeJob<String> {
         @Override
-        public String execute(JobExecutionContext context, Object... args) {
-            return context.ignite().name() + Arrays.stream(args).map(Object::toString).collect(Collectors.joining("_"));
+        public CompletableFuture<String> executeAsync(JobExecutionContext context, Object... args) {
+            return completedFuture(
+                    context.ignite().name() + Arrays.stream(args).map(Object::toString).collect(Collectors.joining("_")));
         }
     }
 
     private static class ConcatJob implements ComputeJob<String> {
         @Override
-        public String execute(JobExecutionContext context, Object... args) {
+        public CompletableFuture<String> executeAsync(JobExecutionContext context, Object... args) {
             if (args == null) {
-                return null;
+                return nullCompletedFuture();
             }
 
-            return Arrays.stream(args).map(o -> o == null ? "null" : o.toString()).collect(Collectors.joining("_"));
+            return completedFuture(
+                    Arrays.stream(args).map(o -> o == null ? "null" : o.toString()).collect(Collectors.joining("_")));
         }
     }
 
     private static class IgniteExceptionJob implements ComputeJob<String> {
         @Override
-        public String execute(JobExecutionContext context, Object... args) {
+        public CompletableFuture<String> executeAsync(JobExecutionContext context, Object... args) {
             throw new CustomException(TRACE_ID, COLUMN_ALREADY_EXISTS_ERR, "Custom job error", null);
         }
     }
 
     private static class ExceptionJob implements ComputeJob<String> {
         @Override
-        public String execute(JobExecutionContext context, Object... args) {
-            throw new ArithmeticException("math err");
+        public CompletableFuture<String> executeAsync(JobExecutionContext context, Object... args) {
+            boolean asyncJob = args.length > 0 && (Boolean) args[0];
+
+            if (asyncJob) {
+                return CompletableFuture.failedFuture(new ArithmeticException("math err"));

Review Comment:
   Fixed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20645 Make ComputeJob.execute asynchronous [ignite-3]

Posted by "ptupitsyn (via GitHub)" <gi...@apache.org>.
ptupitsyn commented on code in PR #3920:
URL: https://github.com/apache/ignite-3/pull/3920#discussion_r1642823033


##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/requests/table/ClientStreamerWithReceiverBatchSendRequest.java:
##########
@@ -102,7 +102,7 @@ public static CompletableFuture<Void> process(
 
     private static class ReceiverRunnerJob implements ComputeJob<List<Object>> {
         @Override
-        public @Nullable List<Object> execute(JobExecutionContext context, Object... args) {
+        public CompletableFuture<List<Object>> executeAsync(JobExecutionContext context, Object... args) {

Review Comment:
   Fixed



##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/requests/table/ClientStreamerWithReceiverBatchSendRequest.java:
##########
@@ -115,7 +115,7 @@ private static class ReceiverRunnerJob implements ComputeJob<List<Object>> {
 
             CompletableFuture<List<Object>> receiveFut = receiver.receive(receiverInfo.items(), receiverContext, receiverInfo.args());
 
-            return receiveFut == null ? null : receiveFut.join();
+            return receiveFut == null ? nullCompletedFuture() : receiveFut;

Review Comment:
   Fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20645 Make ComputeJob.execute asynchronous [ignite-3]

Posted by "ptupitsyn (via GitHub)" <gi...@apache.org>.
ptupitsyn commented on code in PR #3920:
URL: https://github.com/apache/ignite-3/pull/3920#discussion_r1639558436


##########
modules/compute/src/main/java/org/apache/ignite/internal/compute/state/InMemoryComputeStateMachine.java:
##########
@@ -139,6 +139,8 @@ private void changeJobState(UUID jobId, Function<JobState, JobState> newStateFun
             JobState currentState = currentStatus.state();
             JobState newState = newStateFunction.apply(currentState);
 
+            System.out.println("changeJobState currentState: " + currentState + ", newState: " + newState);

Review Comment:
   Good catch, removed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20645 Make ComputeJob.execute asynchronous [ignite-3]

Posted by "isapego (via GitHub)" <gi...@apache.org>.
isapego commented on code in PR #3920:
URL: https://github.com/apache/ignite-3/pull/3920#discussion_r1639489418


##########
modules/api/src/main/java/org/apache/ignite/compute/ComputeJob.java:
##########
@@ -17,18 +17,22 @@
 
 package org.apache.ignite.compute;
 
+import java.util.concurrent.CompletableFuture;
+import org.jetbrains.annotations.Nullable;
+
 /**
  * A Compute job that may be executed on a single Ignite node, on several nodes, or on the entire cluster.
  *
  * @param <R> Job result type.
  */
+@SuppressWarnings("InterfaceMayBeAnnotatedFunctional")
 public interface ComputeJob<R> {
     /**
      * Executes the job on an Ignite node.
      *
      * @param context The execution context.
      * @param args Job arguments.
-     * @return Job result.
+     * @return Job future. Can be null if the job is synchronous and does not return any result.

Review Comment:
   Performance reasons?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20645 Make ComputeJob.execute asynchronous [ignite-3]

Posted by "Pochatkin (via GitHub)" <gi...@apache.org>.
Pochatkin commented on code in PR #3920:
URL: https://github.com/apache/ignite-3/pull/3920#discussion_r1639492881


##########
modules/compute/src/main/java/org/apache/ignite/internal/compute/state/InMemoryComputeStateMachine.java:
##########
@@ -139,6 +139,8 @@ private void changeJobState(UUID jobId, Function<JobState, JobState> newStateFun
             JobState currentState = currentStatus.state();
             JobState newState = newStateFunction.apply(currentState);
 
+            System.out.println("changeJobState currentState: " + currentState + ", newState: " + newState);

Review Comment:
   Debug log?



##########
modules/compute/src/test/java/org/apache/ignite/internal/compute/loader/JobClassLoaderFactoryTest.java:
##########
@@ -90,8 +91,8 @@ public void unit1BothVersions() throws Exception {
 
             // and classes are loaded in the aplhabetical order
             ComputeJob<Integer> job1 = (ComputeJob<Integer>) unitJobClass.getDeclaredConstructor().newInstance();
-            Integer result1 = job1.execute(null);
-            assertEquals(1, result1);
+            CompletableFuture<Integer> result1 = job1.executeAsync(null);
+            assertEquals(1, result1.join());

Review Comment:
   assertThat(result1, willBe(1));



##########
modules/compute/src/test/java/org/apache/ignite/internal/compute/loader/JobClassLoaderFactoryTest.java:
##########
@@ -64,14 +65,14 @@ public void unit1() throws Exception {
             // then classes from the first unit are loaded from the first class loader
             Class<?> clazz1 = classLoader1.loadClass(UNIT_JOB_CLASS_NAME);
             ComputeJob<Integer> job1 = (ComputeJob<Integer>) clazz1.getDeclaredConstructor().newInstance();
-            Integer result1 = job1.execute(null);
-            assertEquals(1, result1);
+            CompletableFuture<Integer> result1 = job1.executeAsync(null);
+            assertEquals(1, result1.join());
 
             // and classes from the second unit are loaded from the second class loader
             Class<?> clazz2 = classLoader2.loadClass(UNIT_JOB_CLASS_NAME);
             ComputeJob<String> job2 = (ComputeJob<String>) clazz2.getDeclaredConstructor().newInstance();
-            String result2 = job2.execute(null);
-            assertEquals("Hello World!", result2);
+            CompletableFuture<String> result2 = job2.executeAsync(null);
+            assertEquals("Hello World!", result2.join());

Review Comment:
   assertThat(result2, willBe("Hello World!"));



##########
modules/api/src/main/java/org/apache/ignite/compute/ComputeJob.java:
##########
@@ -17,18 +17,22 @@
 
 package org.apache.ignite.compute;
 
+import java.util.concurrent.CompletableFuture;
+import org.jetbrains.annotations.Nullable;
+
 /**
  * A Compute job that may be executed on a single Ignite node, on several nodes, or on the entire cluster.
  *
  * @param <R> Job result type.
  */
+@SuppressWarnings("InterfaceMayBeAnnotatedFunctional")
 public interface ComputeJob<R> {
     /**
      * Executes the job on an Ignite node.
      *
      * @param context The execution context.
      * @param args Job arguments.
-     * @return Job result.
+     * @return Job future. Can be null if the job is synchronous and does not return any result.

Review Comment:
   Do we really want to have Nullable futute? Mby in this case user should have CF<Void> ?



##########
modules/compute/src/test/java/org/apache/ignite/internal/compute/loader/JobClassLoaderFactoryTest.java:
##########
@@ -64,14 +65,14 @@ public void unit1() throws Exception {
             // then classes from the first unit are loaded from the first class loader
             Class<?> clazz1 = classLoader1.loadClass(UNIT_JOB_CLASS_NAME);
             ComputeJob<Integer> job1 = (ComputeJob<Integer>) clazz1.getDeclaredConstructor().newInstance();
-            Integer result1 = job1.execute(null);
-            assertEquals(1, result1);
+            CompletableFuture<Integer> result1 = job1.executeAsync(null);
+            assertEquals(1, result1.join());

Review Comment:
   assertThat(result1, willBe(1));



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20645 Make ComputeJob.execute asynchronous [ignite-3]

Posted by "ptupitsyn (via GitHub)" <gi...@apache.org>.
ptupitsyn commented on code in PR #3920:
URL: https://github.com/apache/ignite-3/pull/3920#discussion_r1639514238


##########
modules/api/src/main/java/org/apache/ignite/compute/ComputeJob.java:
##########
@@ -17,18 +17,22 @@
 
 package org.apache.ignite.compute;
 
+import java.util.concurrent.CompletableFuture;
+import org.jetbrains.annotations.Nullable;
+
 /**
  * A Compute job that may be executed on a single Ignite node, on several nodes, or on the entire cluster.
  *
  * @param <R> Job result type.
  */
+@SuppressWarnings("InterfaceMayBeAnnotatedFunctional")
 public interface ComputeJob<R> {
     /**
      * Executes the job on an Ignite node.
      *
      * @param context The execution context.
      * @param args Job arguments.
-     * @return Job result.
+     * @return Job future. Can be null if the job is synchronous and does not return any result.

Review Comment:
   Same question from @isapego above. I don't have a strong opinion, we can require a non-null future.
   
   > user should have CF
   
   CF?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20645 Make ComputeJob.execute asynchronous [ignite-3]

Posted by "ptupitsyn (via GitHub)" <gi...@apache.org>.
ptupitsyn commented on code in PR #3920:
URL: https://github.com/apache/ignite-3/pull/3920#discussion_r1639561953


##########
modules/compute/src/test/java/org/apache/ignite/internal/compute/loader/JobClassLoaderFactoryTest.java:
##########
@@ -90,8 +91,8 @@ public void unit1BothVersions() throws Exception {
 
             // and classes are loaded in the aplhabetical order
             ComputeJob<Integer> job1 = (ComputeJob<Integer>) unitJobClass.getDeclaredConstructor().newInstance();
-            Integer result1 = job1.execute(null);
-            assertEquals(1, result1);
+            CompletableFuture<Integer> result1 = job1.executeAsync(null);
+            assertEquals(1, result1.join());

Review Comment:
   Fixed.



##########
modules/compute/src/test/java/org/apache/ignite/internal/compute/loader/JobClassLoaderFactoryTest.java:
##########
@@ -64,14 +65,14 @@ public void unit1() throws Exception {
             // then classes from the first unit are loaded from the first class loader
             Class<?> clazz1 = classLoader1.loadClass(UNIT_JOB_CLASS_NAME);
             ComputeJob<Integer> job1 = (ComputeJob<Integer>) clazz1.getDeclaredConstructor().newInstance();
-            Integer result1 = job1.execute(null);
-            assertEquals(1, result1);
+            CompletableFuture<Integer> result1 = job1.executeAsync(null);
+            assertEquals(1, result1.join());
 
             // and classes from the second unit are loaded from the second class loader
             Class<?> clazz2 = classLoader2.loadClass(UNIT_JOB_CLASS_NAME);
             ComputeJob<String> job2 = (ComputeJob<String>) clazz2.getDeclaredConstructor().newInstance();
-            String result2 = job2.execute(null);
-            assertEquals("Hello World!", result2);
+            CompletableFuture<String> result2 = job2.executeAsync(null);
+            assertEquals("Hello World!", result2.join());

Review Comment:
   Fixed.



##########
modules/compute/src/test/java/org/apache/ignite/internal/compute/loader/JobClassLoaderFactoryTest.java:
##########
@@ -64,14 +65,14 @@ public void unit1() throws Exception {
             // then classes from the first unit are loaded from the first class loader
             Class<?> clazz1 = classLoader1.loadClass(UNIT_JOB_CLASS_NAME);
             ComputeJob<Integer> job1 = (ComputeJob<Integer>) clazz1.getDeclaredConstructor().newInstance();
-            Integer result1 = job1.execute(null);
-            assertEquals(1, result1);
+            CompletableFuture<Integer> result1 = job1.executeAsync(null);
+            assertEquals(1, result1.join());

Review Comment:
   Fixed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20645 Make ComputeJob.execute asynchronous [ignite-3]

Posted by "ptupitsyn (via GitHub)" <gi...@apache.org>.
ptupitsyn commented on code in PR #3920:
URL: https://github.com/apache/ignite-3/pull/3920#discussion_r1639517128


##########
modules/compute/src/test/java/org/apache/ignite/internal/compute/loader/JobClassLoaderFactoryTest.java:
##########
@@ -64,14 +65,14 @@ public void unit1() throws Exception {
             // then classes from the first unit are loaded from the first class loader
             Class<?> clazz1 = classLoader1.loadClass(UNIT_JOB_CLASS_NAME);
             ComputeJob<Integer> job1 = (ComputeJob<Integer>) clazz1.getDeclaredConstructor().newInstance();
-            Integer result1 = job1.execute(null);
-            assertEquals(1, result1);
+            CompletableFuture<Integer> result1 = job1.executeAsync(null);
+            assertEquals(1, result1.join());

Review Comment:
   Is it better and why? I'm trying to keep the changes to a minimum here, with `join()` you can see easier that the test is the same.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20645 Make ComputeJob.execute asynchronous [ignite-3]

Posted by "ptupitsyn (via GitHub)" <gi...@apache.org>.
ptupitsyn commented on code in PR #3920:
URL: https://github.com/apache/ignite-3/pull/3920#discussion_r1639513244


##########
modules/api/src/main/java/org/apache/ignite/compute/ComputeJob.java:
##########
@@ -17,18 +17,22 @@
 
 package org.apache.ignite.compute;
 
+import java.util.concurrent.CompletableFuture;
+import org.jetbrains.annotations.Nullable;
+
 /**
  * A Compute job that may be executed on a single Ignite node, on several nodes, or on the entire cluster.
  *
  * @param <R> Job result type.
  */
+@SuppressWarnings("InterfaceMayBeAnnotatedFunctional")
 public interface ComputeJob<R> {
     /**
      * Executes the job on an Ignite node.
      *
      * @param context The execution context.
      * @param args Job arguments.
-     * @return Job result.
+     * @return Job future. Can be null if the job is synchronous and does not return any result.

Review Comment:
   * Very small performance improvement
   * A bit easier for the user at the expense of a one-line check in Ignite code
   
   Do you think we should disallow nulls?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20645 Make ComputeJob.execute asynchronous [ignite-3]

Posted by "ptupitsyn (via GitHub)" <gi...@apache.org>.
ptupitsyn merged PR #3920:
URL: https://github.com/apache/ignite-3/pull/3920


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20645 Make ComputeJob.execute asynchronous [ignite-3]

Posted by "ptupitsyn (via GitHub)" <gi...@apache.org>.
ptupitsyn commented on code in PR #3920:
URL: https://github.com/apache/ignite-3/pull/3920#discussion_r1642208959


##########
modules/compute/src/main/java/org/apache/ignite/internal/compute/task/TaskExecutionInternal.java:
##########
@@ -93,7 +93,8 @@ public TaskExecutionInternal(
         splitExecution = executorService.submit(
                 () -> {
                     MapReduceTask<R> task = instantiateTask(taskClass);
-                    return new SplitResult<>(task, task.split(context, args));
+
+                    return completedFuture(new SplitResult<>(task, task.split(context, args)));

Review Comment:
   Yes: https://issues.apache.org/jira/browse/IGNITE-22512



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20645 Make ComputeJob.execute asynchronous [ignite-3]

Posted by "ptupitsyn (via GitHub)" <gi...@apache.org>.
ptupitsyn commented on code in PR #3920:
URL: https://github.com/apache/ignite-3/pull/3920#discussion_r1642825994


##########
modules/client/src/test/java/org/apache/ignite/client/fakes/FakeCompute.java:
##########
@@ -104,11 +104,12 @@ public <R> JobExecution<R> executeAsyncWithFailover(
         }
 
         if (jobClassName.startsWith("org.apache.ignite")) {
-            Class<ComputeJob<Object>> jobClass = ComputeUtils.jobClass(this.getClass().getClassLoader(), jobClassName);
-            ComputeJob<Object> job = ComputeUtils.instantiateJob(jobClass);
-            Object jobRes = job.execute(new JobExecutionContextImpl(ignite, new AtomicBoolean(), this.getClass().getClassLoader()), args);
+            Class<ComputeJob<R>> jobClass = ComputeUtils.jobClass(this.getClass().getClassLoader(), jobClassName);
+            ComputeJob<R> job = ComputeUtils.instantiateJob(jobClass);
+            CompletableFuture<R> jobFut = job.executeAsync(
+                    new JobExecutionContextImpl(ignite, new AtomicBoolean(), this.getClass().getClassLoader()), args);
 
-            return jobExecution(completedFuture((R) jobRes));
+            return jobExecution(jobFut);

Review Comment:
   Fixed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20645 Make ComputeJob.execute asynchronous [ignite-3]

Posted by "Pochatkin (via GitHub)" <gi...@apache.org>.
Pochatkin commented on code in PR #3920:
URL: https://github.com/apache/ignite-3/pull/3920#discussion_r1639934264


##########
modules/api/src/main/java/org/apache/ignite/compute/ComputeJob.java:
##########
@@ -17,18 +17,22 @@
 
 package org.apache.ignite.compute;
 
+import java.util.concurrent.CompletableFuture;
+import org.jetbrains.annotations.Nullable;
+
 /**
  * A Compute job that may be executed on a single Ignite node, on several nodes, or on the entire cluster.
  *
  * @param <R> Job result type.
  */
+@SuppressWarnings("InterfaceMayBeAnnotatedFunctional")
 public interface ComputeJob<R> {
     /**
      * Executes the job on an Ignite node.
      *
      * @param context The execution context.
      * @param args Job arguments.
-     * @return Job result.
+     * @return Job future. Can be null if the job is synchronous and does not return any result.

Review Comment:
   CF=CompletableFuture



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20645 Make ComputeJob.execute asynchronous [ignite-3]

Posted by "valepakh (via GitHub)" <gi...@apache.org>.
valepakh commented on code in PR #3920:
URL: https://github.com/apache/ignite-3/pull/3920#discussion_r1639935905


##########
modules/compute/src/main/java/org/apache/ignite/internal/compute/task/TaskExecutionInternal.java:
##########
@@ -93,7 +93,8 @@ public TaskExecutionInternal(
         splitExecution = executorService.submit(
                 () -> {
                     MapReduceTask<R> task = instantiateTask(taskClass);
-                    return new SplitResult<>(task, task.split(context, args));
+
+                    return completedFuture(new SplitResult<>(task, task.split(context, args)));

Review Comment:
   Should we also make `MapReduceTask.split` and `reduce` asynchronous?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20645 Make ComputeJob.execute asynchronous [ignite-3]

Posted by "ptupitsyn (via GitHub)" <gi...@apache.org>.
ptupitsyn commented on code in PR #3920:
URL: https://github.com/apache/ignite-3/pull/3920#discussion_r1642210656


##########
modules/api/src/main/java/org/apache/ignite/compute/ComputeJob.java:
##########
@@ -17,18 +17,22 @@
 
 package org.apache.ignite.compute;
 
+import java.util.concurrent.CompletableFuture;
+import org.jetbrains.annotations.Nullable;
+
 /**
  * A Compute job that may be executed on a single Ignite node, on several nodes, or on the entire cluster.
  *
  * @param <R> Job result type.
  */
+@SuppressWarnings("InterfaceMayBeAnnotatedFunctional")
 public interface ComputeJob<R> {
     /**
      * Executes the job on an Ignite node.
      *
      * @param context The execution context.
      * @param args Job arguments.
-     * @return Job result.
+     * @return Job future. Can be null if the job is synchronous and does not return any result.

Review Comment:
   The user can return `completedFuture()` or `null`, it does not make any difference. Let's keep it this way.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-20645 Make ComputeJob.execute asynchronous [ignite-3]

Posted by "valepakh (via GitHub)" <gi...@apache.org>.
valepakh commented on code in PR #3920:
URL: https://github.com/apache/ignite-3/pull/3920#discussion_r1642532578


##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/requests/table/ClientStreamerWithReceiverBatchSendRequest.java:
##########
@@ -102,7 +102,7 @@ public static CompletableFuture<Void> process(
 
     private static class ReceiverRunnerJob implements ComputeJob<List<Object>> {
         @Override
-        public @Nullable List<Object> execute(JobExecutionContext context, Object... args) {
+        public CompletableFuture<List<Object>> executeAsync(JobExecutionContext context, Object... args) {

Review Comment:
   Let's keep the nullable annotation here and return nullable value below



##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/requests/table/ClientStreamerWithReceiverBatchSendRequest.java:
##########
@@ -115,7 +115,7 @@ private static class ReceiverRunnerJob implements ComputeJob<List<Object>> {
 
             CompletableFuture<List<Object>> receiveFut = receiver.receive(receiverInfo.items(), receiverContext, receiverInfo.args());
 
-            return receiveFut == null ? null : receiveFut.join();
+            return receiveFut == null ? nullCompletedFuture() : receiveFut;

Review Comment:
   This could be simplified to `return receiver.receive(receiverInfo.items(), receiverContext, receiverInfo.args());`



##########
modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItThinClientComputeTest.java:
##########
@@ -737,39 +745,47 @@ private List<ClusterNode> sortedNodes() {
 
     private static class NodeNameJob implements ComputeJob<String> {
         @Override
-        public String execute(JobExecutionContext context, Object... args) {
-            return context.ignite().name() + Arrays.stream(args).map(Object::toString).collect(Collectors.joining("_"));
+        public CompletableFuture<String> executeAsync(JobExecutionContext context, Object... args) {
+            return completedFuture(
+                    context.ignite().name() + Arrays.stream(args).map(Object::toString).collect(Collectors.joining("_")));
         }
     }
 
     private static class ConcatJob implements ComputeJob<String> {
         @Override
-        public String execute(JobExecutionContext context, Object... args) {
+        public CompletableFuture<String> executeAsync(JobExecutionContext context, Object... args) {
             if (args == null) {
-                return null;
+                return nullCompletedFuture();
             }
 
-            return Arrays.stream(args).map(o -> o == null ? "null" : o.toString()).collect(Collectors.joining("_"));
+            return completedFuture(
+                    Arrays.stream(args).map(o -> o == null ? "null" : o.toString()).collect(Collectors.joining("_")));
         }
     }
 
     private static class IgniteExceptionJob implements ComputeJob<String> {
         @Override
-        public String execute(JobExecutionContext context, Object... args) {
+        public CompletableFuture<String> executeAsync(JobExecutionContext context, Object... args) {
             throw new CustomException(TRACE_ID, COLUMN_ALREADY_EXISTS_ERR, "Custom job error", null);
         }
     }
 
     private static class ExceptionJob implements ComputeJob<String> {
         @Override
-        public String execute(JobExecutionContext context, Object... args) {
-            throw new ArithmeticException("math err");
+        public CompletableFuture<String> executeAsync(JobExecutionContext context, Object... args) {
+            boolean asyncJob = args.length > 0 && (Boolean) args[0];
+
+            if (asyncJob) {
+                return CompletableFuture.failedFuture(new ArithmeticException("math err"));

Review Comment:
   Static import for `failedFuture`?



##########
modules/client/src/test/java/org/apache/ignite/client/fakes/FakeCompute.java:
##########
@@ -104,11 +104,12 @@ public <R> JobExecution<R> executeAsyncWithFailover(
         }
 
         if (jobClassName.startsWith("org.apache.ignite")) {
-            Class<ComputeJob<Object>> jobClass = ComputeUtils.jobClass(this.getClass().getClassLoader(), jobClassName);
-            ComputeJob<Object> job = ComputeUtils.instantiateJob(jobClass);
-            Object jobRes = job.execute(new JobExecutionContextImpl(ignite, new AtomicBoolean(), this.getClass().getClassLoader()), args);
+            Class<ComputeJob<R>> jobClass = ComputeUtils.jobClass(this.getClass().getClassLoader(), jobClassName);
+            ComputeJob<R> job = ComputeUtils.instantiateJob(jobClass);
+            CompletableFuture<R> jobFut = job.executeAsync(
+                    new JobExecutionContextImpl(ignite, new AtomicBoolean(), this.getClass().getClassLoader()), args);
 
-            return jobExecution(completedFuture((R) jobRes));
+            return jobExecution(jobFut);

Review Comment:
   If you keep the `executeAsync` nullable, you should check the result here



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org