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

[PR] IGNITE-25348 Batch spitting in a client [ignite-3]

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

   Thank you for submitting the pull request.
   
   To streamline the review process of the patch and ensure better code quality
   we ask both an author and a reviewer to verify the following:
   
   ### The Review Checklist
   - [ ] **Formal criteria:** TC status, codestyle, mandatory documentation. Also make sure to complete the following:  
   \- There is a single JIRA ticket related to the pull request.  
   \- The web-link to the pull request is attached to the JIRA ticket.  
   \- The JIRA ticket has the Patch Available state.  
   \- The description of the JIRA ticket explains WHAT was made, WHY and HOW.  
   \- The pull request title is treated as the final commit message. The following pattern must be used: IGNITE-XXXX Change summary where XXXX - number of JIRA issue.
   - [ ] **Design:** new code conforms with the design principles of the components it is added to.
   - [ ] **Patch quality:** patch cannot be split into smaller pieces, its size must be reasonable.
   - [ ] **Code quality:** code is clean and readable, necessary developer documentation is added if needed.
   - [ ] **Tests code quality:** test set covers positive/negative scenarios, happy/edge cases. Tests are effective in terms of execution time and resources.
   
   ### Notes
   - [Apache Ignite Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Java+Code+Style+Guide)


-- 
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-25348 Java thin: add partition-aware batch splitting [ignite-3]

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


##########
modules/client/src/main/java/org/apache/ignite/internal/client/table/ClientTable.java:
##########
@@ -877,12 +877,135 @@ int tryGetPartitionCount() {
         return partitionCount;
     }
 
