korlov42 commented on code in PR #1700:
URL: https://github.com/apache/ignite-3/pull/1700#discussion_r1117075362


##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/metadata/IgniteMdFragmentMapping.java:
##########
@@ -219,6 +221,26 @@ public FragmentMapping fragmentMapping(IgniteValues rel, 
RelMetadataQuery mq, Ma
         return FragmentMapping.create(rel.sourceId(), group);
     }
 
+    /**
+     * See {@link IgniteMdFragmentMapping#fragmentMapping(RelNode, 
RelMetadataQuery, MappingQueryContext)}.
+     */
+    public FragmentMapping fragmentMapping(IgniteTableModify rel, 
RelMetadataQuery mq, MappingQueryContext ctx) {
+        FragmentMapping mapping = 
fragmentMappingForMetadataQuery(rel.getInput(), mq, ctx);
+
+        // In case of the statement like UPDATE t SET a = a + 1
+        // this will be the second call to the collation group, hence the 
result may differ.
+        // But such query should be rejected during execution, since we will 
try to do RW read
+        // from replica that is not primary anymore.
+        List<NodeWithTerm> assignments = 
rel.getTable().unwrap(IgniteTable.class)
+                .colocationGroup(ctx).assignments().stream()
+                .map(CollectionUtils::first)
+                .collect(Collectors.toList());

Review Comment:
   I've got a better idea :) https://issues.apache.org/jira/browse/IGNITE-18901



##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/ExecutionServiceImpl.java:
##########
@@ -679,26 +670,41 @@ public IgniteRel visit(IgniteTableScan rel) {
                     return super.visit(rel);
                 }
 
-                private void enlist(SourceAwareIgniteRel rel) {
-                    InternalIgniteTable tbl = 
rel.getTable().unwrap(InternalIgniteTable.class);
-                    ColocationGroup grp = 
fragment.mapping().findGroup(rel.sourceId());
+                @Override
+                public IgniteRel visit(IgniteTableModify rel) {
+                    UUID tableId = 
rel.getTable().unwrap(IgniteTable.class).id();
+                    List<NodeWithTerm> assignments = 
fragment.mapping().updatingTableAssignments();
 
-                    if (grp.assignments().isEmpty()) {
+                    enlist(tableId, assignments);
+
+                    return super.visit(rel);
+                }
+
+                private void enlist(UUID tableId, List<NodeWithTerm> 
assignments) {
+                    if (assignments.isEmpty()) {
                         return;
                     }
 
-                    int partsCnt = grp.assignments().size();
+                    int partsCnt = assignments.size();
 
-                    tx.assignCommitPartition(new TablePartitionId(tbl.id(), 
ThreadLocalRandom.current().nextInt(partsCnt)));
+                    tx.assignCommitPartition(new TablePartitionId(tableId, 
ThreadLocalRandom.current().nextInt(partsCnt)));
 
                     for (int p = 0; p < partsCnt; p++) {
-                        List<NodeWithTerm> assign = grp.assignments().get(p);
-                        NodeWithTerm leaderWithTerm = assign.get(0);
+                        NodeWithTerm leaderWithTerm = assignments.get(p);
 
-                        tx.enlist(new TablePartitionId(tbl.id(), p),
+                        tx.enlist(new TablePartitionId(tableId, p),
                                 new 
IgniteBiTuple<>(topSrvc.getByConsistentId(leaderWithTerm.name()), 
leaderWithTerm.term()));
                     }
                 }
+
+                private void enlist(SourceAwareIgniteRel rel) {
+                    UUID tableId = 
rel.getTable().unwrap(IgniteTable.class).id();
+                    List<NodeWithTerm> assignments = 
fragment.mapping().findGroup(rel.sourceId()).assignments().stream()
+                            .map(l -> l.get(0))

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



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to