Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IGNITE-23601 Create broadcast partitioned compute method #4871

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,102 @@ default <T, R> Map<ClusterNode, R> executeBroadcast(
return map;
}

/**
* Submits a {@link ComputeJob} of the given class for an execution on nodes where the primary replicas of a partitions of the specified
ptupitsyn marked this conversation as resolved.
Show resolved Hide resolved
* table are located. The partition objects are passed to the job in the {@link JobExecutionContext#partitions()}. At most one job is
* executed on a node.
*
* @param tableName Table name.
* @param descriptor Job descriptor.
* @param arg Job argument.
* @param <T> Job argument (T)ype.
* @param <R> Job (R)esult type.
* @return Future that will be completed with the map from the node to the job execution objects when jobs are submitted for the
* execution.
*/
<T, R> CompletableFuture<Map<ClusterNode, JobExecution<R>>> submitBroadcastPartitioned(
String tableName,
JobDescriptor<T, R> descriptor,
@Nullable T arg
);

/**
* Executes a {@link ComputeJob} of the given class on nodes where the primary replicas of a partitions of the specified table are
* located. The partition objects are passed to the job in the {@link JobExecutionContext#partitions()}. At most one job is executed on
* a node.
*
* @param tableName Table name.
* @param descriptor Job descriptor.
* @param arg Job argument.
* @param <T> Job argument (T)ype.
* @param <R> Job (R)esult type.
* @return Future that will be completed with the map from the node to the job execution results.
*/
default <T, R> CompletableFuture<Map<ClusterNode, R>> executeBroadcastPartitionedAsync(
String tableName,
JobDescriptor<T, R> descriptor,
@Nullable T arg
) {
return executeBroadcastPartitionedAsync(tableName, descriptor, null, arg);
}

/**
* Executes a {@link ComputeJob} of the given class on nodes where the primary replicas of a partitions of the specified table are
* located. The partition objects are passed to the job in the {@link JobExecutionContext#partitions()}. At most one job is executed on
* a node.
*
* @param tableName Table name.
* @param descriptor Job descriptor.
* @param arg Job argument.
* @param <T> Job argument (T)ype.
* @param <R> Job (R)esult type.
* @return Future that will be completed with the map from the node to the job execution results.
*/
<T, R> CompletableFuture<Map<ClusterNode, R>> executeBroadcastPartitionedAsync(
String tableName,
JobDescriptor<T, R> descriptor,
@Nullable CancellationToken cancellationToken,
@Nullable T arg
);

/**
* Executes a {@link ComputeJob} of the given class on nodes where the primary replicas of a partitions of the specified table are
* located. The partition objects are passed to the job in the {@link JobExecutionContext#partitions()}. At most one job is executed on
* a node.
*
* @param tableName Table name.
* @param descriptor Job descriptor.
* @param arg Job argument.
* @param <T> Job argument (T)ype.
* @param <R> Job (R)esult type.
* @return Map from the node to the job execution results.
*/
default <T, R> Map<ClusterNode, R> executeBroadcastPartitioned(
String tableName,
JobDescriptor<T, R> descriptor,
@Nullable T arg
) {
return executeBroadcastPartitioned(tableName, descriptor, null, arg);
}

/**
* Executes a {@link ComputeJob} of the given class on nodes where the primary replicas of a partitions of the specified table are
* located. The partition indices are passed to the job in the {@link JobExecutionContext#partitions()}.
*
* @param tableName Table name.
* @param descriptor Job descriptor.
* @param arg Job argument.
* @param <T> Job argument (T)ype.
* @param <R> Job (R)esult type.
* @return Map from the node to the job execution results.
*/
<T, R> Map<ClusterNode, R> executeBroadcastPartitioned(
String tableName,
JobDescriptor<T, R> descriptor,
@Nullable CancellationToken cancellationToken,
@Nullable T arg
);

/**
* Submits a {@link MapReduceTask} of the given class for an execution.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@

package org.apache.ignite.compute;

import java.util.List;
import org.apache.ignite.Ignite;
import org.apache.ignite.table.partition.Partition;
import org.jetbrains.annotations.Nullable;

/**
* Context of the {@link ComputeJob} execution.
Expand All @@ -36,4 +39,13 @@ public interface JobExecutionContext {
* @return {@code true} when the job was cancelled.
*/
boolean isCancelled();

/**
* List of partitions associated with this job. Not a {@code null} only when
* {@link IgniteCompute#submitBroadcastPartitioned(String, JobDescriptor, Object)} method is used to submit jobs. In this case, the list
* contains partitions that are local on the node executing the job.
*
* @return list of partitions associated with this job.
*/
@Nullable List<Partition> partitions();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.ignite.internal.client.compute;

