isapego commented on code in PR #3812:
URL: https://github.com/apache/ignite-3/pull/3812#discussion_r1611502174


##########
modules/client-handler/src/main/java/org/apache/ignite/client/handler/requests/table/ClientStreamerWithReceiverBatchSendRequest.java:
##########
@@ -0,0 +1,129 @@
+/*
+ * 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.client.handler.requests.table;
+
+import static 
org.apache.ignite.client.handler.requests.table.ClientTableCommon.readTableAsync;
+import static 
org.apache.ignite.lang.ErrorGroups.Compute.COMPUTE_JOB_FAILED_ERR;
+
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.compute.ComputeException;
+import org.apache.ignite.compute.ComputeJob;
+import org.apache.ignite.compute.DeploymentUnit;
+import org.apache.ignite.compute.JobExecution;
+import org.apache.ignite.compute.JobExecutionContext;
+import org.apache.ignite.compute.JobExecutionOptions;
+import org.apache.ignite.internal.client.proto.ClientMessagePacker;
+import org.apache.ignite.internal.client.proto.ClientMessageUnpacker;
+import org.apache.ignite.internal.client.proto.StreamerReceiverSerializer;
+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.table.partition.HashPartition;
+import org.apache.ignite.internal.util.ExceptionUtils;
+import org.apache.ignite.lang.IgniteException;
+import org.apache.ignite.table.DataStreamerReceiver;
+import org.apache.ignite.table.DataStreamerReceiverContext;
+import org.apache.ignite.table.manager.IgniteTables;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Client streamer batch request.
+ */
+public class ClientStreamerWithReceiverBatchSendRequest {
+    /**
+     * Processes the request.
+     *
+     * @param in        Unpacker.
+     * @param out       Packer.
+     * @param tables    Ignite tables.
+     * @return Future.
+     */
+    public static CompletableFuture<Void> process(
+            ClientMessageUnpacker in,
+            ClientMessagePacker out,
+            IgniteTables tables,
+            IgniteComputeInternal compute
+    ) {
+        return readTableAsync(in, tables).thenCompose(table -> {
+            int partition = in.unpackInt();
+            List<DeploymentUnit> deploymentUnits = in.unpackDeploymentUnits();
+            boolean returnResults = in.unpackBoolean();
+
+            // Payload = binary tuple of (receiverClassName, receiverArgs, 
items). We pass it to the job without deserialization.
+            int payloadElementCount = in.unpackInt();
+            byte[] payload = in.readBinary();
+
+            return table.partitionManager().primaryReplicaAsync(new 
HashPartition(partition)).thenCompose(primaryReplica -> {
+                // Use Compute to execute receiver on the target node with 
failover, class loading, scheduling.
+                JobExecution<List<Object>> jobExecution = 
compute.executeAsyncWithFailover(
+                        Set.of(primaryReplica),
+                        deploymentUnits,
+                        ReceiverRunnerJob.class.getName(),
+                        JobExecutionOptions.DEFAULT,
+                        payloadElementCount,
+                        payload);

Review Comment:
   This will result in the same receiver class being constructed and destructed 
for every batch, probably resulting in poorer performance and additional 
garbage. We should probably construct and deploy it once, and keep it alive 
while the streamer is working, if it's possible. We can still re-use compute 
API for that, probably.



-- 
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-unsubscr...@ignite.apache.org

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

Reply via email to