rpuch commented on code in PR #4974:
URL: https://github.com/apache/ignite-3/pull/4974#discussion_r1898574660


##########
modules/transactions/src/integrationTest/java/org/apache/ignite/internal/tx/readonly/ItReadOnlyTxAndLowWatermarkTest.java:
##########
@@ -0,0 +1,251 @@
+/*
+ * 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.tx.readonly;
+
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static java.util.stream.Collectors.toList;
+import static org.apache.ignite.internal.TestWrappers.unwrapIgniteImpl;
+import static 
org.apache.ignite.internal.TestWrappers.unwrapInternalTransaction;
+import static 
org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static 
org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.hasToString;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.isA;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assumptions.assumeFalse;
+
+import java.util.List;
+import java.util.stream.IntStream;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.lowwatermark.LowWatermarkImpl;
+import 
org.apache.ignite.internal.schema.configuration.GcExtensionConfiguration;
+import 
org.apache.ignite.internal.schema.configuration.LowWatermarkConfiguration;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.tx.impl.ResourceVacuumManager;
+import org.apache.ignite.lang.ErrorGroups.Transactions;
+import org.apache.ignite.lang.IgniteException;
+import org.apache.ignite.sql.ResultSet;
+import org.apache.ignite.sql.SqlException;
+import org.apache.ignite.sql.SqlRow;
+import org.apache.ignite.table.KeyValueView;
+import org.apache.ignite.tx.Transaction;
+import org.apache.ignite.tx.TransactionException;
+import org.apache.ignite.tx.TransactionOptions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EnumSource;
+import org.junitpioneer.jupiter.cartesian.CartesianTest;
+import org.junitpioneer.jupiter.cartesian.CartesianTest.Enum;
+import org.junitpioneer.jupiter.cartesian.CartesianTest.Values;
+
+class ItReadOnlyTxAndLowWatermarkTest extends ClusterPerTestIntegrationTest {
+    private static final String TABLE_NAME = "TEST_TABLE";
+
+    // 100 keys to make sure that at least one key ends up on every of 2 nodes.
+    private static final int KEY_COUNT = 100;
+
+    private static final long SHORT_DATA_AVAILABILITY_TIME_MS = 1000;
+
+    @Override
+    protected int initialNodes() {
+        // 2 nodes to have a non-coordinator node in cluster.
+        return 2;
+    }
+
+    @Override
+    protected void customizeInitParameters(InitParametersBuilder builder) {
+        builder.clusterConfiguration("ignite.gc.lowWatermark: {\n"
+                // Update frequently.
+                + "  updateInterval: 100\n"
+                + "}");
+    }
+
+    @BeforeEach
+    void createTable() {
+        node(0).sql().executeScript("CREATE TABLE " + TABLE_NAME + " (ID INT 
PRIMARY KEY, VAL VARCHAR)");
+    }
+
+    @ParameterizedTest
+    @EnumSource(TransactionalReader.class)
+    void 
roTransactionNoticesTupleVersionsMissingDueToGcOnDataNodes(TransactionalReader 
reader) throws Exception {
+        // TODO: remove the assumption when IGNITE-24119 is fixed.
+        assumeFalse(reader == TransactionalReader.MULTI_GET);
+
+        updateDataAvailabilityTimeToShortPeriod();
+
+        Ignite coordinator = node(0);
+        KeyValueView<Integer, String> kvView = kvView(coordinator);
+
+        insertOriginalValues(KEY_COUNT, kvView);
+
+        Transaction roTx = coordinator.transactions().begin(new 
TransactionOptions().readOnly(true));
+
+        updateToNewValues(KEY_COUNT, kvView);
+
+        waitTillLwmTriesToRaiseAndEraseOverrittenVersions();
+
+        IgniteException ex = assertThrows(IgniteException.class, () -> 
reader.read(coordinator, roTx));
+        assertThat(ex, isA(reader.sql() ? SqlException.class : 
TransactionException.class));
+        assertThat(ex, hasToString(containsString("Read timestamp is not 
available anymore.")));
+        assertThat("Wrong error code: " + ex.codeAsString(), ex.code(), 
is(Transactions.TX_STALE_READ_ONLY_OPERATION_ERR));
+    }
+
+    private void updateDataAvailabilityTimeToShortPeriod() {
+        IgniteImpl igniteImpl = unwrapIgniteImpl(node(0));
+
+        LowWatermarkConfiguration lwmConfig = igniteImpl.clusterConfiguration()
+                .getConfiguration(GcExtensionConfiguration.KEY)
+                .gc()
+                .lowWatermark();
+
+        
assertThat(lwmConfig.dataAvailabilityTime().update(SHORT_DATA_AVAILABILITY_TIME_MS),
 willCompleteSuccessfully());
+    }
+
+    private static KeyValueView<Integer, String> kvView(Ignite coordinator) {
+        return 
coordinator.tables().table(TABLE_NAME).keyValueView(Integer.class, 
String.class);
+    }
+
+    private static void insertOriginalValues(int keyCount, 
KeyValueView<Integer, String> kvView) {
+        for (int i = 0; i < keyCount; i++) {
+            kvView.put(null, i, "original-" + i);
+        }
+    }
+
+    private static void updateToNewValues(int keyCount, KeyValueView<Integer, 
String> kvView) {
+        for (int i = 0; i < keyCount; i++) {
+            kvView.put(null, i, "updated-" + i);
+        }
+    }
+
+    private static void waitTillLwmTriesToRaiseAndEraseOverrittenVersions() 
throws InterruptedException {
+        Thread.sleep(2 * SHORT_DATA_AVAILABILITY_TIME_MS);
+    }
+
+    @CartesianTest
+    @WithSystemProperty(key = 
ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = 
"100")
+    void lwmIsAllowedToBeRaisedOnDataNodesAfterRoTransactionFinish(

Review Comment:
   Added the corresponding test, it showed that this doesn't work, indeed. 
Implemented registration of transaction as a resource (analogous to cursors): 
on coordinator leave, the LWM is unlocked for this transaction



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