Copilot commented on code in PR #13215:
URL: https://github.com/apache/ignite/pull/13215#discussion_r3371192570


##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java:
##########
@@ -251,25 +251,20 @@ public IgniteInternalCache<K, V> delegate() {
     }
 
     /** {@inheritDoc} */
-    @Override public GridCacheProxyImpl<K, V> setSkipStore(boolean skipStore) {
+    @Override public GridCacheProxyImpl<K, V> withSkipStore() {
         CacheOperationContext prev = gate.enter(opCtx);
 
         try {
-            if (opCtx != null && opCtx.skipStore() == skipStore)
-                return this;
+            if (opCtx != null) {
+                if (opCtx.skipStore())
+                    return this;
+                else
+                    opCtx = opCtx.withSkipStore();
+            }
+            else
+                opCtx = 
CacheOperationContext.builder().skipStore(true).build();
 
-            return new GridCacheProxyImpl<>(ctx, delegate,
-                opCtx != null ? opCtx.setSkipStore(skipStore) :
-                    new CacheOperationContext(
-                        skipStore,
-                        false,
-                        false,
-                        null,
-                        false,
-                        null,
-                        false,
-                        null,
-                        null));
+            return new GridCacheProxyImpl<>(ctx, delegate, opCtx);

Review Comment:
   `opCtx` is a mutable field, but this method reassigns it (`opCtx = ...`) 
before creating a new proxy. That mutates the current cache proxy instance, so 
callers that keep a reference to the original projection may unexpectedly 
observe changed flags (and it can create racy behavior if the proxy is shared 
across threads). Use a local `newOpCtx` variable and pass it to the new proxy 
without modifying `this.opCtx` (same pattern should be applied to other 
projection methods in this class that currently do `opCtx = ...`).



##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/PublicApiIntegrationTest.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * 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.internal.processors.query.calcite.integration;
+
+import java.util.List;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.calcite.CalciteQueryEngineConfiguration;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.SqlConfiguration;
+import org.apache.ignite.transactions.Transaction;
+import org.junit.Test;
+
+import static 
org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
+import static 
org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED;
+
+/** Public api integration tests. */
+public class PublicApiIntegrationTest extends AbstractBasicIntegrationTest {
+    /** */
+    @Override protected IgniteConfiguration getConfiguration(String 
igniteInstanceName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
+
+        cfg.setSqlConfiguration(new SqlConfiguration()
+            .setQueryEnginesConfiguration(new 
CalciteQueryEngineConfiguration().setDefault(true)));
+
+        return cfg;
+    }
+
+    /** */
+    @Test
+    public void testSimpleInsert() {
+        IgniteCache<Object, Object> cache = 
client.createCache(DEFAULT_CACHE_NAME);
+
+        runQuery(0, nodeCount() * 10, false, cache);
+
+        cache = cache.withKeepBinary();
+
+        runQuery(nodeCount() * 10, 2 * nodeCount() * 10, false, cache);
+
+        List<List<?>> res = cache.query(new SqlFieldsQuery("SELECT * FROM 
emp")).getAll();
+
+        assertEquals("Unexpected result set size: " + res.size(), 1, 
res.size());
+    }
+
+    /** */
+    @Test
+    public void testTxInsert() {
+        CacheConfiguration<Object, Object> ccfg = new 
CacheConfiguration<>(DEFAULT_CACHE_NAME);
+        ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
+
+        IgniteCache<?, ?> cache = client.createCache(ccfg);
+
+        runQuery(0, nodeCount() * 10, true, cache);
+
+        cache = cache.withKeepBinary();
+
+        runQuery(nodeCount() * 10, 2 * nodeCount() * 10, true, cache);
+
+        List<List<?>> res = cache.query(new SqlFieldsQuery("SELECT * FROM 
emp")).getAll();
+
+        assertEquals("Unexpected result set size: " + res.size(), 1, 
res.size());
+    }
+
+    /** */
+    private void runQuery(int begin, int end, boolean transactional, 
IgniteCache<?, ?> cache) {
+        Transaction tx = null;
+
+        cache.query(new SqlFieldsQuery("CREATE TABLE IF NOT EXISTS emp(empid 
INTEGER, deptid INTEGER, name VARCHAR, salary INTEGER, " +
+            "PRIMARY KEY(empid, deptid)) WITH \"AFFINITY_KEY=deptid" + 
(transactional ? ", ATOMICITY=transactional" : "") + "\""))
+            .getAll();
+
+        if (transactional) {
+            //noinspection resource
+            tx = client.transactions().txStart(PESSIMISTIC, READ_COMMITTED);
+        }
+
+        for (int i = begin; i < end; i++) {
+            cache.query(new SqlFieldsQuery("INSERT INTO emp (empid, deptid, 
name, salary) VALUES (?, ?, ?, ?)").setArgs(
+                i, i % 2, "Employee " + i, i / 10)).getAll();
+
+            cache.query(new SqlFieldsQuery("UPDATE emp SET name = '' WHERE 
empid = ? AND deptid = ?").setArgs(i, i % 2)).getAll();
+            cache.query(new SqlFieldsQuery("DELETE FROM emp WHERE empid = 
?").setArgs(i - 1)).getAll();
+
+            new SqlFieldsQuery("MERGE INTO emp(empid, deptid) VALUES (?, 
?)").setArgs(-i, -i);

Review Comment:
   The `MERGE` statement is currently constructed but never executed, so it 
doesn’t validate Calcite DML behavior (and it’s dead code). If the intent is to 
cover MERGE as part of the DML set, execute it via `cache.query(...).getAll()`; 
using the current row’s PK avoids changing the final row count asserted by the 
test.



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java:
##########
@@ -327,21 +311,17 @@ public IgniteInternalCache<K, V> delegate() {
 
     /** {@inheritDoc} */
     @Override public <K1, V1> GridCacheProxyImpl<K1, V1> keepBinary() {
-        if (opCtx != null && opCtx.isKeepBinary())
-            return (GridCacheProxyImpl<K1, V1>)this;
+        if (opCtx != null) {
+            if (opCtx.isKeepBinary())
+                return (GridCacheProxyImpl<K1, V1>)this;
+            else
+                opCtx = opCtx.withKeepBinary();
+        }
+        else
+            opCtx = CacheOperationContext.builder().keepBinary(true).build();
 
         return new GridCacheProxyImpl<>((GridCacheContext<K1, V1>)ctx,
-            (GridCacheAdapter<K1, V1>)delegate,
-            opCtx != null ? opCtx.keepBinary() :
-                new CacheOperationContext(false,
-                    false,
-                    true,
-                    null,
-                    false,
-                    null,
-                    false,
-                    null,
-                    null));
+            (GridCacheAdapter<K1, V1>)delegate, opCtx);

Review Comment:
   `keepBinary()` currently reassigns the proxy field `opCtx` (without even 
going through the cache gateway), which mutates this cache proxy instance. 
Projection methods are expected to return a new proxy with the extra flag while 
leaving the original projection unchanged; mutating `this.opCtx` can lead to 
surprising behavior and thread-safety issues if the same proxy is reused 
concurrently.



##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java:
##########
@@ -1604,17 +1578,37 @@ public IgniteInternalCache<K, V> delegate() {
         CacheOperationContext prev = gate.enter(opCtx);
 
         try {
-            return new GridCacheProxyImpl<>(ctx, delegate,
-                new CacheOperationContext(
-                    false,
-                    false,
-                    false,
-                    null,
-                    true,
-                    null,
-                    false,
-                    null,
-                    null));
+            if (opCtx != null) {
+                if (opCtx.noRetries())
+                    return this;
+                else
+                    opCtx = opCtx.withNoRetries();
+            }
+            else
+                opCtx = 
CacheOperationContext.builder().noRetries(true).build();
+
+            return new GridCacheProxyImpl<>(ctx, delegate, opCtx);
+        }
+        finally {
+            gate.leave(prev);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalCache<K, V> withCalciteEngine() {
+        CacheOperationContext prev = gate.enter(opCtx);
+
+        try {
+            if (opCtx != null) {
+                if (opCtx.calciteEngine())
+                    return this;
+                else
+                    opCtx = opCtx.withCalciteEngine();
+            }
+            else
+                opCtx = 
CacheOperationContext.builder().calciteEngine(true).build();
+
+            return new GridCacheProxyImpl<>(ctx, delegate, opCtx);

Review Comment:
   `withCalciteEngine()` reassigns the proxy field `opCtx` and then returns a 
new proxy. This mutates the current cache proxy instance, so callers can see 
unexpected flag changes on the original projection (and it can be racy when the 
proxy is shared). Compute the new context into a local variable and keep 
`this.opCtx` unchanged.



##########
modules/benchmarks/src/main/java/org/apache/ignite/internal/benchmarks/jmh/sql/JmhSqlInsertBenchmark.java:
##########
@@ -0,0 +1,142 @@
+/*
+ * 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.internal.benchmarks.jmh.sql;
+
+import java.util.concurrent.TimeUnit;
+import java.util.stream.IntStream;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.Threads;
+import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+
+import static java.lang.String.format;
+import static java.util.stream.Collectors.joining;
+
+/**
+ * Benchmark for insertion operation, comparing SQL APIs.
+ */
+@State(Scope.Benchmark)
+@Fork(1)
+@Threads(1)
+@Warmup(iterations = 10, time = 2)
+@Measurement(iterations = 10, time = 2)
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.MICROSECONDS)
+public class JmhSqlInsertBenchmark extends JmhSqlAbstractBenchmark {
+    /** */
+    private int id;
+
+    /** */
+    private static final String FIELD_VAL = "a".repeat(100);
+
+    /** */
+    private static final String TABLE_NAME = "dept";
+
+    /** */
+    private String insertStr;
+
+    /** */
+    private String multiInsertStr;
+
+    /**
+     * Initiate new tables.
+     */
+    @Override public void setup() {
+        super.setup();

Review Comment:
   `JmhSqlAbstractBenchmark.setup()` is annotated with `@Setup(Level.Trial)`, 
but this class overrides `setup()` without the `@Setup` annotation. In JMH, the 
override will hide the annotated base method, so the cluster/table 
initialization likely won’t run at all. Add `@Setup(Level.Trial)` on the 
overriding method (or rename the method) to ensure it is executed.



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