+    /**
+     * Batch with indexes.
+     *
+     * @param <E> Batch type element.
+     */
+    static class Batch<E> {
+        List<E> batch = new ArrayList<>();
+        List<Integer> originalIndices = new ArrayList<>();
+
+        void add(E entry, int origIdx) {
+            batch.add(entry);
+            originalIndices.add(origIdx);
+        }
+    }
+
+    private static <E> void reduceWithKeepOrder(List<E> agg, List<E> cur, List<Integer> originalIndices) {
+        for (int i = 0; i < cur.size(); i++) {
+            E val = cur.get(i);
+            Integer orig = originalIndices.get(i);
+            agg.set(orig, val);
+        }
+    }
+
+    <R, E> CompletableFuture<R> split(
+            Transaction tx,
+            Collection<E> keys,
+            BiFunction<Collection<E>, PartitionAwarenessProvider, CompletableFuture<R>> fun,
+            @Nullable R initialValue,
+            Reducer<R> reducer,
+            BiFunction<ClientSchema, E, Integer> hashFunc
+    ) {
+        assert tx != null;
+
+        CompletableFuture<ClientSchema> schemaFut = getSchema(latestSchemaVer);
+        CompletableFuture<List<String>> partitionsFut = getPartitionAssignment();
+
+        return CompletableFuture.allOf(schemaFut, partitionsFut)
+                .thenCompose(v -> {
+                    @Nullable List<String> aff = partitionsFut.getNow(null);
+                    Map<Integer, List<E>> mapped = new HashMap<>();
+                    List<CompletableFuture<R>> res = new ArrayList<>();
+
+                    if (aff == null) {
+                        return fun.apply(keys, PartitionAwarenessProvider.NULL_PROVIDER);
+                    }
+
+                    for (E key : keys) {
+                        ClientSchema schema = schemaFut.getNow(null);

Review Comment:
   Can be moved out of the loop.



##########
modules/client/src/main/java/org/apache/ignite/internal/client/table/ClientTable.java:
##########
@@ -877,12 +877,135 @@ int tryGetPartitionCount() {
         return partitionCount;
     }
 
+    /**
+     * Batch with indexes.
+     *
+     * @param <E> Batch type element.
+     */
+    static class Batch<E> {
+        List<E> batch = new ArrayList<>();
+        List<Integer> originalIndices = new ArrayList<>();
+
+        void add(E entry, int origIdx) {
+            batch.add(entry);
+            originalIndices.add(origIdx);
+        }
+    }
+
+    private static <E> void reduceWithKeepOrder(List<E> agg, List<E> cur, List<Integer> originalIndices) {
+        for (int i = 0; i < cur.size(); i++) {
+            E val = cur.get(i);
+            Integer orig = originalIndices.get(i);
+            agg.set(orig, val);
+        }
+    }
+
+    <R, E> CompletableFuture<R> split(
+            Transaction tx,
+            Collection<E> keys,
+            BiFunction<Collection<E>, PartitionAwarenessProvider, CompletableFuture<R>> fun,
+            @Nullable R initialValue,
+            Reducer<R> reducer,
+            BiFunction<ClientSchema, E, Integer> hashFunc
+    ) {
+        assert tx != null;
+
+        CompletableFuture<ClientSchema> schemaFut = getSchema(latestSchemaVer);
+        CompletableFuture<List<String>> partitionsFut = getPartitionAssignment();
+
+        return CompletableFuture.allOf(schemaFut, partitionsFut)
+                .thenCompose(v -> {
+                    @Nullable List<String> aff = partitionsFut.getNow(null);
+                    Map<Integer, List<E>> mapped = new HashMap<>();
+                    List<CompletableFuture<R>> res = new ArrayList<>();

Review Comment:
   let's move below null check and specify capacity:
   
   ```suggestion
                       Map<Integer, List<E>> mapped = new HashMap<>(aff.size());
                       List<CompletableFuture<R>> res = new ArrayList<>(aff.size());
   ```



##########
modules/client/src/main/java/org/apache/ignite/internal/client/table/ClientTable.java:
##########
@@ -877,12 +877,135 @@ int tryGetPartitionCount() {
         return partitionCount;
     }
 
+    /**
+     * Batch with indexes.
+     *
+     * @param <E> Batch type element.
+     */
+    static class Batch<E> {
+        List<E> batch = new ArrayList<>();
+        List<Integer> originalIndices = new ArrayList<>();
+
+        void add(E entry, int origIdx) {
+            batch.add(entry);
+            originalIndices.add(origIdx);
+        }
+    }
+
+    private static <E> void reduceWithKeepOrder(List<E> agg, List<E> cur, List<Integer> originalIndices) {
+        for (int i = 0; i < cur.size(); i++) {
+            E val = cur.get(i);
+            Integer orig = originalIndices.get(i);
+            agg.set(orig, val);
+        }
+    }
+
+    <R, E> CompletableFuture<R> split(
+            Transaction tx,
+            Collection<E> keys,
+            BiFunction<Collection<E>, PartitionAwarenessProvider, CompletableFuture<R>> fun,
+            @Nullable R initialValue,
+            Reducer<R> reducer,
+            BiFunction<ClientSchema, E, Integer> hashFunc
+    ) {
+        assert tx != null;
+
+        CompletableFuture<ClientSchema> schemaFut = getSchema(latestSchemaVer);
+        CompletableFuture<List<String>> partitionsFut = getPartitionAssignment();
+
+        return CompletableFuture.allOf(schemaFut, partitionsFut)
+                .thenCompose(v -> {
+                    @Nullable List<String> aff = partitionsFut.getNow(null);
+                    Map<Integer, List<E>> mapped = new HashMap<>();
+                    List<CompletableFuture<R>> res = new ArrayList<>();
+
+                    if (aff == null) {
+                        return fun.apply(keys, PartitionAwarenessProvider.NULL_PROVIDER);
+                    }
+
+                    for (E key : keys) {
+                        ClientSchema schema = schemaFut.getNow(null);
+                        int hash = hashFunc.apply(schema, key);
+                        Integer part = Math.abs(hash % aff.size());
+                        mapped.computeIfAbsent(part, k -> new ArrayList<>()).add(key);
+                    }
+
+                    for (Entry<Integer, List<E>> entry : mapped.entrySet()) {
+                        res.add(fun.apply(entry.getValue(), PartitionAwarenessProvider.of(entry.getKey())));
+                    }
+
+                    return CompletableFuture.allOf(res.toArray(new CompletableFuture[0])).thenApply(ignored -> {
+                        R in = initialValue;
+
+                        for (CompletableFuture<R> val : res) {
+                            in = reducer.reduce(in, val.getNow(null));
+                        }
+
+                        return in;
+                    });
+                });
+    }
+
+    <E> CompletableFuture<List<E>> split(
+            Transaction tx,
+            Collection<E> keys,
+            BiFunction<Collection<E>, PartitionAwarenessProvider, CompletableFuture<List<E>>> fun,
+            BiFunction<ClientSchema, E, Integer> hashFunc
+    ) {
+        assert tx != null;
+
+        CompletableFuture<ClientSchema> schemaFut = getSchema(latestSchemaVer);
+        CompletableFuture<List<String>> partitionsFut = getPartitionAssignment();
+
+        return CompletableFuture.allOf(schemaFut, partitionsFut)
+                .thenCompose(v -> {
+                    @Nullable List<String> aff = partitionsFut.getNow(null);
+                    Map<Integer, Batch<E>> mapped = new HashMap<>();
+
+                    if (aff == null) {
+                        return fun.apply(keys, PartitionAwarenessProvider.NULL_PROVIDER);
+                    }
+
+                    int idx = 0;
+                    for (E key : keys) {
+                        ClientSchema schema = schemaFut.getNow(null);

Review Comment:
   Can be moved out of the loop.



-- 
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-25348 Java thin: add partition-aware batch splitting [ignite-3]

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


##########
modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItThinClientTransactionsTest.java:
##########
@@ -736,25 +756,145 @@ void testMixedMappingScenarioWithNoopEnlistment() throws Exception {
         for (Entry<Tuple, Tuple> entry : batch0.entrySet()) {
             recs.add(kv(entry.getKey().intValue(0), entry.getValue().stringValue(0)));
         }
-        assertEquals(0, recView.insertAll(tx0, recs).size()); // Proxy write
-        assertEquals(recs.size(), recView.insertAll(tx0, recs).size()); // Proxy no-op write
 
-        assertEquals(0, recView.deleteAllExact(tx0, recs).size()); // Proxy write
-        assertEquals(recs.size(), recView.deleteAllExact(tx0, recs).size()); // Proxy no-op write
+        partitions += partitions(batch0.keySet(), table);
+        assertEquals(0, recView.insertAll(tx0, recs).size()); // Batch split write
+        partitions += partitions(batch0.keySet(), table);
+        assertEquals(recs.size(), recView.insertAll(tx0, recs).size()); // Batch split no-op write
+
+        partitions += partitions(batch0.keySet(), table);
+        assertEquals(0, recView.deleteAllExact(tx0, recs).size()); // Batch split write
+        partitions += partitions(batch0.keySet(), table);
+        assertEquals(recs.size(), recView.deleteAllExact(tx0, recs).size()); // Batch split no-op write
 
         assertTrue(recView.deleteExact(tx0, rec0)); // Write
         assertFalse(recView.deleteExact(tx0, rec0)); // No-op write
 
         tx0.commit();
 
         // Expecting each write operation to trigger add/remove events.
-        int exp = 20;
+        int exp = 20 + partitions;
         Mockito.verify(spyed, Mockito.times(exp)).addInflight(tx0.startedTx().txId());
         Mockito.verify(spyed, Mockito.times(exp)).removeInflight(Mockito.eq(tx0.startedTx().txId()), Mockito.any());
 
-        for (Entry<Tuple, Tuple> entry : data.entrySet()) {
-            view.put(null, entry.getKey(), entry.getValue());
+        // Check if all locks are released.
+        Map<Tuple, Tuple> batch = new HashMap<>();
+
+        for (Tuple tup : tuples0) {
+            batch.put(tup, val(tup.intValue(0) + ""));
+        }
+
+        for (Tuple tup : tuples1) {
+            batch.put(tup, val(tup.intValue(0) + ""));
         }
+
+        view.putAll(null, batch);
+    }
+
+    @Test
+    void testBatchScenarioWithNoopEnlistmentImplicit() {
+        Map<Partition, ClusterNode> map = table().partitionManager().primaryReplicasAsync().join();
+
+        ClientTable table = (ClientTable) table();
+
+        IgniteImpl server0 = TestWrappers.unwrapIgniteImpl(server(0));
+        IgniteImpl server1 = TestWrappers.unwrapIgniteImpl(server(1));
+
+        List<Tuple> tuples0 = generateKeysForNode(600, 50, map, server0.clusterService().topologyService().localMember(), table);
+        List<Tuple> tuples1 = generateKeysForNode(610, 50, map, server1.clusterService().topologyService().localMember(), table);
+
+        Map<Tuple, Tuple> batch = new HashMap<>();
+
+        for (Tuple tup : tuples0) {
+            batch.put(tup, val(tup.intValue(0) + ""));
+        }
+
+        for (Tuple tup : tuples1) {
+            batch.put(tup, val(tup.intValue(0) + ""));
+        }
+
+        KeyValueView<Tuple, Tuple> view = table.keyValueView();
+        view.putAll(null, batch);
+
+        assertEquals(batch.size(), view.getAll(null, batch.keySet()).size());
+
+        assertEquals(0, view.removeAll(null, batch.keySet()).size());
+        assertEquals(batch.size(), view.removeAll(null, batch.keySet()).size());
+    }
+
+    @Test
+    void testBatchScenarioWithNoopEnlistmentExplicit() {

Review Comment:
   I would add a check that all inflits are 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-25348 Java thin: add partition-aware batch splitting [ignite-3]

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


##########
modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/client/ItThinClientTransactionsTest.java:
##########
@@ -736,25 +756,145 @@ void testMixedMappingScenarioWithNoopEnlistment() throws Exception {
         for (Entry<Tuple, Tuple> entry : batch0.entrySet()) {
             recs.add(kv(entry.getKey().intValue(0), entry.getValue().stringValue(0)));
         }
-        assertEquals(0, recView.insertAll(tx0, recs).size()); // Proxy write
-        assertEquals(recs.size(), recView.insertAll(tx0, recs).size()); // Proxy no-op write
 
-        assertEquals(0, recView.deleteAllExact(tx0, recs).size()); // Proxy write
-        assertEquals(recs.size(), recView.deleteAllExact(tx0, recs).size()); // Proxy no-op write
+        partitions += partitions(batch0.keySet(), table);
+        assertEquals(0, recView.insertAll(tx0, recs).size()); // Batch split write
+        partitions += partitions(batch0.keySet(), table);
+        assertEquals(recs.size(), recView.insertAll(tx0, recs).size()); // Batch split no-op write
+
+        partitions += partitions(batch0.keySet(), table);
+        assertEquals(0, recView.deleteAllExact(tx0, recs).size()); // Batch split write
+        partitions += partitions(batch0.keySet(), table);
+        assertEquals(recs.size(), recView.deleteAllExact(tx0, recs).size()); // Batch split no-op write
 
         assertTrue(recView.deleteExact(tx0, rec0)); // Write
         assertFalse(recView.deleteExact(tx0, rec0)); // No-op write
 
         tx0.commit();
 
         // Expecting each write operation to trigger add/remove events.
-        int exp = 20;
+        int exp = 20 + partitions;
         Mockito.verify(spyed, Mockito.times(exp)).addInflight(tx0.startedTx().txId());
         Mockito.verify(spyed, Mockito.times(exp)).removeInflight(Mockito.eq(tx0.startedTx().txId()), Mockito.any());
 
-        for (Entry<Tuple, Tuple> entry : data.entrySet()) {
-            view.put(null, entry.getKey(), entry.getValue());
+        // Check if all locks are released.
+        Map<Tuple, Tuple> batch = new HashMap<>();
+
+        for (Tuple tup : tuples0) {
+            batch.put(tup, val(tup.intValue(0) + ""));
+        }
+
+        for (Tuple tup : tuples1) {
+            batch.put(tup, val(tup.intValue(0) + ""));
         }
+
+        view.putAll(null, batch);
+    }
+
+    @Test
+    void testBatchScenarioWithNoopEnlistmentImplicit() {
+        Map<Partition, ClusterNode> map = table().partitionManager().primaryReplicasAsync().join();
+
+        ClientTable table = (ClientTable) table();
+
+        IgniteImpl server0 = TestWrappers.unwrapIgniteImpl(server(0));
+        IgniteImpl server1 = TestWrappers.unwrapIgniteImpl(server(1));
+
+        List<Tuple> tuples0 = generateKeysForNode(600, 50, map, server0.clusterService().topologyService().localMember(), table);
+        List<Tuple> tuples1 = generateKeysForNode(610, 50, map, server1.clusterService().topologyService().localMember(), table);
+
+        Map<Tuple, Tuple> batch = new HashMap<>();
+
+        for (Tuple tup : tuples0) {
+            batch.put(tup, val(tup.intValue(0) + ""));
+        }
+
+        for (Tuple tup : tuples1) {
+            batch.put(tup, val(tup.intValue(0) + ""));
+        }
+
+        KeyValueView<Tuple, Tuple> view = table.keyValueView();
+        view.putAll(null, batch);
+
+        assertEquals(batch.size(), view.getAll(null, batch.keySet()).size());
+
+        assertEquals(0, view.removeAll(null, batch.keySet()).size());
+        assertEquals(batch.size(), view.removeAll(null, batch.keySet()).size());
+    }
+
+    @Test
+    void testBatchScenarioWithNoopEnlistmentExplicit() {

Review Comment:
   🆗 



##########
modules/client/src/main/java/org/apache/ignite/internal/client/table/ClientTable.java:
##########
@@ -877,12 +886,148 @@ int tryGetPartitionCount() {
         return partitionCount;
     }
 
+    /**
+     * Batch with indexes.
+     *
+     * @param <E> Batch type element.
+     */
+    static class Batch<E> {
+        List<E> batch = new ArrayList<>();
+        List<Integer> originalIndices = new ArrayList<>();
+
+        void add(E entry, int origIdx) {
+            batch.add(entry);
+            originalIndices.add(origIdx);
+        }
+    }
+
+    private static <E> void reduceWithKeepOrder(List<E> agg, List<E> cur, List<Integer> originalIndices) {
+        for (int i = 0; i < cur.size(); i++) {
+            E val = cur.get(i);
+            Integer orig = originalIndices.get(i);
+            agg.set(orig, val);
+        }
+    }
+
+    <R, E> CompletableFuture<R> split(
+            Transaction tx,
+            Collection<E> keys,
+            BiFunction<Collection<E>, PartitionAwarenessProvider, CompletableFuture<R>> fun,
+            @Nullable R initialValue,
+            Reducer<R> reducer,
+            BiFunction<ClientSchema, E, Integer> hashFunc
+    ) {
+        assert tx != null;
+
+        CompletableFuture<ClientSchema> schemaFut = getSchema(latestSchemaVer);
+        CompletableFuture<List<String>> partitionsFut = getPartitionAssignment();
+
+        return CompletableFuture.allOf(schemaFut, partitionsFut)
+                .thenCompose(v -> {
+                    List<E> unmapped = new ArrayList<>();
+                    Map<Integer, List<E>> mapped = new HashMap<>();
+                    for (E key : keys) {
+                        ClientSchema schema = schemaFut.getNow(null);
+                        @Nullable List<String> aff = partitionsFut.getNow(null);

Review 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-25348 Java thin: add partition-aware batch splitting [ignite-3]

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


##########
modules/client/src/main/java/org/apache/ignite/internal/client/table/ClientTable.java:
##########
@@ -877,12 +886,148 @@ int tryGetPartitionCount() {
         return partitionCount;
     }
 
+    /**
+     * Batch with indexes.
+     *
+     * @param <E> Batch type element.
+     */
+    static class Batch<E> {
+        List<E> batch = new ArrayList<>();
+        List<Integer> originalIndices = new ArrayList<>();
+
+        void add(E entry, int origIdx) {
+            batch.add(entry);
+            originalIndices.add(origIdx);
+        }
+    }
+
+    private static <E> void reduceWithKeepOrder(List<E> agg, List<E> cur, List<Integer> originalIndices) {
+        for (int i = 0; i < cur.size(); i++) {
+            E val = cur.get(i);
+            Integer orig = originalIndices.get(i);
+            agg.set(orig, val);
+        }
+    }
+
+    <R, E> CompletableFuture<R> split(
+            Transaction tx,
+            Collection<E> keys,
+            BiFunction<Collection<E>, PartitionAwarenessProvider, CompletableFuture<R>> fun,
+            @Nullable R initialValue,
+            Reducer<R> reducer,
+            BiFunction<ClientSchema, E, Integer> hashFunc
+    ) {
+        assert tx != null;
+
+        CompletableFuture<ClientSchema> schemaFut = getSchema(latestSchemaVer);
+        CompletableFuture<List<String>> partitionsFut = getPartitionAssignment();
+
+        return CompletableFuture.allOf(schemaFut, partitionsFut)
+                .thenCompose(v -> {
+                    List<E> unmapped = new ArrayList<>();
+                    Map<Integer, List<E>> mapped = new HashMap<>();
+                    for (E key : keys) {
+                        ClientSchema schema = schemaFut.getNow(null);
+                        @Nullable List<String> aff = partitionsFut.getNow(null);
+                        int hash = hashFunc.apply(schema, key);
+                        Integer part = aff == null ? null : Math.abs(hash % aff.size());

Review Comment:
   I think we can move this check outside of the loop and exit early if the assignment is not available (**or empty** - all elements can be null).



##########
modules/client/src/main/java/org/apache/ignite/internal/client/table/PartitionAwarenessProvider.java:
##########
@@ -17,45 +17,42 @@
 
 package org.apache.ignite.internal.client.table;
 
-import java.util.function.BiFunction;
+import java.util.function.Function;
 import org.jetbrains.annotations.Nullable;
 
 /**
  * Partition awareness provider.
- * Represents 3 use cases:
- * 1. Partition awareness is enabled. Use hashFunc to determine partition.
- * 2. Transaction is used. Use specific channel.
- * 3. Null instance = No partition awareness and no transaction. Use any channel.
+ * Used to calculate a partition for a specific operation.
  */
 public class PartitionAwarenessProvider {
-    private final @Nullable Integer partition;
+    static PartitionAwarenessProvider NULL_PROVIDER = of((Integer) null);
 
-    private final @Nullable BiFunction<ClientSchema, Boolean, Integer> hashFunc;
+    private final @Nullable Integer partition;
 
-    private PartitionAwarenessProvider(@Nullable BiFunction<ClientSchema, Boolean, Integer> hashFunc, @Nullable Integer partition) {
-        assert hashFunc != null ^ partition != null;
+    private final @Nullable Function<ClientSchema, Integer> hashFunc;
 
+    private PartitionAwarenessProvider(@Nullable Function<ClientSchema, Integer> hashFunc, @Nullable Integer partition) {
         this.hashFunc = hashFunc;
         this.partition = partition;
     }
 
-    public static PartitionAwarenessProvider of(Integer partition) {
+    public static PartitionAwarenessProvider of(@Nullable Integer partition) {

Review Comment:
   Let's remove `@Nullable` here, it is only needed for `NULL_PROVIDER` where the warning can be suppressed. For all other usages it should not be null.



##########
modules/client/src/main/java/org/apache/ignite/internal/client/table/ClientTable.java:
##########
@@ -877,12 +886,148 @@ int tryGetPartitionCount() {
         return partitionCount;
     }
 
+    /**
+     * Batch with indexes.
+     *
+     * @param <E> Batch type element.
+     */
+    static class Batch<E> {
+        List<E> batch = new ArrayList<>();
+        List<Integer> originalIndices = new ArrayList<>();
+
+        void add(E entry, int origIdx) {
+            batch.add(entry);
+            originalIndices.add(origIdx);
+        }
+    }
+
+    private static <E> void reduceWithKeepOrder(List<E> agg, List<E> cur, List<Integer> originalIndices) {
+        for (int i = 0; i < cur.size(); i++) {
+            E val = cur.get(i);
+            Integer orig = originalIndices.get(i);
+            agg.set(orig, val);
+        }
+    }
+
+    <R, E> CompletableFuture<R> split(
+            Transaction tx,
+            Collection<E> keys,
+            BiFunction<Collection<E>, PartitionAwarenessProvider, CompletableFuture<R>> fun,
+            @Nullable R initialValue,
+            Reducer<R> reducer,
+            BiFunction<ClientSchema, E, Integer> hashFunc
+    ) {
+        assert tx != null;
+
+        CompletableFuture<ClientSchema> schemaFut = getSchema(latestSchemaVer);
+        CompletableFuture<List<String>> partitionsFut = getPartitionAssignment();
+
+        return CompletableFuture.allOf(schemaFut, partitionsFut)
+                .thenCompose(v -> {
+                    List<E> unmapped = new ArrayList<>();
+                    Map<Integer, List<E>> mapped = new HashMap<>();
+                    for (E key : keys) {
+                        ClientSchema schema = schemaFut.getNow(null);
+                        @Nullable List<String> aff = partitionsFut.getNow(null);
+                        int hash = hashFunc.apply(schema, key);
+                        Integer part = aff == null ? null : Math.abs(hash % aff.size());
+                        if (part == null) {
+                            unmapped.add(key);
+                        } else {
+                            mapped.computeIfAbsent(part, k -> new ArrayList<>()).add(key);
+                        }
+                    }
+
+                    List<CompletableFuture<R>> res = new ArrayList<>();
+
+                    if (!unmapped.isEmpty()) {
+                        // Disable awareness for unmapped keys.
+                        res.add(fun.apply(unmapped, PartitionAwarenessProvider.NULL_PROVIDER));
+                    }
+
+                    for (Entry<Integer, List<E>> entry : mapped.entrySet()) {
+                        res.add(fun.apply(entry.getValue(), PartitionAwarenessProvider.of(entry.getKey())));
+                    }
+
+                    return CompletableFuture.allOf(res.toArray(new CompletableFuture[0])).thenApply(ignored -> {
+                        R in = initialValue;
+
+                        for (CompletableFuture<R> val : res) {
+                            in = reducer.reduce(in, val.getNow(null));
+                        }
+
+                        return in;
+                    });
+                });
+    }
+
+    <E> CompletableFuture<List<E>> split(
+            Transaction tx,
+            Collection<E> keys,
+            BiFunction<Collection<E>, PartitionAwarenessProvider, CompletableFuture<List<E>>> fun,
+            BiFunction<ClientSchema, E, Integer> hashFunc
+    ) {
+        assert tx != null;
+
+        CompletableFuture<ClientSchema> schemaFut = getSchema(latestSchemaVer);
+        CompletableFuture<List<String>> partitionsFut = getPartitionAssignment();
+
+        return CompletableFuture.allOf(schemaFut, partitionsFut)
+                .thenCompose(v -> {
+                    Batch<E> unmapped = new Batch<>();
+                    Map<Integer, Batch<E>> mapped = new HashMap<>();
+                    int idx = 0;
+                    for (E key : keys) {
+                        ClientSchema schema = schemaFut.getNow(null);
+                        @Nullable List<String> aff = partitionsFut.getNow(null);
+                        int hash = hashFunc.apply(schema, key);
+                        Integer part = aff == null ? null : Math.abs(hash % aff.size());

Review Comment:
   Same as above - move what's possible outside of the loop.



-- 
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-25348 Java thin: add partition-aware batch splitting [ignite-3]

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


##########
modules/client/src/main/java/org/apache/ignite/internal/client/table/ClientTable.java:
##########
@@ -877,12 +877,135 @@ int tryGetPartitionCount() {
         return partitionCount;
     }
 
+    /**
+     * Batch with indexes.
+     *
+     * @param <E> Batch type element.
+     */
+    static class Batch<E> {
+        List<E> batch = new ArrayList<>();
+        List<Integer> originalIndices = new ArrayList<>();
+
+        void add(E entry, int origIdx) {
+            batch.add(entry);
+            originalIndices.add(origIdx);
+        }
+    }
+
+    private static <E> void reduceWithKeepOrder(List<E> agg, List<E> cur, List<Integer> originalIndices) {
+        for (int i = 0; i < cur.size(); i++) {
+            E val = cur.get(i);
+            Integer orig = originalIndices.get(i);
+            agg.set(orig, val);
+        }
+    }
+
+    <R, E> CompletableFuture<R> split(
+            Transaction tx,
+            Collection<E> keys,
+            BiFunction<Collection<E>, PartitionAwarenessProvider, CompletableFuture<R>> fun,
+            @Nullable R initialValue,
+            Reducer<R> reducer,
+            BiFunction<ClientSchema, E, Integer> hashFunc
+    ) {
+        assert tx != null;
+
+        CompletableFuture<ClientSchema> schemaFut = getSchema(latestSchemaVer);
+        CompletableFuture<List<String>> partitionsFut = getPartitionAssignment();
+
+        return CompletableFuture.allOf(schemaFut, partitionsFut)
+                .thenCompose(v -> {
+                    @Nullable List<String> aff = partitionsFut.getNow(null);
+                    Map<Integer, List<E>> mapped = new HashMap<>();
+                    List<CompletableFuture<R>> res = new ArrayList<>();
+
+                    if (aff == null) {
+                        return fun.apply(keys, PartitionAwarenessProvider.NULL_PROVIDER);
+                    }
+
+                    for (E key : keys) {
+                        ClientSchema schema = schemaFut.getNow(null);
+                        int hash = hashFunc.apply(schema, key);
+                        Integer part = Math.abs(hash % aff.size());
+                        mapped.computeIfAbsent(part, k -> new ArrayList<>()).add(key);
+                    }
+
+                    for (Entry<Integer, List<E>> entry : mapped.entrySet()) {
+                        res.add(fun.apply(entry.getValue(), PartitionAwarenessProvider.of(entry.getKey())));
+                    }
+
+                    return CompletableFuture.allOf(res.toArray(new CompletableFuture[0])).thenApply(ignored -> {
+                        R in = initialValue;
+
+                        for (CompletableFuture<R> val : res) {
+                            in = reducer.reduce(in, val.getNow(null));
+                        }
+
+                        return in;
+                    });
+                });
+    }
+
+    <E> CompletableFuture<List<E>> split(
+            Transaction tx,
+            Collection<E> keys,
+            BiFunction<Collection<E>, PartitionAwarenessProvider, CompletableFuture<List<E>>> fun,
+            BiFunction<ClientSchema, E, Integer> hashFunc
+    ) {
+        assert tx != null;
+
+        CompletableFuture<ClientSchema> schemaFut = getSchema(latestSchemaVer);
+        CompletableFuture<List<String>> partitionsFut = getPartitionAssignment();
+
+        return CompletableFuture.allOf(schemaFut, partitionsFut)
+                .thenCompose(v -> {
+                    @Nullable List<String> aff = partitionsFut.getNow(null);
+                    Map<Integer, Batch<E>> mapped = new HashMap<>();
+
+                    if (aff == null) {
+                        return fun.apply(keys, PartitionAwarenessProvider.NULL_PROVIDER);
+                    }
+
+                    int idx = 0;
+                    for (E key : keys) {
+                        ClientSchema schema = schemaFut.getNow(null);

Review Comment:
   🆗 



##########
modules/client/src/main/java/org/apache/ignite/internal/client/table/ClientTable.java:
##########
@@ -877,12 +877,135 @@ int tryGetPartitionCount() {
         return partitionCount;
     }
 
+    /**
+     * Batch with indexes.
+     *
+     * @param <E> Batch type element.
+     */
+    static class Batch<E> {
+        List<E> batch = new ArrayList<>();
+        List<Integer> originalIndices = new ArrayList<>();
+
+        void add(E entry, int origIdx) {
+            batch.add(entry);
+            originalIndices.add(origIdx);
+        }
+    }
+
+    private static <E> void reduceWithKeepOrder(List<E> agg, List<E> cur, List<Integer> originalIndices) {
+        for (int i = 0; i < cur.size(); i++) {
+            E val = cur.get(i);
+            Integer orig = originalIndices.get(i);
+            agg.set(orig, val);
+        }
+    }
+
+    <R, E> CompletableFuture<R> split(
+            Transaction tx,
+            Collection<E> keys,
+            BiFunction<Collection<E>, PartitionAwarenessProvider, CompletableFuture<R>> fun,
+            @Nullable R initialValue,
+            Reducer<R> reducer,
+            BiFunction<ClientSchema, E, Integer> hashFunc
+    ) {
+        assert tx != null;
+
+        CompletableFuture<ClientSchema> schemaFut = getSchema(latestSchemaVer);
+        CompletableFuture<List<String>> partitionsFut = getPartitionAssignment();
+
+        return CompletableFuture.allOf(schemaFut, partitionsFut)
+                .thenCompose(v -> {
+                    @Nullable List<String> aff = partitionsFut.getNow(null);
+                    Map<Integer, List<E>> mapped = new HashMap<>();
+                    List<CompletableFuture<R>> res = new ArrayList<>();

Review 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-25348 Java thin: add partition-aware batch splitting [ignite-3]

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


##########
modules/client/src/main/java/org/apache/ignite/internal/client/table/ClientTable.java:
##########
@@ -877,12 +877,135 @@ int tryGetPartitionCount() {
         return partitionCount;
     }
 
+    /**
+     * Batch with indexes.
+     *
+     * @param <E> Batch type element.
+     */
+    static class Batch<E> {
+        List<E> batch = new ArrayList<>();
+        List<Integer> originalIndices = new ArrayList<>();
+
+        void add(E entry, int origIdx) {
+            batch.add(entry);
+            originalIndices.add(origIdx);
+        }
+    }
+
+    private static <E> void reduceWithKeepOrder(List<E> agg, List<E> cur, List<Integer> originalIndices) {
+        for (int i = 0; i < cur.size(); i++) {
+            E val = cur.get(i);
+            Integer orig = originalIndices.get(i);
+            agg.set(orig, val);
+        }
+    }
+
+    <R, E> CompletableFuture<R> split(
+            Transaction tx,
+            Collection<E> keys,
+            BiFunction<Collection<E>, PartitionAwarenessProvider, CompletableFuture<R>> fun,
+            @Nullable R initialValue,
+            Reducer<R> reducer,
+            BiFunction<ClientSchema, E, Integer> hashFunc
+    ) {
+        assert tx != null;
+
+        CompletableFuture<ClientSchema> schemaFut = getSchema(latestSchemaVer);
+        CompletableFuture<List<String>> partitionsFut = getPartitionAssignment();
+
+        return CompletableFuture.allOf(schemaFut, partitionsFut)
+                .thenCompose(v -> {
+                    @Nullable List<String> aff = partitionsFut.getNow(null);
+                    Map<Integer, List<E>> mapped = new HashMap<>();
+                    List<CompletableFuture<R>> res = new ArrayList<>();
+
+                    if (aff == null) {
+                        return fun.apply(keys, PartitionAwarenessProvider.NULL_PROVIDER);
+                    }
+
+                    for (E key : keys) {
+                        ClientSchema schema = schemaFut.getNow(null);

Review 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-25348 Java thin: add partition-aware batch splitting [ignite-3]

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


##########
modules/client/src/main/java/org/apache/ignite/internal/client/table/ClientTable.java:
##########
@@ -877,12 +886,148 @@ int tryGetPartitionCount() {
         return partitionCount;
     }
 
+    /**
+     * Batch with indexes.
+     *
+     * @param <E> Batch type element.
+     */
+    static class Batch<E> {
+        List<E> batch = new ArrayList<>();
+        List<Integer> originalIndices = new ArrayList<>();
+
+        void add(E entry, int origIdx) {
+            batch.add(entry);
+            originalIndices.add(origIdx);
+        }
+    }
+
+    private static <E> void reduceWithKeepOrder(List<E> agg, List<E> cur, List<Integer> originalIndices) {
+        for (int i = 0; i < cur.size(); i++) {
+            E val = cur.get(i);
+            Integer orig = originalIndices.get(i);
+            agg.set(orig, val);
+        }
+    }
+
+    <R, E> CompletableFuture<R> split(
+            Transaction tx,
+            Collection<E> keys,
+            BiFunction<Collection<E>, PartitionAwarenessProvider, CompletableFuture<R>> fun,
+            @Nullable R initialValue,
+            Reducer<R> reducer,
+            BiFunction<ClientSchema, E, Integer> hashFunc
+    ) {
+        assert tx != null;
+
+        CompletableFuture<ClientSchema> schemaFut = getSchema(latestSchemaVer);
+        CompletableFuture<List<String>> partitionsFut = getPartitionAssignment();
+
+        return CompletableFuture.allOf(schemaFut, partitionsFut)
+                .thenCompose(v -> {
+                    List<E> unmapped = new ArrayList<>();
+                    Map<Integer, List<E>> mapped = new HashMap<>();
+                    for (E key : keys) {
+                        ClientSchema schema = schemaFut.getNow(null);
+                        @Nullable List<String> aff = partitionsFut.getNow(null);
+                        int hash = hashFunc.apply(schema, key);
+                        Integer part = aff == null ? null : Math.abs(hash % aff.size());

Review Comment:
   Good catch. Simplified the splitting code.



##########
modules/client/src/main/java/org/apache/ignite/internal/client/table/ClientTable.java:
##########
@@ -877,12 +886,148 @@ int tryGetPartitionCount() {
         return partitionCount;
     }
 
+    /**
+     * Batch with indexes.
+     *
+     * @param <E> Batch type element.
+     */
+    static class Batch<E> {
+        List<E> batch = new ArrayList<>();
+        List<Integer> originalIndices = new ArrayList<>();
+
+        void add(E entry, int origIdx) {
+            batch.add(entry);
+            originalIndices.add(origIdx);
+        }
+    }
+
+    private static <E> void reduceWithKeepOrder(List<E> agg, List<E> cur, List<Integer> originalIndices) {
+        for (int i = 0; i < cur.size(); i++) {
+            E val = cur.get(i);
+            Integer orig = originalIndices.get(i);
+            agg.set(orig, val);
+        }
+    }
+
+    <R, E> CompletableFuture<R> split(
+            Transaction tx,
+            Collection<E> keys,
+            BiFunction<Collection<E>, PartitionAwarenessProvider, CompletableFuture<R>> fun,
+            @Nullable R initialValue,
+            Reducer<R> reducer,
+            BiFunction<ClientSchema, E, Integer> hashFunc
+    ) {
+        assert tx != null;
+
+        CompletableFuture<ClientSchema> schemaFut = getSchema(latestSchemaVer);
+        CompletableFuture<List<String>> partitionsFut = getPartitionAssignment();
+
+        return CompletableFuture.allOf(schemaFut, partitionsFut)
+                .thenCompose(v -> {
+                    List<E> unmapped = new ArrayList<>();
+                    Map<Integer, List<E>> mapped = new HashMap<>();
+                    for (E key : keys) {
+                        ClientSchema schema = schemaFut.getNow(null);
+                        @Nullable List<String> aff = partitionsFut.getNow(null);
+                        int hash = hashFunc.apply(schema, key);
+                        Integer part = aff == null ? null : Math.abs(hash % aff.size());
+                        if (part == null) {
+                            unmapped.add(key);
+                        } else {
+                            mapped.computeIfAbsent(part, k -> new ArrayList<>()).add(key);
+                        }
+                    }
+
+                    List<CompletableFuture<R>> res = new ArrayList<>();
+
+                    if (!unmapped.isEmpty()) {
+                        // Disable awareness for unmapped keys.
+                        res.add(fun.apply(unmapped, PartitionAwarenessProvider.NULL_PROVIDER));
+                    }
+
+                    for (Entry<Integer, List<E>> entry : mapped.entrySet()) {
+                        res.add(fun.apply(entry.getValue(), PartitionAwarenessProvider.of(entry.getKey())));
+                    }
+
+                    return CompletableFuture.allOf(res.toArray(new CompletableFuture[0])).thenApply(ignored -> {
+                        R in = initialValue;
+
+                        for (CompletableFuture<R> val : res) {
+                            in = reducer.reduce(in, val.getNow(null));
+                        }
+
+                        return in;
+                    });
+                });
+    }
+
+    <E> CompletableFuture<List<E>> split(
+            Transaction tx,
+            Collection<E> keys,
+            BiFunction<Collection<E>, PartitionAwarenessProvider, CompletableFuture<List<E>>> fun,
+            BiFunction<ClientSchema, E, Integer> hashFunc
+    ) {
+        assert tx != null;
+
+        CompletableFuture<ClientSchema> schemaFut = getSchema(latestSchemaVer);
+        CompletableFuture<List<String>> partitionsFut = getPartitionAssignment();
+
+        return CompletableFuture.allOf(schemaFut, partitionsFut)
+                .thenCompose(v -> {
+                    Batch<E> unmapped = new Batch<>();
+                    Map<Integer, Batch<E>> mapped = new HashMap<>();
+                    int idx = 0;
+                    for (E key : keys) {
+                        ClientSchema schema = schemaFut.getNow(null);
+                        @Nullable List<String> aff = partitionsFut.getNow(null);
+                        int hash = hashFunc.apply(schema, key);
+                        Integer part = aff == null ? null : Math.abs(hash % aff.size());

Review 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-25348 Java thin: add partition-aware batch splitting [ignite-3]

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


##########
modules/client/src/main/java/org/apache/ignite/internal/client/table/PartitionAwarenessProvider.java:
##########
@@ -17,45 +17,42 @@
 
 package org.apache.ignite.internal.client.table;
 
-import java.util.function.BiFunction;
+import java.util.function.Function;
 import org.jetbrains.annotations.Nullable;
 
 /**
  * Partition awareness provider.
- * Represents 3 use cases:
- * 1. Partition awareness is enabled. Use hashFunc to determine partition.
- * 2. Transaction is used. Use specific channel.
- * 3. Null instance = No partition awareness and no transaction. Use any channel.
+ * Used to calculate a partition for a specific operation.
  */
 public class PartitionAwarenessProvider {
-    private final @Nullable Integer partition;
+    static PartitionAwarenessProvider NULL_PROVIDER = of((Integer) null);
 
-    private final @Nullable BiFunction<ClientSchema, Boolean, Integer> hashFunc;
+    private final @Nullable Integer partition;
 
-    private PartitionAwarenessProvider(@Nullable BiFunction<ClientSchema, Boolean, Integer> hashFunc, @Nullable Integer partition) {
-        assert hashFunc != null ^ partition != null;
+    private final @Nullable Function<ClientSchema, Integer> hashFunc;
 
+    private PartitionAwarenessProvider(@Nullable Function<ClientSchema, Integer> hashFunc, @Nullable Integer partition) {
         this.hashFunc = hashFunc;
         this.partition = partition;
     }
 
-    public static PartitionAwarenessProvider of(Integer partition) {
+    public static PartitionAwarenessProvider of(@Nullable Integer partition) {

Review 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-25348 Java thin: add partition-aware batch splitting [ignite-3]

Posted by "ascherbakoff (via GitHub)" <gi...@apache.org>.
ascherbakoff closed pull request #6007: IGNITE-25348 Java thin: add partition-aware batch splitting
URL: https://github.com/apache/ignite-3/pull/6007


-- 
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-25348 Java thin: add partition-aware batch splitting [ignite-3]

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

   > Fixed a critical bug causing no-op direct mapping not to enlist in client transaction.
   > Fixed a bug causing empty entries stay in client tx inflight map.
   
   @ascherbakoff please create tickets for both of those, and let's have separate PRs so we can review and manage fixes in isolation.


-- 
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-25348 Java thin: add partition-aware batch splitting [ignite-3]

Posted by "ascherbakoff (via GitHub)" <gi...@apache.org>.
ascherbakoff commented on PR #6007:
URL: https://github.com/apache/ignite-3/pull/6007#issuecomment-2988214063

   > > 3. Fixed a critical bug causing no-op direct mapping not to enlist in client transaction.
   > > 4. Fixed a bug causing empty entries stay in client tx inflight map.
   > 
   > @ascherbakoff please create tickets for both of those and let's have separate PRs so we can review and manage fixes in isolation.
   
   @ptupitsyn I agree in general, but let's keep it as is this time for the sake of simplicity.  I've added detailed bug description to PR head.
   


-- 
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-25348 Java thin: add partition-aware batch splitting [ignite-3]

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


##########
modules/client/src/main/java/org/apache/ignite/internal/client/table/ClientTable.java:
##########
@@ -877,12 +886,148 @@ int tryGetPartitionCount() {
         return partitionCount;
     }
 
+    /**
+     * Batch with indexes.
+     *
+     * @param <E> Batch type element.
+     */
+    static class Batch<E> {
+        List<E> batch = new ArrayList<>();
+        List<Integer> originalIndices = new ArrayList<>();
+
+        void add(E entry, int origIdx) {
+            batch.add(entry);
+            originalIndices.add(origIdx);
+        }
+    }
+
+    private static <E> void reduceWithKeepOrder(List<E> agg, List<E> cur, List<Integer> originalIndices) {
+        for (int i = 0; i < cur.size(); i++) {
+            E val = cur.get(i);
+            Integer orig = originalIndices.get(i);
+            agg.set(orig, val);
+        }
+    }
+
+    <R, E> CompletableFuture<R> split(
+            Transaction tx,
+            Collection<E> keys,
+            BiFunction<Collection<E>, PartitionAwarenessProvider, CompletableFuture<R>> fun,
+            @Nullable R initialValue,
+            Reducer<R> reducer,
+            BiFunction<ClientSchema, E, Integer> hashFunc
+    ) {
+        assert tx != null;
+
+        CompletableFuture<ClientSchema> schemaFut = getSchema(latestSchemaVer);
+        CompletableFuture<List<String>> partitionsFut = getPartitionAssignment();
+
+        return CompletableFuture.allOf(schemaFut, partitionsFut)
+                .thenCompose(v -> {
+                    List<E> unmapped = new ArrayList<>();
+                    Map<Integer, List<E>> mapped = new HashMap<>();
+                    for (E key : keys) {
+                        ClientSchema schema = schemaFut.getNow(null);
+                        @Nullable List<String> aff = partitionsFut.getNow(null);

Review Comment:
   Let's move outside of the loop.



-- 
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