import static java.util.concurrent.CompletableFuture.completedFuture;
import static java.util.concurrent.CompletableFuture.failedFuture;
import static org.apache.ignite.lang.ErrorGroups.Client.TABLE_ID_NOT_FOUND_ERR;

import java.util.ArrayList;
Expand Down Expand Up @@ -236,6 +237,39 @@ public <T, R> R executeMapReduce(TaskDescriptor<T, R> taskDescriptor, @Nullable
return sync(executeMapReduceAsync(taskDescriptor, cancellationToken, arg));
}

@Override
public <T, R> CompletableFuture<Map<ClusterNode, JobExecution<R>>> submitBroadcastPartitioned(
String tableName,
JobDescriptor<T, R> descriptor,
@Nullable T arg
) {
Objects.requireNonNull(tableName);
Objects.requireNonNull(descriptor);
// TODO https://issues.apache.org/jira/browse/IGNITE-23936
return failedFuture(new UnsupportedOperationException("Not implemented"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Please create a ticket and add TODO for client impl. Ideally also tickets for other clients (.NET, C++).

}

@Override
public <T, R> CompletableFuture<Map<ClusterNode, R>> executeBroadcastPartitionedAsync(
String tableName,
JobDescriptor<T, R> descriptor,
@Nullable CancellationToken cancellationToken,
@Nullable T arg
) {
// TODO https://issues.apache.org/jira/browse/IGNITE-23936
return failedFuture(new UnsupportedOperationException("Not implemented"));
}

@Override
public <T, R> Map<ClusterNode, R> executeBroadcastPartitioned(
String tableName,
JobDescriptor<T, R> descriptor,
@Nullable CancellationToken cancellationToken,
@Nullable T arg
) {
return sync(executeBroadcastPartitionedAsync(tableName, descriptor, cancellationToken, arg));
}

private <T, R> CompletableFuture<SubmitTaskResult> doExecuteMapReduceAsync(TaskDescriptor<T, R> taskDescriptor, @Nullable T arg) {
return ch.serviceAsync(
ClientOp.COMPUTE_EXECUTE_MAPREDUCE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.ignite.client.fakes;

import static java.util.concurrent.CompletableFuture.completedFuture;
import static java.util.concurrent.CompletableFuture.failedFuture;
import static org.apache.ignite.compute.JobStatus.COMPLETED;
import static org.apache.ignite.compute.JobStatus.EXECUTING;
import static org.apache.ignite.compute.JobStatus.FAILED;
Expand Down Expand Up @@ -122,7 +123,7 @@ public <R> JobExecution<R> executeAsyncWithFailover(
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);
new JobExecutionContextImpl(ignite, new AtomicBoolean(), this.getClass().getClassLoader(), null), args);

return jobExecution(jobFut != null ? jobFut : nullCompletedFuture());
}
Expand Down Expand Up @@ -201,6 +202,35 @@ public <T, R> R executeMapReduce(TaskDescriptor<T, R> taskDescriptor, @Nullable
return sync(executeMapReduceAsync(taskDescriptor, cancellationToken, arg));
}

@Override
public <T, R> CompletableFuture<Map<ClusterNode, JobExecution<R>>> submitBroadcastPartitioned(
String tableName,
JobDescriptor<T, R> descriptor,
@Nullable T arg
) {
return failedFuture(new UnsupportedOperationException("Not implemented"));
}

@Override
public <T, R> CompletableFuture<Map<ClusterNode, R>> executeBroadcastPartitionedAsync(
String tableName,
JobDescriptor<T, R> descriptor,
@Nullable CancellationToken cancellationToken,
@Nullable T arg
) {
return failedFuture(new UnsupportedOperationException("Not implemented"));
}

@Override
public <T, R> Map<ClusterNode, R> executeBroadcastPartitioned(
String tableName,
JobDescriptor<T, R> descriptor,
@Nullable CancellationToken cancellationToken,
@Nullable T arg
) {
return sync(executeBroadcastPartitionedAsync(tableName, descriptor, cancellationToken, arg));
}

private <R> JobExecution<R> completedExecution(R result) {
return jobExecution(completedFuture(result));
}
Expand Down
1 change: 1 addition & 0 deletions modules/compute/jobs.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ processIntegrationTestResources {

dependencies {
jobsImplementation project(':ignite-api')
jobsImplementation project(':ignite-core')
unit1Implementation project(':ignite-api')
unit2Implementation project(':ignite-api')

Expand Down
Loading