You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "denis-chudov (via GitHub)" <gi...@apache.org> on 2024/04/11 07:50:35 UTC
[PR] IGNITE-21763 [ignite-3]
denis-chudov opened a new pull request, #3591:
URL: https://github.com/apache/ignite-3/pull/3591
https://issues.apache.org/jira/browse/IGNITE-21763
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1581265831
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
+public class ItTxResourcesVacuumTest extends ClusterPerTestIntegrationTest {
+ /** Table name. */
+ private static final String TABLE_NAME = "test_table";
+
+ private static final Tuple INITIAL_TUPLE = Tuple.create().set("key", 1L).set("val", "1");
+
+ private static final Function<Tuple, Tuple> NEXT_TUPLE = t -> Tuple.create()
+ .set("key", t.longValue("key") + 1)
+ .set("val", "" + (t.longValue("key") + 1));
+
+ private static final int REPLICAS = 2;
Review Comment:
Added zone with 3 replicas in #testRoReadTheCorrectDataInBetween
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1578118915
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
+public class ItTxResourcesVacuumTest extends ClusterPerTestIntegrationTest {
+ /** Table name. */
+ private static final String TABLE_NAME = "test_table";
+
+ private static final Tuple INITIAL_TUPLE = Tuple.create().set("key", 1L).set("val", "1");
+
+ private static final Function<Tuple, Tuple> NEXT_TUPLE = t -> Tuple.create()
+ .set("key", t.longValue("key") + 1)
+ .set("val", "" + (t.longValue("key") + 1));
+
+ private static final int REPLICAS = 2;
Review Comment:
The case of not converted WI-s is covered in #testVacuumWithCleanupDelay.
The number of replica is 2 because it's less than cluster size (3 nodes), this allows to have some nodes that are not included to the commit partition group in some multi-partition transactions, and thus have only volatile state on them and never have persistent.
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1580520929
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTransactionTestUtils.java:
##########
@@ -0,0 +1,204 @@
+/*
+ * 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.table;
+
+import static java.util.Objects.requireNonNull;
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.TestWrappers.unwrapIgniteTransaction;
+import static org.apache.ignite.internal.TestWrappers.unwrapRecordBinaryViewImpl;
+import static org.apache.ignite.internal.TestWrappers.unwrapTableImpl;
+import static org.apache.ignite.internal.distributionzones.rebalance.RebalanceUtil.stablePartAssignmentsKey;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.Function;
+import org.apache.ignite.internal.affinity.Assignment;
+import org.apache.ignite.internal.affinity.Assignments;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.lang.ByteArray;
+import org.apache.ignite.internal.metastorage.Entry;
+import org.apache.ignite.internal.metastorage.MetaStorageManager;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.ReplicationGroupId;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.schema.BinaryRowEx;
+import org.apache.ignite.internal.tx.impl.ReadWriteTransactionImpl;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Test utils for transaction integration tests.
+ */
+public class ItTransactionTestUtils {
+ /**
+ * Get the names of the nodes that are assignments of the given partition.
+ *
+ * @param node Any node in the cluster.
+ * @param grpId Group id.
+ * @return Node names.
+ */
+ public static Set<String> partitionAssignment(IgniteImpl node, TablePartitionId grpId) {
Review Comment:
Test itself.
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1580570773
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
+public class ItTxResourcesVacuumTest extends ClusterPerTestIntegrationTest {
+ /** Table name. */
+ private static final String TABLE_NAME = "test_table";
+
+ private static final Tuple INITIAL_TUPLE = Tuple.create().set("key", 1L).set("val", "1");
+
+ private static final Function<Tuple, Tuple> NEXT_TUPLE = t -> Tuple.create()
+ .set("key", t.longValue("key") + 1)
+ .set("val", "" + (t.longValue("key") + 1));
+
+ private static final int REPLICAS = 2;
+
+ /** Nodes bootstrap configuration pattern. */
+ private static final String NODE_BOOTSTRAP_CFG_TEMPLATE = "{\n"
+ + " network: {\n"
+ + " port: {},\n"
+ + " nodeFinder: {\n"
+ + " netClusterNodes: [ {} ]\n"
+ + " }\n"
+ + " },\n"
+ + " clientConnector: { port:{} },\n"
+ + " rest.port: {},\n"
+ + " raft: { responseTimeout: 30000 },"
+ + " compute.threadPoolSize: 1\n"
+ + "}";
+
+ private ExecutorService txStateStorageExecutor = Executors.newSingleThreadExecutor();
+
+ @BeforeEach
+ @Override
+ public void setup(TestInfo testInfo) throws Exception {
+ super.setup(testInfo);
+
+ String zoneSql = "create zone test_zone with partitions=20, replicas=" + REPLICAS
+ + ", storage_profiles='" + DEFAULT_STORAGE_PROFILE + "'";
+ String sql = "create table " + TABLE_NAME + " (key bigint primary key, val varchar(20)) with primary_zone='TEST_ZONE'";
+
+ cluster.doInSession(0, session -> {
+ executeUpdate(zoneSql, session);
+ executeUpdate(sql, session);
+ });
+
+ txStateStorageExecutor = Executors.newSingleThreadExecutor(IgniteThreadFactory.create("test", "tx-state-storage-test-pool", log,
+ ThreadOperation.STORAGE_READ));
+ }
+
+ @Override
+ @AfterEach
+ public void tearDown() {
+ shutdownAndAwaitTermination(txStateStorageExecutor, 10, TimeUnit.SECONDS);
+
+ super.tearDown();
+ }
+
+ @Override
+ protected void customizeInitParameters(InitParametersBuilder builder) {
+ super.customizeInitParameters(builder);
+
+ builder.clusterConfiguration("{"
+ + " transaction: {"
+ + " implicitTransactionTimeout: 30000,"
+ + " txnResourceTtl: 2"
+ + " },"
+ + " replication: {"
+ + " rpcTimeout: 30000"
+ + " },"
+ + "}");
+ }
+
+ @Override
+ protected int initialNodes() {
+ return 3;
+ }
+
+ /**
+ * Returns node bootstrap config template.
+ *
+ * @return Node bootstrap config template.
+ */
+ @Override
+ protected String getNodeBootstrapConfigTemplate() {
+ return NODE_BOOTSTRAP_CFG_TEMPLATE;
+ }
+
+ @Test
+ public void testVacuum() throws InterruptedException {
+ IgniteImpl node = anyNode();
+
+ RecordView<Tuple> view = node.tables().table(TABLE_NAME).recordView();
+
+ // Put some value into the table.
+ Transaction tx = node.transactions().begin();
+ UUID txId = txId(tx);
+
+ log.info("Test: Loading the data [tx={}].", txId);
+
+ Tuple tuple = findTupleToBeHostedOnNode(node, TABLE_NAME, tx, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ int partId = partitionIdForTuple(node, TABLE_NAME, tuple, tx);
+
+ Set<String> nodes = partitionAssignment(node, new TablePartitionId(tableId(node, TABLE_NAME), partId));
+
+ view.upsert(tx, tuple);
+
+ tx.commit();
+
+ log.info("Test: Tx committed [tx={}].", txId);
+
+ checkVolatileTxStateOnNodes(nodes, txId);
+ waitForTxStateReplication(nodes, txId, partId, 10_000);
+
+ waitForTxStateVacuum(txId, partId, true, 10_000);
Review Comment:
In one test only?
--
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-21763 [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1569188055
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbStorage.java:
##########
@@ -231,12 +231,21 @@ public boolean compareAndSet(UUID txId, @Nullable TxState txStateExpected, TxMet
}
@Override
- public void remove(UUID txId) {
+ public void remove(UUID txId, long commandIndex, long commandTerm) {
Review Comment:
fixed
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1580546725
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
Review Comment:
Ok, I mean that it's definitely required to check scheduler based logic, but for some scenarios it's just not needed, thus it's possible to manually trigger vacuum() there. And I can't see such manual interactions in the test.
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1578107534
##########
modules/transactions/src/testFixtures/java/org/apache/ignite/internal/tx/storage/state/AbstractTxStateStorageTest.java:
##########
@@ -83,6 +86,21 @@ protected void afterTest() throws Exception {
@Test
public void testPutGetRemove() {
+ testPutGetRemove0((storage, txIds) -> {
+ int index = 0;
+
+ for (UUID txId : txIds) {
+ storage.remove(txId, index++, 1);
+ }
+ });
+ }
+
+ @Test
+ public void testPutGetRemoveAll() {
Review Comment:
will be discussed in [IGNITE-22094](https://issues.apache.org/jira/browse/IGNITE-22094)
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1582617995
##########
modules/index/build.gradle:
##########
@@ -76,6 +76,7 @@ dependencies {
integrationTestImplementation testFixtures(project(':ignite-sql-engine'))
integrationTestImplementation testFixtures(project(':ignite-table'))
integrationTestImplementation testFixtures(project(':ignite-storage-api'))
+ integrationTestImplementation testFixtures(project(':ignite-transactions'))
Review Comment:
Why?
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1575792698
##########
modules/transactions/src/testFixtures/java/org/apache/ignite/internal/tx/storage/state/test/TestTxStateStorage.java:
##########
@@ -108,10 +108,15 @@ public boolean compareAndSet(UUID txId, @Nullable TxState txStateExpected, TxMet
}
@Override
- public void remove(UUID txId) {
+ public void remove(UUID txId, long commandIndex, long commandTerm) {
checkStorageClosedOrInProgressOfRebalance();
storage.remove(txId);
+
+ if (rebalanceFutureReference.get() == null) {
+ lastAppliedIndex = commandIndex;
Review Comment:
in any case, the `put` issue is not related to this ticket, let's create a separate one
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1581266162
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
Review Comment:
changed to manual trigger in some tests
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1580522883
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTransactionTestUtils.java:
##########
@@ -0,0 +1,204 @@
+/*
+ * 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.table;
+
+import static java.util.Objects.requireNonNull;
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.TestWrappers.unwrapIgniteTransaction;
+import static org.apache.ignite.internal.TestWrappers.unwrapRecordBinaryViewImpl;
+import static org.apache.ignite.internal.TestWrappers.unwrapTableImpl;
+import static org.apache.ignite.internal.distributionzones.rebalance.RebalanceUtil.stablePartAssignmentsKey;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.Function;
+import org.apache.ignite.internal.affinity.Assignment;
+import org.apache.ignite.internal.affinity.Assignments;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.lang.ByteArray;
+import org.apache.ignite.internal.metastorage.Entry;
+import org.apache.ignite.internal.metastorage.MetaStorageManager;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.ReplicationGroupId;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.schema.BinaryRowEx;
+import org.apache.ignite.internal.tx.impl.ReadWriteTransactionImpl;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Test utils for transaction integration tests.
+ */
+public class ItTransactionTestUtils {
+ /**
+ * Get the names of the nodes that are assignments of the given partition.
+ *
+ * @param node Any node in the cluster.
+ * @param grpId Group id.
+ * @return Node names.
+ */
+ public static Set<String> partitionAssignment(IgniteImpl node, TablePartitionId grpId) {
+ MetaStorageManager metaStorageManager = node.metaStorageManager();
+
+ ByteArray stableAssignmentKey = stablePartAssignmentsKey(grpId);
+
+ CompletableFuture<Entry> assignmentEntryFut = metaStorageManager.get(stableAssignmentKey);
+
+ assertThat(assignmentEntryFut, willCompleteSuccessfully());
+
+ Entry e = assignmentEntryFut.join();
+
+ assertNotNull(e);
+ assertFalse(e.empty());
+ assertFalse(e.tombstone());
+
+ Set<Assignment> a = requireNonNull(Assignments.fromBytes(e.value())).nodes();
+
+ return a.stream().filter(Assignment::isPeer).map(Assignment::consistentId).collect(toSet());
+ }
+
+ /**
+ * Calculate the partition id on which the given tuple would be placed.
+ *
+ * @param node Any node in the cluster.
+ * @param tableName Table name.
+ * @param tuple Data tuple.
+ * @param tx Transaction, if present.
+ * @return Partition id.
+ */
+ public static int partitionIdForTuple(IgniteImpl node, String tableName, Tuple tuple, @Nullable Transaction tx) {
+ TableImpl table = table(node, tableName);
+ RecordBinaryViewImpl view = unwrapRecordBinaryViewImpl(table.recordView());
+
+ CompletableFuture<BinaryRowEx> rowFut = view.marshal(tx, tuple);
+ assertThat(rowFut, willCompleteSuccessfully());
+ BinaryRowEx row = rowFut.join();
+
+ return table.internalTable().partitionId(row);
+ }
+
+ /**
+ * Generates some tuple that would be placed in the partition that is hosted on the given node in the cluster.
+ *
+ * @param node Node that should host the result tuple.
+ * @param tableName Table name.
+ * @param tx Transaction, if present.
+ * @param initialTuple Initial tuple, for calculation.
+ * @param nextTuple This function will be used to generate new tuples in order to find suitable one.
+ * @param primary Whether the given node should be the primary node.
+ * @return Tuple that would be placed on the given node.
+ */
+ public static Tuple findTupleToBeHostedOnNode(
Review Comment:
There were several points/questions in my comment. E.g.
> why do we need transaction to find the tuple
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1580625506
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,798 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.TxState.FINISHING;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.message.TxFinishReplicaRequest;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.apache.ignite.tx.TransactionOptions;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
+public class ItTxResourcesVacuumTest extends ClusterPerTestIntegrationTest {
+ /** Table name. */
+ private static final String TABLE_NAME = "test_table";
+
+ private static final Tuple INITIAL_TUPLE = Tuple.create().set("key", 1L).set("val", "1");
+
+ private static final Function<Tuple, Tuple> NEXT_TUPLE = t -> Tuple.create()
+ .set("key", t.longValue("key") + 1)
+ .set("val", "" + (t.longValue("key") + 1));
+
+ private static final int REPLICAS = 2;
+
+ /** Nodes bootstrap configuration pattern. */
+ private static final String NODE_BOOTSTRAP_CFG_TEMPLATE = "{\n"
+ + " network: {\n"
+ + " port: {},\n"
+ + " nodeFinder: {\n"
+ + " netClusterNodes: [ {} ]\n"
+ + " }\n"
+ + " },\n"
+ + " clientConnector: { port:{} },\n"
+ + " rest.port: {},\n"
+ + " raft: { responseTimeout: 30000 },"
+ + " compute.threadPoolSize: 1\n"
+ + "}";
+
+ private ExecutorService txStateStorageExecutor = Executors.newSingleThreadExecutor();
+
+ @BeforeEach
+ @Override
+ public void setup(TestInfo testInfo) throws Exception {
+ super.setup(testInfo);
+
+ String zoneSql = "create zone test_zone with partitions=20, replicas=" + REPLICAS
+ + ", storage_profiles='" + DEFAULT_STORAGE_PROFILE + "'";
+ String sql = "create table " + TABLE_NAME + " (key bigint primary key, val varchar(20)) with primary_zone='TEST_ZONE'";
+
+ cluster.doInSession(0, session -> {
+ executeUpdate(zoneSql, session);
+ executeUpdate(sql, session);
+ });
+
+ txStateStorageExecutor = Executors.newSingleThreadExecutor(IgniteThreadFactory.create("test", "tx-state-storage-test-pool", log,
+ ThreadOperation.STORAGE_READ));
+ }
+
+ @Override
+ @AfterEach
+ public void tearDown() {
+ shutdownAndAwaitTermination(txStateStorageExecutor, 10, TimeUnit.SECONDS);
+
+ super.tearDown();
+ }
+
+ @Override
+ protected void customizeInitParameters(InitParametersBuilder builder) {
+ super.customizeInitParameters(builder);
+
+ builder.clusterConfiguration("{"
+ + " transaction: {"
+ + " txnResourceTtl: 1"
+ + " },"
+ + " replication: {"
+ + " rpcTimeout: 30000"
+ + " },"
+ + "}");
+ }
+
+ /**
+ * Returns node bootstrap config template.
+ *
+ * @return Node bootstrap config template.
+ */
+ @Override
+ protected String getNodeBootstrapConfigTemplate() {
+ return NODE_BOOTSTRAP_CFG_TEMPLATE;
+ }
+
+ /**
+ * Simple vacuum test, checking also that PENDING and FINISHING states are not removed.
+ *
+ * <ul>
+ * <li>Run a transaction;</li>
+ * <li>Insert a value;</li>
+ * <li>Wait 3 seconds;</li>
+ * <li>Check that the volatile PENDING state of the transaction is preserved;</li>
+ * <li>Block {@link TxFinishReplicaRequest};</li>
+ * <li>Start the tx commit;</li>
+ * <li>While the state is FINISHING, wait 3 seconds;</li>
+ * <li>Check that the volatile state of the transaction is preserved;</li>
+ * <li>Unblock {@link TxFinishReplicaRequest};</li>
+ * <li>Check that both volatile and persistent state is vacuumized;</li>
+ * <li>Check that the committed value is correct.</li>
+ * </ul>
+ */
+ @Test
+ public void testVacuum() throws InterruptedException {
+ IgniteImpl node = anyNode();
+
+ RecordView<Tuple> view = node.tables().table(TABLE_NAME).recordView();
+
+ // Put some value into the table.
+ Transaction tx = node.transactions().begin();
+ UUID txId = txId(tx);
+
+ log.info("Test: Loading the data [tx={}].", txId);
+
+ Tuple tuple = findTupleToBeHostedOnNode(node, TABLE_NAME, tx, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ int partId = partitionIdForTuple(node, TABLE_NAME, tuple, tx);
+
+ Set<String> nodes = partitionAssignment(node, new TablePartitionId(tableId(node, TABLE_NAME), partId));
+
+ view.upsert(tx, tuple);
+
+ // Check that the volatile PENDING state of the transaction is preserved.
+ Thread.sleep(3000);
Review Comment:
Let's adjust the test in order to have waitForCondition instead of Thread.sleep. In case of no-action awaiting, let's just check that vacuumization happened but pending still there.
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc merged PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591
--
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-21763 [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1569190398
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/VolatileTxStateMetaStorage.java:
##########
@@ -118,35 +129,56 @@ public Collection<TxStateMeta> states() {
* @param vacuumObservationTimestamp Timestamp of the vacuum attempt.
* @param txnResourceTtl Transactional resource time to live in milliseconds.
*/
- public void vacuum(long vacuumObservationTimestamp, long txnResourceTtl) {
+ public void vacuum(
+ long vacuumObservationTimestamp,
+ long txnResourceTtl,
+ Function<Map<TablePartitionId, Set<UUID>>, CompletableFuture<IgniteBiTuple<Set<UUID>, Integer>>> beforeVacuum
+ ) {
LOG.info("Vacuum started [vacuumObservationTimestamp={}, txnResourceTtl={}].", vacuumObservationTimestamp, txnResourceTtl);
AtomicInteger vacuumizedTxnsCount = new AtomicInteger(0);
AtomicInteger markedAsInitiallyDetectedTxnsCount = new AtomicInteger(0);
AtomicInteger alreadyMarkedTxnsCount = new AtomicInteger(0);
AtomicInteger skippedFotFurtherProcessingUnfinishedTxnsCount = new AtomicInteger(0);
+ Map<TablePartitionId, Set<UUID>> txIds = new HashMap<>();
+ Map<UUID, Long> timestamps = new HashMap<>();
+
txStateMap.forEach((txId, meta) -> {
txStateMap.computeIfPresent(txId, (txId0, meta0) -> {
if (TxState.isFinalState(meta0.txState())) {
- if (txnResourceTtl == 0) {
Review Comment:
it's not like skipped, I moved it to `shouldBeVacuumized` for the sake of better readability
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1572498142
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/raft/PartitionListener.java:
##########
@@ -406,18 +413,18 @@ private UpdateCommandResult handleUpdateAllCommand(UpdateAllCommand cmd, long co
* Handler for the {@link WriteIntentSwitchCommand}.
*
* @param cmd Command.
- * @param commandIndex Index of the RAFT command.
- * @param commandTerm Term of the RAFT command.
+ * @param commandIndex Index of the RAFT cmd.
+ * @param commandTerm Term of the RAFT cmd.
*/
private void handleWriteIntentSwitchCommand(WriteIntentSwitchCommand cmd, long commandIndex, long commandTerm) {
- // Skips the write command because the storage has already executed it.
+ // Skips the write cmd because the storage has already executed it.
if (commandIndex <= storage.lastAppliedIndex()) {
return;
}
UUID txId = cmd.txId();
- markFinished(txId, cmd.commit(), cmd.commitTimestamp());
+ markFinished(txId, cmd.commit(), cmd.commitTimestamp(), null);
Review Comment:
And why we need it to be present on all nodes of commit partition?
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1581266601
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
+public class ItTxResourcesVacuumTest extends ClusterPerTestIntegrationTest {
+ /** Table name. */
+ private static final String TABLE_NAME = "test_table";
+
+ private static final Tuple INITIAL_TUPLE = Tuple.create().set("key", 1L).set("val", "1");
+
+ private static final Function<Tuple, Tuple> NEXT_TUPLE = t -> Tuple.create()
+ .set("key", t.longValue("key") + 1)
+ .set("val", "" + (t.longValue("key") + 1));
+
+ private static final int REPLICAS = 2;
+
+ /** Nodes bootstrap configuration pattern. */
+ private static final String NODE_BOOTSTRAP_CFG_TEMPLATE = "{\n"
+ + " network: {\n"
+ + " port: {},\n"
+ + " nodeFinder: {\n"
+ + " netClusterNodes: [ {} ]\n"
+ + " }\n"
+ + " },\n"
+ + " clientConnector: { port:{} },\n"
+ + " rest.port: {},\n"
+ + " raft: { responseTimeout: 30000 },"
+ + " compute.threadPoolSize: 1\n"
+ + "}";
+
+ private ExecutorService txStateStorageExecutor = Executors.newSingleThreadExecutor();
+
+ @BeforeEach
+ @Override
+ public void setup(TestInfo testInfo) throws Exception {
+ super.setup(testInfo);
+
+ String zoneSql = "create zone test_zone with partitions=20, replicas=" + REPLICAS
+ + ", storage_profiles='" + DEFAULT_STORAGE_PROFILE + "'";
+ String sql = "create table " + TABLE_NAME + " (key bigint primary key, val varchar(20)) with primary_zone='TEST_ZONE'";
+
+ cluster.doInSession(0, session -> {
+ executeUpdate(zoneSql, session);
+ executeUpdate(sql, session);
+ });
+
+ txStateStorageExecutor = Executors.newSingleThreadExecutor(IgniteThreadFactory.create("test", "tx-state-storage-test-pool", log,
+ ThreadOperation.STORAGE_READ));
+ }
+
+ @Override
+ @AfterEach
+ public void tearDown() {
+ shutdownAndAwaitTermination(txStateStorageExecutor, 10, TimeUnit.SECONDS);
+
+ super.tearDown();
+ }
+
+ @Override
+ protected void customizeInitParameters(InitParametersBuilder builder) {
+ super.customizeInitParameters(builder);
+
+ builder.clusterConfiguration("{"
+ + " transaction: {"
+ + " implicitTransactionTimeout: 30000,"
+ + " txnResourceTtl: 2"
+ + " },"
+ + " replication: {"
+ + " rpcTimeout: 30000"
+ + " },"
+ + "}");
+ }
+
+ @Override
+ protected int initialNodes() {
+ return 3;
+ }
+
+ /**
+ * Returns node bootstrap config template.
+ *
+ * @return Node bootstrap config template.
+ */
+ @Override
+ protected String getNodeBootstrapConfigTemplate() {
+ return NODE_BOOTSTRAP_CFG_TEMPLATE;
+ }
+
+ @Test
+ public void testVacuum() throws InterruptedException {
+ IgniteImpl node = anyNode();
+
+ RecordView<Tuple> view = node.tables().table(TABLE_NAME).recordView();
+
+ // Put some value into the table.
+ Transaction tx = node.transactions().begin();
+ UUID txId = txId(tx);
+
+ log.info("Test: Loading the data [tx={}].", txId);
+
+ Tuple tuple = findTupleToBeHostedOnNode(node, TABLE_NAME, tx, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ int partId = partitionIdForTuple(node, TABLE_NAME, tuple, tx);
+
+ Set<String> nodes = partitionAssignment(node, new TablePartitionId(tableId(node, TABLE_NAME), partId));
+
+ view.upsert(tx, tuple);
+
+ tx.commit();
+
+ log.info("Test: Tx committed [tx={}].", txId);
+
+ checkVolatileTxStateOnNodes(nodes, txId);
+ waitForTxStateReplication(nodes, txId, partId, 10_000);
+
+ waitForTxStateVacuum(txId, partId, true, 10_000);
Review Comment:
added more RO checks
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/PersistentTxStateVacuumizer.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.internal.tx.impl;
+
+import static org.apache.ignite.internal.util.CompletableFutures.allOf;
+import static org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture;
+import static org.apache.ignite.internal.util.ExceptionUtils.unwrapCause;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import org.apache.ignite.internal.hlc.ClockService;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.placementdriver.PlacementDriver;
+import org.apache.ignite.internal.replicator.ReplicaService;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.replicator.exception.PrimaryReplicaMissException;
+import org.apache.ignite.internal.tx.message.TxMessagesFactory;
+import org.apache.ignite.internal.tx.message.VacuumTxStateReplicaRequest;
+import org.apache.ignite.network.ClusterNode;
+
+/**
+ * Implements the logic of persistent tx states vacuum.
+ */
+public class PersistentTxStateVacuumizer {
+ private static final IgniteLogger LOG = Loggers.forClass(PersistentTxStateVacuumizer.class);
+
+ private static final TxMessagesFactory TX_MESSAGES_FACTORY = new TxMessagesFactory();
+
+ private final ReplicaService replicaService;
+
+ private final ClusterNode localNode;
+
+ private final ClockService clockService;
+
+ private final PlacementDriver placementDriver;
+
+ /**
+ * Constructor.
+ *
+ * @param replicaService Replica service.
+ * @param localNode Local node.
+ * @param clockService Clock service.
+ * @param placementDriver Placement driver.
+ */
+ public PersistentTxStateVacuumizer(
+ ReplicaService replicaService,
+ ClusterNode localNode,
+ ClockService clockService,
+ PlacementDriver placementDriver
+ ) {
+ this.replicaService = replicaService;
+ this.localNode = localNode;
+ this.clockService = clockService;
+ this.placementDriver = placementDriver;
+ }
+
+ /**
+ * Vacuum persistent tx states.
+ *
+ * @param txIds Transaction ids to vacuum; map of commit partition ids to sets of tx ids.
+ * @return A future, result is the set of successfully vacuumized txn states.
+ */
+ public CompletableFuture<Set<UUID>> vacuumPersistentTxStates(Map<TablePartitionId, Set<UUID>> txIds) {
+ Set<UUID> successful = ConcurrentHashMap.newKeySet();
+ List<CompletableFuture<?>> futures = new ArrayList<>();
+ HybridTimestamp now = clockService.now();
+
+ txIds.forEach((commitPartitionId, txs) -> {
+ CompletableFuture<?> future = placementDriver.getPrimaryReplica(commitPartitionId, now)
+ .thenCompose(replicaMeta -> {
+ // If the primary replica is absent this means that another replica would become primary and
Review Comment:
fixed
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1579029801
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
+public class ItTxResourcesVacuumTest extends ClusterPerTestIntegrationTest {
+ /** Table name. */
+ private static final String TABLE_NAME = "test_table";
+
+ private static final Tuple INITIAL_TUPLE = Tuple.create().set("key", 1L).set("val", "1");
+
+ private static final Function<Tuple, Tuple> NEXT_TUPLE = t -> Tuple.create()
+ .set("key", t.longValue("key") + 1)
+ .set("val", "" + (t.longValue("key") + 1));
+
+ private static final int REPLICAS = 2;
+
+ /** Nodes bootstrap configuration pattern. */
+ private static final String NODE_BOOTSTRAP_CFG_TEMPLATE = "{\n"
+ + " network: {\n"
+ + " port: {},\n"
+ + " nodeFinder: {\n"
+ + " netClusterNodes: [ {} ]\n"
+ + " }\n"
+ + " },\n"
+ + " clientConnector: { port:{} },\n"
+ + " rest.port: {},\n"
+ + " raft: { responseTimeout: 30000 },"
+ + " compute.threadPoolSize: 1\n"
+ + "}";
+
+ private ExecutorService txStateStorageExecutor = Executors.newSingleThreadExecutor();
+
+ @BeforeEach
+ @Override
+ public void setup(TestInfo testInfo) throws Exception {
+ super.setup(testInfo);
+
+ String zoneSql = "create zone test_zone with partitions=20, replicas=" + REPLICAS
+ + ", storage_profiles='" + DEFAULT_STORAGE_PROFILE + "'";
+ String sql = "create table " + TABLE_NAME + " (key bigint primary key, val varchar(20)) with primary_zone='TEST_ZONE'";
+
+ cluster.doInSession(0, session -> {
+ executeUpdate(zoneSql, session);
+ executeUpdate(sql, session);
+ });
+
+ txStateStorageExecutor = Executors.newSingleThreadExecutor(IgniteThreadFactory.create("test", "tx-state-storage-test-pool", log,
+ ThreadOperation.STORAGE_READ));
+ }
+
+ @Override
+ @AfterEach
+ public void tearDown() {
+ shutdownAndAwaitTermination(txStateStorageExecutor, 10, TimeUnit.SECONDS);
+
+ super.tearDown();
+ }
+
+ @Override
+ protected void customizeInitParameters(InitParametersBuilder builder) {
+ super.customizeInitParameters(builder);
+
+ builder.clusterConfiguration("{"
+ + " transaction: {"
+ + " implicitTransactionTimeout: 30000,"
+ + " txnResourceTtl: 2"
+ + " },"
+ + " replication: {"
+ + " rpcTimeout: 30000"
+ + " },"
+ + "}");
+ }
+
+ @Override
+ protected int initialNodes() {
+ return 3;
+ }
+
+ /**
+ * Returns node bootstrap config template.
+ *
+ * @return Node bootstrap config template.
+ */
+ @Override
+ protected String getNodeBootstrapConfigTemplate() {
+ return NODE_BOOTSTRAP_CFG_TEMPLATE;
+ }
+
+ @Test
+ public void testVacuum() throws InterruptedException {
+ IgniteImpl node = anyNode();
+
+ RecordView<Tuple> view = node.tables().table(TABLE_NAME).recordView();
+
+ // Put some value into the table.
+ Transaction tx = node.transactions().begin();
+ UUID txId = txId(tx);
+
+ log.info("Test: Loading the data [tx={}].", txId);
+
+ Tuple tuple = findTupleToBeHostedOnNode(node, TABLE_NAME, tx, INITIAL_TUPLE, NEXT_TUPLE, true);
Review Comment:
I believe so, for example, there are the scenarios when we have one value that is going to be hosted on 2 replicas of 2 nodes of 3, and w should generate some value that would be hosted on 3rd node. At least, having the utility method that is able to generate such value is the easiest way to do so, isn't it?
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
+public class ItTxResourcesVacuumTest extends ClusterPerTestIntegrationTest {
+ /** Table name. */
+ private static final String TABLE_NAME = "test_table";
+
+ private static final Tuple INITIAL_TUPLE = Tuple.create().set("key", 1L).set("val", "1");
+
+ private static final Function<Tuple, Tuple> NEXT_TUPLE = t -> Tuple.create()
+ .set("key", t.longValue("key") + 1)
+ .set("val", "" + (t.longValue("key") + 1));
+
+ private static final int REPLICAS = 2;
+
+ /** Nodes bootstrap configuration pattern. */
+ private static final String NODE_BOOTSTRAP_CFG_TEMPLATE = "{\n"
+ + " network: {\n"
+ + " port: {},\n"
+ + " nodeFinder: {\n"
+ + " netClusterNodes: [ {} ]\n"
+ + " }\n"
+ + " },\n"
+ + " clientConnector: { port:{} },\n"
+ + " rest.port: {},\n"
+ + " raft: { responseTimeout: 30000 },"
+ + " compute.threadPoolSize: 1\n"
+ + "}";
+
+ private ExecutorService txStateStorageExecutor = Executors.newSingleThreadExecutor();
+
+ @BeforeEach
+ @Override
+ public void setup(TestInfo testInfo) throws Exception {
+ super.setup(testInfo);
+
+ String zoneSql = "create zone test_zone with partitions=20, replicas=" + REPLICAS
+ + ", storage_profiles='" + DEFAULT_STORAGE_PROFILE + "'";
+ String sql = "create table " + TABLE_NAME + " (key bigint primary key, val varchar(20)) with primary_zone='TEST_ZONE'";
+
+ cluster.doInSession(0, session -> {
+ executeUpdate(zoneSql, session);
+ executeUpdate(sql, session);
+ });
+
+ txStateStorageExecutor = Executors.newSingleThreadExecutor(IgniteThreadFactory.create("test", "tx-state-storage-test-pool", log,
+ ThreadOperation.STORAGE_READ));
+ }
+
+ @Override
+ @AfterEach
+ public void tearDown() {
+ shutdownAndAwaitTermination(txStateStorageExecutor, 10, TimeUnit.SECONDS);
+
+ super.tearDown();
+ }
+
+ @Override
+ protected void customizeInitParameters(InitParametersBuilder builder) {
+ super.customizeInitParameters(builder);
+
+ builder.clusterConfiguration("{"
+ + " transaction: {"
+ + " implicitTransactionTimeout: 30000,"
+ + " txnResourceTtl: 2"
+ + " },"
+ + " replication: {"
+ + " rpcTimeout: 30000"
+ + " },"
+ + "}");
+ }
+
+ @Override
+ protected int initialNodes() {
+ return 3;
+ }
+
+ /**
+ * Returns node bootstrap config template.
+ *
+ * @return Node bootstrap config template.
+ */
+ @Override
+ protected String getNodeBootstrapConfigTemplate() {
+ return NODE_BOOTSTRAP_CFG_TEMPLATE;
+ }
+
+ @Test
+ public void testVacuum() throws InterruptedException {
+ IgniteImpl node = anyNode();
+
+ RecordView<Tuple> view = node.tables().table(TABLE_NAME).recordView();
+
+ // Put some value into the table.
+ Transaction tx = node.transactions().begin();
+ UUID txId = txId(tx);
+
+ log.info("Test: Loading the data [tx={}].", txId);
+
+ Tuple tuple = findTupleToBeHostedOnNode(node, TABLE_NAME, tx, INITIAL_TUPLE, NEXT_TUPLE, true);
Review Comment:
I believe so, for example, there are the scenarios when we have one value that is going to be hosted on 2 replicas of 2 nodes of 3, and we should generate some value that would be hosted on 3rd node. At least, having the utility method that is able to generate such value is the easiest way to do so, isn't it?
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1580546725
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
Review Comment:
Ok, I mean that it's definitely required to check scheduler based logic, but for some scenarios it's just not needed, thus it's possible to manually trigger vacuum() there. And I can't see such manual interactions in the test. I believe that it might reduce test run time, that is currently 2 minutes locally.
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1582618998
##########
modules/placement-driver/build.gradle:
##########
@@ -66,6 +66,7 @@ dependencies {
integrationTestImplementation(testFixtures(project(':ignite-distribution-zones')))
integrationTestImplementation(testFixtures(project(':ignite-runner')))
integrationTestImplementation(testFixtures(project(':ignite-replicator')))
+ integrationTestImplementation(testFixtures(project(':ignite-transactions')))
Review Comment:
I believe it's because of ItTransactionTestUtils, right? If it is, it's incorrect, placement driver and others should not depend on ignite-transactions, even in case of test dependencies. Please consider moving ItTransactionTestUtils to some common module - "core" 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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1578076743
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/PersistentTxStateVacuumizer.java:
##########
@@ -0,0 +1,124 @@
+/*
+ * 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.impl;
+
+import static org.apache.ignite.internal.util.CompletableFutures.allOf;
+import static org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture;
+import static org.apache.ignite.internal.util.ExceptionUtils.unwrapCause;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import org.apache.ignite.internal.hlc.ClockService;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.placementdriver.PlacementDriver;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.ReplicaService;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.replicator.exception.PrimaryReplicaMissException;
+import org.apache.ignite.internal.tx.message.TxMessagesFactory;
+import org.apache.ignite.internal.tx.message.VacuumTxStateReplicaRequest;
+import org.apache.ignite.network.ClusterNode;
+
+/**
+ * Implements the logic of persistent tx states vacuum.
+ */
+public class PersistentTxStateVacuumizer {
+ private static final IgniteLogger LOG = Loggers.forClass(PersistentTxStateVacuumizer.class);
+
+ private static final TxMessagesFactory TX_MESSAGES_FACTORY = new TxMessagesFactory();
+
+ private final ReplicaService replicaService;
+
+ private final ClusterNode localNode;
+
+ private final ClockService clockService;
+
+ private final PlacementDriver placementDriver;
+
+ /**
+ * Constructor.
+ *
+ * @param replicaService Replica service.
+ * @param localNode Local node.
+ * @param clockService Clock service.
+ * @param placementDriver Placement driver.
+ */
+ public PersistentTxStateVacuumizer(
+ ReplicaService replicaService,
+ ClusterNode localNode,
+ ClockService clockService,
+ PlacementDriver placementDriver
+ ) {
+ this.replicaService = replicaService;
+ this.localNode = localNode;
+ this.clockService = clockService;
+ this.placementDriver = placementDriver;
+ }
+
+ /**
+ * Vacuum persistent tx states.
+ *
+ * @param txIds Transaction ids to vacuum; map of commit partition ids to sets of tx ids.
+ * @return A future, result is the set of successfully vacuumized txn states.
+ */
+ public CompletableFuture<Set<UUID>> vacuumPersistentTxStates(Map<TablePartitionId, Set<UUID>> txIds) {
+ Set<UUID> successful = ConcurrentHashMap.newKeySet();
+ List<CompletableFuture<?>> futures = new ArrayList<>();
+ HybridTimestamp now = clockService.now();
+
+ txIds.forEach((commitPartitionId, txs) -> {
+ ReplicaMeta replicaMeta = placementDriver.getPrimaryReplica(commitPartitionId, now).join();
+
+ if (replicaMeta != null) {
+ VacuumTxStateReplicaRequest request = TX_MESSAGES_FACTORY.vacuumTxStateReplicaRequest()
+ .enlistmentConsistencyToken(replicaMeta.getStartTime().longValue())
+ .groupId(commitPartitionId)
+ .transactionIds(txs)
+ .build();
+
+ CompletableFuture<?> future;
+
+ if (localNode.id().equals(replicaMeta.getLeaseholderId())) {
Review Comment:
added 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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1578123209
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
Review Comment:
`igniteNode.txManager().vacuum()` - test only
But here I need to have this shortened vacuum interval and test methods waiting for vacuum because
- I can't be sure that the corresponding tx state meets the requirements to be vacuumized by the moment I call `txManager().vacuum()
- the vacuum is two step, so I would need more than 1 manual call with a time interval between calls
- the vacuum runs async tx state vacuum request
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1578243327
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
+public class ItTxResourcesVacuumTest extends ClusterPerTestIntegrationTest {
+ /** Table name. */
+ private static final String TABLE_NAME = "test_table";
+
+ private static final Tuple INITIAL_TUPLE = Tuple.create().set("key", 1L).set("val", "1");
+
+ private static final Function<Tuple, Tuple> NEXT_TUPLE = t -> Tuple.create()
+ .set("key", t.longValue("key") + 1)
+ .set("val", "" + (t.longValue("key") + 1));
+
+ private static final int REPLICAS = 2;
+
+ /** Nodes bootstrap configuration pattern. */
+ private static final String NODE_BOOTSTRAP_CFG_TEMPLATE = "{\n"
+ + " network: {\n"
+ + " port: {},\n"
+ + " nodeFinder: {\n"
+ + " netClusterNodes: [ {} ]\n"
+ + " }\n"
+ + " },\n"
+ + " clientConnector: { port:{} },\n"
+ + " rest.port: {},\n"
+ + " raft: { responseTimeout: 30000 },"
+ + " compute.threadPoolSize: 1\n"
+ + "}";
+
+ private ExecutorService txStateStorageExecutor = Executors.newSingleThreadExecutor();
+
+ @BeforeEach
+ @Override
+ public void setup(TestInfo testInfo) throws Exception {
+ super.setup(testInfo);
+
+ String zoneSql = "create zone test_zone with partitions=20, replicas=" + REPLICAS
+ + ", storage_profiles='" + DEFAULT_STORAGE_PROFILE + "'";
+ String sql = "create table " + TABLE_NAME + " (key bigint primary key, val varchar(20)) with primary_zone='TEST_ZONE'";
+
+ cluster.doInSession(0, session -> {
+ executeUpdate(zoneSql, session);
+ executeUpdate(sql, session);
+ });
+
+ txStateStorageExecutor = Executors.newSingleThreadExecutor(IgniteThreadFactory.create("test", "tx-state-storage-test-pool", log,
+ ThreadOperation.STORAGE_READ));
+ }
+
+ @Override
+ @AfterEach
+ public void tearDown() {
+ shutdownAndAwaitTermination(txStateStorageExecutor, 10, TimeUnit.SECONDS);
+
+ super.tearDown();
+ }
+
+ @Override
+ protected void customizeInitParameters(InitParametersBuilder builder) {
+ super.customizeInitParameters(builder);
+
+ builder.clusterConfiguration("{"
+ + " transaction: {"
+ + " implicitTransactionTimeout: 30000,"
+ + " txnResourceTtl: 2"
+ + " },"
+ + " replication: {"
+ + " rpcTimeout: 30000"
+ + " },"
+ + "}");
+ }
+
+ @Override
+ protected int initialNodes() {
+ return 3;
+ }
+
+ /**
+ * Returns node bootstrap config template.
+ *
+ * @return Node bootstrap config template.
+ */
+ @Override
+ protected String getNodeBootstrapConfigTemplate() {
+ return NODE_BOOTSTRAP_CFG_TEMPLATE;
+ }
+
+ @Test
Review Comment:
Added test related to abandoned tx.
--
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-21763 [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1569191487
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/VolatileTxStateMetaStorage.java:
##########
@@ -155,14 +187,62 @@ public void vacuum(long vacuumObservationTimestamp, long txnResourceTtl) {
});
});
- LOG.info("Vacuum finished [vacuumObservationTimestamp={}, txnResourceTtl={}, vacuumizedTxnsCount={},"
- + " markedAsInitiallyDetectedTxnsCount={}, alreadyMarkedTxnsCount={}, skippedFotFurtherProcessingUnfinishedTxnsCount={}].",
- vacuumObservationTimestamp,
- txnResourceTtl,
- vacuumizedTxnsCount,
- markedAsInitiallyDetectedTxnsCount,
- alreadyMarkedTxnsCount,
- skippedFotFurtherProcessingUnfinishedTxnsCount
+ beforeVacuum.apply(txIds)
+ .thenAccept(tuple -> {
+ Set<UUID> successful = tuple.get1();
+
+ for (UUID txId : successful) {
+ txStateMap.compute(txId, (k, v) -> {
+ if (v == null) {
+ return null;
+ } else {
+ Long cleanupCompletionTs = timestamps.get(txId);
+
+ return (cleanupCompletionTs != null && Objects.equals(cleanupCompletionTs, v.cleanupCompletionTimestamp()))
Review Comment:
changed this condition
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1575066409
##########
modules/runner/src/testFixtures/java/org/apache/ignite/internal/table/NodeUtils.java:
##########
@@ -49,16 +50,16 @@ public class NodeUtils {
*
* @param nodes Nodes collection.
* @param groupId Group id.
- * @param preferablePrimary Primary replica name which is preferred for being primary or {@code null}.
+ * @param preferablePrimaryFilter Primary replica preferable nodes filter, accepts the node consistent id.
* @return New primary replica name.
* @throws InterruptedException If failed.
*/
public static String transferPrimary(
Collection<IgniteImpl> nodes,
ReplicationGroupId groupId,
- @Nullable String preferablePrimary
+ @Nullable Predicate<String> preferablePrimaryFilter
Review Comment:
Is it all about ::contains support? Don't you think that it's a bit too complicated?
Anyway, I'd definitely preserve original method as sugar.
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1582617995
##########
modules/index/build.gradle:
##########
@@ -76,6 +76,7 @@ dependencies {
integrationTestImplementation testFixtures(project(':ignite-sql-engine'))
integrationTestImplementation testFixtures(project(':ignite-table'))
integrationTestImplementation testFixtures(project(':ignite-storage-api'))
+ integrationTestImplementation testFixtures(project(':ignite-transactions'))
Review Comment:
Why?
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1582642453
##########
modules/placement-driver/build.gradle:
##########
@@ -66,6 +66,7 @@ dependencies {
integrationTestImplementation(testFixtures(project(':ignite-distribution-zones')))
integrationTestImplementation(testFixtures(project(':ignite-runner')))
integrationTestImplementation(testFixtures(project(':ignite-replicator')))
+ integrationTestImplementation(testFixtures(project(':ignite-transactions')))
Review Comment:
It's because of TestWrappers which I moved to transactions from runner. I thought about moving them to core but there are many of higher-level entities like TableImpl.
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1578066810
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTransactionTestUtils.java:
##########
@@ -0,0 +1,204 @@
+/*
+ * 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.table;
+
+import static java.util.Objects.requireNonNull;
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.TestWrappers.unwrapIgniteTransaction;
+import static org.apache.ignite.internal.TestWrappers.unwrapRecordBinaryViewImpl;
+import static org.apache.ignite.internal.TestWrappers.unwrapTableImpl;
+import static org.apache.ignite.internal.distributionzones.rebalance.RebalanceUtil.stablePartAssignmentsKey;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.Function;
+import org.apache.ignite.internal.affinity.Assignment;
+import org.apache.ignite.internal.affinity.Assignments;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.lang.ByteArray;
+import org.apache.ignite.internal.metastorage.Entry;
+import org.apache.ignite.internal.metastorage.MetaStorageManager;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.ReplicationGroupId;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.schema.BinaryRowEx;
+import org.apache.ignite.internal.tx.impl.ReadWriteTransactionImpl;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Test utils for transaction integration tests.
+ */
+public class ItTransactionTestUtils {
Review Comment:
moved to ignite-transactions test fixtures
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1578242823
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
+public class ItTxResourcesVacuumTest extends ClusterPerTestIntegrationTest {
+ /** Table name. */
+ private static final String TABLE_NAME = "test_table";
+
+ private static final Tuple INITIAL_TUPLE = Tuple.create().set("key", 1L).set("val", "1");
+
+ private static final Function<Tuple, Tuple> NEXT_TUPLE = t -> Tuple.create()
+ .set("key", t.longValue("key") + 1)
+ .set("val", "" + (t.longValue("key") + 1));
+
+ private static final int REPLICAS = 2;
+
+ /** Nodes bootstrap configuration pattern. */
+ private static final String NODE_BOOTSTRAP_CFG_TEMPLATE = "{\n"
+ + " network: {\n"
+ + " port: {},\n"
+ + " nodeFinder: {\n"
+ + " netClusterNodes: [ {} ]\n"
+ + " }\n"
+ + " },\n"
+ + " clientConnector: { port:{} },\n"
+ + " rest.port: {},\n"
+ + " raft: { responseTimeout: 30000 },"
+ + " compute.threadPoolSize: 1\n"
+ + "}";
+
+ private ExecutorService txStateStorageExecutor = Executors.newSingleThreadExecutor();
+
+ @BeforeEach
+ @Override
+ public void setup(TestInfo testInfo) throws Exception {
+ super.setup(testInfo);
+
+ String zoneSql = "create zone test_zone with partitions=20, replicas=" + REPLICAS
+ + ", storage_profiles='" + DEFAULT_STORAGE_PROFILE + "'";
+ String sql = "create table " + TABLE_NAME + " (key bigint primary key, val varchar(20)) with primary_zone='TEST_ZONE'";
+
+ cluster.doInSession(0, session -> {
+ executeUpdate(zoneSql, session);
+ executeUpdate(sql, session);
+ });
+
+ txStateStorageExecutor = Executors.newSingleThreadExecutor(IgniteThreadFactory.create("test", "tx-state-storage-test-pool", log,
+ ThreadOperation.STORAGE_READ));
+ }
+
+ @Override
+ @AfterEach
+ public void tearDown() {
+ shutdownAndAwaitTermination(txStateStorageExecutor, 10, TimeUnit.SECONDS);
+
+ super.tearDown();
+ }
+
+ @Override
+ protected void customizeInitParameters(InitParametersBuilder builder) {
+ super.customizeInitParameters(builder);
+
+ builder.clusterConfiguration("{"
+ + " transaction: {"
+ + " implicitTransactionTimeout: 30000,"
+ + " txnResourceTtl: 2"
+ + " },"
+ + " replication: {"
+ + " rpcTimeout: 30000"
+ + " },"
+ + "}");
+ }
+
+ @Override
+ protected int initialNodes() {
+ return 3;
+ }
+
+ /**
+ * Returns node bootstrap config template.
+ *
+ * @return Node bootstrap config template.
+ */
+ @Override
+ protected String getNodeBootstrapConfigTemplate() {
+ return NODE_BOOTSTRAP_CFG_TEMPLATE;
+ }
+
Review Comment:
Checks that pending and finishing transactions are not vacuumized are added to txVacuumTest.
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1578240205
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
+public class ItTxResourcesVacuumTest extends ClusterPerTestIntegrationTest {
+ /** Table name. */
+ private static final String TABLE_NAME = "test_table";
+
+ private static final Tuple INITIAL_TUPLE = Tuple.create().set("key", 1L).set("val", "1");
+
+ private static final Function<Tuple, Tuple> NEXT_TUPLE = t -> Tuple.create()
+ .set("key", t.longValue("key") + 1)
+ .set("val", "" + (t.longValue("key") + 1));
+
+ private static final int REPLICAS = 2;
+
+ /** Nodes bootstrap configuration pattern. */
+ private static final String NODE_BOOTSTRAP_CFG_TEMPLATE = "{\n"
+ + " network: {\n"
+ + " port: {},\n"
+ + " nodeFinder: {\n"
+ + " netClusterNodes: [ {} ]\n"
+ + " }\n"
+ + " },\n"
+ + " clientConnector: { port:{} },\n"
+ + " rest.port: {},\n"
+ + " raft: { responseTimeout: 30000 },"
+ + " compute.threadPoolSize: 1\n"
+ + "}";
+
+ private ExecutorService txStateStorageExecutor = Executors.newSingleThreadExecutor();
+
+ @BeforeEach
+ @Override
+ public void setup(TestInfo testInfo) throws Exception {
+ super.setup(testInfo);
+
+ String zoneSql = "create zone test_zone with partitions=20, replicas=" + REPLICAS
+ + ", storage_profiles='" + DEFAULT_STORAGE_PROFILE + "'";
+ String sql = "create table " + TABLE_NAME + " (key bigint primary key, val varchar(20)) with primary_zone='TEST_ZONE'";
+
+ cluster.doInSession(0, session -> {
+ executeUpdate(zoneSql, session);
+ executeUpdate(sql, session);
+ });
+
+ txStateStorageExecutor = Executors.newSingleThreadExecutor(IgniteThreadFactory.create("test", "tx-state-storage-test-pool", log,
+ ThreadOperation.STORAGE_READ));
+ }
+
+ @Override
+ @AfterEach
+ public void tearDown() {
+ shutdownAndAwaitTermination(txStateStorageExecutor, 10, TimeUnit.SECONDS);
+
+ super.tearDown();
+ }
+
+ @Override
+ protected void customizeInitParameters(InitParametersBuilder builder) {
+ super.customizeInitParameters(builder);
+
+ builder.clusterConfiguration("{"
+ + " transaction: {"
+ + " implicitTransactionTimeout: 30000,"
+ + " txnResourceTtl: 2"
+ + " },"
+ + " replication: {"
+ + " rpcTimeout: 30000"
+ + " },"
+ + "}");
+ }
+
+ @Override
+ protected int initialNodes() {
+ return 3;
+ }
+
+ /**
+ * Returns node bootstrap config template.
+ *
+ * @return Node bootstrap config template.
+ */
+ @Override
+ protected String getNodeBootstrapConfigTemplate() {
+ return NODE_BOOTSTRAP_CFG_TEMPLATE;
+ }
+
+ @Test
+ public void testVacuum() throws InterruptedException {
Review Comment:
Right.
Added javadoc.
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
+public class ItTxResourcesVacuumTest extends ClusterPerTestIntegrationTest {
+ /** Table name. */
+ private static final String TABLE_NAME = "test_table";
+
+ private static final Tuple INITIAL_TUPLE = Tuple.create().set("key", 1L).set("val", "1");
+
+ private static final Function<Tuple, Tuple> NEXT_TUPLE = t -> Tuple.create()
+ .set("key", t.longValue("key") + 1)
+ .set("val", "" + (t.longValue("key") + 1));
+
+ private static final int REPLICAS = 2;
+
+ /** Nodes bootstrap configuration pattern. */
+ private static final String NODE_BOOTSTRAP_CFG_TEMPLATE = "{\n"
+ + " network: {\n"
+ + " port: {},\n"
+ + " nodeFinder: {\n"
+ + " netClusterNodes: [ {} ]\n"
+ + " }\n"
+ + " },\n"
+ + " clientConnector: { port:{} },\n"
+ + " rest.port: {},\n"
+ + " raft: { responseTimeout: 30000 },"
+ + " compute.threadPoolSize: 1\n"
+ + "}";
+
+ private ExecutorService txStateStorageExecutor = Executors.newSingleThreadExecutor();
+
+ @BeforeEach
+ @Override
+ public void setup(TestInfo testInfo) throws Exception {
+ super.setup(testInfo);
+
+ String zoneSql = "create zone test_zone with partitions=20, replicas=" + REPLICAS
+ + ", storage_profiles='" + DEFAULT_STORAGE_PROFILE + "'";
+ String sql = "create table " + TABLE_NAME + " (key bigint primary key, val varchar(20)) with primary_zone='TEST_ZONE'";
+
+ cluster.doInSession(0, session -> {
+ executeUpdate(zoneSql, session);
+ executeUpdate(sql, session);
+ });
+
+ txStateStorageExecutor = Executors.newSingleThreadExecutor(IgniteThreadFactory.create("test", "tx-state-storage-test-pool", log,
+ ThreadOperation.STORAGE_READ));
+ }
+
+ @Override
+ @AfterEach
+ public void tearDown() {
+ shutdownAndAwaitTermination(txStateStorageExecutor, 10, TimeUnit.SECONDS);
+
+ super.tearDown();
+ }
+
+ @Override
+ protected void customizeInitParameters(InitParametersBuilder builder) {
+ super.customizeInitParameters(builder);
+
+ builder.clusterConfiguration("{"
+ + " transaction: {"
+ + " implicitTransactionTimeout: 30000,"
+ + " txnResourceTtl: 2"
+ + " },"
+ + " replication: {"
+ + " rpcTimeout: 30000"
+ + " },"
+ + "}");
+ }
+
+ @Override
+ protected int initialNodes() {
+ return 3;
+ }
+
+ /**
+ * Returns node bootstrap config template.
+ *
+ * @return Node bootstrap config template.
+ */
+ @Override
+ protected String getNodeBootstrapConfigTemplate() {
+ return NODE_BOOTSTRAP_CFG_TEMPLATE;
+ }
+
+ @Test
+ public void testVacuum() throws InterruptedException {
+ IgniteImpl node = anyNode();
+
+ RecordView<Tuple> view = node.tables().table(TABLE_NAME).recordView();
+
+ // Put some value into the table.
+ Transaction tx = node.transactions().begin();
+ UUID txId = txId(tx);
+
+ log.info("Test: Loading the data [tx={}].", txId);
+
+ Tuple tuple = findTupleToBeHostedOnNode(node, TABLE_NAME, tx, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ int partId = partitionIdForTuple(node, TABLE_NAME, tuple, tx);
+
+ Set<String> nodes = partitionAssignment(node, new TablePartitionId(tableId(node, TABLE_NAME), partId));
+
+ view.upsert(tx, tuple);
+
+ tx.commit();
+
+ log.info("Test: Tx committed [tx={}].", txId);
+
+ checkVolatileTxStateOnNodes(nodes, txId);
+ waitForTxStateReplication(nodes, txId, partId, 10_000);
+
+ waitForTxStateVacuum(txId, partId, true, 10_000);
Review Comment:
Added this test.
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1578241558
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
+public class ItTxResourcesVacuumTest extends ClusterPerTestIntegrationTest {
+ /** Table name. */
+ private static final String TABLE_NAME = "test_table";
+
+ private static final Tuple INITIAL_TUPLE = Tuple.create().set("key", 1L).set("val", "1");
+
+ private static final Function<Tuple, Tuple> NEXT_TUPLE = t -> Tuple.create()
+ .set("key", t.longValue("key") + 1)
+ .set("val", "" + (t.longValue("key") + 1));
+
+ private static final int REPLICAS = 2;
+
+ /** Nodes bootstrap configuration pattern. */
+ private static final String NODE_BOOTSTRAP_CFG_TEMPLATE = "{\n"
+ + " network: {\n"
+ + " port: {},\n"
+ + " nodeFinder: {\n"
+ + " netClusterNodes: [ {} ]\n"
+ + " }\n"
+ + " },\n"
+ + " clientConnector: { port:{} },\n"
+ + " rest.port: {},\n"
+ + " raft: { responseTimeout: 30000 },"
+ + " compute.threadPoolSize: 1\n"
+ + "}";
+
+ private ExecutorService txStateStorageExecutor = Executors.newSingleThreadExecutor();
+
+ @BeforeEach
+ @Override
+ public void setup(TestInfo testInfo) throws Exception {
+ super.setup(testInfo);
+
+ String zoneSql = "create zone test_zone with partitions=20, replicas=" + REPLICAS
+ + ", storage_profiles='" + DEFAULT_STORAGE_PROFILE + "'";
+ String sql = "create table " + TABLE_NAME + " (key bigint primary key, val varchar(20)) with primary_zone='TEST_ZONE'";
+
+ cluster.doInSession(0, session -> {
+ executeUpdate(zoneSql, session);
+ executeUpdate(sql, session);
+ });
+
+ txStateStorageExecutor = Executors.newSingleThreadExecutor(IgniteThreadFactory.create("test", "tx-state-storage-test-pool", log,
+ ThreadOperation.STORAGE_READ));
+ }
+
+ @Override
+ @AfterEach
+ public void tearDown() {
+ shutdownAndAwaitTermination(txStateStorageExecutor, 10, TimeUnit.SECONDS);
+
+ super.tearDown();
+ }
+
+ @Override
+ protected void customizeInitParameters(InitParametersBuilder builder) {
+ super.customizeInitParameters(builder);
+
+ builder.clusterConfiguration("{"
+ + " transaction: {"
+ + " implicitTransactionTimeout: 30000,"
+ + " txnResourceTtl: 2"
+ + " },"
+ + " replication: {"
+ + " rpcTimeout: 30000"
+ + " },"
+ + "}");
+ }
+
+ @Override
+ protected int initialNodes() {
+ return 3;
+ }
+
+ /**
+ * Returns node bootstrap config template.
+ *
+ * @return Node bootstrap config template.
+ */
+ @Override
+ protected String getNodeBootstrapConfigTemplate() {
+ return NODE_BOOTSTRAP_CFG_TEMPLATE;
+ }
+
+ @Test
+ public void testVacuum() throws InterruptedException {
+ IgniteImpl node = anyNode();
+
+ RecordView<Tuple> view = node.tables().table(TABLE_NAME).recordView();
+
+ // Put some value into the table.
+ Transaction tx = node.transactions().begin();
+ UUID txId = txId(tx);
+
+ log.info("Test: Loading the data [tx={}].", txId);
+
+ Tuple tuple = findTupleToBeHostedOnNode(node, TABLE_NAME, tx, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ int partId = partitionIdForTuple(node, TABLE_NAME, tuple, tx);
+
+ Set<String> nodes = partitionAssignment(node, new TablePartitionId(tableId(node, TABLE_NAME), partId));
+
+ view.upsert(tx, tuple);
+
+ tx.commit();
+
+ log.info("Test: Tx committed [tx={}].", txId);
+
+ checkVolatileTxStateOnNodes(nodes, txId);
+ waitForTxStateReplication(nodes, txId, partId, 10_000);
+
+ waitForTxStateVacuum(txId, partId, true, 10_000);
+ }
+
+ @Test
+ public void testVacuumWithCleanupDelay() throws InterruptedException {
Review Comment:
Added steps to javadocs.
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1578105897
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbStorage.java:
##########
@@ -169,34 +170,66 @@ public void put(UUID txId, TxMeta txMeta) {
@Override
public boolean compareAndSet(UUID txId, @Nullable TxState txStateExpected, TxMeta txMeta, long commandIndex, long commandTerm) {
- return busy(() -> {
- try (WriteBatch writeBatch = new WriteBatch()) {
- byte[] txIdBytes = txIdToKey(txId);
+ return updateData(writeBatch -> {
Review Comment:
this is outside of this ticket's scope
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1579026948
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTransactionTestUtils.java:
##########
@@ -0,0 +1,204 @@
+/*
+ * 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.table;
+
+import static java.util.Objects.requireNonNull;
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.TestWrappers.unwrapIgniteTransaction;
+import static org.apache.ignite.internal.TestWrappers.unwrapRecordBinaryViewImpl;
+import static org.apache.ignite.internal.TestWrappers.unwrapTableImpl;
+import static org.apache.ignite.internal.distributionzones.rebalance.RebalanceUtil.stablePartAssignmentsKey;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.Function;
+import org.apache.ignite.internal.affinity.Assignment;
+import org.apache.ignite.internal.affinity.Assignments;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.lang.ByteArray;
+import org.apache.ignite.internal.metastorage.Entry;
+import org.apache.ignite.internal.metastorage.MetaStorageManager;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.ReplicationGroupId;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.schema.BinaryRowEx;
+import org.apache.ignite.internal.tx.impl.ReadWriteTransactionImpl;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Test utils for transaction integration tests.
+ */
+public class ItTransactionTestUtils {
+ /**
+ * Get the names of the nodes that are assignments of the given partition.
+ *
+ * @param node Any node in the cluster.
+ * @param grpId Group id.
+ * @return Node names.
+ */
+ public static Set<String> partitionAssignment(IgniteImpl node, TablePartitionId grpId) {
+ MetaStorageManager metaStorageManager = node.metaStorageManager();
+
+ ByteArray stableAssignmentKey = stablePartAssignmentsKey(grpId);
+
+ CompletableFuture<Entry> assignmentEntryFut = metaStorageManager.get(stableAssignmentKey);
+
+ assertThat(assignmentEntryFut, willCompleteSuccessfully());
+
+ Entry e = assignmentEntryFut.join();
+
+ assertNotNull(e);
+ assertFalse(e.empty());
+ assertFalse(e.tombstone());
+
+ Set<Assignment> a = requireNonNull(Assignments.fromBytes(e.value())).nodes();
+
+ return a.stream().filter(Assignment::isPeer).map(Assignment::consistentId).collect(toSet());
+ }
+
+ /**
+ * Calculate the partition id on which the given tuple would be placed.
+ *
+ * @param node Any node in the cluster.
+ * @param tableName Table name.
+ * @param tuple Data tuple.
+ * @param tx Transaction, if present.
+ * @return Partition id.
+ */
+ public static int partitionIdForTuple(IgniteImpl node, String tableName, Tuple tuple, @Nullable Transaction tx) {
+ TableImpl table = table(node, tableName);
+ RecordBinaryViewImpl view = unwrapRecordBinaryViewImpl(table.recordView());
+
+ CompletableFuture<BinaryRowEx> rowFut = view.marshal(tx, tuple);
+ assertThat(rowFut, willCompleteSuccessfully());
+ BinaryRowEx row = rowFut.join();
+
+ return table.internalTable().partitionId(row);
+ }
+
+ /**
+ * Generates some tuple that would be placed in the partition that is hosted on the given node in the cluster.
+ *
+ * @param node Node that should host the result tuple.
+ * @param tableName Table name.
+ * @param tx Transaction, if present.
+ * @param initialTuple Initial tuple, for calculation.
+ * @param nextTuple This function will be used to generate new tuples in order to find suitable one.
+ * @param primary Whether the given node should be the primary node.
+ * @return Tuple that would be placed on the given node.
+ */
+ public static Tuple findTupleToBeHostedOnNode(
Review Comment:
Max attempts is needed to avoid endless loop, and it should never be reached in case of decently even distribution of primary replicas.
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1581266872
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,798 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.TxState.FINISHING;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.message.TxFinishReplicaRequest;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.apache.ignite.tx.TransactionOptions;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
+public class ItTxResourcesVacuumTest extends ClusterPerTestIntegrationTest {
+ /** Table name. */
+ private static final String TABLE_NAME = "test_table";
+
+ private static final Tuple INITIAL_TUPLE = Tuple.create().set("key", 1L).set("val", "1");
+
+ private static final Function<Tuple, Tuple> NEXT_TUPLE = t -> Tuple.create()
+ .set("key", t.longValue("key") + 1)
+ .set("val", "" + (t.longValue("key") + 1));
+
+ private static final int REPLICAS = 2;
+
+ /** Nodes bootstrap configuration pattern. */
+ private static final String NODE_BOOTSTRAP_CFG_TEMPLATE = "{\n"
+ + " network: {\n"
+ + " port: {},\n"
+ + " nodeFinder: {\n"
+ + " netClusterNodes: [ {} ]\n"
+ + " }\n"
+ + " },\n"
+ + " clientConnector: { port:{} },\n"
+ + " rest.port: {},\n"
+ + " raft: { responseTimeout: 30000 },"
+ + " compute.threadPoolSize: 1\n"
+ + "}";
+
+ private ExecutorService txStateStorageExecutor = Executors.newSingleThreadExecutor();
+
+ @BeforeEach
+ @Override
+ public void setup(TestInfo testInfo) throws Exception {
+ super.setup(testInfo);
+
+ String zoneSql = "create zone test_zone with partitions=20, replicas=" + REPLICAS
+ + ", storage_profiles='" + DEFAULT_STORAGE_PROFILE + "'";
+ String sql = "create table " + TABLE_NAME + " (key bigint primary key, val varchar(20)) with primary_zone='TEST_ZONE'";
+
+ cluster.doInSession(0, session -> {
+ executeUpdate(zoneSql, session);
+ executeUpdate(sql, session);
+ });
+
+ txStateStorageExecutor = Executors.newSingleThreadExecutor(IgniteThreadFactory.create("test", "tx-state-storage-test-pool", log,
+ ThreadOperation.STORAGE_READ));
+ }
+
+ @Override
+ @AfterEach
+ public void tearDown() {
+ shutdownAndAwaitTermination(txStateStorageExecutor, 10, TimeUnit.SECONDS);
+
+ super.tearDown();
+ }
+
+ @Override
+ protected void customizeInitParameters(InitParametersBuilder builder) {
+ super.customizeInitParameters(builder);
+
+ builder.clusterConfiguration("{"
+ + " transaction: {"
+ + " txnResourceTtl: 1"
+ + " },"
+ + " replication: {"
+ + " rpcTimeout: 30000"
+ + " },"
+ + "}");
+ }
+
+ /**
+ * Returns node bootstrap config template.
+ *
+ * @return Node bootstrap config template.
+ */
+ @Override
+ protected String getNodeBootstrapConfigTemplate() {
+ return NODE_BOOTSTRAP_CFG_TEMPLATE;
+ }
+
+ /**
+ * Simple vacuum test, checking also that PENDING and FINISHING states are not removed.
+ *
+ * <ul>
+ * <li>Run a transaction;</li>
+ * <li>Insert a value;</li>
+ * <li>Wait 3 seconds;</li>
+ * <li>Check that the volatile PENDING state of the transaction is preserved;</li>
+ * <li>Block {@link TxFinishReplicaRequest};</li>
+ * <li>Start the tx commit;</li>
+ * <li>While the state is FINISHING, wait 3 seconds;</li>
+ * <li>Check that the volatile state of the transaction is preserved;</li>
+ * <li>Unblock {@link TxFinishReplicaRequest};</li>
+ * <li>Check that both volatile and persistent state is vacuumized;</li>
+ * <li>Check that the committed value is correct.</li>
+ * </ul>
+ */
+ @Test
+ public void testVacuum() throws InterruptedException {
+ IgniteImpl node = anyNode();
+
+ RecordView<Tuple> view = node.tables().table(TABLE_NAME).recordView();
+
+ // Put some value into the table.
+ Transaction tx = node.transactions().begin();
+ UUID txId = txId(tx);
+
+ log.info("Test: Loading the data [tx={}].", txId);
+
+ Tuple tuple = findTupleToBeHostedOnNode(node, TABLE_NAME, tx, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ int partId = partitionIdForTuple(node, TABLE_NAME, tuple, tx);
+
+ Set<String> nodes = partitionAssignment(node, new TablePartitionId(tableId(node, TABLE_NAME), partId));
+
+ view.upsert(tx, tuple);
+
+ // Check that the volatile PENDING state of the transaction is preserved.
+ Thread.sleep(3000);
+ assertTrue(checkVolatileTxStateOnNodes(nodes, txId));
+
+ CompletableFuture<Void> finishStartedFuture = new CompletableFuture<>();
+ CompletableFuture<Void> finishAllowedFuture = new CompletableFuture<>();
+
+ node.dropMessages((n, msg) -> {
+ if (msg instanceof TxFinishReplicaRequest) {
+ finishStartedFuture.complete(null);
+
+ finishAllowedFuture.join();
+ }
+
+ return false;
+ });
+
+ CompletableFuture<Void> commitFut = runAsync(tx::commit);
+
+ assertThat(finishStartedFuture, willCompleteSuccessfully());
+
+ // While the state is FINISHING, wait 3 seconds.
+ assertEquals(FINISHING, volatileTxState(node, txId).txState());
+ Thread.sleep(3000);
+
+ // Check that the volatile state of the transaction is preserved.
+ assertTrue(checkVolatileTxStateOnNodes(nodes, txId));
+
+ finishAllowedFuture.complete(null);
+
+ assertThat(commitFut, willCompleteSuccessfully());
+
+ log.info("Test: Tx committed [tx={}].", txId);
+
+ waitForTxStateReplication(nodes, txId, partId, 10_000);
+
+ // Check that both volatile and persistent state is vacuumized..
+ waitForTxStateVacuum(txId, partId, true, 10_000);
+
+ // Trying to read the value.
+ Tuple data = view.get(null, Tuple.create().set("key", tuple.longValue("key")));
+ assertEquals(tuple, data);
+ }
+
+ /**
+ * Check that the ABANDONED transaction state is preserved until recovery.
+ *
+ * <ul>
+ * <li>Start a transaction from a coordinator that would be not included into commit partition group;</li>
+ * <li>Insert a value;</li>
+ * <li>Stop the tx coordinator;</li>
+ * <li>Wait 3 seconds;</li>
+ * <li>Check that the volatile state of the transaction is preserved;</li>
+ * <li>Try to read the value using another transaction, which starts the tx recovery;</li>
+ * <li>Check that abandoned tx is rolled back and thus the value is null;</li>
+ * <li>Check that the abandoned transaction is recovered; its volatile and persistent states are vacuumized.</li>
+ * </ul>
+ */
+ @Test
+ public void testAbandonedTxnsAreNotVacuumizedUntilRecovered() throws InterruptedException {
+ IgniteImpl leaseholder = cluster.node(0);
+
+ Tuple tuple = findTupleToBeHostedOnNode(leaseholder, TABLE_NAME, null, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ int partId = partitionIdForTuple(anyNode(), TABLE_NAME, tuple, null);
+
+ TablePartitionId groupId = new TablePartitionId(tableId(anyNode(), TABLE_NAME), partId);
+
+ Set<String> txNodes = partitionAssignment(anyNode(), groupId);
+
+ IgniteImpl abandonedTxCoord = findNode(n -> !txNodes.contains(n.name()));
+
+ RecordView<Tuple> view = abandonedTxCoord.tables().table(TABLE_NAME).recordView();
+
+ Transaction abandonedTx = abandonedTxCoord.transactions().begin();
+ UUID abandonedTxId = txId(abandonedTx);
+ view.upsert(abandonedTx, tuple);
+
+ stopNode(abandonedTxCoord.name());
+
+ Thread.sleep(3000);
+
+ // Check that the volatile state of the transaction is preserved.
+ assertTrue(checkVolatileTxStateOnNodes(txNodes, abandonedTxId));
+
+ // Try to read the value using another transaction, which starts the tx recovery.
+ RecordView<Tuple> viewLh = leaseholder.tables().table(TABLE_NAME).recordView();
+ Tuple value = viewLh.get(null, Tuple.create().set("key", tuple.longValue("key")));
+ // Check that abandoned tx is rolled back and thus the value is null.
+ assertNull(value);
+
+ // Check that the abandoned transaction is recovered; its volatile and persistent states are vacuumized.
+ waitForTxStateVacuum(txNodes, abandonedTxId, partId, true, 10_000);
+ }
+
+ /**
+ * Check that the tx state on commit partition is vacuumized only when cleanup is completed.
+ *
+ * <ul>
+ * <li>Start a transaction;</li>
+ * <li>Generate some tuple and define on which nodes it would be hosted;</li>
+ * <li>Choose one more node that doesn't host the first tuple and choose a tuple that will be sent on this node as primary;</li>
+ * <li>Upsert both tuples within a transaction;</li>
+ * <li>Block {@link TxCleanupMessage}-s from commit partition primary;</li>
+ * <li>Start a tx commit;</li>
+ * <li>Wait for vacuum completion on a node that doesn't host the commit partition;</li>
+ * <li>Unblock {@link TxCleanupMessage}-s;</li>
+ * <li>Wait for the tx state vacuum on the commit partition group.</li>
+ * </ul>
+ */
+ @Test
+ public void testVacuumWithCleanupDelay() throws InterruptedException {
+ IgniteImpl node = anyNode();
+
+ RecordView<Tuple> view = node.tables().table(TABLE_NAME).recordView();
+
+ // Put some value into the table.
+ Transaction tx = node.transactions().begin();
+ UUID txId = txId(tx);
+
+ log.info("Test: Loading the data [tx={}].", txId);
+
+ // Generate some tuple and define on which nodes it would be hosted.
+ Tuple tuple0 = findTupleToBeHostedOnNode(node, TABLE_NAME, tx, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ int commitPartId = partitionIdForTuple(node, TABLE_NAME, tuple0, tx);
+
+ TablePartitionId commitPartGrpId = new TablePartitionId(tableId(node, TABLE_NAME), commitPartId);
+
+ ReplicaMeta replicaMeta = waitAndGetPrimaryReplica(node, commitPartGrpId);
+ IgniteImpl commitPartitionLeaseholder = findNode(n -> n.id().equals(replicaMeta.getLeaseholderId()));
+
+ Set<String> commitPartNodes = partitionAssignment(node, new TablePartitionId(tableId(node, TABLE_NAME), commitPartId));
+
+ log.info("Test: Commit partition [leaseholder={}, hostingNodes={}].", commitPartitionLeaseholder.name(), commitPartNodes);
+
+ // Some node that does not host the commit partition, will be the primary node for upserting another tuple.
+ IgniteImpl leaseholderForAnotherTuple = findNode(n -> !commitPartNodes.contains(n.name()));
+
+ log.info("Test: leaseholderForAnotherTuple={}", leaseholderForAnotherTuple.name());
+
+ Tuple tuple1 = findTupleToBeHostedOnNode(leaseholderForAnotherTuple, TABLE_NAME, tx, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ // Upsert both tuples within a transaction.
+ view.upsert(tx, tuple0);
+ view.upsert(tx, tuple1);
+
+ CompletableFuture<Void> cleanupStarted = new CompletableFuture<>();
+ CompletableFuture<Void> cleanupAllowed = new CompletableFuture<>();
+
+ commitPartitionLeaseholder.dropMessages((n, msg) -> {
+ if (msg instanceof TxCleanupMessage) {
+ cleanupStarted.complete(null);
+
+ log.info("Test: cleanup started.");
+
+ if (commitPartNodes.contains(n)) {
+ cleanupAllowed.join();
+ }
+ }
+
+ return false;
+ });
+
+ CompletableFuture<Void> commitFut = tx.commitAsync();
+
+ waitForTxStateReplication(commitPartNodes, txId, commitPartId, 10_000);
+
+ assertThat(cleanupStarted, willCompleteSuccessfully());
+
+ // Wait for vacuum completion on a node that doesn't host the commit partition.
+ waitForTxStateVacuum(Set.of(leaseholderForAnotherTuple.name()), txId, 0, false, 10_000);
+
+ // Unblocking cleanup.
+ cleanupAllowed.complete(null);
+
+ assertThat(commitFut, willCompleteSuccessfully());
+
+ // Wait for the cleanup on the commit partition group.
+ waitForTxStateVacuum(txId, commitPartId, true, 10_000);
+
+ // Trying to read the values.
+ Tuple data0 = view.get(null, Tuple.create().set("key", tuple0.longValue("key")));
+ assertEquals(tuple0, data0);
+
+ Tuple data1 = view.get(null, Tuple.create().set("key", tuple1.longValue("key")));
+ assertEquals(tuple1, data1);
+ }
+
+ /**
+ * Check that the tx state on commit partition is vacuumized only when cleanup is completed.
+ *
+ * <ul>
+ * <li>Start a transaction;</li>
+ * <li>Upsert a value;</li>
+ * <li>Block {@link TxCleanupMessage}-s;</li>
+ * <li>Start a tx commit;</li>
+ * <li>Transfer the primary replica;</li>
+ * <li>Unblock the {@link TxCleanupMessage}-s;</li>
+ * <li>Ensure that tx states are finally vacuumized.</li>
+ * </ul>
+ */
+ @Test
+ public void testCommitPartitionPrimaryChangesBeforeVacuum() throws InterruptedException {
+ IgniteImpl node = anyNode();
+
+ RecordView<Tuple> view = node.tables().table(TABLE_NAME).recordView();
+
+ // Put some value into the table.
+ Transaction tx = node.transactions().begin();
+ UUID txId = txId(tx);
+
+ log.info("Test: Loading the data [tx={}].", txId);
+
+ Tuple tuple = findTupleToBeHostedOnNode(node, TABLE_NAME, tx, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ int commitPartId = partitionIdForTuple(node, TABLE_NAME, tuple, tx);
+
+ TablePartitionId commitPartGrpId = new TablePartitionId(tableId(node, TABLE_NAME), commitPartId);
+
+ ReplicaMeta replicaMeta = waitAndGetPrimaryReplica(node, commitPartGrpId);
+ IgniteImpl commitPartitionLeaseholder = findNode(n -> n.id().equals(replicaMeta.getLeaseholderId()));
+
+ Set<String> commitPartNodes = partitionAssignment(node, new TablePartitionId(tableId(node, TABLE_NAME), commitPartId));
+
+ log.info("Test: Commit partition [leaseholder={}, hostingNodes={}].", commitPartitionLeaseholder.name(), commitPartNodes);
+
+ view.upsert(tx, tuple);
+
+ CompletableFuture<Void> cleanupStarted = new CompletableFuture<>();
+ CompletableFuture<Void> cleanupAllowedFut = new CompletableFuture<>();
+ boolean[] cleanupAllowed = new boolean[1];
+
+ commitPartitionLeaseholder.dropMessages((n, msg) -> {
+ if (msg instanceof TxCleanupMessage && !cleanupAllowed[0]) {
+ cleanupStarted.complete(null);
+
+ cleanupAllowedFut.join();
+ }
+
+ return false;
+ });
+
+ CompletableFuture<Void> commitFut = tx.commitAsync();
+
+ assertThat(cleanupStarted, willCompleteSuccessfully());
+
+ transferPrimary(cluster.runningNodes().collect(toSet()), commitPartGrpId, commitPartNodes::contains);
+
+ cleanupAllowedFut.complete(null);
+
+ cleanupAllowed[0] = true;
+
+ assertThat(commitFut, willCompleteSuccessfully());
+
+ log.info("Test: tx committed.");
+
+ waitForTxStateVacuum(txId, commitPartId, true, 10_000);
+
+ // Trying to read the value.
+ Tuple data = view.get(null, Tuple.create().set("key", tuple.longValue("key")));
+ assertEquals(tuple, data);
+ }
+
+ /**
+ * Check that the tx state on commit partition is vacuumized only when cleanup is completed.
+ *
+ * <ul>
+ * <li>Start a transaction;</li>
+ * <li>Upsert a tuple;</li>
+ * <li>Block {@link TxCleanupMessage}-s from commit partition primary;</li>
+ * <li>Start a tx commit;</li>
+ * <li>Wait for tx cleanup to start;</li>
+ * <li>Wait for volatile tx state vacuum;</li>
+ * <li>Unblock {@link TxCleanupMessage}-s;</li>
+ * <li>Wait for the tx state vacuum on the commit partition group.</li>
+ * </ul>
+ */
+ @Test
+ public void testVacuumPersistentStateAfterCleanupDelayAndVolatileStateVacuum() throws InterruptedException {
+ IgniteImpl node = anyNode();
+
+ RecordView<Tuple> view = node.tables().table(TABLE_NAME).recordView();
+
+ // Put some value into the table.
+ Transaction tx = node.transactions().begin();
+ UUID txId = txId(tx);
+
+ log.info("Test: Loading the data [tx={}].", txId);
+
+ Tuple tuple = findTupleToBeHostedOnNode(node, TABLE_NAME, tx, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ int commitPartId = partitionIdForTuple(node, TABLE_NAME, tuple, tx);
+
+ TablePartitionId commitPartGrpId = new TablePartitionId(tableId(node, TABLE_NAME), commitPartId);
+
+ ReplicaMeta replicaMeta = waitAndGetPrimaryReplica(node, commitPartGrpId);
+ IgniteImpl commitPartitionLeaseholder = findNode(n -> n.id().equals(replicaMeta.getLeaseholderId()));
+
+ Set<String> commitPartNodes = partitionAssignment(node, new TablePartitionId(tableId(node, TABLE_NAME), commitPartId));
+
+ log.info("Test: Commit partition [leaseholder={}, hostingNodes={}].", commitPartitionLeaseholder.name(), commitPartNodes);
+
+ view.upsert(tx, tuple);
+
+ CompletableFuture<Void> cleanupStarted = new CompletableFuture<>();
+ CompletableFuture<Void> cleanupAllowedFut = new CompletableFuture<>();
+ boolean[] cleanupAllowed = new boolean[1];
+
+ commitPartitionLeaseholder.dropMessages((n, msg) -> {
+ if (msg instanceof TxCleanupMessage && !cleanupAllowed[0]) {
+ cleanupStarted.complete(null);
+
+ cleanupAllowedFut.join();
+
+ return true;
+ }
+
+ return false;
+ });
+
+ CompletableFuture<Void> commitFut = tx.commitAsync();
+
+ assertThat(cleanupStarted, willCompleteSuccessfully());
+
+ // Wait for volatile tx state vacuum. This is possible because tx finish is complete.
+ waitForTxStateVacuum(txId, commitPartId, false, 10_000);
+
+ log.info("Test: volatile state vacuumized");
+
+ cleanupAllowedFut.complete(null);
+
+ cleanupAllowed[0] = true;
+
+ assertThat(commitFut, willCompleteSuccessfully());
+
+ waitForTxStateVacuum(txId, commitPartId, true, 10_000);
+
+ // Trying to read the data.
+ Tuple data = view.get(null, Tuple.create().set("key", tuple.longValue("key")));
+ assertEquals(tuple, data);
+ }
+
+ /**
+ * Checks that the tx recovery doesn't change tx finish result from COMMITTED to ABORTED if it once saved in the persistent storage.
+ *
+ * <ul>
+ * <li>Start a transaction tx0;</li>
+ * <li>Upsert some value;</li>
+ * <li>Block {@link TxCleanupMessage}-s;</li>
+ * <li>Start the commit of tx0 and with for tx state COMMITTED to be replicated in persistent storage;</li>
+ * <li>Stop the tx0's coordinator;</li>
+ * <li>Wait for tx0's state vacuum;</li>
+ * <li>Try to get the data that has been committed by tx0, ensure the data is correct.</li>
+ * </ul>
+ */
+ @Test
+ public void testRecoveryAfterPersistentStateVacuumized() throws InterruptedException {
+ // This node isn't going to be stopped, so let it be node 0.
+ IgniteImpl commitPartitionLeaseholder = cluster.node(0);
+
+ Tuple tuple0 = findTupleToBeHostedOnNode(commitPartitionLeaseholder, TABLE_NAME, null, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ int commitPartId = partitionIdForTuple(commitPartitionLeaseholder, TABLE_NAME, tuple0, null);
+
+ Set<String> commitPartitionNodes = partitionAssignment(commitPartitionLeaseholder,
+ new TablePartitionId(tableId(commitPartitionLeaseholder, TABLE_NAME), commitPartId));
+
+ // Choose some node that doesn't host the partition as a tx coordinator.
+ IgniteImpl coord0 = findNode(n -> !commitPartitionNodes.contains(n.name()));
+
+ RecordView<Tuple> view0 = coord0.tables().table(TABLE_NAME).recordView();
+
+ // Put some value into the table.
+ Transaction tx0 = coord0.transactions().begin();
+ UUID txId0 = txId(tx0);
+
+ log.info("Test: Transaction 0 [tx={}].", txId0);
+
+ log.info("Test: Commit partition of transaction 0 [leaseholder={}, hostingNodes={}].", commitPartitionLeaseholder.name(),
+ commitPartitionNodes);
+
+ view0.upsert(tx0, tuple0);
+
+ CompletableFuture<Void> cleanupStarted = new CompletableFuture<>();
+ boolean[] cleanupAllowed = new boolean[1];
Review Comment:
removed
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,798 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.TxState.FINISHING;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.message.TxFinishReplicaRequest;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.apache.ignite.tx.TransactionOptions;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
+public class ItTxResourcesVacuumTest extends ClusterPerTestIntegrationTest {
+ /** Table name. */
+ private static final String TABLE_NAME = "test_table";
+
+ private static final Tuple INITIAL_TUPLE = Tuple.create().set("key", 1L).set("val", "1");
+
+ private static final Function<Tuple, Tuple> NEXT_TUPLE = t -> Tuple.create()
+ .set("key", t.longValue("key") + 1)
+ .set("val", "" + (t.longValue("key") + 1));
+
+ private static final int REPLICAS = 2;
+
+ /** Nodes bootstrap configuration pattern. */
+ private static final String NODE_BOOTSTRAP_CFG_TEMPLATE = "{\n"
+ + " network: {\n"
+ + " port: {},\n"
+ + " nodeFinder: {\n"
+ + " netClusterNodes: [ {} ]\n"
+ + " }\n"
+ + " },\n"
+ + " clientConnector: { port:{} },\n"
+ + " rest.port: {},\n"
+ + " raft: { responseTimeout: 30000 },"
+ + " compute.threadPoolSize: 1\n"
+ + "}";
+
+ private ExecutorService txStateStorageExecutor = Executors.newSingleThreadExecutor();
+
+ @BeforeEach
+ @Override
+ public void setup(TestInfo testInfo) throws Exception {
+ super.setup(testInfo);
+
+ String zoneSql = "create zone test_zone with partitions=20, replicas=" + REPLICAS
+ + ", storage_profiles='" + DEFAULT_STORAGE_PROFILE + "'";
+ String sql = "create table " + TABLE_NAME + " (key bigint primary key, val varchar(20)) with primary_zone='TEST_ZONE'";
+
+ cluster.doInSession(0, session -> {
+ executeUpdate(zoneSql, session);
+ executeUpdate(sql, session);
+ });
+
+ txStateStorageExecutor = Executors.newSingleThreadExecutor(IgniteThreadFactory.create("test", "tx-state-storage-test-pool", log,
+ ThreadOperation.STORAGE_READ));
+ }
+
+ @Override
+ @AfterEach
+ public void tearDown() {
+ shutdownAndAwaitTermination(txStateStorageExecutor, 10, TimeUnit.SECONDS);
+
+ super.tearDown();
+ }
+
+ @Override
+ protected void customizeInitParameters(InitParametersBuilder builder) {
+ super.customizeInitParameters(builder);
+
+ builder.clusterConfiguration("{"
+ + " transaction: {"
+ + " txnResourceTtl: 1"
+ + " },"
+ + " replication: {"
+ + " rpcTimeout: 30000"
+ + " },"
+ + "}");
+ }
+
+ /**
+ * Returns node bootstrap config template.
+ *
+ * @return Node bootstrap config template.
+ */
+ @Override
+ protected String getNodeBootstrapConfigTemplate() {
+ return NODE_BOOTSTRAP_CFG_TEMPLATE;
+ }
+
+ /**
+ * Simple vacuum test, checking also that PENDING and FINISHING states are not removed.
+ *
+ * <ul>
+ * <li>Run a transaction;</li>
+ * <li>Insert a value;</li>
+ * <li>Wait 3 seconds;</li>
+ * <li>Check that the volatile PENDING state of the transaction is preserved;</li>
+ * <li>Block {@link TxFinishReplicaRequest};</li>
+ * <li>Start the tx commit;</li>
+ * <li>While the state is FINISHING, wait 3 seconds;</li>
+ * <li>Check that the volatile state of the transaction is preserved;</li>
+ * <li>Unblock {@link TxFinishReplicaRequest};</li>
+ * <li>Check that both volatile and persistent state is vacuumized;</li>
+ * <li>Check that the committed value is correct.</li>
+ * </ul>
+ */
+ @Test
+ public void testVacuum() throws InterruptedException {
+ IgniteImpl node = anyNode();
+
+ RecordView<Tuple> view = node.tables().table(TABLE_NAME).recordView();
+
+ // Put some value into the table.
+ Transaction tx = node.transactions().begin();
+ UUID txId = txId(tx);
+
+ log.info("Test: Loading the data [tx={}].", txId);
+
+ Tuple tuple = findTupleToBeHostedOnNode(node, TABLE_NAME, tx, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ int partId = partitionIdForTuple(node, TABLE_NAME, tuple, tx);
+
+ Set<String> nodes = partitionAssignment(node, new TablePartitionId(tableId(node, TABLE_NAME), partId));
+
+ view.upsert(tx, tuple);
+
+ // Check that the volatile PENDING state of the transaction is preserved.
+ Thread.sleep(3000);
Review Comment:
removed sleeps
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1580728477
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/raft/PartitionListener.java:
##########
@@ -406,18 +413,18 @@ private UpdateCommandResult handleUpdateAllCommand(UpdateAllCommand cmd, long co
* Handler for the {@link WriteIntentSwitchCommand}.
*
* @param cmd Command.
- * @param commandIndex Index of the RAFT command.
- * @param commandTerm Term of the RAFT command.
+ * @param commandIndex Index of the RAFT cmd.
+ * @param commandTerm Term of the RAFT cmd.
*/
private void handleWriteIntentSwitchCommand(WriteIntentSwitchCommand cmd, long commandIndex, long commandTerm) {
- // Skips the write command because the storage has already executed it.
+ // Skips the write cmd because the storage has already executed it.
if (commandIndex <= storage.lastAppliedIndex()) {
return;
}
UUID txId = cmd.txId();
- markFinished(txId, cmd.commit(), cmd.commitTimestamp());
+ markFinished(txId, cmd.commit(), cmd.commitTimestamp(), null);
Review Comment:
Discussed personally. We need commitPartitionid.
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/VolatileTxStateMetaStorage.java:
##########
@@ -118,35 +129,56 @@ public Collection<TxStateMeta> states() {
* @param vacuumObservationTimestamp Timestamp of the vacuum attempt.
* @param txnResourceTtl Transactional resource time to live in milliseconds.
*/
- public void vacuum(long vacuumObservationTimestamp, long txnResourceTtl) {
+ public void vacuum(
+ long vacuumObservationTimestamp,
+ long txnResourceTtl,
+ Function<Map<TablePartitionId, Set<UUID>>, CompletableFuture<IgniteBiTuple<Set<UUID>, Integer>>> beforeVacuum
+ ) {
LOG.info("Vacuum started [vacuumObservationTimestamp={}, txnResourceTtl={}].", vacuumObservationTimestamp, txnResourceTtl);
AtomicInteger vacuumizedTxnsCount = new AtomicInteger(0);
AtomicInteger markedAsInitiallyDetectedTxnsCount = new AtomicInteger(0);
AtomicInteger alreadyMarkedTxnsCount = new AtomicInteger(0);
AtomicInteger skippedFotFurtherProcessingUnfinishedTxnsCount = new AtomicInteger(0);
+ Map<TablePartitionId, Set<UUID>> txIds = new HashMap<>();
+ Map<UUID, Long> timestamps = new HashMap<>();
+
txStateMap.forEach((txId, meta) -> {
txStateMap.computeIfPresent(txId, (txId0, meta0) -> {
if (TxState.isFinalState(meta0.txState())) {
- if (txnResourceTtl == 0) {
- vacuumizedTxnsCount.incrementAndGet();
- return null;
- } else if (meta0.initialVacuumObservationTimestamp() == null) {
+ Long initialVacuumObservationTimestamp = meta0.initialVacuumObservationTimestamp();
+
+ if (initialVacuumObservationTimestamp == null) {
markedAsInitiallyDetectedTxnsCount.incrementAndGet();
- return new TxStateMeta(
- meta0.txState(),
- meta0.txCoordinatorId(),
- meta0.commitPartitionId(),
- meta0.commitTimestamp(),
- vacuumObservationTimestamp
- );
- } else if (meta0.initialVacuumObservationTimestamp() + txnResourceTtl < vacuumObservationTimestamp) {
- vacuumizedTxnsCount.incrementAndGet();
- return null;
+
+ return markInitialVacuumObservationTimestamp(meta0, vacuumObservationTimestamp);
} else {
- alreadyMarkedTxnsCount.incrementAndGet();
- return meta0;
+ Long cleanupCompletionTimestamp = meta0.cleanupCompletionTimestamp();
+
+ boolean shouldBeVacuumized = shouldBeVacuumized(requireNonNull(initialVacuumObservationTimestamp),
+ cleanupCompletionTimestamp, txnResourceTtl, vacuumObservationTimestamp);
+
+ if (shouldBeVacuumized) {
+ if (meta0.commitPartitionId() == null) {
Review Comment:
Discussed personally. We need commitPartitionid.
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1578076407
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/PersistentTxStateVacuumizer.java:
##########
@@ -0,0 +1,124 @@
+/*
+ * 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.impl;
+
+import static org.apache.ignite.internal.util.CompletableFutures.allOf;
+import static org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture;
+import static org.apache.ignite.internal.util.ExceptionUtils.unwrapCause;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import org.apache.ignite.internal.hlc.ClockService;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.placementdriver.PlacementDriver;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.ReplicaService;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.replicator.exception.PrimaryReplicaMissException;
+import org.apache.ignite.internal.tx.message.TxMessagesFactory;
+import org.apache.ignite.internal.tx.message.VacuumTxStateReplicaRequest;
+import org.apache.ignite.network.ClusterNode;
+
+/**
+ * Implements the logic of persistent tx states vacuum.
+ */
+public class PersistentTxStateVacuumizer {
+ private static final IgniteLogger LOG = Loggers.forClass(PersistentTxStateVacuumizer.class);
+
+ private static final TxMessagesFactory TX_MESSAGES_FACTORY = new TxMessagesFactory();
+
+ private final ReplicaService replicaService;
+
+ private final ClusterNode localNode;
+
+ private final ClockService clockService;
+
+ private final PlacementDriver placementDriver;
+
+ /**
+ * Constructor.
+ *
+ * @param replicaService Replica service.
+ * @param localNode Local node.
+ * @param clockService Clock service.
+ * @param placementDriver Placement driver.
+ */
+ public PersistentTxStateVacuumizer(
+ ReplicaService replicaService,
+ ClusterNode localNode,
+ ClockService clockService,
+ PlacementDriver placementDriver
+ ) {
+ this.replicaService = replicaService;
+ this.localNode = localNode;
+ this.clockService = clockService;
+ this.placementDriver = placementDriver;
+ }
+
+ /**
+ * Vacuum persistent tx states.
+ *
+ * @param txIds Transaction ids to vacuum; map of commit partition ids to sets of tx ids.
+ * @return A future, result is the set of successfully vacuumized txn states.
+ */
+ public CompletableFuture<Set<UUID>> vacuumPersistentTxStates(Map<TablePartitionId, Set<UUID>> txIds) {
+ Set<UUID> successful = ConcurrentHashMap.newKeySet();
+ List<CompletableFuture<?>> futures = new ArrayList<>();
+ HybridTimestamp now = clockService.now();
+
+ txIds.forEach((commitPartitionId, txs) -> {
+ ReplicaMeta replicaMeta = placementDriver.getPrimaryReplica(commitPartitionId, now).join();
Review Comment:
my bad, fixed
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1578064982
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTransactionPrimaryChangeTest.java:
##########
@@ -87,7 +85,8 @@ protected void customizeInitParameters(InitParametersBuilder builder) {
builder.clusterConfiguration("{"
+ " transaction: {"
- + " implicitTransactionTimeout: 30000"
+ + " implicitTransactionTimeout: 30000,"
+ + " txnResourceTtl: 2"
Review Comment:
may be changed to 1
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTransactionTestUtils.java:
##########
@@ -0,0 +1,204 @@
+/*
+ * 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.table;
+
+import static java.util.Objects.requireNonNull;
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.TestWrappers.unwrapIgniteTransaction;
+import static org.apache.ignite.internal.TestWrappers.unwrapRecordBinaryViewImpl;
+import static org.apache.ignite.internal.TestWrappers.unwrapTableImpl;
+import static org.apache.ignite.internal.distributionzones.rebalance.RebalanceUtil.stablePartAssignmentsKey;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.Function;
+import org.apache.ignite.internal.affinity.Assignment;
+import org.apache.ignite.internal.affinity.Assignments;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.lang.ByteArray;
+import org.apache.ignite.internal.metastorage.Entry;
+import org.apache.ignite.internal.metastorage.MetaStorageManager;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.ReplicationGroupId;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.schema.BinaryRowEx;
+import org.apache.ignite.internal.tx.impl.ReadWriteTransactionImpl;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Test utils for transaction integration tests.
+ */
+public class ItTransactionTestUtils {
Review Comment:
moved
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1578076085
##########
modules/table/src/main/java/org/apache/ignite/internal/table/RecordBinaryViewImpl.java:
##########
@@ -402,6 +404,24 @@ private static Row marshal(Tuple tuple, TupleMarshaller marshaller, boolean keyO
}
}
+ /**
+ * Marshal a tuple to a row. Test-only public method.
+ *
+ * @param tx Transaction, if present.
+ * @param rec Tuple record.
+ * @return A future, with row as a result.
+ */
+ @TestOnly
+ public CompletableFuture<BinaryRowEx> marshal(@Nullable Transaction tx, Tuple rec) {
+ Objects.requireNonNull(rec);
+
+ return doOperation(tx, schemaVersion -> {
Review Comment:
renamed to `tupleToBinaryRow`
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1578107048
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbStorage.java:
##########
@@ -169,34 +170,66 @@ public void put(UUID txId, TxMeta txMeta) {
@Override
public boolean compareAndSet(UUID txId, @Nullable TxState txStateExpected, TxMeta txMeta, long commandIndex, long commandTerm) {
- return busy(() -> {
- try (WriteBatch writeBatch = new WriteBatch()) {
- byte[] txIdBytes = txIdToKey(txId);
+ return updateData(writeBatch -> {
+ byte[] txIdBytes = txIdToKey(txId);
- byte[] txMetaExistingBytes = sharedStorage.db().get(sharedStorage.readOptions, txIdToKey(txId));
+ byte[] txMetaExistingBytes = sharedStorage.db().get(sharedStorage.readOptions, txIdToKey(txId));
- boolean result;
+ boolean result;
- if (txMetaExistingBytes == null && txStateExpected == null) {
- writeBatch.put(txIdBytes, toBytes(txMeta));
+ if (txMetaExistingBytes == null && txStateExpected == null) {
+ writeBatch.put(txIdBytes, toBytes(txMeta));
- result = true;
- } else {
- if (txMetaExistingBytes != null) {
- TxMeta txMetaExisting = fromBytes(txMetaExistingBytes);
+ result = true;
+ } else {
+ if (txMetaExistingBytes != null) {
+ TxMeta txMetaExisting = fromBytes(txMetaExistingBytes);
- if (txMetaExisting.txState() == txStateExpected) {
- writeBatch.put(txIdBytes, toBytes(txMeta));
+ if (txMetaExisting.txState() == txStateExpected) {
+ writeBatch.put(txIdBytes, toBytes(txMeta));
- result = true;
- } else {
- result = txMetaExisting.txState() == txMeta.txState()
- && Objects.equals(txMetaExisting.commitTimestamp(), txMeta.commitTimestamp());
- }
+ result = true;
} else {
- result = false;
+ result = txMetaExisting.txState() == txMeta.txState()
+ && Objects.equals(txMetaExisting.commitTimestamp(), txMeta.commitTimestamp());
}
+ } else {
+ result = false;
}
+ }
+
+ return result;
+ }, commandIndex, commandTerm);
+ }
+
+ @Override
+ public void remove(UUID txId, long commandIndex, long commandTerm) {
+ updateData(writeBatch -> {
+ throwExceptionIfStorageInProgressOfRebalance();
+
+ writeBatch.delete(txIdToKey(txId));
+
+ return null;
+ }, commandIndex, commandTerm);
+ }
+
+ @Override
+ public void removeAll(Collection<UUID> txIds, long commandIndex, long commandTerm) {
+ updateData(writeBatch -> {
+ throwExceptionIfStorageInProgressOfRebalance();
Review Comment:
will be discussed in IGNITE-22094
--
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-21763 [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1566233794
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/message/VacuumTxStateReplicaRequest.java:
##########
@@ -0,0 +1,30 @@
+/*
+ * 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.message;
+
+import static org.apache.ignite.internal.tx.message.TxMessageGroup.VACUUM_TX_STATE_REPLICA_REQUEST;
+
+import java.util.Set;
+import java.util.UUID;
+import org.apache.ignite.internal.network.annotations.Transferable;
+import org.apache.ignite.internal.replicator.message.ReplicaRequest;
+
+@Transferable(VACUUM_TX_STATE_REPLICA_REQUEST)
+public interface VacuumTxStateReplicaRequest extends ReplicaRequest {
Review Comment:
yes, sure
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1580544405
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
+public class ItTxResourcesVacuumTest extends ClusterPerTestIntegrationTest {
+ /** Table name. */
+ private static final String TABLE_NAME = "test_table";
+
+ private static final Tuple INITIAL_TUPLE = Tuple.create().set("key", 1L).set("val", "1");
+
+ private static final Function<Tuple, Tuple> NEXT_TUPLE = t -> Tuple.create()
+ .set("key", t.longValue("key") + 1)
+ .set("val", "" + (t.longValue("key") + 1));
+
+ private static final int REPLICAS = 2;
Review Comment:
Do you mean that there are not only tests that check corresponding invariants on top of 2 replicas, but also ones what uses 3 replicas?
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1580539171
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/PersistentTxStateVacuumizer.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.internal.tx.impl;
+
+import static org.apache.ignite.internal.util.CompletableFutures.allOf;
+import static org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture;
+import static org.apache.ignite.internal.util.ExceptionUtils.unwrapCause;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import org.apache.ignite.internal.hlc.ClockService;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.placementdriver.PlacementDriver;
+import org.apache.ignite.internal.replicator.ReplicaService;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.replicator.exception.PrimaryReplicaMissException;
+import org.apache.ignite.internal.tx.message.TxMessagesFactory;
+import org.apache.ignite.internal.tx.message.VacuumTxStateReplicaRequest;
+import org.apache.ignite.network.ClusterNode;
+
+/**
+ * Implements the logic of persistent tx states vacuum.
+ */
+public class PersistentTxStateVacuumizer {
+ private static final IgniteLogger LOG = Loggers.forClass(PersistentTxStateVacuumizer.class);
+
+ private static final TxMessagesFactory TX_MESSAGES_FACTORY = new TxMessagesFactory();
+
+ private final ReplicaService replicaService;
+
+ private final ClusterNode localNode;
+
+ private final ClockService clockService;
+
+ private final PlacementDriver placementDriver;
+
+ /**
+ * Constructor.
+ *
+ * @param replicaService Replica service.
+ * @param localNode Local node.
+ * @param clockService Clock service.
+ * @param placementDriver Placement driver.
+ */
+ public PersistentTxStateVacuumizer(
+ ReplicaService replicaService,
+ ClusterNode localNode,
+ ClockService clockService,
+ PlacementDriver placementDriver
+ ) {
+ this.replicaService = replicaService;
+ this.localNode = localNode;
+ this.clockService = clockService;
+ this.placementDriver = placementDriver;
+ }
+
+ /**
+ * Vacuum persistent tx states.
+ *
+ * @param txIds Transaction ids to vacuum; map of commit partition ids to sets of tx ids.
+ * @return A future, result is the set of successfully vacuumized txn states.
+ */
+ public CompletableFuture<Set<UUID>> vacuumPersistentTxStates(Map<TablePartitionId, Set<UUID>> txIds) {
+ Set<UUID> successful = ConcurrentHashMap.newKeySet();
+ List<CompletableFuture<?>> futures = new ArrayList<>();
+ HybridTimestamp now = clockService.now();
+
+ txIds.forEach((commitPartitionId, txs) -> {
+ CompletableFuture<?> future = placementDriver.getPrimaryReplica(commitPartitionId, now)
+ .thenCompose(replicaMeta -> {
+ // If the primary replica is absent this means that another replica would become primary and
Review Comment:
1. If absent or doesn't match localNode.id()
2. Just "on primary replica election" ... cleanup completion timestamp recalculated
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1580520929
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTransactionTestUtils.java:
##########
@@ -0,0 +1,204 @@
+/*
+ * 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.table;
+
+import static java.util.Objects.requireNonNull;
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.TestWrappers.unwrapIgniteTransaction;
+import static org.apache.ignite.internal.TestWrappers.unwrapRecordBinaryViewImpl;
+import static org.apache.ignite.internal.TestWrappers.unwrapTableImpl;
+import static org.apache.ignite.internal.distributionzones.rebalance.RebalanceUtil.stablePartAssignmentsKey;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.Function;
+import org.apache.ignite.internal.affinity.Assignment;
+import org.apache.ignite.internal.affinity.Assignments;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.lang.ByteArray;
+import org.apache.ignite.internal.metastorage.Entry;
+import org.apache.ignite.internal.metastorage.MetaStorageManager;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.ReplicationGroupId;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.schema.BinaryRowEx;
+import org.apache.ignite.internal.tx.impl.ReadWriteTransactionImpl;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Test utils for transaction integration tests.
+ */
+public class ItTransactionTestUtils {
+ /**
+ * Get the names of the nodes that are assignments of the given partition.
+ *
+ * @param node Any node in the cluster.
+ * @param grpId Group id.
+ * @return Node names.
+ */
+ public static Set<String> partitionAssignment(IgniteImpl node, TablePartitionId grpId) {
Review Comment:
Test itself. Up to you.
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1574736503
##########
modules/runner/src/testFixtures/java/org/apache/ignite/internal/table/NodeUtils.java:
##########
@@ -49,16 +50,16 @@ public class NodeUtils {
*
* @param nodes Nodes collection.
* @param groupId Group id.
- * @param preferablePrimary Primary replica name which is preferred for being primary or {@code null}.
+ * @param preferablePrimaryFilter Primary replica preferable nodes filter, accepts the node consistent id.
* @return New primary replica name.
* @throws InterruptedException If failed.
*/
public static String transferPrimary(
Collection<IgniteImpl> nodes,
ReplicationGroupId groupId,
- @Nullable String preferablePrimary
+ @Nullable Predicate<String> preferablePrimaryFilter
Review Comment:
Should we move it towards node id instead of node name in order to support transferring primary to the same node after restart?
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTransactionTestUtils.java:
##########
@@ -0,0 +1,204 @@
+/*
+ * 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.table;
+
+import static java.util.Objects.requireNonNull;
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.TestWrappers.unwrapIgniteTransaction;
+import static org.apache.ignite.internal.TestWrappers.unwrapRecordBinaryViewImpl;
+import static org.apache.ignite.internal.TestWrappers.unwrapTableImpl;
+import static org.apache.ignite.internal.distributionzones.rebalance.RebalanceUtil.stablePartAssignmentsKey;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.Function;
+import org.apache.ignite.internal.affinity.Assignment;
+import org.apache.ignite.internal.affinity.Assignments;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.lang.ByteArray;
+import org.apache.ignite.internal.metastorage.Entry;
+import org.apache.ignite.internal.metastorage.MetaStorageManager;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.ReplicationGroupId;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.schema.BinaryRowEx;
+import org.apache.ignite.internal.tx.impl.ReadWriteTransactionImpl;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Test utils for transaction integration tests.
+ */
+public class ItTransactionTestUtils {
+ /**
+ * Get the names of the nodes that are assignments of the given partition.
+ *
+ * @param node Any node in the cluster.
+ * @param grpId Group id.
+ * @return Node names.
+ */
+ public static Set<String> partitionAssignment(IgniteImpl node, TablePartitionId grpId) {
+ MetaStorageManager metaStorageManager = node.metaStorageManager();
+
+ ByteArray stableAssignmentKey = stablePartAssignmentsKey(grpId);
+
+ CompletableFuture<Entry> assignmentEntryFut = metaStorageManager.get(stableAssignmentKey);
+
+ assertThat(assignmentEntryFut, willCompleteSuccessfully());
+
+ Entry e = assignmentEntryFut.join();
+
+ assertNotNull(e);
+ assertFalse(e.empty());
+ assertFalse(e.tombstone());
+
+ Set<Assignment> a = requireNonNull(Assignments.fromBytes(e.value())).nodes();
+
+ return a.stream().filter(Assignment::isPeer).map(Assignment::consistentId).collect(toSet());
+ }
+
+ /**
+ * Calculate the partition id on which the given tuple would be placed.
+ *
+ * @param node Any node in the cluster.
+ * @param tableName Table name.
+ * @param tuple Data tuple.
+ * @param tx Transaction, if present.
+ * @return Partition id.
+ */
+ public static int partitionIdForTuple(IgniteImpl node, String tableName, Tuple tuple, @Nullable Transaction tx) {
+ TableImpl table = table(node, tableName);
+ RecordBinaryViewImpl view = unwrapRecordBinaryViewImpl(table.recordView());
+
+ CompletableFuture<BinaryRowEx> rowFut = view.marshal(tx, tuple);
+ assertThat(rowFut, willCompleteSuccessfully());
+ BinaryRowEx row = rowFut.join();
+
+ return table.internalTable().partitionId(row);
+ }
+
+ /**
+ * Generates some tuple that would be placed in the partition that is hosted on the given node in the cluster.
+ *
+ * @param node Node that should host the result tuple.
+ * @param tableName Table name.
+ * @param tx Transaction, if present.
+ * @param initialTuple Initial tuple, for calculation.
+ * @param nextTuple This function will be used to generate new tuples in order to find suitable one.
+ * @param primary Whether the given node should be the primary node.
+ * @return Tuple that would be placed on the given node.
+ */
+ public static Tuple findTupleToBeHostedOnNode(
Review Comment:
Methods in given class look dirty. Not only misplaced and thus hard to find, but also with variety of strange parameters (why do we need transaction to find the tuple) along with initialTuple, nextTuple and last but not lease - suspicious implementation details, like max attempts.
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/PersistentTxStateVacuumizer.java:
##########
@@ -0,0 +1,124 @@
+/*
+ * 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.impl;
+
+import static org.apache.ignite.internal.util.CompletableFutures.allOf;
+import static org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture;
+import static org.apache.ignite.internal.util.ExceptionUtils.unwrapCause;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import org.apache.ignite.internal.hlc.ClockService;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.placementdriver.PlacementDriver;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.ReplicaService;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.replicator.exception.PrimaryReplicaMissException;
+import org.apache.ignite.internal.tx.message.TxMessagesFactory;
+import org.apache.ignite.internal.tx.message.VacuumTxStateReplicaRequest;
+import org.apache.ignite.network.ClusterNode;
+
+/**
+ * Implements the logic of persistent tx states vacuum.
+ */
+public class PersistentTxStateVacuumizer {
+ private static final IgniteLogger LOG = Loggers.forClass(PersistentTxStateVacuumizer.class);
+
+ private static final TxMessagesFactory TX_MESSAGES_FACTORY = new TxMessagesFactory();
+
+ private final ReplicaService replicaService;
+
+ private final ClusterNode localNode;
+
+ private final ClockService clockService;
+
+ private final PlacementDriver placementDriver;
+
+ /**
+ * Constructor.
+ *
+ * @param replicaService Replica service.
+ * @param localNode Local node.
+ * @param clockService Clock service.
+ * @param placementDriver Placement driver.
+ */
+ public PersistentTxStateVacuumizer(
+ ReplicaService replicaService,
+ ClusterNode localNode,
+ ClockService clockService,
+ PlacementDriver placementDriver
+ ) {
+ this.replicaService = replicaService;
+ this.localNode = localNode;
+ this.clockService = clockService;
+ this.placementDriver = placementDriver;
+ }
+
+ /**
+ * Vacuum persistent tx states.
+ *
+ * @param txIds Transaction ids to vacuum; map of commit partition ids to sets of tx ids.
+ * @return A future, result is the set of successfully vacuumized txn states.
+ */
+ public CompletableFuture<Set<UUID>> vacuumPersistentTxStates(Map<TablePartitionId, Set<UUID>> txIds) {
+ Set<UUID> successful = ConcurrentHashMap.newKeySet();
+ List<CompletableFuture<?>> futures = new ArrayList<>();
+ HybridTimestamp now = clockService.now();
+
+ txIds.forEach((commitPartitionId, txs) -> {
+ ReplicaMeta replicaMeta = placementDriver.getPrimaryReplica(commitPartitionId, now).join();
+
+ if (replicaMeta != null) {
+ VacuumTxStateReplicaRequest request = TX_MESSAGES_FACTORY.vacuumTxStateReplicaRequest()
+ .enlistmentConsistencyToken(replicaMeta.getStartTime().longValue())
+ .groupId(commitPartitionId)
+ .transactionIds(txs)
+ .build();
+
+ CompletableFuture<?> future;
+
+ if (localNode.id().equals(replicaMeta.getLeaseholderId())) {
+ future = replicaService.invoke(localNode, request).whenComplete((v, e) -> {
+ if (e == null) {
+ successful.addAll(txs);
+ } else if (!(unwrapCause(e) instanceof PrimaryReplicaMissException)) {
Review Comment:
Please add javadoc, explaining why we can fully ignore PrimaryReplicaMissException (BTW I'd also log it at debug level)
and why it's safe to only log the exceptions without any further explicit actions.
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
+public class ItTxResourcesVacuumTest extends ClusterPerTestIntegrationTest {
+ /** Table name. */
+ private static final String TABLE_NAME = "test_table";
+
+ private static final Tuple INITIAL_TUPLE = Tuple.create().set("key", 1L).set("val", "1");
+
+ private static final Function<Tuple, Tuple> NEXT_TUPLE = t -> Tuple.create()
+ .set("key", t.longValue("key") + 1)
+ .set("val", "" + (t.longValue("key") + 1));
+
+ private static final int REPLICAS = 2;
+
+ /** Nodes bootstrap configuration pattern. */
+ private static final String NODE_BOOTSTRAP_CFG_TEMPLATE = "{\n"
+ + " network: {\n"
+ + " port: {},\n"
+ + " nodeFinder: {\n"
+ + " netClusterNodes: [ {} ]\n"
+ + " }\n"
+ + " },\n"
+ + " clientConnector: { port:{} },\n"
+ + " rest.port: {},\n"
+ + " raft: { responseTimeout: 30000 },"
+ + " compute.threadPoolSize: 1\n"
+ + "}";
+
+ private ExecutorService txStateStorageExecutor = Executors.newSingleThreadExecutor();
+
+ @BeforeEach
+ @Override
+ public void setup(TestInfo testInfo) throws Exception {
+ super.setup(testInfo);
+
+ String zoneSql = "create zone test_zone with partitions=20, replicas=" + REPLICAS
+ + ", storage_profiles='" + DEFAULT_STORAGE_PROFILE + "'";
Review Comment:
We should check it for persistestans/in-memory, simple DEFAULT_STORAGE_PROFILE check is not enough.
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
+public class ItTxResourcesVacuumTest extends ClusterPerTestIntegrationTest {
+ /** Table name. */
+ private static final String TABLE_NAME = "test_table";
+
+ private static final Tuple INITIAL_TUPLE = Tuple.create().set("key", 1L).set("val", "1");
+
+ private static final Function<Tuple, Tuple> NEXT_TUPLE = t -> Tuple.create()
+ .set("key", t.longValue("key") + 1)
+ .set("val", "" + (t.longValue("key") + 1));
+
+ private static final int REPLICAS = 2;
+
+ /** Nodes bootstrap configuration pattern. */
+ private static final String NODE_BOOTSTRAP_CFG_TEMPLATE = "{\n"
+ + " network: {\n"
+ + " port: {},\n"
+ + " nodeFinder: {\n"
+ + " netClusterNodes: [ {} ]\n"
+ + " }\n"
+ + " },\n"
+ + " clientConnector: { port:{} },\n"
+ + " rest.port: {},\n"
+ + " raft: { responseTimeout: 30000 },"
+ + " compute.threadPoolSize: 1\n"
+ + "}";
+
+ private ExecutorService txStateStorageExecutor = Executors.newSingleThreadExecutor();
+
+ @BeforeEach
+ @Override
+ public void setup(TestInfo testInfo) throws Exception {
+ super.setup(testInfo);
+
+ String zoneSql = "create zone test_zone with partitions=20, replicas=" + REPLICAS
+ + ", storage_profiles='" + DEFAULT_STORAGE_PROFILE + "'";
+ String sql = "create table " + TABLE_NAME + " (key bigint primary key, val varchar(20)) with primary_zone='TEST_ZONE'";
+
+ cluster.doInSession(0, session -> {
+ executeUpdate(zoneSql, session);
+ executeUpdate(sql, session);
+ });
+
+ txStateStorageExecutor = Executors.newSingleThreadExecutor(IgniteThreadFactory.create("test", "tx-state-storage-test-pool", log,
+ ThreadOperation.STORAGE_READ));
+ }
+
+ @Override
+ @AfterEach
+ public void tearDown() {
+ shutdownAndAwaitTermination(txStateStorageExecutor, 10, TimeUnit.SECONDS);
+
+ super.tearDown();
+ }
+
+ @Override
+ protected void customizeInitParameters(InitParametersBuilder builder) {
+ super.customizeInitParameters(builder);
+
+ builder.clusterConfiguration("{"
+ + " transaction: {"
+ + " implicitTransactionTimeout: 30000,"
+ + " txnResourceTtl: 2"
+ + " },"
+ + " replication: {"
+ + " rpcTimeout: 30000"
+ + " },"
+ + "}");
+ }
+
+ @Override
+ protected int initialNodes() {
+ return 3;
+ }
+
+ /**
+ * Returns node bootstrap config template.
+ *
+ * @return Node bootstrap config template.
+ */
+ @Override
+ protected String getNodeBootstrapConfigTemplate() {
+ return NODE_BOOTSTRAP_CFG_TEMPLATE;
+ }
+
+ @Test
+ public void testVacuum() throws InterruptedException {
+ IgniteImpl node = anyNode();
+
+ RecordView<Tuple> view = node.tables().table(TABLE_NAME).recordView();
+
+ // Put some value into the table.
+ Transaction tx = node.transactions().begin();
+ UUID txId = txId(tx);
+
+ log.info("Test: Loading the data [tx={}].", txId);
+
+ Tuple tuple = findTupleToBeHostedOnNode(node, TABLE_NAME, tx, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ int partId = partitionIdForTuple(node, TABLE_NAME, tuple, tx);
+
+ Set<String> nodes = partitionAssignment(node, new TablePartitionId(tableId(node, TABLE_NAME), partId));
+
+ view.upsert(tx, tuple);
+
+ tx.commit();
+
+ log.info("Test: Tx committed [tx={}].", txId);
+
+ checkVolatileTxStateOnNodes(nodes, txId);
+ waitForTxStateReplication(nodes, txId, partId, 10_000);
+
+ waitForTxStateVacuum(txId, partId, true, 10_000);
Review Comment:
In _every_ vacuum test I'd add check the data by reading corresponding expected values both with RW and RO transactions. It's also important to read the data with RO readTimestamp in between WI creation and vacuumization.
Mean following.
1. Tx1:: put(k1,v1), commit (commitTimestamp t10).
2. Tx2:: put(k1,v2), commit (commitTimestamp t20).
3. Vacuum both tx1, tx2 states.
4. RW T3:: get(k1) -> expect v2.
5. RO Tx4:: get(k1, /** readTimestamp */ t25) -> expect v2
6. RO Tx5:: get(k1, /** readTimestamp */ t15) -> expect v1
7. RO Tx6:: get(k1, /** readTimestamp */ t5) -> expect null
In order to "set" proper readTimestamp you can just start RO in proper moment in time and do enlist actual operation whenever you actually need.
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
+public class ItTxResourcesVacuumTest extends ClusterPerTestIntegrationTest {
+ /** Table name. */
+ private static final String TABLE_NAME = "test_table";
+
+ private static final Tuple INITIAL_TUPLE = Tuple.create().set("key", 1L).set("val", "1");
+
+ private static final Function<Tuple, Tuple> NEXT_TUPLE = t -> Tuple.create()
+ .set("key", t.longValue("key") + 1)
+ .set("val", "" + (t.longValue("key") + 1));
+
+ private static final int REPLICAS = 2;
+
+ /** Nodes bootstrap configuration pattern. */
+ private static final String NODE_BOOTSTRAP_CFG_TEMPLATE = "{\n"
+ + " network: {\n"
+ + " port: {},\n"
+ + " nodeFinder: {\n"
+ + " netClusterNodes: [ {} ]\n"
+ + " }\n"
+ + " },\n"
+ + " clientConnector: { port:{} },\n"
+ + " rest.port: {},\n"
+ + " raft: { responseTimeout: 30000 },"
+ + " compute.threadPoolSize: 1\n"
+ + "}";
+
+ private ExecutorService txStateStorageExecutor = Executors.newSingleThreadExecutor();
+
+ @BeforeEach
+ @Override
+ public void setup(TestInfo testInfo) throws Exception {
+ super.setup(testInfo);
+
+ String zoneSql = "create zone test_zone with partitions=20, replicas=" + REPLICAS
+ + ", storage_profiles='" + DEFAULT_STORAGE_PROFILE + "'";
+ String sql = "create table " + TABLE_NAME + " (key bigint primary key, val varchar(20)) with primary_zone='TEST_ZONE'";
+
+ cluster.doInSession(0, session -> {
+ executeUpdate(zoneSql, session);
+ executeUpdate(sql, session);
+ });
+
+ txStateStorageExecutor = Executors.newSingleThreadExecutor(IgniteThreadFactory.create("test", "tx-state-storage-test-pool", log,
+ ThreadOperation.STORAGE_READ));
+ }
+
+ @Override
+ @AfterEach
+ public void tearDown() {
+ shutdownAndAwaitTermination(txStateStorageExecutor, 10, TimeUnit.SECONDS);
+
+ super.tearDown();
+ }
+
+ @Override
+ protected void customizeInitParameters(InitParametersBuilder builder) {
+ super.customizeInitParameters(builder);
+
+ builder.clusterConfiguration("{"
+ + " transaction: {"
+ + " implicitTransactionTimeout: 30000,"
+ + " txnResourceTtl: 2"
+ + " },"
+ + " replication: {"
+ + " rpcTimeout: 30000"
+ + " },"
+ + "}");
+ }
+
+ @Override
+ protected int initialNodes() {
+ return 3;
+ }
+
+ /**
+ * Returns node bootstrap config template.
+ *
+ * @return Node bootstrap config template.
+ */
+ @Override
+ protected String getNodeBootstrapConfigTemplate() {
+ return NODE_BOOTSTRAP_CFG_TEMPLATE;
+ }
+
+ @Test
+ public void testVacuum() throws InterruptedException {
+ IgniteImpl node = anyNode();
+
+ RecordView<Tuple> view = node.tables().table(TABLE_NAME).recordView();
+
+ // Put some value into the table.
+ Transaction tx = node.transactions().begin();
+ UUID txId = txId(tx);
+
+ log.info("Test: Loading the data [tx={}].", txId);
+
+ Tuple tuple = findTupleToBeHostedOnNode(node, TABLE_NAME, tx, INITIAL_TUPLE, NEXT_TUPLE, true);
Review Comment:
Why so complicated? Do we really need to find specific node within given scenario?
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
+public class ItTxResourcesVacuumTest extends ClusterPerTestIntegrationTest {
+ /** Table name. */
+ private static final String TABLE_NAME = "test_table";
+
+ private static final Tuple INITIAL_TUPLE = Tuple.create().set("key", 1L).set("val", "1");
+
+ private static final Function<Tuple, Tuple> NEXT_TUPLE = t -> Tuple.create()
+ .set("key", t.longValue("key") + 1)
+ .set("val", "" + (t.longValue("key") + 1));
+
+ private static final int REPLICAS = 2;
+
+ /** Nodes bootstrap configuration pattern. */
+ private static final String NODE_BOOTSTRAP_CFG_TEMPLATE = "{\n"
+ + " network: {\n"
+ + " port: {},\n"
+ + " nodeFinder: {\n"
+ + " netClusterNodes: [ {} ]\n"
+ + " }\n"
+ + " },\n"
+ + " clientConnector: { port:{} },\n"
+ + " rest.port: {},\n"
+ + " raft: { responseTimeout: 30000 },"
+ + " compute.threadPoolSize: 1\n"
+ + "}";
+
+ private ExecutorService txStateStorageExecutor = Executors.newSingleThreadExecutor();
+
+ @BeforeEach
+ @Override
+ public void setup(TestInfo testInfo) throws Exception {
+ super.setup(testInfo);
+
+ String zoneSql = "create zone test_zone with partitions=20, replicas=" + REPLICAS
+ + ", storage_profiles='" + DEFAULT_STORAGE_PROFILE + "'";
+ String sql = "create table " + TABLE_NAME + " (key bigint primary key, val varchar(20)) with primary_zone='TEST_ZONE'";
+
+ cluster.doInSession(0, session -> {
+ executeUpdate(zoneSql, session);
+ executeUpdate(sql, session);
+ });
+
+ txStateStorageExecutor = Executors.newSingleThreadExecutor(IgniteThreadFactory.create("test", "tx-state-storage-test-pool", log,
+ ThreadOperation.STORAGE_READ));
+ }
+
+ @Override
+ @AfterEach
+ public void tearDown() {
+ shutdownAndAwaitTermination(txStateStorageExecutor, 10, TimeUnit.SECONDS);
+
+ super.tearDown();
+ }
+
+ @Override
+ protected void customizeInitParameters(InitParametersBuilder builder) {
+ super.customizeInitParameters(builder);
+
+ builder.clusterConfiguration("{"
+ + " transaction: {"
+ + " implicitTransactionTimeout: 30000,"
+ + " txnResourceTtl: 2"
+ + " },"
+ + " replication: {"
+ + " rpcTimeout: 30000"
+ + " },"
+ + "}");
+ }
+
+ @Override
+ protected int initialNodes() {
+ return 3;
+ }
+
+ /**
+ * Returns node bootstrap config template.
+ *
+ * @return Node bootstrap config template.
+ */
+ @Override
+ protected String getNodeBootstrapConfigTemplate() {
+ return NODE_BOOTSTRAP_CFG_TEMPLATE;
+ }
+
+ @Test
Review Comment:
Do we have test that checks that abandoned transactions aren't vacuumized but will be after abortion on recovery?
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/PersistentTxStateVacuumizer.java:
##########
@@ -0,0 +1,124 @@
+/*
+ * 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.impl;
+
+import static org.apache.ignite.internal.util.CompletableFutures.allOf;
+import static org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture;
+import static org.apache.ignite.internal.util.ExceptionUtils.unwrapCause;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import org.apache.ignite.internal.hlc.ClockService;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.placementdriver.PlacementDriver;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.ReplicaService;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.replicator.exception.PrimaryReplicaMissException;
+import org.apache.ignite.internal.tx.message.TxMessagesFactory;
+import org.apache.ignite.internal.tx.message.VacuumTxStateReplicaRequest;
+import org.apache.ignite.network.ClusterNode;
+
+/**
+ * Implements the logic of persistent tx states vacuum.
+ */
+public class PersistentTxStateVacuumizer {
+ private static final IgniteLogger LOG = Loggers.forClass(PersistentTxStateVacuumizer.class);
+
+ private static final TxMessagesFactory TX_MESSAGES_FACTORY = new TxMessagesFactory();
+
+ private final ReplicaService replicaService;
+
+ private final ClusterNode localNode;
+
+ private final ClockService clockService;
+
+ private final PlacementDriver placementDriver;
+
+ /**
+ * Constructor.
+ *
+ * @param replicaService Replica service.
+ * @param localNode Local node.
+ * @param clockService Clock service.
+ * @param placementDriver Placement driver.
+ */
+ public PersistentTxStateVacuumizer(
+ ReplicaService replicaService,
+ ClusterNode localNode,
+ ClockService clockService,
+ PlacementDriver placementDriver
+ ) {
+ this.replicaService = replicaService;
+ this.localNode = localNode;
+ this.clockService = clockService;
+ this.placementDriver = placementDriver;
+ }
+
+ /**
+ * Vacuum persistent tx states.
+ *
+ * @param txIds Transaction ids to vacuum; map of commit partition ids to sets of tx ids.
+ * @return A future, result is the set of successfully vacuumized txn states.
+ */
+ public CompletableFuture<Set<UUID>> vacuumPersistentTxStates(Map<TablePartitionId, Set<UUID>> txIds) {
+ Set<UUID> successful = ConcurrentHashMap.newKeySet();
+ List<CompletableFuture<?>> futures = new ArrayList<>();
+ HybridTimestamp now = clockService.now();
+
+ txIds.forEach((commitPartitionId, txs) -> {
+ ReplicaMeta replicaMeta = placementDriver.getPrimaryReplica(commitPartitionId, now).join();
Review Comment:
join? No way, let's make it asynchronous.
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/PersistentTxStateVacuumizer.java:
##########
@@ -0,0 +1,124 @@
+/*
+ * 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.impl;
+
+import static org.apache.ignite.internal.util.CompletableFutures.allOf;
+import static org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture;
+import static org.apache.ignite.internal.util.ExceptionUtils.unwrapCause;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import org.apache.ignite.internal.hlc.ClockService;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.placementdriver.PlacementDriver;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.ReplicaService;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.replicator.exception.PrimaryReplicaMissException;
+import org.apache.ignite.internal.tx.message.TxMessagesFactory;
+import org.apache.ignite.internal.tx.message.VacuumTxStateReplicaRequest;
+import org.apache.ignite.network.ClusterNode;
+
+/**
+ * Implements the logic of persistent tx states vacuum.
+ */
+public class PersistentTxStateVacuumizer {
+ private static final IgniteLogger LOG = Loggers.forClass(PersistentTxStateVacuumizer.class);
+
+ private static final TxMessagesFactory TX_MESSAGES_FACTORY = new TxMessagesFactory();
+
+ private final ReplicaService replicaService;
+
+ private final ClusterNode localNode;
+
+ private final ClockService clockService;
+
+ private final PlacementDriver placementDriver;
+
+ /**
+ * Constructor.
+ *
+ * @param replicaService Replica service.
+ * @param localNode Local node.
+ * @param clockService Clock service.
+ * @param placementDriver Placement driver.
+ */
+ public PersistentTxStateVacuumizer(
+ ReplicaService replicaService,
+ ClusterNode localNode,
+ ClockService clockService,
+ PlacementDriver placementDriver
+ ) {
+ this.replicaService = replicaService;
+ this.localNode = localNode;
+ this.clockService = clockService;
+ this.placementDriver = placementDriver;
+ }
+
+ /**
+ * Vacuum persistent tx states.
+ *
+ * @param txIds Transaction ids to vacuum; map of commit partition ids to sets of tx ids.
+ * @return A future, result is the set of successfully vacuumized txn states.
+ */
+ public CompletableFuture<Set<UUID>> vacuumPersistentTxStates(Map<TablePartitionId, Set<UUID>> txIds) {
+ Set<UUID> successful = ConcurrentHashMap.newKeySet();
+ List<CompletableFuture<?>> futures = new ArrayList<>();
+ HybridTimestamp now = clockService.now();
+
+ txIds.forEach((commitPartitionId, txs) -> {
+ ReplicaMeta replicaMeta = placementDriver.getPrimaryReplica(commitPartitionId, now).join();
+
+ if (replicaMeta != null) {
+ VacuumTxStateReplicaRequest request = TX_MESSAGES_FACTORY.vacuumTxStateReplicaRequest()
+ .enlistmentConsistencyToken(replicaMeta.getStartTime().longValue())
+ .groupId(commitPartitionId)
+ .transactionIds(txs)
+ .build();
+
+ CompletableFuture<?> future;
+
+ if (localNode.id().equals(replicaMeta.getLeaseholderId())) {
Review Comment:
Please add javadoc explaining why we won't send the request if ids doesn't match.
##########
modules/table/src/main/java/org/apache/ignite/internal/table/RecordBinaryViewImpl.java:
##########
@@ -402,6 +404,24 @@ private static Row marshal(Tuple tuple, TupleMarshaller marshaller, boolean keyO
}
}
+ /**
+ * Marshal a tuple to a row. Test-only public method.
+ *
+ * @param tx Transaction, if present.
+ * @param rec Tuple record.
+ * @return A future, with row as a result.
+ */
+ @TestOnly
+ public CompletableFuture<BinaryRowEx> marshal(@Nullable Transaction tx, Tuple rec) {
+ Objects.requireNonNull(rec);
+
+ return doOperation(tx, schemaVersion -> {
Review Comment:
Semantics is broken here: semantically marshal is a part of doOperation and not vice versa, meaning that it's counterintuitive to have marshal wrapped with doOperation wrapped with marshal.
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbStorage.java:
##########
@@ -169,34 +170,66 @@ public void put(UUID txId, TxMeta txMeta) {
@Override
public boolean compareAndSet(UUID txId, @Nullable TxState txStateExpected, TxMeta txMeta, long commandIndex, long commandTerm) {
- return busy(() -> {
- try (WriteBatch writeBatch = new WriteBatch()) {
- byte[] txIdBytes = txIdToKey(txId);
+ return updateData(writeBatch -> {
Review Comment:
And what about other operations like `TxStateStorage#put`? I believe we should also update index and term there.
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTransactionTestUtils.java:
##########
@@ -0,0 +1,204 @@
+/*
+ * 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.table;
+
+import static java.util.Objects.requireNonNull;
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.TestWrappers.unwrapIgniteTransaction;
+import static org.apache.ignite.internal.TestWrappers.unwrapRecordBinaryViewImpl;
+import static org.apache.ignite.internal.TestWrappers.unwrapTableImpl;
+import static org.apache.ignite.internal.distributionzones.rebalance.RebalanceUtil.stablePartAssignmentsKey;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.Function;
+import org.apache.ignite.internal.affinity.Assignment;
+import org.apache.ignite.internal.affinity.Assignments;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.lang.ByteArray;
+import org.apache.ignite.internal.metastorage.Entry;
+import org.apache.ignite.internal.metastorage.MetaStorageManager;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.ReplicationGroupId;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.schema.BinaryRowEx;
+import org.apache.ignite.internal.tx.impl.ReadWriteTransactionImpl;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Test utils for transaction integration tests.
+ */
+public class ItTransactionTestUtils {
Review Comment:
Why we have Transaction...Utils in table module?
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTransactionTestUtils.java:
##########
@@ -0,0 +1,204 @@
+/*
+ * 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.table;
+
+import static java.util.Objects.requireNonNull;
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.TestWrappers.unwrapIgniteTransaction;
+import static org.apache.ignite.internal.TestWrappers.unwrapRecordBinaryViewImpl;
+import static org.apache.ignite.internal.TestWrappers.unwrapTableImpl;
+import static org.apache.ignite.internal.distributionzones.rebalance.RebalanceUtil.stablePartAssignmentsKey;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.Function;
+import org.apache.ignite.internal.affinity.Assignment;
+import org.apache.ignite.internal.affinity.Assignments;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.lang.ByteArray;
+import org.apache.ignite.internal.metastorage.Entry;
+import org.apache.ignite.internal.metastorage.MetaStorageManager;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.ReplicationGroupId;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.schema.BinaryRowEx;
+import org.apache.ignite.internal.tx.impl.ReadWriteTransactionImpl;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Test utils for transaction integration tests.
+ */
+public class ItTransactionTestUtils {
Review Comment:
I'd say it should go to testFixtures.
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTransactionTestUtils.java:
##########
@@ -0,0 +1,204 @@
+/*
+ * 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.table;
+
+import static java.util.Objects.requireNonNull;
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.TestWrappers.unwrapIgniteTransaction;
+import static org.apache.ignite.internal.TestWrappers.unwrapRecordBinaryViewImpl;
+import static org.apache.ignite.internal.TestWrappers.unwrapTableImpl;
+import static org.apache.ignite.internal.distributionzones.rebalance.RebalanceUtil.stablePartAssignmentsKey;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.Function;
+import org.apache.ignite.internal.affinity.Assignment;
+import org.apache.ignite.internal.affinity.Assignments;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.lang.ByteArray;
+import org.apache.ignite.internal.metastorage.Entry;
+import org.apache.ignite.internal.metastorage.MetaStorageManager;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.ReplicationGroupId;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.schema.BinaryRowEx;
+import org.apache.ignite.internal.tx.impl.ReadWriteTransactionImpl;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Test utils for transaction integration tests.
+ */
+public class ItTransactionTestUtils {
+ /**
+ * Get the names of the nodes that are assignments of the given partition.
+ *
+ * @param node Any node in the cluster.
+ * @param grpId Group id.
+ * @return Node names.
+ */
+ public static Set<String> partitionAssignment(IgniteImpl node, TablePartitionId grpId) {
Review Comment:
To be honest I'd never guess that ItTransactionTestUtils is a holder for such method.
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTransactionPrimaryChangeTest.java:
##########
@@ -87,7 +85,8 @@ protected void customizeInitParameters(InitParametersBuilder builder) {
builder.clusterConfiguration("{"
+ " transaction: {"
- + " implicitTransactionTimeout: 30000"
+ + " implicitTransactionTimeout: 30000,"
+ + " txnResourceTtl: 2"
Review Comment:
Why it's 2 here?
##########
modules/table/src/main/java/org/apache/ignite/internal/table/RecordBinaryViewImpl.java:
##########
@@ -402,6 +404,24 @@ private static Row marshal(Tuple tuple, TupleMarshaller marshaller, boolean keyO
}
}
+ /**
+ * Marshal a tuple to a row. Test-only public method.
+ *
+ * @param tx Transaction, if present.
+ * @param rec Tuple record.
+ * @return A future, with row as a result.
+ */
+ @TestOnly
+ public CompletableFuture<BinaryRowEx> marshal(@Nullable Transaction tx, Tuple rec) {
Review Comment:
Why do we need tx in marshal operation?
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
+public class ItTxResourcesVacuumTest extends ClusterPerTestIntegrationTest {
+ /** Table name. */
+ private static final String TABLE_NAME = "test_table";
+
+ private static final Tuple INITIAL_TUPLE = Tuple.create().set("key", 1L).set("val", "1");
+
+ private static final Function<Tuple, Tuple> NEXT_TUPLE = t -> Tuple.create()
+ .set("key", t.longValue("key") + 1)
+ .set("val", "" + (t.longValue("key") + 1));
+
+ private static final int REPLICAS = 2;
+
+ /** Nodes bootstrap configuration pattern. */
+ private static final String NODE_BOOTSTRAP_CFG_TEMPLATE = "{\n"
+ + " network: {\n"
+ + " port: {},\n"
+ + " nodeFinder: {\n"
+ + " netClusterNodes: [ {} ]\n"
+ + " }\n"
+ + " },\n"
+ + " clientConnector: { port:{} },\n"
+ + " rest.port: {},\n"
+ + " raft: { responseTimeout: 30000 },"
+ + " compute.threadPoolSize: 1\n"
+ + "}";
+
+ private ExecutorService txStateStorageExecutor = Executors.newSingleThreadExecutor();
+
+ @BeforeEach
+ @Override
+ public void setup(TestInfo testInfo) throws Exception {
+ super.setup(testInfo);
+
+ String zoneSql = "create zone test_zone with partitions=20, replicas=" + REPLICAS
+ + ", storage_profiles='" + DEFAULT_STORAGE_PROFILE + "'";
+ String sql = "create table " + TABLE_NAME + " (key bigint primary key, val varchar(20)) with primary_zone='TEST_ZONE'";
+
+ cluster.doInSession(0, session -> {
+ executeUpdate(zoneSql, session);
+ executeUpdate(sql, session);
+ });
+
+ txStateStorageExecutor = Executors.newSingleThreadExecutor(IgniteThreadFactory.create("test", "tx-state-storage-test-pool", log,
+ ThreadOperation.STORAGE_READ));
+ }
+
+ @Override
+ @AfterEach
+ public void tearDown() {
+ shutdownAndAwaitTermination(txStateStorageExecutor, 10, TimeUnit.SECONDS);
+
+ super.tearDown();
+ }
+
+ @Override
+ protected void customizeInitParameters(InitParametersBuilder builder) {
+ super.customizeInitParameters(builder);
+
+ builder.clusterConfiguration("{"
+ + " transaction: {"
+ + " implicitTransactionTimeout: 30000,"
+ + " txnResourceTtl: 2"
+ + " },"
+ + " replication: {"
+ + " rpcTimeout: 30000"
+ + " },"
+ + "}");
+ }
+
+ @Override
+ protected int initialNodes() {
+ return 3;
+ }
+
+ /**
+ * Returns node bootstrap config template.
+ *
+ * @return Node bootstrap config template.
+ */
+ @Override
+ protected String getNodeBootstrapConfigTemplate() {
+ return NODE_BOOTSTRAP_CFG_TEMPLATE;
+ }
+
+ @Test
+ public void testVacuum() throws InterruptedException {
+ IgniteImpl node = anyNode();
+
+ RecordView<Tuple> view = node.tables().table(TABLE_NAME).recordView();
+
+ // Put some value into the table.
+ Transaction tx = node.transactions().begin();
+ UUID txId = txId(tx);
+
+ log.info("Test: Loading the data [tx={}].", txId);
+
+ Tuple tuple = findTupleToBeHostedOnNode(node, TABLE_NAME, tx, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ int partId = partitionIdForTuple(node, TABLE_NAME, tuple, tx);
+
+ Set<String> nodes = partitionAssignment(node, new TablePartitionId(tableId(node, TABLE_NAME), partId));
+
+ view.upsert(tx, tuple);
+
+ tx.commit();
+
+ log.info("Test: Tx committed [tx={}].", txId);
+
+ checkVolatileTxStateOnNodes(nodes, txId);
+ waitForTxStateReplication(nodes, txId, partId, 10_000);
Review Comment:
Why do we need to awaitTxStateReplication?
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbStorage.java:
##########
@@ -169,34 +170,66 @@ public void put(UUID txId, TxMeta txMeta) {
@Override
public boolean compareAndSet(UUID txId, @Nullable TxState txStateExpected, TxMeta txMeta, long commandIndex, long commandTerm) {
- return busy(() -> {
- try (WriteBatch writeBatch = new WriteBatch()) {
- byte[] txIdBytes = txIdToKey(txId);
+ return updateData(writeBatch -> {
+ byte[] txIdBytes = txIdToKey(txId);
- byte[] txMetaExistingBytes = sharedStorage.db().get(sharedStorage.readOptions, txIdToKey(txId));
+ byte[] txMetaExistingBytes = sharedStorage.db().get(sharedStorage.readOptions, txIdToKey(txId));
- boolean result;
+ boolean result;
- if (txMetaExistingBytes == null && txStateExpected == null) {
- writeBatch.put(txIdBytes, toBytes(txMeta));
+ if (txMetaExistingBytes == null && txStateExpected == null) {
+ writeBatch.put(txIdBytes, toBytes(txMeta));
- result = true;
- } else {
- if (txMetaExistingBytes != null) {
- TxMeta txMetaExisting = fromBytes(txMetaExistingBytes);
+ result = true;
+ } else {
+ if (txMetaExistingBytes != null) {
+ TxMeta txMetaExisting = fromBytes(txMetaExistingBytes);
- if (txMetaExisting.txState() == txStateExpected) {
- writeBatch.put(txIdBytes, toBytes(txMeta));
+ if (txMetaExisting.txState() == txStateExpected) {
+ writeBatch.put(txIdBytes, toBytes(txMeta));
- result = true;
- } else {
- result = txMetaExisting.txState() == txMeta.txState()
- && Objects.equals(txMetaExisting.commitTimestamp(), txMeta.commitTimestamp());
- }
+ result = true;
} else {
- result = false;
+ result = txMetaExisting.txState() == txMeta.txState()
+ && Objects.equals(txMetaExisting.commitTimestamp(), txMeta.commitTimestamp());
}
+ } else {
+ result = false;
}
+ }
+
+ return result;
+ }, commandIndex, commandTerm);
+ }
+
+ @Override
+ public void remove(UUID txId, long commandIndex, long commandTerm) {
+ updateData(writeBatch -> {
+ throwExceptionIfStorageInProgressOfRebalance();
+
+ writeBatch.delete(txIdToKey(txId));
+
+ return null;
+ }, commandIndex, commandTerm);
+ }
+
+ @Override
+ public void removeAll(Collection<UUID> txIds, long commandIndex, long commandTerm) {
+ updateData(writeBatch -> {
+ throwExceptionIfStorageInProgressOfRebalance();
Review Comment:
1. Do we have this check in CAS and put? Why?
2. Why it's inside updateData?
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
+public class ItTxResourcesVacuumTest extends ClusterPerTestIntegrationTest {
+ /** Table name. */
+ private static final String TABLE_NAME = "test_table";
+
+ private static final Tuple INITIAL_TUPLE = Tuple.create().set("key", 1L).set("val", "1");
+
+ private static final Function<Tuple, Tuple> NEXT_TUPLE = t -> Tuple.create()
+ .set("key", t.longValue("key") + 1)
+ .set("val", "" + (t.longValue("key") + 1));
+
+ private static final int REPLICAS = 2;
Review Comment:
Why it's 2? We are mostly interested in checking the fact that there will be a minority that won't have it's WI converted to regular values and still we will be able to do all the RW/RO load.
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
Review Comment:
Curious, how do you manually trigger the vacuum?
##########
modules/transactions/src/testFixtures/java/org/apache/ignite/internal/tx/storage/state/AbstractTxStateStorageTest.java:
##########
@@ -83,6 +86,21 @@ protected void afterTest() throws Exception {
@Test
public void testPutGetRemove() {
+ testPutGetRemove0((storage, txIds) -> {
+ int index = 0;
+
+ for (UUID txId : txIds) {
+ storage.remove(txId, index++, 1);
+ }
+ });
+ }
+
+ @Test
+ public void testPutGetRemoveAll() {
Review Comment:
Single test only? What about empty collection case, duplications?
BTW, from my point of view it worth extracting storage updates(new removeAll and index/term bug fixing) to separate ticket.
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
+public class ItTxResourcesVacuumTest extends ClusterPerTestIntegrationTest {
+ /** Table name. */
+ private static final String TABLE_NAME = "test_table";
+
+ private static final Tuple INITIAL_TUPLE = Tuple.create().set("key", 1L).set("val", "1");
+
+ private static final Function<Tuple, Tuple> NEXT_TUPLE = t -> Tuple.create()
+ .set("key", t.longValue("key") + 1)
+ .set("val", "" + (t.longValue("key") + 1));
+
+ private static final int REPLICAS = 2;
+
+ /** Nodes bootstrap configuration pattern. */
+ private static final String NODE_BOOTSTRAP_CFG_TEMPLATE = "{\n"
+ + " network: {\n"
+ + " port: {},\n"
+ + " nodeFinder: {\n"
+ + " netClusterNodes: [ {} ]\n"
+ + " }\n"
+ + " },\n"
+ + " clientConnector: { port:{} },\n"
+ + " rest.port: {},\n"
+ + " raft: { responseTimeout: 30000 },"
+ + " compute.threadPoolSize: 1\n"
+ + "}";
+
+ private ExecutorService txStateStorageExecutor = Executors.newSingleThreadExecutor();
+
+ @BeforeEach
+ @Override
+ public void setup(TestInfo testInfo) throws Exception {
+ super.setup(testInfo);
+
+ String zoneSql = "create zone test_zone with partitions=20, replicas=" + REPLICAS
+ + ", storage_profiles='" + DEFAULT_STORAGE_PROFILE + "'";
+ String sql = "create table " + TABLE_NAME + " (key bigint primary key, val varchar(20)) with primary_zone='TEST_ZONE'";
+
+ cluster.doInSession(0, session -> {
+ executeUpdate(zoneSql, session);
+ executeUpdate(sql, session);
+ });
+
+ txStateStorageExecutor = Executors.newSingleThreadExecutor(IgniteThreadFactory.create("test", "tx-state-storage-test-pool", log,
+ ThreadOperation.STORAGE_READ));
+ }
+
+ @Override
+ @AfterEach
+ public void tearDown() {
+ shutdownAndAwaitTermination(txStateStorageExecutor, 10, TimeUnit.SECONDS);
+
+ super.tearDown();
+ }
+
+ @Override
+ protected void customizeInitParameters(InitParametersBuilder builder) {
+ super.customizeInitParameters(builder);
+
+ builder.clusterConfiguration("{"
+ + " transaction: {"
+ + " implicitTransactionTimeout: 30000,"
+ + " txnResourceTtl: 2"
+ + " },"
+ + " replication: {"
+ + " rpcTimeout: 30000"
+ + " },"
+ + "}");
+ }
+
+ @Override
+ protected int initialNodes() {
+ return 3;
+ }
+
+ /**
+ * Returns node bootstrap config template.
+ *
+ * @return Node bootstrap config template.
+ */
+ @Override
+ protected String getNodeBootstrapConfigTemplate() {
+ return NODE_BOOTSTRAP_CFG_TEMPLATE;
+ }
+
+ @Test
+ public void testVacuum() throws InterruptedException {
Review Comment:
Within given test you do check that **timer** calls vacuum and the last removes both persistent and volatile states, right?
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
+public class ItTxResourcesVacuumTest extends ClusterPerTestIntegrationTest {
+ /** Table name. */
+ private static final String TABLE_NAME = "test_table";
+
+ private static final Tuple INITIAL_TUPLE = Tuple.create().set("key", 1L).set("val", "1");
+
+ private static final Function<Tuple, Tuple> NEXT_TUPLE = t -> Tuple.create()
+ .set("key", t.longValue("key") + 1)
+ .set("val", "" + (t.longValue("key") + 1));
+
+ private static final int REPLICAS = 2;
+
+ /** Nodes bootstrap configuration pattern. */
+ private static final String NODE_BOOTSTRAP_CFG_TEMPLATE = "{\n"
+ + " network: {\n"
+ + " port: {},\n"
+ + " nodeFinder: {\n"
+ + " netClusterNodes: [ {} ]\n"
+ + " }\n"
+ + " },\n"
+ + " clientConnector: { port:{} },\n"
+ + " rest.port: {},\n"
+ + " raft: { responseTimeout: 30000 },"
+ + " compute.threadPoolSize: 1\n"
+ + "}";
+
+ private ExecutorService txStateStorageExecutor = Executors.newSingleThreadExecutor();
+
+ @BeforeEach
+ @Override
+ public void setup(TestInfo testInfo) throws Exception {
+ super.setup(testInfo);
+
+ String zoneSql = "create zone test_zone with partitions=20, replicas=" + REPLICAS
+ + ", storage_profiles='" + DEFAULT_STORAGE_PROFILE + "'";
+ String sql = "create table " + TABLE_NAME + " (key bigint primary key, val varchar(20)) with primary_zone='TEST_ZONE'";
+
+ cluster.doInSession(0, session -> {
+ executeUpdate(zoneSql, session);
+ executeUpdate(sql, session);
+ });
+
+ txStateStorageExecutor = Executors.newSingleThreadExecutor(IgniteThreadFactory.create("test", "tx-state-storage-test-pool", log,
+ ThreadOperation.STORAGE_READ));
+ }
+
+ @Override
+ @AfterEach
+ public void tearDown() {
+ shutdownAndAwaitTermination(txStateStorageExecutor, 10, TimeUnit.SECONDS);
+
+ super.tearDown();
+ }
+
+ @Override
+ protected void customizeInitParameters(InitParametersBuilder builder) {
+ super.customizeInitParameters(builder);
+
+ builder.clusterConfiguration("{"
+ + " transaction: {"
+ + " implicitTransactionTimeout: 30000,"
+ + " txnResourceTtl: 2"
+ + " },"
+ + " replication: {"
+ + " rpcTimeout: 30000"
+ + " },"
+ + "}");
+ }
+
+ @Override
+ protected int initialNodes() {
+ return 3;
+ }
+
+ /**
+ * Returns node bootstrap config template.
+ *
+ * @return Node bootstrap config template.
+ */
+ @Override
+ protected String getNodeBootstrapConfigTemplate() {
+ return NODE_BOOTSTRAP_CFG_TEMPLATE;
+ }
+
Review Comment:
Do we have test that checks that pending/finishing transactions aren't vacuumized?
##########
modules/transactions/src/testFixtures/java/org/apache/ignite/internal/tx/storage/state/test/TestTxStateStorage.java:
##########
@@ -108,10 +108,15 @@ public boolean compareAndSet(UUID txId, @Nullable TxState txStateExpected, TxMet
}
@Override
- public void remove(UUID txId) {
+ public void remove(UUID txId, long commandIndex, long commandTerm) {
checkStorageClosedOrInProgressOfRebalance();
storage.remove(txId);
+
+ if (rebalanceFutureReference.get() == null) {
+ lastAppliedIndex = commandIndex;
Review Comment:
Nice joke! Despite the fact that put is not used in regular flow right now, it definitely might be used and thus should be implemented correctly.
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
+public class ItTxResourcesVacuumTest extends ClusterPerTestIntegrationTest {
+ /** Table name. */
+ private static final String TABLE_NAME = "test_table";
+
+ private static final Tuple INITIAL_TUPLE = Tuple.create().set("key", 1L).set("val", "1");
+
+ private static final Function<Tuple, Tuple> NEXT_TUPLE = t -> Tuple.create()
+ .set("key", t.longValue("key") + 1)
+ .set("val", "" + (t.longValue("key") + 1));
+
+ private static final int REPLICAS = 2;
+
+ /** Nodes bootstrap configuration pattern. */
+ private static final String NODE_BOOTSTRAP_CFG_TEMPLATE = "{\n"
+ + " network: {\n"
+ + " port: {},\n"
+ + " nodeFinder: {\n"
+ + " netClusterNodes: [ {} ]\n"
+ + " }\n"
+ + " },\n"
+ + " clientConnector: { port:{} },\n"
+ + " rest.port: {},\n"
+ + " raft: { responseTimeout: 30000 },"
+ + " compute.threadPoolSize: 1\n"
+ + "}";
+
+ private ExecutorService txStateStorageExecutor = Executors.newSingleThreadExecutor();
+
+ @BeforeEach
+ @Override
+ public void setup(TestInfo testInfo) throws Exception {
+ super.setup(testInfo);
+
+ String zoneSql = "create zone test_zone with partitions=20, replicas=" + REPLICAS
+ + ", storage_profiles='" + DEFAULT_STORAGE_PROFILE + "'";
+ String sql = "create table " + TABLE_NAME + " (key bigint primary key, val varchar(20)) with primary_zone='TEST_ZONE'";
+
+ cluster.doInSession(0, session -> {
+ executeUpdate(zoneSql, session);
+ executeUpdate(sql, session);
+ });
+
+ txStateStorageExecutor = Executors.newSingleThreadExecutor(IgniteThreadFactory.create("test", "tx-state-storage-test-pool", log,
+ ThreadOperation.STORAGE_READ));
+ }
+
+ @Override
+ @AfterEach
+ public void tearDown() {
+ shutdownAndAwaitTermination(txStateStorageExecutor, 10, TimeUnit.SECONDS);
+
+ super.tearDown();
+ }
+
+ @Override
+ protected void customizeInitParameters(InitParametersBuilder builder) {
+ super.customizeInitParameters(builder);
+
+ builder.clusterConfiguration("{"
+ + " transaction: {"
+ + " implicitTransactionTimeout: 30000,"
+ + " txnResourceTtl: 2"
+ + " },"
+ + " replication: {"
+ + " rpcTimeout: 30000"
+ + " },"
+ + "}");
+ }
+
+ @Override
+ protected int initialNodes() {
+ return 3;
+ }
+
+ /**
+ * Returns node bootstrap config template.
+ *
+ * @return Node bootstrap config template.
+ */
+ @Override
+ protected String getNodeBootstrapConfigTemplate() {
+ return NODE_BOOTSTRAP_CFG_TEMPLATE;
+ }
+
+ @Test
+ public void testVacuum() throws InterruptedException {
+ IgniteImpl node = anyNode();
+
+ RecordView<Tuple> view = node.tables().table(TABLE_NAME).recordView();
+
+ // Put some value into the table.
+ Transaction tx = node.transactions().begin();
+ UUID txId = txId(tx);
+
+ log.info("Test: Loading the data [tx={}].", txId);
+
+ Tuple tuple = findTupleToBeHostedOnNode(node, TABLE_NAME, tx, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ int partId = partitionIdForTuple(node, TABLE_NAME, tuple, tx);
+
+ Set<String> nodes = partitionAssignment(node, new TablePartitionId(tableId(node, TABLE_NAME), partId));
+
+ view.upsert(tx, tuple);
+
+ tx.commit();
+
+ log.info("Test: Tx committed [tx={}].", txId);
+
+ checkVolatileTxStateOnNodes(nodes, txId);
+ waitForTxStateReplication(nodes, txId, partId, 10_000);
+
+ waitForTxStateVacuum(txId, partId, true, 10_000);
+ }
+
+ @Test
+ public void testVacuumWithCleanupDelay() throws InterruptedException {
Review Comment:
Test name isn't fully self descriptive and test itself is a bit overcomplicated. Please share brief test explanation with javadoc, e.g. "Ensure that volatile txn state, removed by the vacuum, will be restored by txn cleanup finalization and fully removed by the next vacuum iteration."
I'd also highly prefer several comments within test, something like following:
```
// Populate table with some data, hold txn cleanup for a while.
...
some code goes here
...
// Trigger vacuum and ensure that volatile txn state was vacuumized despite the fact that txn cleanup wasn't finished yet.
...
some code goes here
...
// Release txn cleanup and check that txn persistent state was updated with cleanupFinishedTimestamp.
...
some code goes here
...
// Trigger one more vacuum iteration and ensure that both persistent and volatile states were vacuumized.
...
some code goes here
...
// Read some data (with vacuumized txn states) with RW transaction.
...
// Read some data (with vacuumized txn states) with RO transaction with readTimestamp t25 (gt than tx1 commit timestamp)
...
```
And finally I'd put all that comments altogether within test steps in test javadoc, so basically it will look like following:
```
/**
* Ensure that volatile txn state, removed by the vacuum, will be restored by txn cleanup finalization and fully removed by the next vacuum iteration.
*
* <ul>
* <li>Populate table with some data, hold txn cleanup for a while.</li>
* <li>Trigger vacuum and ensure that volatile txn state was vacuumized despite the fact that txn cleanup wasn't finished yet.</li>
* ...
* </ul>
*/
@Test
void testVauumWithCleanupDelay() {
// Populate table with some data, hold txn cleanup for a while.
...
some code goes here
...
// Trigger vacuum and ensure that volatile txn state was vacuumized despite the fact that txn cleanup wasn't finished yet.
...
some code goes here
...
}
```
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/VolatileTxStateMetaStorage.java:
##########
@@ -118,35 +129,56 @@ public Collection<TxStateMeta> states() {
* @param vacuumObservationTimestamp Timestamp of the vacuum attempt.
* @param txnResourceTtl Transactional resource time to live in milliseconds.
*/
- public void vacuum(long vacuumObservationTimestamp, long txnResourceTtl) {
+ public void vacuum(
+ long vacuumObservationTimestamp,
+ long txnResourceTtl,
+ Function<Map<TablePartitionId, Set<UUID>>, CompletableFuture<IgniteBiTuple<Set<UUID>, Integer>>> beforeVacuum
+ ) {
LOG.info("Vacuum started [vacuumObservationTimestamp={}, txnResourceTtl={}].", vacuumObservationTimestamp, txnResourceTtl);
AtomicInteger vacuumizedTxnsCount = new AtomicInteger(0);
AtomicInteger markedAsInitiallyDetectedTxnsCount = new AtomicInteger(0);
AtomicInteger alreadyMarkedTxnsCount = new AtomicInteger(0);
AtomicInteger skippedFotFurtherProcessingUnfinishedTxnsCount = new AtomicInteger(0);
+ Map<TablePartitionId, Set<UUID>> txIds = new HashMap<>();
+ Map<UUID, Long> timestamps = new HashMap<>();
+
txStateMap.forEach((txId, meta) -> {
txStateMap.computeIfPresent(txId, (txId0, meta0) -> {
if (TxState.isFinalState(meta0.txState())) {
- if (txnResourceTtl == 0) {
- vacuumizedTxnsCount.incrementAndGet();
- return null;
- } else if (meta0.initialVacuumObservationTimestamp() == null) {
+ Long initialVacuumObservationTimestamp = meta0.initialVacuumObservationTimestamp();
+
+ if (initialVacuumObservationTimestamp == null) {
markedAsInitiallyDetectedTxnsCount.incrementAndGet();
- return new TxStateMeta(
- meta0.txState(),
- meta0.txCoordinatorId(),
- meta0.commitPartitionId(),
- meta0.commitTimestamp(),
- vacuumObservationTimestamp
- );
- } else if (meta0.initialVacuumObservationTimestamp() + txnResourceTtl < vacuumObservationTimestamp) {
- vacuumizedTxnsCount.incrementAndGet();
- return null;
+
+ return markInitialVacuumObservationTimestamp(meta0, vacuumObservationTimestamp);
} else {
- alreadyMarkedTxnsCount.incrementAndGet();
- return meta0;
+ Long cleanupCompletionTimestamp = meta0.cleanupCompletionTimestamp();
+
+ boolean shouldBeVacuumized = shouldBeVacuumized(requireNonNull(initialVacuumObservationTimestamp),
+ cleanupCompletionTimestamp, txnResourceTtl, vacuumObservationTimestamp);
+
+ if (shouldBeVacuumized) {
+ if (meta0.commitPartitionId() == null) {
Review Comment:
mm?
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
+public class ItTxResourcesVacuumTest extends ClusterPerTestIntegrationTest {
+ /** Table name. */
+ private static final String TABLE_NAME = "test_table";
+
+ private static final Tuple INITIAL_TUPLE = Tuple.create().set("key", 1L).set("val", "1");
+
+ private static final Function<Tuple, Tuple> NEXT_TUPLE = t -> Tuple.create()
+ .set("key", t.longValue("key") + 1)
+ .set("val", "" + (t.longValue("key") + 1));
+
+ private static final int REPLICAS = 2;
+
+ /** Nodes bootstrap configuration pattern. */
+ private static final String NODE_BOOTSTRAP_CFG_TEMPLATE = "{\n"
+ + " network: {\n"
+ + " port: {},\n"
+ + " nodeFinder: {\n"
+ + " netClusterNodes: [ {} ]\n"
+ + " }\n"
+ + " },\n"
+ + " clientConnector: { port:{} },\n"
+ + " rest.port: {},\n"
+ + " raft: { responseTimeout: 30000 },"
+ + " compute.threadPoolSize: 1\n"
+ + "}";
+
+ private ExecutorService txStateStorageExecutor = Executors.newSingleThreadExecutor();
+
+ @BeforeEach
+ @Override
+ public void setup(TestInfo testInfo) throws Exception {
+ super.setup(testInfo);
+
+ String zoneSql = "create zone test_zone with partitions=20, replicas=" + REPLICAS
+ + ", storage_profiles='" + DEFAULT_STORAGE_PROFILE + "'";
+ String sql = "create table " + TABLE_NAME + " (key bigint primary key, val varchar(20)) with primary_zone='TEST_ZONE'";
+
+ cluster.doInSession(0, session -> {
+ executeUpdate(zoneSql, session);
+ executeUpdate(sql, session);
+ });
+
+ txStateStorageExecutor = Executors.newSingleThreadExecutor(IgniteThreadFactory.create("test", "tx-state-storage-test-pool", log,
+ ThreadOperation.STORAGE_READ));
+ }
+
+ @Override
+ @AfterEach
+ public void tearDown() {
+ shutdownAndAwaitTermination(txStateStorageExecutor, 10, TimeUnit.SECONDS);
+
+ super.tearDown();
+ }
+
+ @Override
+ protected void customizeInitParameters(InitParametersBuilder builder) {
+ super.customizeInitParameters(builder);
+
+ builder.clusterConfiguration("{"
+ + " transaction: {"
+ + " implicitTransactionTimeout: 30000,"
+ + " txnResourceTtl: 2"
+ + " },"
+ + " replication: {"
+ + " rpcTimeout: 30000"
+ + " },"
+ + "}");
+ }
+
+ @Override
+ protected int initialNodes() {
+ return 3;
+ }
+
+ /**
+ * Returns node bootstrap config template.
+ *
+ * @return Node bootstrap config template.
+ */
+ @Override
+ protected String getNodeBootstrapConfigTemplate() {
+ return NODE_BOOTSTRAP_CFG_TEMPLATE;
+ }
+
+ @Test
+ public void testVacuum() throws InterruptedException {
+ IgniteImpl node = anyNode();
+
+ RecordView<Tuple> view = node.tables().table(TABLE_NAME).recordView();
+
+ // Put some value into the table.
+ Transaction tx = node.transactions().begin();
+ UUID txId = txId(tx);
+
+ log.info("Test: Loading the data [tx={}].", txId);
+
+ Tuple tuple = findTupleToBeHostedOnNode(node, TABLE_NAME, tx, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ int partId = partitionIdForTuple(node, TABLE_NAME, tuple, tx);
+
+ Set<String> nodes = partitionAssignment(node, new TablePartitionId(tableId(node, TABLE_NAME), partId));
+
+ view.upsert(tx, tuple);
+
+ tx.commit();
+
+ log.info("Test: Tx committed [tx={}].", txId);
+
+ checkVolatileTxStateOnNodes(nodes, txId);
+ waitForTxStateReplication(nodes, txId, partId, 10_000);
+
+ waitForTxStateVacuum(txId, partId, true, 10_000);
+ }
+
+ @Test
+ public void testVacuumWithCleanupDelay() throws InterruptedException {
Review Comment:
Steps provided here are more about `testVacuumPersistentStateAfterCleanupDelayAndVolatileStateVacuum()` but it's not important.
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
+public class ItTxResourcesVacuumTest extends ClusterPerTestIntegrationTest {
+ /** Table name. */
+ private static final String TABLE_NAME = "test_table";
+
+ private static final Tuple INITIAL_TUPLE = Tuple.create().set("key", 1L).set("val", "1");
+
+ private static final Function<Tuple, Tuple> NEXT_TUPLE = t -> Tuple.create()
+ .set("key", t.longValue("key") + 1)
+ .set("val", "" + (t.longValue("key") + 1));
+
+ private static final int REPLICAS = 2;
+
+ /** Nodes bootstrap configuration pattern. */
+ private static final String NODE_BOOTSTRAP_CFG_TEMPLATE = "{\n"
+ + " network: {\n"
+ + " port: {},\n"
+ + " nodeFinder: {\n"
+ + " netClusterNodes: [ {} ]\n"
+ + " }\n"
+ + " },\n"
+ + " clientConnector: { port:{} },\n"
+ + " rest.port: {},\n"
+ + " raft: { responseTimeout: 30000 },"
+ + " compute.threadPoolSize: 1\n"
+ + "}";
+
+ private ExecutorService txStateStorageExecutor = Executors.newSingleThreadExecutor();
+
+ @BeforeEach
+ @Override
+ public void setup(TestInfo testInfo) throws Exception {
+ super.setup(testInfo);
+
+ String zoneSql = "create zone test_zone with partitions=20, replicas=" + REPLICAS
+ + ", storage_profiles='" + DEFAULT_STORAGE_PROFILE + "'";
+ String sql = "create table " + TABLE_NAME + " (key bigint primary key, val varchar(20)) with primary_zone='TEST_ZONE'";
+
+ cluster.doInSession(0, session -> {
+ executeUpdate(zoneSql, session);
+ executeUpdate(sql, session);
+ });
+
+ txStateStorageExecutor = Executors.newSingleThreadExecutor(IgniteThreadFactory.create("test", "tx-state-storage-test-pool", log,
+ ThreadOperation.STORAGE_READ));
+ }
+
+ @Override
+ @AfterEach
+ public void tearDown() {
+ shutdownAndAwaitTermination(txStateStorageExecutor, 10, TimeUnit.SECONDS);
+
+ super.tearDown();
+ }
+
+ @Override
+ protected void customizeInitParameters(InitParametersBuilder builder) {
+ super.customizeInitParameters(builder);
+
+ builder.clusterConfiguration("{"
+ + " transaction: {"
+ + " implicitTransactionTimeout: 30000,"
+ + " txnResourceTtl: 2"
+ + " },"
+ + " replication: {"
+ + " rpcTimeout: 30000"
+ + " },"
+ + "}");
+ }
+
+ @Override
+ protected int initialNodes() {
+ return 3;
+ }
+
+ /**
+ * Returns node bootstrap config template.
+ *
+ * @return Node bootstrap config template.
+ */
+ @Override
+ protected String getNodeBootstrapConfigTemplate() {
+ return NODE_BOOTSTRAP_CFG_TEMPLATE;
+ }
+
+ @Test
+ public void testVacuum() throws InterruptedException {
+ IgniteImpl node = anyNode();
+
+ RecordView<Tuple> view = node.tables().table(TABLE_NAME).recordView();
+
+ // Put some value into the table.
+ Transaction tx = node.transactions().begin();
+ UUID txId = txId(tx);
+
+ log.info("Test: Loading the data [tx={}].", txId);
+
+ Tuple tuple = findTupleToBeHostedOnNode(node, TABLE_NAME, tx, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ int partId = partitionIdForTuple(node, TABLE_NAME, tuple, tx);
+
+ Set<String> nodes = partitionAssignment(node, new TablePartitionId(tableId(node, TABLE_NAME), partId));
+
+ view.upsert(tx, tuple);
+
+ tx.commit();
+
+ log.info("Test: Tx committed [tx={}].", txId);
+
+ checkVolatileTxStateOnNodes(nodes, txId);
+ waitForTxStateReplication(nodes, txId, partId, 10_000);
+
+ waitForTxStateVacuum(txId, partId, true, 10_000);
+ }
+
+ @Test
+ public void testVacuumWithCleanupDelay() throws InterruptedException {
+ IgniteImpl node = anyNode();
+
+ RecordView<Tuple> view = node.tables().table(TABLE_NAME).recordView();
+
+ // Put some value into the table.
+ Transaction tx = node.transactions().begin();
+ UUID txId = txId(tx);
+
+ log.info("Test: Loading the data [tx={}].", txId);
+
+ Tuple tuple0 = findTupleToBeHostedOnNode(node, TABLE_NAME, tx, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ int commitPartId = partitionIdForTuple(node, TABLE_NAME, tuple0, tx);
+
+ TablePartitionId commitPartGrpId = new TablePartitionId(tableId(node, TABLE_NAME), commitPartId);
+
+ ReplicaMeta replicaMeta = waitAndGetPrimaryReplica(node, commitPartGrpId);
+ IgniteImpl commitPartitionLeaseholder = findNode(n -> n.id().equals(replicaMeta.getLeaseholderId()));
+
+ Set<String> commitPartNodes = partitionAssignment(node, new TablePartitionId(tableId(node, TABLE_NAME), commitPartId));
+
+ log.info("Test: Commit partition [leaseholder={}, hostingNodes={}].", commitPartitionLeaseholder.name(), commitPartNodes);
+
+ // Some node that does not host the commit partition, will be the primary node for upserting another tuple.
+ IgniteImpl leaseholderForAnotherTuple = findNode(n -> !commitPartNodes.contains(n.name()));
+
+ log.info("Test: leaseholderForAnotherTuple={}", leaseholderForAnotherTuple.name());
+
+ Tuple tuple1 = findTupleToBeHostedOnNode(leaseholderForAnotherTuple, TABLE_NAME, tx, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ view.upsert(tx, tuple0);
+ view.upsert(tx, tuple1);
+
+ CompletableFuture<Void> cleanupStarted = new CompletableFuture<>();
+ CompletableFuture<Void> cleanupAllowed = new CompletableFuture<>();
+
+ commitPartitionLeaseholder.dropMessages((n, msg) -> {
+ if (msg instanceof TxCleanupMessage) {
+ cleanupStarted.complete(null);
+
+ log.info("Test: cleanup started.");
+
+ if (commitPartNodes.contains(n)) {
+ cleanupAllowed.join();
+ }
+ }
+
+ return false;
+ });
+
+ CompletableFuture<Void> commitFut = tx.commitAsync();
+
+ checkVolatileTxStateOnNodes(commitPartNodes, txId);
+ waitForTxStateReplication(commitPartNodes, txId, commitPartId, 10_000);
+
+ assertThat(cleanupStarted, willCompleteSuccessfully());
+
+ waitForTxStateVacuum(Set.of(leaseholderForAnotherTuple.name()), txId, 0, false, 10_000);
+
+ checkPersistentTxStateOnNodes(commitPartNodes, txId, commitPartId);
+
+ cleanupAllowed.complete(null);
+
+ assertThat(commitFut, willCompleteSuccessfully());
+
+ waitForTxStateVacuum(txId, commitPartId, true, 10_000);
+ }
+
+ @Test
+ public void testCommitPartitionPrimaryChangesBeforeVacuum() throws InterruptedException {
+ IgniteImpl node = anyNode();
+
+ RecordView<Tuple> view = node.tables().table(TABLE_NAME).recordView();
+
+ // Put some value into the table.
+ Transaction tx = node.transactions().begin();
+ UUID txId = txId(tx);
+
+ log.info("Test: Loading the data [tx={}].", txId);
+
+ Tuple tuple = findTupleToBeHostedOnNode(node, TABLE_NAME, tx, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ int commitPartId = partitionIdForTuple(node, TABLE_NAME, tuple, tx);
+
+ TablePartitionId commitPartGrpId = new TablePartitionId(tableId(node, TABLE_NAME), commitPartId);
+
+ ReplicaMeta replicaMeta = waitAndGetPrimaryReplica(node, commitPartGrpId);
+ IgniteImpl commitPartitionLeaseholder = findNode(n -> n.id().equals(replicaMeta.getLeaseholderId()));
+
+ Set<String> commitPartNodes = partitionAssignment(node, new TablePartitionId(tableId(node, TABLE_NAME), commitPartId));
+
+ log.info("Test: Commit partition [leaseholder={}, hostingNodes={}].", commitPartitionLeaseholder.name(), commitPartNodes);
+
+ view.upsert(tx, tuple);
+
+ CompletableFuture<Void> cleanupStarted = new CompletableFuture<>();
+ CompletableFuture<Void> cleanupAllowedFut = new CompletableFuture<>();
+ boolean[] cleanupAllowed = new boolean[1];
+
+ commitPartitionLeaseholder.dropMessages((n, msg) -> {
+ if (msg instanceof TxCleanupMessage && !cleanupAllowed[0]) {
+ cleanupStarted.complete(null);
+
+ cleanupAllowedFut.join();
+
+ return true;
+ }
+
+ return false;
+ });
+
+ CompletableFuture<Void> commitFut = tx.commitAsync();
+
+ assertThat(cleanupStarted, willCompleteSuccessfully());
+
+ transferPrimary(cluster.runningNodes().collect(toSet()), commitPartGrpId, commitPartNodes::contains);
+
+ cleanupAllowedFut.complete(null);
+
+ cleanupAllowed[0] = true;
+
+ assertThat(commitFut, willCompleteSuccessfully());
+
+ waitForTxStateVacuum(txId, commitPartId, true, 10_000);
+ }
+
+ @Test
+ public void testVacuumPersistentStateAfterCleanupDelayAndVolatileStateVacuum() throws InterruptedException {
+ IgniteImpl node = anyNode();
+
+ RecordView<Tuple> view = node.tables().table(TABLE_NAME).recordView();
+
+ // Put some value into the table.
+ Transaction tx = node.transactions().begin();
+ UUID txId = txId(tx);
+
+ log.info("Test: Loading the data [tx={}].", txId);
+
+ Tuple tuple = findTupleToBeHostedOnNode(node, TABLE_NAME, tx, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ int commitPartId = partitionIdForTuple(node, TABLE_NAME, tuple, tx);
+
+ TablePartitionId commitPartGrpId = new TablePartitionId(tableId(node, TABLE_NAME), commitPartId);
+
+ ReplicaMeta replicaMeta = waitAndGetPrimaryReplica(node, commitPartGrpId);
+ IgniteImpl commitPartitionLeaseholder = findNode(n -> n.id().equals(replicaMeta.getLeaseholderId()));
+
+ Set<String> commitPartNodes = partitionAssignment(node, new TablePartitionId(tableId(node, TABLE_NAME), commitPartId));
+
+ log.info("Test: Commit partition [leaseholder={}, hostingNodes={}].", commitPartitionLeaseholder.name(), commitPartNodes);
+
+ view.upsert(tx, tuple);
+
+ CompletableFuture<Void> cleanupStarted = new CompletableFuture<>();
+ CompletableFuture<Void> cleanupAllowedFut = new CompletableFuture<>();
+ boolean[] cleanupAllowed = new boolean[1];
+
+ commitPartitionLeaseholder.dropMessages((n, msg) -> {
+ if (msg instanceof TxCleanupMessage && !cleanupAllowed[0]) {
+ cleanupStarted.complete(null);
+
+ cleanupAllowedFut.join();
+
+ return true;
+ }
+
+ return false;
+ });
+
+ CompletableFuture<Void> commitFut = tx.commitAsync();
+
+ assertThat(cleanupStarted, willCompleteSuccessfully());
+
+ transferPrimary(cluster.runningNodes().collect(toSet()), commitPartGrpId, commitPartNodes::contains);
+
+ cleanupAllowedFut.complete(null);
+
+ cleanupAllowed[0] = true;
+
+ assertThat(commitFut, willCompleteSuccessfully());
+
+ waitForTxStateVacuum(txId, commitPartId, true, 10_000);
+ }
+
+ @Test
+ public void testRecoveryAfterPersistentStateVacuumized() throws InterruptedException {
+ // This node isn't going to be stopped, so let it be node 0.
+ IgniteImpl commitPartitionLeaseholder = cluster.runningNodes().collect(Collectors.toList()).get(0);
+
+ Tuple tuple0 = findTupleToBeHostedOnNode(commitPartitionLeaseholder, TABLE_NAME, null, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ int commitPartId = partitionIdForTuple(commitPartitionLeaseholder, TABLE_NAME, tuple0, null);
+
+ Set<String> commitPartitionNodes = partitionAssignment(commitPartitionLeaseholder,
+ new TablePartitionId(tableId(commitPartitionLeaseholder, TABLE_NAME), commitPartId));
+
+ // Choose some node that doesn't host the partition as a tx coordinator.
+ IgniteImpl coord0 = findNode(n -> !commitPartitionNodes.contains(n.name()));
+
+ RecordView<Tuple> view0 = coord0.tables().table(TABLE_NAME).recordView();
+
+ // Put some value into the table.
+ Transaction tx0 = coord0.transactions().begin();
+ UUID txId0 = txId(tx0);
+
+ log.info("Test: Transaction 0 [tx={}].", txId0);
+
+ log.info("Test: Commit partition of transaction 0 [leaseholder={}, hostingNodes={}].", commitPartitionLeaseholder.name(),
+ commitPartitionNodes);
+
+ view0.upsert(tx0, tuple0);
+
+ CompletableFuture<Void> cleanupStarted = new CompletableFuture<>();
+ boolean[] cleanupAllowed = new boolean[1];
+
+ commitPartitionLeaseholder.dropMessages((n, msg) -> {
+ if (msg instanceof TxCleanupMessage) {
+ cleanupStarted.complete(null);
+
+ return cleanupAllowed[0];
+ }
+
+ return false;
+ });
+
+ log.info("Test: Committing the transaction 0 [tx={}].", txId0);
+
+ tx0.commitAsync();
+
+ assertThat(cleanupStarted, willCompleteSuccessfully());
+
+ // Check that the final tx state COMMITTED is saved to the persistent tx storage.
+ assertTrue(waitForCondition(() -> cluster.runningNodes().filter(n -> commitPartitionNodes.contains(n.name())).allMatch(n -> {
+ TransactionMeta meta = persistentTxState(n, txId0, commitPartId);
+
+ return meta != null && meta.txState() == COMMITTED;
+ }), 10_000));
+
+ // Stop the first transaction coordinator.
+ stopNode(coord0.name());
+
+ // No cleanup happened, waiting for vacuum on the remaining nodes that participated on tx0.
+ waitForTxStateVacuum(txId0, commitPartId, true, 10_000);
+
+ // Preparing to run another tx.
+ IgniteImpl coord1 = anyNode();
+
+ RecordView<Tuple> view1 = coord1.tables().table(TABLE_NAME).recordView();
+
+ Transaction tx1 = coord1.transactions().begin();
+ UUID txId1 = txId(tx1);
+
+ log.info("Test: Transaction 1 [tx={}].", txId1);
+
+ // Tx 1 should get the data committed by tx 0.
+ Tuple keyTuple = Tuple.create().set("key", tuple0.longValue("key"));
+ Tuple tx0Data = view1.get(tx1, keyTuple);
+ assertEquals(tuple0.longValue("key"), tx0Data.longValue("key"));
+ assertEquals(tuple0.stringValue("val"), tx0Data.stringValue("val"));
+
+ tx1.commit();
+
+ waitForTxStateVacuum(txId0, commitPartId, true, 10_000);
+ waitForTxStateVacuum(txId0, commitPartId, true, 10_000);
+ }
+
+ private boolean checkVolatileTxStateOnNodes(Set<String> nodeConsistentIds, UUID txId) {
+ return cluster.runningNodes()
+ .filter(n -> nodeConsistentIds.contains(n.name()))
+ .allMatch(n -> volatileTxState(n, txId) != null);
+ }
+
+ private boolean checkPersistentTxStateOnNodes(Set<String> nodeConsistentIds, UUID txId, int partId) {
+ return cluster.runningNodes()
+ .filter(n -> nodeConsistentIds.contains(n.name()))
+ .allMatch(n -> persistentTxState(n, txId, partId) != null);
+ }
+
+ private void waitForTxStateReplication(Set<String> nodeConsistentIds, UUID txId, int partId, long timeMs)
+ throws InterruptedException {
+ assertTrue(waitForCondition(() -> checkPersistentTxStateOnNodes(nodeConsistentIds, txId, partId), timeMs));
+ }
+
+ private void waitForTxStateVacuum(UUID txId, int partId, boolean checkPersistent, long timeMs) throws InterruptedException {
Review Comment:
It's not clear what given method does? Does it check that txnState was vacuumized? Does it waitVacuum on all data replicas? Or only commit partition? Why do we need partId here? Please add the javadoc and rename the method if it actually ensures that state was vacuumized.
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1578242823
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
+public class ItTxResourcesVacuumTest extends ClusterPerTestIntegrationTest {
+ /** Table name. */
+ private static final String TABLE_NAME = "test_table";
+
+ private static final Tuple INITIAL_TUPLE = Tuple.create().set("key", 1L).set("val", "1");
+
+ private static final Function<Tuple, Tuple> NEXT_TUPLE = t -> Tuple.create()
+ .set("key", t.longValue("key") + 1)
+ .set("val", "" + (t.longValue("key") + 1));
+
+ private static final int REPLICAS = 2;
+
+ /** Nodes bootstrap configuration pattern. */
+ private static final String NODE_BOOTSTRAP_CFG_TEMPLATE = "{\n"
+ + " network: {\n"
+ + " port: {},\n"
+ + " nodeFinder: {\n"
+ + " netClusterNodes: [ {} ]\n"
+ + " }\n"
+ + " },\n"
+ + " clientConnector: { port:{} },\n"
+ + " rest.port: {},\n"
+ + " raft: { responseTimeout: 30000 },"
+ + " compute.threadPoolSize: 1\n"
+ + "}";
+
+ private ExecutorService txStateStorageExecutor = Executors.newSingleThreadExecutor();
+
+ @BeforeEach
+ @Override
+ public void setup(TestInfo testInfo) throws Exception {
+ super.setup(testInfo);
+
+ String zoneSql = "create zone test_zone with partitions=20, replicas=" + REPLICAS
+ + ", storage_profiles='" + DEFAULT_STORAGE_PROFILE + "'";
+ String sql = "create table " + TABLE_NAME + " (key bigint primary key, val varchar(20)) with primary_zone='TEST_ZONE'";
+
+ cluster.doInSession(0, session -> {
+ executeUpdate(zoneSql, session);
+ executeUpdate(sql, session);
+ });
+
+ txStateStorageExecutor = Executors.newSingleThreadExecutor(IgniteThreadFactory.create("test", "tx-state-storage-test-pool", log,
+ ThreadOperation.STORAGE_READ));
+ }
+
+ @Override
+ @AfterEach
+ public void tearDown() {
+ shutdownAndAwaitTermination(txStateStorageExecutor, 10, TimeUnit.SECONDS);
+
+ super.tearDown();
+ }
+
+ @Override
+ protected void customizeInitParameters(InitParametersBuilder builder) {
+ super.customizeInitParameters(builder);
+
+ builder.clusterConfiguration("{"
+ + " transaction: {"
+ + " implicitTransactionTimeout: 30000,"
+ + " txnResourceTtl: 2"
+ + " },"
+ + " replication: {"
+ + " rpcTimeout: 30000"
+ + " },"
+ + "}");
+ }
+
+ @Override
+ protected int initialNodes() {
+ return 3;
+ }
+
+ /**
+ * Returns node bootstrap config template.
+ *
+ * @return Node bootstrap config template.
+ */
+ @Override
+ protected String getNodeBootstrapConfigTemplate() {
+ return NODE_BOOTSTRAP_CFG_TEMPLATE;
+ }
+
Review Comment:
Checks that pending transactions are not vacuumized are added to txVacuumTest.
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1578064713
##########
modules/runner/src/testFixtures/java/org/apache/ignite/internal/table/NodeUtils.java:
##########
@@ -49,16 +50,16 @@ public class NodeUtils {
*
* @param nodes Nodes collection.
* @param groupId Group id.
- * @param preferablePrimary Primary replica name which is preferred for being primary or {@code null}.
+ * @param preferablePrimaryFilter Primary replica preferable nodes filter, accepts the node consistent id.
* @return New primary replica name.
* @throws InterruptedException If failed.
*/
public static String transferPrimary(
Collection<IgniteImpl> nodes,
ReplicationGroupId groupId,
- @Nullable String preferablePrimary
+ @Nullable Predicate<String> preferablePrimaryFilter
Review Comment:
Not sure we have to support this, here we need just to identify some node, and the name is enough here
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1578072458
##########
modules/table/src/main/java/org/apache/ignite/internal/table/RecordBinaryViewImpl.java:
##########
@@ -402,6 +404,24 @@ private static Row marshal(Tuple tuple, TupleMarshaller marshaller, boolean keyO
}
}
+ /**
+ * Marshal a tuple to a row. Test-only public method.
+ *
+ * @param tx Transaction, if present.
+ * @param rec Tuple record.
+ * @return A future, with row as a result.
+ */
+ @TestOnly
+ public CompletableFuture<BinaryRowEx> marshal(@Nullable Transaction tx, Tuple rec) {
Review Comment:
to pick up the schema version corresponding to tx start time, if it's present
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1578127286
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
+public class ItTxResourcesVacuumTest extends ClusterPerTestIntegrationTest {
+ /** Table name. */
+ private static final String TABLE_NAME = "test_table";
+
+ private static final Tuple INITIAL_TUPLE = Tuple.create().set("key", 1L).set("val", "1");
+
+ private static final Function<Tuple, Tuple> NEXT_TUPLE = t -> Tuple.create()
+ .set("key", t.longValue("key") + 1)
+ .set("val", "" + (t.longValue("key") + 1));
+
+ private static final int REPLICAS = 2;
+
+ /** Nodes bootstrap configuration pattern. */
+ private static final String NODE_BOOTSTRAP_CFG_TEMPLATE = "{\n"
+ + " network: {\n"
+ + " port: {},\n"
+ + " nodeFinder: {\n"
+ + " netClusterNodes: [ {} ]\n"
+ + " }\n"
+ + " },\n"
+ + " clientConnector: { port:{} },\n"
+ + " rest.port: {},\n"
+ + " raft: { responseTimeout: 30000 },"
+ + " compute.threadPoolSize: 1\n"
+ + "}";
+
+ private ExecutorService txStateStorageExecutor = Executors.newSingleThreadExecutor();
+
+ @BeforeEach
+ @Override
+ public void setup(TestInfo testInfo) throws Exception {
+ super.setup(testInfo);
+
+ String zoneSql = "create zone test_zone with partitions=20, replicas=" + REPLICAS
+ + ", storage_profiles='" + DEFAULT_STORAGE_PROFILE + "'";
+ String sql = "create table " + TABLE_NAME + " (key bigint primary key, val varchar(20)) with primary_zone='TEST_ZONE'";
+
+ cluster.doInSession(0, session -> {
+ executeUpdate(zoneSql, session);
+ executeUpdate(sql, session);
+ });
+
+ txStateStorageExecutor = Executors.newSingleThreadExecutor(IgniteThreadFactory.create("test", "tx-state-storage-test-pool", log,
+ ThreadOperation.STORAGE_READ));
+ }
+
+ @Override
+ @AfterEach
+ public void tearDown() {
+ shutdownAndAwaitTermination(txStateStorageExecutor, 10, TimeUnit.SECONDS);
+
+ super.tearDown();
+ }
+
+ @Override
+ protected void customizeInitParameters(InitParametersBuilder builder) {
+ super.customizeInitParameters(builder);
+
+ builder.clusterConfiguration("{"
+ + " transaction: {"
+ + " implicitTransactionTimeout: 30000,"
+ + " txnResourceTtl: 2"
+ + " },"
+ + " replication: {"
+ + " rpcTimeout: 30000"
+ + " },"
+ + "}");
+ }
+
+ @Override
+ protected int initialNodes() {
+ return 3;
+ }
+
+ /**
+ * Returns node bootstrap config template.
+ *
+ * @return Node bootstrap config template.
+ */
+ @Override
+ protected String getNodeBootstrapConfigTemplate() {
+ return NODE_BOOTSTRAP_CFG_TEMPLATE;
+ }
+
+ @Test
+ public void testVacuum() throws InterruptedException {
+ IgniteImpl node = anyNode();
+
+ RecordView<Tuple> view = node.tables().table(TABLE_NAME).recordView();
+
+ // Put some value into the table.
+ Transaction tx = node.transactions().begin();
+ UUID txId = txId(tx);
+
+ log.info("Test: Loading the data [tx={}].", txId);
+
+ Tuple tuple = findTupleToBeHostedOnNode(node, TABLE_NAME, tx, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ int partId = partitionIdForTuple(node, TABLE_NAME, tuple, tx);
+
+ Set<String> nodes = partitionAssignment(node, new TablePartitionId(tableId(node, TABLE_NAME), partId));
+
+ view.upsert(tx, tuple);
+
+ tx.commit();
+
+ log.info("Test: Tx committed [tx={}].", txId);
+
+ checkVolatileTxStateOnNodes(nodes, txId);
+ waitForTxStateReplication(nodes, txId, partId, 10_000);
Review Comment:
to make sure the tx state was actually present in the persistent storage before it is vacuumized
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1580582765
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,798 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.runAsync;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.TxState.FINISHING;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.tx.test.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.message.TxFinishReplicaRequest;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.apache.ignite.tx.TransactionOptions;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
+public class ItTxResourcesVacuumTest extends ClusterPerTestIntegrationTest {
+ /** Table name. */
+ private static final String TABLE_NAME = "test_table";
+
+ private static final Tuple INITIAL_TUPLE = Tuple.create().set("key", 1L).set("val", "1");
+
+ private static final Function<Tuple, Tuple> NEXT_TUPLE = t -> Tuple.create()
+ .set("key", t.longValue("key") + 1)
+ .set("val", "" + (t.longValue("key") + 1));
+
+ private static final int REPLICAS = 2;
+
+ /** Nodes bootstrap configuration pattern. */
+ private static final String NODE_BOOTSTRAP_CFG_TEMPLATE = "{\n"
+ + " network: {\n"
+ + " port: {},\n"
+ + " nodeFinder: {\n"
+ + " netClusterNodes: [ {} ]\n"
+ + " }\n"
+ + " },\n"
+ + " clientConnector: { port:{} },\n"
+ + " rest.port: {},\n"
+ + " raft: { responseTimeout: 30000 },"
+ + " compute.threadPoolSize: 1\n"
+ + "}";
+
+ private ExecutorService txStateStorageExecutor = Executors.newSingleThreadExecutor();
+
+ @BeforeEach
+ @Override
+ public void setup(TestInfo testInfo) throws Exception {
+ super.setup(testInfo);
+
+ String zoneSql = "create zone test_zone with partitions=20, replicas=" + REPLICAS
+ + ", storage_profiles='" + DEFAULT_STORAGE_PROFILE + "'";
+ String sql = "create table " + TABLE_NAME + " (key bigint primary key, val varchar(20)) with primary_zone='TEST_ZONE'";
+
+ cluster.doInSession(0, session -> {
+ executeUpdate(zoneSql, session);
+ executeUpdate(sql, session);
+ });
+
+ txStateStorageExecutor = Executors.newSingleThreadExecutor(IgniteThreadFactory.create("test", "tx-state-storage-test-pool", log,
+ ThreadOperation.STORAGE_READ));
+ }
+
+ @Override
+ @AfterEach
+ public void tearDown() {
+ shutdownAndAwaitTermination(txStateStorageExecutor, 10, TimeUnit.SECONDS);
+
+ super.tearDown();
+ }
+
+ @Override
+ protected void customizeInitParameters(InitParametersBuilder builder) {
+ super.customizeInitParameters(builder);
+
+ builder.clusterConfiguration("{"
+ + " transaction: {"
+ + " txnResourceTtl: 1"
+ + " },"
+ + " replication: {"
+ + " rpcTimeout: 30000"
+ + " },"
+ + "}");
+ }
+
+ /**
+ * Returns node bootstrap config template.
+ *
+ * @return Node bootstrap config template.
+ */
+ @Override
+ protected String getNodeBootstrapConfigTemplate() {
+ return NODE_BOOTSTRAP_CFG_TEMPLATE;
+ }
+
+ /**
+ * Simple vacuum test, checking also that PENDING and FINISHING states are not removed.
+ *
+ * <ul>
+ * <li>Run a transaction;</li>
+ * <li>Insert a value;</li>
+ * <li>Wait 3 seconds;</li>
+ * <li>Check that the volatile PENDING state of the transaction is preserved;</li>
+ * <li>Block {@link TxFinishReplicaRequest};</li>
+ * <li>Start the tx commit;</li>
+ * <li>While the state is FINISHING, wait 3 seconds;</li>
+ * <li>Check that the volatile state of the transaction is preserved;</li>
+ * <li>Unblock {@link TxFinishReplicaRequest};</li>
+ * <li>Check that both volatile and persistent state is vacuumized;</li>
+ * <li>Check that the committed value is correct.</li>
+ * </ul>
+ */
+ @Test
+ public void testVacuum() throws InterruptedException {
+ IgniteImpl node = anyNode();
+
+ RecordView<Tuple> view = node.tables().table(TABLE_NAME).recordView();
+
+ // Put some value into the table.
+ Transaction tx = node.transactions().begin();
+ UUID txId = txId(tx);
+
+ log.info("Test: Loading the data [tx={}].", txId);
+
+ Tuple tuple = findTupleToBeHostedOnNode(node, TABLE_NAME, tx, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ int partId = partitionIdForTuple(node, TABLE_NAME, tuple, tx);
+
+ Set<String> nodes = partitionAssignment(node, new TablePartitionId(tableId(node, TABLE_NAME), partId));
+
+ view.upsert(tx, tuple);
+
+ // Check that the volatile PENDING state of the transaction is preserved.
+ Thread.sleep(3000);
+ assertTrue(checkVolatileTxStateOnNodes(nodes, txId));
+
+ CompletableFuture<Void> finishStartedFuture = new CompletableFuture<>();
+ CompletableFuture<Void> finishAllowedFuture = new CompletableFuture<>();
+
+ node.dropMessages((n, msg) -> {
+ if (msg instanceof TxFinishReplicaRequest) {
+ finishStartedFuture.complete(null);
+
+ finishAllowedFuture.join();
+ }
+
+ return false;
+ });
+
+ CompletableFuture<Void> commitFut = runAsync(tx::commit);
+
+ assertThat(finishStartedFuture, willCompleteSuccessfully());
+
+ // While the state is FINISHING, wait 3 seconds.
+ assertEquals(FINISHING, volatileTxState(node, txId).txState());
+ Thread.sleep(3000);
+
+ // Check that the volatile state of the transaction is preserved.
+ assertTrue(checkVolatileTxStateOnNodes(nodes, txId));
+
+ finishAllowedFuture.complete(null);
+
+ assertThat(commitFut, willCompleteSuccessfully());
+
+ log.info("Test: Tx committed [tx={}].", txId);
+
+ waitForTxStateReplication(nodes, txId, partId, 10_000);
+
+ // Check that both volatile and persistent state is vacuumized..
+ waitForTxStateVacuum(txId, partId, true, 10_000);
+
+ // Trying to read the value.
+ Tuple data = view.get(null, Tuple.create().set("key", tuple.longValue("key")));
+ assertEquals(tuple, data);
+ }
+
+ /**
+ * Check that the ABANDONED transaction state is preserved until recovery.
+ *
+ * <ul>
+ * <li>Start a transaction from a coordinator that would be not included into commit partition group;</li>
+ * <li>Insert a value;</li>
+ * <li>Stop the tx coordinator;</li>
+ * <li>Wait 3 seconds;</li>
+ * <li>Check that the volatile state of the transaction is preserved;</li>
+ * <li>Try to read the value using another transaction, which starts the tx recovery;</li>
+ * <li>Check that abandoned tx is rolled back and thus the value is null;</li>
+ * <li>Check that the abandoned transaction is recovered; its volatile and persistent states are vacuumized.</li>
+ * </ul>
+ */
+ @Test
+ public void testAbandonedTxnsAreNotVacuumizedUntilRecovered() throws InterruptedException {
+ IgniteImpl leaseholder = cluster.node(0);
+
+ Tuple tuple = findTupleToBeHostedOnNode(leaseholder, TABLE_NAME, null, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ int partId = partitionIdForTuple(anyNode(), TABLE_NAME, tuple, null);
+
+ TablePartitionId groupId = new TablePartitionId(tableId(anyNode(), TABLE_NAME), partId);
+
+ Set<String> txNodes = partitionAssignment(anyNode(), groupId);
+
+ IgniteImpl abandonedTxCoord = findNode(n -> !txNodes.contains(n.name()));
+
+ RecordView<Tuple> view = abandonedTxCoord.tables().table(TABLE_NAME).recordView();
+
+ Transaction abandonedTx = abandonedTxCoord.transactions().begin();
+ UUID abandonedTxId = txId(abandonedTx);
+ view.upsert(abandonedTx, tuple);
+
+ stopNode(abandonedTxCoord.name());
+
+ Thread.sleep(3000);
+
+ // Check that the volatile state of the transaction is preserved.
+ assertTrue(checkVolatileTxStateOnNodes(txNodes, abandonedTxId));
+
+ // Try to read the value using another transaction, which starts the tx recovery.
+ RecordView<Tuple> viewLh = leaseholder.tables().table(TABLE_NAME).recordView();
+ Tuple value = viewLh.get(null, Tuple.create().set("key", tuple.longValue("key")));
+ // Check that abandoned tx is rolled back and thus the value is null.
+ assertNull(value);
+
+ // Check that the abandoned transaction is recovered; its volatile and persistent states are vacuumized.
+ waitForTxStateVacuum(txNodes, abandonedTxId, partId, true, 10_000);
+ }
+
+ /**
+ * Check that the tx state on commit partition is vacuumized only when cleanup is completed.
+ *
+ * <ul>
+ * <li>Start a transaction;</li>
+ * <li>Generate some tuple and define on which nodes it would be hosted;</li>
+ * <li>Choose one more node that doesn't host the first tuple and choose a tuple that will be sent on this node as primary;</li>
+ * <li>Upsert both tuples within a transaction;</li>
+ * <li>Block {@link TxCleanupMessage}-s from commit partition primary;</li>
+ * <li>Start a tx commit;</li>
+ * <li>Wait for vacuum completion on a node that doesn't host the commit partition;</li>
+ * <li>Unblock {@link TxCleanupMessage}-s;</li>
+ * <li>Wait for the tx state vacuum on the commit partition group.</li>
+ * </ul>
+ */
+ @Test
+ public void testVacuumWithCleanupDelay() throws InterruptedException {
+ IgniteImpl node = anyNode();
+
+ RecordView<Tuple> view = node.tables().table(TABLE_NAME).recordView();
+
+ // Put some value into the table.
+ Transaction tx = node.transactions().begin();
+ UUID txId = txId(tx);
+
+ log.info("Test: Loading the data [tx={}].", txId);
+
+ // Generate some tuple and define on which nodes it would be hosted.
+ Tuple tuple0 = findTupleToBeHostedOnNode(node, TABLE_NAME, tx, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ int commitPartId = partitionIdForTuple(node, TABLE_NAME, tuple0, tx);
+
+ TablePartitionId commitPartGrpId = new TablePartitionId(tableId(node, TABLE_NAME), commitPartId);
+
+ ReplicaMeta replicaMeta = waitAndGetPrimaryReplica(node, commitPartGrpId);
+ IgniteImpl commitPartitionLeaseholder = findNode(n -> n.id().equals(replicaMeta.getLeaseholderId()));
+
+ Set<String> commitPartNodes = partitionAssignment(node, new TablePartitionId(tableId(node, TABLE_NAME), commitPartId));
+
+ log.info("Test: Commit partition [leaseholder={}, hostingNodes={}].", commitPartitionLeaseholder.name(), commitPartNodes);
+
+ // Some node that does not host the commit partition, will be the primary node for upserting another tuple.
+ IgniteImpl leaseholderForAnotherTuple = findNode(n -> !commitPartNodes.contains(n.name()));
+
+ log.info("Test: leaseholderForAnotherTuple={}", leaseholderForAnotherTuple.name());
+
+ Tuple tuple1 = findTupleToBeHostedOnNode(leaseholderForAnotherTuple, TABLE_NAME, tx, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ // Upsert both tuples within a transaction.
+ view.upsert(tx, tuple0);
+ view.upsert(tx, tuple1);
+
+ CompletableFuture<Void> cleanupStarted = new CompletableFuture<>();
+ CompletableFuture<Void> cleanupAllowed = new CompletableFuture<>();
+
+ commitPartitionLeaseholder.dropMessages((n, msg) -> {
+ if (msg instanceof TxCleanupMessage) {
+ cleanupStarted.complete(null);
+
+ log.info("Test: cleanup started.");
+
+ if (commitPartNodes.contains(n)) {
+ cleanupAllowed.join();
+ }
+ }
+
+ return false;
+ });
+
+ CompletableFuture<Void> commitFut = tx.commitAsync();
+
+ waitForTxStateReplication(commitPartNodes, txId, commitPartId, 10_000);
+
+ assertThat(cleanupStarted, willCompleteSuccessfully());
+
+ // Wait for vacuum completion on a node that doesn't host the commit partition.
+ waitForTxStateVacuum(Set.of(leaseholderForAnotherTuple.name()), txId, 0, false, 10_000);
+
+ // Unblocking cleanup.
+ cleanupAllowed.complete(null);
+
+ assertThat(commitFut, willCompleteSuccessfully());
+
+ // Wait for the cleanup on the commit partition group.
+ waitForTxStateVacuum(txId, commitPartId, true, 10_000);
+
+ // Trying to read the values.
+ Tuple data0 = view.get(null, Tuple.create().set("key", tuple0.longValue("key")));
+ assertEquals(tuple0, data0);
+
+ Tuple data1 = view.get(null, Tuple.create().set("key", tuple1.longValue("key")));
+ assertEquals(tuple1, data1);
+ }
+
+ /**
+ * Check that the tx state on commit partition is vacuumized only when cleanup is completed.
+ *
+ * <ul>
+ * <li>Start a transaction;</li>
+ * <li>Upsert a value;</li>
+ * <li>Block {@link TxCleanupMessage}-s;</li>
+ * <li>Start a tx commit;</li>
+ * <li>Transfer the primary replica;</li>
+ * <li>Unblock the {@link TxCleanupMessage}-s;</li>
+ * <li>Ensure that tx states are finally vacuumized.</li>
+ * </ul>
+ */
+ @Test
+ public void testCommitPartitionPrimaryChangesBeforeVacuum() throws InterruptedException {
+ IgniteImpl node = anyNode();
+
+ RecordView<Tuple> view = node.tables().table(TABLE_NAME).recordView();
+
+ // Put some value into the table.
+ Transaction tx = node.transactions().begin();
+ UUID txId = txId(tx);
+
+ log.info("Test: Loading the data [tx={}].", txId);
+
+ Tuple tuple = findTupleToBeHostedOnNode(node, TABLE_NAME, tx, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ int commitPartId = partitionIdForTuple(node, TABLE_NAME, tuple, tx);
+
+ TablePartitionId commitPartGrpId = new TablePartitionId(tableId(node, TABLE_NAME), commitPartId);
+
+ ReplicaMeta replicaMeta = waitAndGetPrimaryReplica(node, commitPartGrpId);
+ IgniteImpl commitPartitionLeaseholder = findNode(n -> n.id().equals(replicaMeta.getLeaseholderId()));
+
+ Set<String> commitPartNodes = partitionAssignment(node, new TablePartitionId(tableId(node, TABLE_NAME), commitPartId));
+
+ log.info("Test: Commit partition [leaseholder={}, hostingNodes={}].", commitPartitionLeaseholder.name(), commitPartNodes);
+
+ view.upsert(tx, tuple);
+
+ CompletableFuture<Void> cleanupStarted = new CompletableFuture<>();
+ CompletableFuture<Void> cleanupAllowedFut = new CompletableFuture<>();
+ boolean[] cleanupAllowed = new boolean[1];
+
+ commitPartitionLeaseholder.dropMessages((n, msg) -> {
+ if (msg instanceof TxCleanupMessage && !cleanupAllowed[0]) {
+ cleanupStarted.complete(null);
+
+ cleanupAllowedFut.join();
+ }
+
+ return false;
+ });
+
+ CompletableFuture<Void> commitFut = tx.commitAsync();
+
+ assertThat(cleanupStarted, willCompleteSuccessfully());
+
+ transferPrimary(cluster.runningNodes().collect(toSet()), commitPartGrpId, commitPartNodes::contains);
+
+ cleanupAllowedFut.complete(null);
+
+ cleanupAllowed[0] = true;
+
+ assertThat(commitFut, willCompleteSuccessfully());
+
+ log.info("Test: tx committed.");
+
+ waitForTxStateVacuum(txId, commitPartId, true, 10_000);
+
+ // Trying to read the value.
+ Tuple data = view.get(null, Tuple.create().set("key", tuple.longValue("key")));
+ assertEquals(tuple, data);
+ }
+
+ /**
+ * Check that the tx state on commit partition is vacuumized only when cleanup is completed.
+ *
+ * <ul>
+ * <li>Start a transaction;</li>
+ * <li>Upsert a tuple;</li>
+ * <li>Block {@link TxCleanupMessage}-s from commit partition primary;</li>
+ * <li>Start a tx commit;</li>
+ * <li>Wait for tx cleanup to start;</li>
+ * <li>Wait for volatile tx state vacuum;</li>
+ * <li>Unblock {@link TxCleanupMessage}-s;</li>
+ * <li>Wait for the tx state vacuum on the commit partition group.</li>
+ * </ul>
+ */
+ @Test
+ public void testVacuumPersistentStateAfterCleanupDelayAndVolatileStateVacuum() throws InterruptedException {
+ IgniteImpl node = anyNode();
+
+ RecordView<Tuple> view = node.tables().table(TABLE_NAME).recordView();
+
+ // Put some value into the table.
+ Transaction tx = node.transactions().begin();
+ UUID txId = txId(tx);
+
+ log.info("Test: Loading the data [tx={}].", txId);
+
+ Tuple tuple = findTupleToBeHostedOnNode(node, TABLE_NAME, tx, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ int commitPartId = partitionIdForTuple(node, TABLE_NAME, tuple, tx);
+
+ TablePartitionId commitPartGrpId = new TablePartitionId(tableId(node, TABLE_NAME), commitPartId);
+
+ ReplicaMeta replicaMeta = waitAndGetPrimaryReplica(node, commitPartGrpId);
+ IgniteImpl commitPartitionLeaseholder = findNode(n -> n.id().equals(replicaMeta.getLeaseholderId()));
+
+ Set<String> commitPartNodes = partitionAssignment(node, new TablePartitionId(tableId(node, TABLE_NAME), commitPartId));
+
+ log.info("Test: Commit partition [leaseholder={}, hostingNodes={}].", commitPartitionLeaseholder.name(), commitPartNodes);
+
+ view.upsert(tx, tuple);
+
+ CompletableFuture<Void> cleanupStarted = new CompletableFuture<>();
+ CompletableFuture<Void> cleanupAllowedFut = new CompletableFuture<>();
+ boolean[] cleanupAllowed = new boolean[1];
+
+ commitPartitionLeaseholder.dropMessages((n, msg) -> {
+ if (msg instanceof TxCleanupMessage && !cleanupAllowed[0]) {
+ cleanupStarted.complete(null);
+
+ cleanupAllowedFut.join();
+
+ return true;
+ }
+
+ return false;
+ });
+
+ CompletableFuture<Void> commitFut = tx.commitAsync();
+
+ assertThat(cleanupStarted, willCompleteSuccessfully());
+
+ // Wait for volatile tx state vacuum. This is possible because tx finish is complete.
+ waitForTxStateVacuum(txId, commitPartId, false, 10_000);
+
+ log.info("Test: volatile state vacuumized");
+
+ cleanupAllowedFut.complete(null);
+
+ cleanupAllowed[0] = true;
+
+ assertThat(commitFut, willCompleteSuccessfully());
+
+ waitForTxStateVacuum(txId, commitPartId, true, 10_000);
+
+ // Trying to read the data.
+ Tuple data = view.get(null, Tuple.create().set("key", tuple.longValue("key")));
+ assertEquals(tuple, data);
+ }
+
+ /**
+ * Checks that the tx recovery doesn't change tx finish result from COMMITTED to ABORTED if it once saved in the persistent storage.
+ *
+ * <ul>
+ * <li>Start a transaction tx0;</li>
+ * <li>Upsert some value;</li>
+ * <li>Block {@link TxCleanupMessage}-s;</li>
+ * <li>Start the commit of tx0 and with for tx state COMMITTED to be replicated in persistent storage;</li>
+ * <li>Stop the tx0's coordinator;</li>
+ * <li>Wait for tx0's state vacuum;</li>
+ * <li>Try to get the data that has been committed by tx0, ensure the data is correct.</li>
+ * </ul>
+ */
+ @Test
+ public void testRecoveryAfterPersistentStateVacuumized() throws InterruptedException {
+ // This node isn't going to be stopped, so let it be node 0.
+ IgniteImpl commitPartitionLeaseholder = cluster.node(0);
+
+ Tuple tuple0 = findTupleToBeHostedOnNode(commitPartitionLeaseholder, TABLE_NAME, null, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ int commitPartId = partitionIdForTuple(commitPartitionLeaseholder, TABLE_NAME, tuple0, null);
+
+ Set<String> commitPartitionNodes = partitionAssignment(commitPartitionLeaseholder,
+ new TablePartitionId(tableId(commitPartitionLeaseholder, TABLE_NAME), commitPartId));
+
+ // Choose some node that doesn't host the partition as a tx coordinator.
+ IgniteImpl coord0 = findNode(n -> !commitPartitionNodes.contains(n.name()));
+
+ RecordView<Tuple> view0 = coord0.tables().table(TABLE_NAME).recordView();
+
+ // Put some value into the table.
+ Transaction tx0 = coord0.transactions().begin();
+ UUID txId0 = txId(tx0);
+
+ log.info("Test: Transaction 0 [tx={}].", txId0);
+
+ log.info("Test: Commit partition of transaction 0 [leaseholder={}, hostingNodes={}].", commitPartitionLeaseholder.name(),
+ commitPartitionNodes);
+
+ view0.upsert(tx0, tuple0);
+
+ CompletableFuture<Void> cleanupStarted = new CompletableFuture<>();
+ boolean[] cleanupAllowed = new boolean[1];
Review Comment:
Contents of array 'cleanupAllowed' are read, but never written to
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1580566170
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
+public class ItTxResourcesVacuumTest extends ClusterPerTestIntegrationTest {
+ /** Table name. */
+ private static final String TABLE_NAME = "test_table";
+
+ private static final Tuple INITIAL_TUPLE = Tuple.create().set("key", 1L).set("val", "1");
+
+ private static final Function<Tuple, Tuple> NEXT_TUPLE = t -> Tuple.create()
+ .set("key", t.longValue("key") + 1)
+ .set("val", "" + (t.longValue("key") + 1));
+
+ private static final int REPLICAS = 2;
+
+ /** Nodes bootstrap configuration pattern. */
+ private static final String NODE_BOOTSTRAP_CFG_TEMPLATE = "{\n"
+ + " network: {\n"
+ + " port: {},\n"
+ + " nodeFinder: {\n"
+ + " netClusterNodes: [ {} ]\n"
+ + " }\n"
+ + " },\n"
+ + " clientConnector: { port:{} },\n"
+ + " rest.port: {},\n"
+ + " raft: { responseTimeout: 30000 },"
+ + " compute.threadPoolSize: 1\n"
+ + "}";
+
+ private ExecutorService txStateStorageExecutor = Executors.newSingleThreadExecutor();
+
+ @BeforeEach
+ @Override
+ public void setup(TestInfo testInfo) throws Exception {
+ super.setup(testInfo);
+
+ String zoneSql = "create zone test_zone with partitions=20, replicas=" + REPLICAS
+ + ", storage_profiles='" + DEFAULT_STORAGE_PROFILE + "'";
Review Comment:
Well, let's say you are right. Test is already long enough.
--
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-21763 [ignite-3]
Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1562041825
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/ResourceVacuumManager.java:
##########
@@ -50,7 +50,7 @@ public class ResourceVacuumManager implements IgniteComponent {
public static final String RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY = "RESOURCE_VACUUM_INTERVAL_MILLISECONDS";
private final int resourceVacuumIntervalMilliseconds = IgniteSystemProperties
- .getInteger(RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, 30_000);
+ .getInteger(RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, 1_000);
Review Comment:
Why?
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/raft/PartitionListener.java:
##########
@@ -77,14 +78,15 @@
import org.apache.ignite.internal.tx.TxState;
import org.apache.ignite.internal.tx.TxStateMeta;
import org.apache.ignite.internal.tx.UpdateCommandResult;
+import org.apache.ignite.internal.tx.message.VacuumTxStatesCommand;
import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
import org.apache.ignite.internal.util.PendingComparableValuesTracker;
import org.apache.ignite.internal.util.TrackerClosedException;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
/**
- * Partition command handler.
+ * Partition cmd handler.
Review Comment:
Why?
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/VolatileTxStateMetaStorage.java:
##########
@@ -155,14 +187,62 @@ public void vacuum(long vacuumObservationTimestamp, long txnResourceTtl) {
});
});
- LOG.info("Vacuum finished [vacuumObservationTimestamp={}, txnResourceTtl={}, vacuumizedTxnsCount={},"
- + " markedAsInitiallyDetectedTxnsCount={}, alreadyMarkedTxnsCount={}, skippedFotFurtherProcessingUnfinishedTxnsCount={}].",
- vacuumObservationTimestamp,
- txnResourceTtl,
- vacuumizedTxnsCount,
- markedAsInitiallyDetectedTxnsCount,
- alreadyMarkedTxnsCount,
- skippedFotFurtherProcessingUnfinishedTxnsCount
+ beforeVacuum.apply(txIds)
+ .thenAccept(tuple -> {
+ Set<UUID> successful = tuple.get1();
+
+ for (UUID txId : successful) {
+ txStateMap.compute(txId, (k, v) -> {
+ if (v == null) {
+ return null;
+ } else {
+ Long cleanupCompletionTs = timestamps.get(txId);
+
+ return (cleanupCompletionTs != null && Objects.equals(cleanupCompletionTs, v.cleanupCompletionTimestamp()))
Review Comment:
Seems that cleanupCompletionTs != null is not needed here, we just may do v.cleanupCompletitionTimestamp.eqauls(cleanupCompletionTs), am I right?
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/PersistentTxStateVacuumizer.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.impl;
+
+import static org.apache.ignite.internal.util.CompletableFutures.allOf;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.ignite.internal.lang.IgniteBiTuple;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.replicator.ReplicaService;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.tx.message.TxMessagesFactory;
+import org.apache.ignite.internal.tx.message.VacuumTxStateReplicaRequest;
+import org.apache.ignite.network.ClusterNode;
+
+public class PersistentTxStateVacuumizer {
+ private static final IgniteLogger LOG = Loggers.forClass(PersistentTxStateVacuumizer.class);
+
+ private static final TxMessagesFactory TX_MESSAGES_FACTORY = new TxMessagesFactory();
+
+ private final ReplicaService replicaService;
+
+ private final ClusterNode localNode;
+
+ public PersistentTxStateVacuumizer(
+ ReplicaService replicaService,
+ ClusterNode localNode) {
+ this.replicaService = replicaService;
+ this.localNode = localNode;
+ }
+
+ public CompletableFuture<IgniteBiTuple<Set<UUID>, Integer>> vacuumPersistentTxStates(Map<TablePartitionId, Set<UUID>> txIds) {
+ Set<UUID> successful = ConcurrentHashMap.newKeySet();
+ AtomicInteger unsuccessfulCount = new AtomicInteger(0);
+ List<CompletableFuture<?>> futures = new ArrayList<>();
+
+ txIds.forEach((commitPartitionId, txs) -> {
+ VacuumTxStateReplicaRequest request = TX_MESSAGES_FACTORY.vacuumTxStateReplicaRequest()
+ .groupId(commitPartitionId)
+ .transactionIds(txs)
+ .build();
+
+ CompletableFuture<?> future = replicaService.invoke(localNode, request).whenComplete((v, e) -> {
+ if (e == null) {
+ successful.addAll(txs);
+ } else {
+ LOG.warn("Failed to vacuum tx states from the persistent storage.", e);
Review Comment:
Seems that such general approach won't actually work with replica miss exceptions. Are you going to cleanup the volatile state in that case?
All in all I believe that we should use getPrimaryReplica instead of localId in order to calculate the recipient node. Looks more robust to me.
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/VolatileTxStateMetaStorage.java:
##########
@@ -155,14 +187,62 @@ public void vacuum(long vacuumObservationTimestamp, long txnResourceTtl) {
});
});
- LOG.info("Vacuum finished [vacuumObservationTimestamp={}, txnResourceTtl={}, vacuumizedTxnsCount={},"
- + " markedAsInitiallyDetectedTxnsCount={}, alreadyMarkedTxnsCount={}, skippedFotFurtherProcessingUnfinishedTxnsCount={}].",
- vacuumObservationTimestamp,
- txnResourceTtl,
- vacuumizedTxnsCount,
- markedAsInitiallyDetectedTxnsCount,
- alreadyMarkedTxnsCount,
- skippedFotFurtherProcessingUnfinishedTxnsCount
+ beforeVacuum.apply(txIds)
+ .thenAccept(tuple -> {
Review Comment:
Seems that we may even skip the future, and just update volatile txn state after successful persistent txn state removal by setting cleanupCompletionTimestamp to null if it's the same as was propagated to the function(currently there's no such propagation). In that case next vacuum iteration will just remove the state from the volatile map. What do you think?
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/raft/PartitionListener.java:
##########
@@ -406,18 +413,18 @@ private UpdateCommandResult handleUpdateAllCommand(UpdateAllCommand cmd, long co
* Handler for the {@link WriteIntentSwitchCommand}.
*
* @param cmd Command.
- * @param commandIndex Index of the RAFT command.
- * @param commandTerm Term of the RAFT command.
+ * @param commandIndex Index of the RAFT cmd.
+ * @param commandTerm Term of the RAFT cmd.
*/
private void handleWriteIntentSwitchCommand(WriteIntentSwitchCommand cmd, long commandIndex, long commandTerm) {
- // Skips the write command because the storage has already executed it.
+ // Skips the write cmd because the storage has already executed it.
if (commandIndex <= storage.lastAppliedIndex()) {
return;
}
UUID txId = cmd.txId();
- markFinished(txId, cmd.commit(), cmd.commitTimestamp());
+ markFinished(txId, cmd.commit(), cmd.commitTimestamp(), null);
Review Comment:
Why did you add commitPartitionId parameter here?
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/VolatileTxStateMetaStorage.java:
##########
@@ -118,35 +129,56 @@ public Collection<TxStateMeta> states() {
* @param vacuumObservationTimestamp Timestamp of the vacuum attempt.
* @param txnResourceTtl Transactional resource time to live in milliseconds.
*/
- public void vacuum(long vacuumObservationTimestamp, long txnResourceTtl) {
+ public void vacuum(
+ long vacuumObservationTimestamp,
+ long txnResourceTtl,
+ Function<Map<TablePartitionId, Set<UUID>>, CompletableFuture<IgniteBiTuple<Set<UUID>, Integer>>> beforeVacuum
+ ) {
LOG.info("Vacuum started [vacuumObservationTimestamp={}, txnResourceTtl={}].", vacuumObservationTimestamp, txnResourceTtl);
AtomicInteger vacuumizedTxnsCount = new AtomicInteger(0);
AtomicInteger markedAsInitiallyDetectedTxnsCount = new AtomicInteger(0);
AtomicInteger alreadyMarkedTxnsCount = new AtomicInteger(0);
AtomicInteger skippedFotFurtherProcessingUnfinishedTxnsCount = new AtomicInteger(0);
+ Map<TablePartitionId, Set<UUID>> txIds = new HashMap<>();
+ Map<UUID, Long> timestamps = new HashMap<>();
+
txStateMap.forEach((txId, meta) -> {
txStateMap.computeIfPresent(txId, (txId0, meta0) -> {
if (TxState.isFinalState(meta0.txState())) {
- if (txnResourceTtl == 0) {
Review Comment:
Do you intentionally skip fast removal in case of txnResourceTtl == 0?
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbStorage.java:
##########
@@ -231,12 +231,21 @@ public boolean compareAndSet(UUID txId, @Nullable TxState txStateExpected, TxMet
}
@Override
- public void remove(UUID txId) {
+ public void remove(UUID txId, long commandIndex, long commandTerm) {
Review Comment:
As mentioned above, let's either add Set<UUID> txId counterpart or even substitute given one.
##########
modules/transactions/src/testFixtures/java/org/apache/ignite/internal/tx/storage/state/test/TestTxStateStorage.java:
##########
@@ -108,10 +108,15 @@ public boolean compareAndSet(UUID txId, @Nullable TxState txStateExpected, TxMet
}
@Override
- public void remove(UUID txId) {
+ public void remove(UUID txId, long commandIndex, long commandTerm) {
checkStorageClosedOrInProgressOfRebalance();
storage.remove(txId);
+
+ if (rebalanceFutureReference.get() == null) {
+ lastAppliedIndex = commandIndex;
Review Comment:
Seems that we don't use neither (long commandIndex, long commandTerm) nor rebalanceFutureReferencein `public void put(UUID txId, TxMeta txMeta)`, at first glance that doesn't look correct. What's also important that it's the fact that we don't use (long commandIndex, long commandTerm) in TxStateRocksDbStorage.
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/VolatileTxStateMetaStorage.java:
##########
@@ -118,35 +129,56 @@ public Collection<TxStateMeta> states() {
* @param vacuumObservationTimestamp Timestamp of the vacuum attempt.
* @param txnResourceTtl Transactional resource time to live in milliseconds.
*/
- public void vacuum(long vacuumObservationTimestamp, long txnResourceTtl) {
+ public void vacuum(
+ long vacuumObservationTimestamp,
+ long txnResourceTtl,
+ Function<Map<TablePartitionId, Set<UUID>>, CompletableFuture<IgniteBiTuple<Set<UUID>, Integer>>> beforeVacuum
+ ) {
LOG.info("Vacuum started [vacuumObservationTimestamp={}, txnResourceTtl={}].", vacuumObservationTimestamp, txnResourceTtl);
AtomicInteger vacuumizedTxnsCount = new AtomicInteger(0);
AtomicInteger markedAsInitiallyDetectedTxnsCount = new AtomicInteger(0);
AtomicInteger alreadyMarkedTxnsCount = new AtomicInteger(0);
AtomicInteger skippedFotFurtherProcessingUnfinishedTxnsCount = new AtomicInteger(0);
+ Map<TablePartitionId, Set<UUID>> txIds = new HashMap<>();
+ Map<UUID, Long> timestamps = new HashMap<>();
+
txStateMap.forEach((txId, meta) -> {
txStateMap.computeIfPresent(txId, (txId0, meta0) -> {
if (TxState.isFinalState(meta0.txState())) {
- if (txnResourceTtl == 0) {
- vacuumizedTxnsCount.incrementAndGet();
- return null;
- } else if (meta0.initialVacuumObservationTimestamp() == null) {
+ Long initialVacuumObservationTimestamp = meta0.initialVacuumObservationTimestamp();
+
+ if (initialVacuumObservationTimestamp == null) {
markedAsInitiallyDetectedTxnsCount.incrementAndGet();
- return new TxStateMeta(
- meta0.txState(),
- meta0.txCoordinatorId(),
- meta0.commitPartitionId(),
- meta0.commitTimestamp(),
- vacuumObservationTimestamp
- );
- } else if (meta0.initialVacuumObservationTimestamp() + txnResourceTtl < vacuumObservationTimestamp) {
- vacuumizedTxnsCount.incrementAndGet();
- return null;
+
+ return markInitialVacuumObservationTimestamp(meta0, vacuumObservationTimestamp);
} else {
- alreadyMarkedTxnsCount.incrementAndGet();
- return meta0;
+ Long cleanupCompletionTimestamp = meta0.cleanupCompletionTimestamp();
+
+ boolean shouldBeVacuumized = shouldBeVacuumized(requireNonNull(initialVacuumObservationTimestamp),
+ cleanupCompletionTimestamp, txnResourceTtl, vacuumObservationTimestamp);
+
+ if (shouldBeVacuumized) {
+ if (meta0.commitPartitionId() == null) {
Review Comment:
I believe that having !null cleanupCompletionTimestamp should be enough here. Not within exact logic, but with slight adjustment.
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/message/VacuumTxStateReplicaRequest.java:
##########
@@ -0,0 +1,30 @@
+/*
+ * 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.message;
+
+import static org.apache.ignite.internal.tx.message.TxMessageGroup.VACUUM_TX_STATE_REPLICA_REQUEST;
+
+import java.util.Set;
+import java.util.UUID;
+import org.apache.ignite.internal.network.annotations.Transferable;
+import org.apache.ignite.internal.replicator.message.ReplicaRequest;
+
+@Transferable(VACUUM_TX_STATE_REPLICA_REQUEST)
+public interface VacuumTxStateReplicaRequest extends ReplicaRequest {
Review Comment:
Curious whether ReplicaRequest is intended or it actually should be PrimaryReplicaRequest?
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/PersistentTxStateVacuumizer.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.impl;
+
+import static org.apache.ignite.internal.util.CompletableFutures.allOf;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.ignite.internal.lang.IgniteBiTuple;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.replicator.ReplicaService;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.tx.message.TxMessagesFactory;
+import org.apache.ignite.internal.tx.message.VacuumTxStateReplicaRequest;
+import org.apache.ignite.network.ClusterNode;
+
+public class PersistentTxStateVacuumizer {
+ private static final IgniteLogger LOG = Loggers.forClass(PersistentTxStateVacuumizer.class);
+
+ private static final TxMessagesFactory TX_MESSAGES_FACTORY = new TxMessagesFactory();
+
+ private final ReplicaService replicaService;
+
+ private final ClusterNode localNode;
+
+ public PersistentTxStateVacuumizer(
+ ReplicaService replicaService,
+ ClusterNode localNode) {
+ this.replicaService = replicaService;
+ this.localNode = localNode;
+ }
+
+ public CompletableFuture<IgniteBiTuple<Set<UUID>, Integer>> vacuumPersistentTxStates(Map<TablePartitionId, Set<UUID>> txIds) {
+ Set<UUID> successful = ConcurrentHashMap.newKeySet();
+ AtomicInteger unsuccessfulCount = new AtomicInteger(0);
+ List<CompletableFuture<?>> futures = new ArrayList<>();
+
+ txIds.forEach((commitPartitionId, txs) -> {
+ VacuumTxStateReplicaRequest request = TX_MESSAGES_FACTORY.vacuumTxStateReplicaRequest()
+ .groupId(commitPartitionId)
+ .transactionIds(txs)
+ .build();
+
+ CompletableFuture<?> future = replicaService.invoke(localNode, request).whenComplete((v, e) -> {
+ if (e == null) {
+ successful.addAll(txs);
+ } else {
+ LOG.warn("Failed to vacuum tx states from the persistent storage.", e);
+
+ unsuccessfulCount.incrementAndGet();
+ }
+ });
+
+ futures.add(future);
Review Comment:
So, do you really want to fail allOf because of one* failed future?
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/raft/PartitionListener.java:
##########
@@ -609,14 +616,32 @@ void handleBuildIndexCommand(BuildIndexCommand cmd, long commandIndex, long comm
* @param commandTerm Command term.
*/
private void handlePrimaryReplicaChangeCommand(PrimaryReplicaChangeCommand cmd, long commandIndex, long commandTerm) {
- // Skips the write command because the storage has already executed it.
+ // Skips the write cmd because the storage has already executed it.
if (commandIndex <= storage.lastAppliedIndex()) {
return;
}
txStateStorage.updateLease(cmd.leaseStartTime(), commandIndex, commandTerm);
}
+ /**
+ * Handler for {@link VacuumTxStatesCommand}.
+ *
+ * @param cmd Command.
+ * @param commandIndex Command index.
+ * @param commandTerm Command term.
+ */
+ private void handleVacuumTxStatesCommand(VacuumTxStatesCommand cmd, long commandIndex, long commandTerm) {
+ // Skips the write cmd because the storage has already executed it.
+ if (commandIndex <= storage.lastAppliedIndex()) {
+ return;
+ }
+
+ for (UUID txId : cmd.txIds()) {
+ txStateStorage.remove(txId, commandIndex, commandTerm);
Review Comment:
It's way to ineffective. Internally in TxStateRocksDbStorage we have batching `writeBatch.delete(txIdToKey(txId));` Please use it by adding `public void remove(Set<UUID> txIds, long commandIndex, long commandTerm)` or similar.
--
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-21763 [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1569184089
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/raft/PartitionListener.java:
##########
@@ -609,14 +616,32 @@ void handleBuildIndexCommand(BuildIndexCommand cmd, long commandIndex, long comm
* @param commandTerm Command term.
*/
private void handlePrimaryReplicaChangeCommand(PrimaryReplicaChangeCommand cmd, long commandIndex, long commandTerm) {
- // Skips the write command because the storage has already executed it.
+ // Skips the write cmd because the storage has already executed it.
if (commandIndex <= storage.lastAppliedIndex()) {
return;
}
txStateStorage.updateLease(cmd.leaseStartTime(), commandIndex, commandTerm);
}
+ /**
+ * Handler for {@link VacuumTxStatesCommand}.
+ *
+ * @param cmd Command.
+ * @param commandIndex Command index.
+ * @param commandTerm Command term.
+ */
+ private void handleVacuumTxStatesCommand(VacuumTxStatesCommand cmd, long commandIndex, long commandTerm) {
+ // Skips the write cmd because the storage has already executed it.
+ if (commandIndex <= storage.lastAppliedIndex()) {
+ return;
+ }
+
+ for (UUID txId : cmd.txIds()) {
+ txStateStorage.remove(txId, commandIndex, commandTerm);
Review Comment:
fixed
--
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-21763 [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1566232357
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/raft/PartitionListener.java:
##########
@@ -77,14 +78,15 @@
import org.apache.ignite.internal.tx.TxState;
import org.apache.ignite.internal.tx.TxStateMeta;
import org.apache.ignite.internal.tx.UpdateCommandResult;
+import org.apache.ignite.internal.tx.message.VacuumTxStatesCommand;
import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
import org.apache.ignite.internal.util.PendingComparableValuesTracker;
import org.apache.ignite.internal.util.TrackerClosedException;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
/**
- * Partition command handler.
+ * Partition cmd handler.
Review Comment:
no reason, wil be fixed
--
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-21763 [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1569187496
##########
modules/transactions/src/testFixtures/java/org/apache/ignite/internal/tx/storage/state/test/TestTxStateStorage.java:
##########
@@ -108,10 +108,15 @@ public boolean compareAndSet(UUID txId, @Nullable TxState txStateExpected, TxMet
}
@Override
- public void remove(UUID txId) {
+ public void remove(UUID txId, long commandIndex, long commandTerm) {
checkStorageClosedOrInProgressOfRebalance();
storage.remove(txId);
+
+ if (rebalanceFutureReference.get() == null) {
+ lastAppliedIndex = commandIndex;
Review Comment:
Seems so, but we don't us `put` in regular flow, it's only used while copying the snapshot data
##########
modules/transactions/src/testFixtures/java/org/apache/ignite/internal/tx/storage/state/test/TestTxStateStorage.java:
##########
@@ -108,10 +108,15 @@ public boolean compareAndSet(UUID txId, @Nullable TxState txStateExpected, TxMet
}
@Override
- public void remove(UUID txId) {
+ public void remove(UUID txId, long commandIndex, long commandTerm) {
checkStorageClosedOrInProgressOfRebalance();
storage.remove(txId);
+
+ if (rebalanceFutureReference.get() == null) {
+ lastAppliedIndex = commandIndex;
Review Comment:
Seems so, but we don't use `put` in regular flow, it's only used while copying the snapshot data
--
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-21763 [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1569197304
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/PersistentTxStateVacuumizer.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.impl;
+
+import static org.apache.ignite.internal.util.CompletableFutures.allOf;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.ignite.internal.lang.IgniteBiTuple;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.replicator.ReplicaService;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.tx.message.TxMessagesFactory;
+import org.apache.ignite.internal.tx.message.VacuumTxStateReplicaRequest;
+import org.apache.ignite.network.ClusterNode;
+
+public class PersistentTxStateVacuumizer {
+ private static final IgniteLogger LOG = Loggers.forClass(PersistentTxStateVacuumizer.class);
+
+ private static final TxMessagesFactory TX_MESSAGES_FACTORY = new TxMessagesFactory();
+
+ private final ReplicaService replicaService;
+
+ private final ClusterNode localNode;
+
+ public PersistentTxStateVacuumizer(
+ ReplicaService replicaService,
+ ClusterNode localNode) {
+ this.replicaService = replicaService;
+ this.localNode = localNode;
+ }
+
+ public CompletableFuture<IgniteBiTuple<Set<UUID>, Integer>> vacuumPersistentTxStates(Map<TablePartitionId, Set<UUID>> txIds) {
+ Set<UUID> successful = ConcurrentHashMap.newKeySet();
+ AtomicInteger unsuccessfulCount = new AtomicInteger(0);
+ List<CompletableFuture<?>> futures = new ArrayList<>();
+
+ txIds.forEach((commitPartitionId, txs) -> {
+ VacuumTxStateReplicaRequest request = TX_MESSAGES_FACTORY.vacuumTxStateReplicaRequest()
+ .groupId(commitPartitionId)
+ .transactionIds(txs)
+ .build();
+
+ CompletableFuture<?> future = replicaService.invoke(localNode, request).whenComplete((v, e) -> {
+ if (e == null) {
+ successful.addAll(txs);
+ } else {
+ LOG.warn("Failed to vacuum tx states from the persistent storage.", e);
Review Comment:
fixed using `getPrimaryReplica`
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1580571320
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
+public class ItTxResourcesVacuumTest extends ClusterPerTestIntegrationTest {
+ /** Table name. */
+ private static final String TABLE_NAME = "test_table";
+
+ private static final Tuple INITIAL_TUPLE = Tuple.create().set("key", 1L).set("val", "1");
+
+ private static final Function<Tuple, Tuple> NEXT_TUPLE = t -> Tuple.create()
+ .set("key", t.longValue("key") + 1)
+ .set("val", "" + (t.longValue("key") + 1));
+
+ private static final int REPLICAS = 2;
+
+ /** Nodes bootstrap configuration pattern. */
+ private static final String NODE_BOOTSTRAP_CFG_TEMPLATE = "{\n"
+ + " network: {\n"
+ + " port: {},\n"
+ + " nodeFinder: {\n"
+ + " netClusterNodes: [ {} ]\n"
+ + " }\n"
+ + " },\n"
+ + " clientConnector: { port:{} },\n"
+ + " rest.port: {},\n"
+ + " raft: { responseTimeout: 30000 },"
+ + " compute.threadPoolSize: 1\n"
+ + "}";
+
+ private ExecutorService txStateStorageExecutor = Executors.newSingleThreadExecutor();
+
+ @BeforeEach
+ @Override
+ public void setup(TestInfo testInfo) throws Exception {
+ super.setup(testInfo);
+
+ String zoneSql = "create zone test_zone with partitions=20, replicas=" + REPLICAS
+ + ", storage_profiles='" + DEFAULT_STORAGE_PROFILE + "'";
+ String sql = "create table " + TABLE_NAME + " (key bigint primary key, val varchar(20)) with primary_zone='TEST_ZONE'";
+
+ cluster.doInSession(0, session -> {
+ executeUpdate(zoneSql, session);
+ executeUpdate(sql, session);
+ });
+
+ txStateStorageExecutor = Executors.newSingleThreadExecutor(IgniteThreadFactory.create("test", "tx-state-storage-test-pool", log,
+ ThreadOperation.STORAGE_READ));
+ }
+
+ @Override
+ @AfterEach
+ public void tearDown() {
+ shutdownAndAwaitTermination(txStateStorageExecutor, 10, TimeUnit.SECONDS);
+
+ super.tearDown();
+ }
+
+ @Override
+ protected void customizeInitParameters(InitParametersBuilder builder) {
+ super.customizeInitParameters(builder);
+
+ builder.clusterConfiguration("{"
+ + " transaction: {"
+ + " implicitTransactionTimeout: 30000,"
+ + " txnResourceTtl: 2"
+ + " },"
+ + " replication: {"
+ + " rpcTimeout: 30000"
+ + " },"
+ + "}");
+ }
+
+ @Override
+ protected int initialNodes() {
+ return 3;
+ }
+
+ /**
+ * Returns node bootstrap config template.
+ *
+ * @return Node bootstrap config template.
+ */
+ @Override
+ protected String getNodeBootstrapConfigTemplate() {
+ return NODE_BOOTSTRAP_CFG_TEMPLATE;
+ }
+
+ @Test
+ public void testVacuum() throws InterruptedException {
+ IgniteImpl node = anyNode();
+
+ RecordView<Tuple> view = node.tables().table(TABLE_NAME).recordView();
+
+ // Put some value into the table.
+ Transaction tx = node.transactions().begin();
+ UUID txId = txId(tx);
+
+ log.info("Test: Loading the data [tx={}].", txId);
+
+ Tuple tuple = findTupleToBeHostedOnNode(node, TABLE_NAME, tx, INITIAL_TUPLE, NEXT_TUPLE, true);
Review Comment:
Argh, pfff, mmm
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1578103619
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/PersistentTxStateVacuumizer.java:
##########
@@ -0,0 +1,124 @@
+/*
+ * 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.impl;
+
+import static org.apache.ignite.internal.util.CompletableFutures.allOf;
+import static org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture;
+import static org.apache.ignite.internal.util.ExceptionUtils.unwrapCause;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import org.apache.ignite.internal.hlc.ClockService;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.placementdriver.PlacementDriver;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.ReplicaService;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.replicator.exception.PrimaryReplicaMissException;
+import org.apache.ignite.internal.tx.message.TxMessagesFactory;
+import org.apache.ignite.internal.tx.message.VacuumTxStateReplicaRequest;
+import org.apache.ignite.network.ClusterNode;
+
+/**
+ * Implements the logic of persistent tx states vacuum.
+ */
+public class PersistentTxStateVacuumizer {
+ private static final IgniteLogger LOG = Loggers.forClass(PersistentTxStateVacuumizer.class);
+
+ private static final TxMessagesFactory TX_MESSAGES_FACTORY = new TxMessagesFactory();
+
+ private final ReplicaService replicaService;
+
+ private final ClusterNode localNode;
+
+ private final ClockService clockService;
+
+ private final PlacementDriver placementDriver;
+
+ /**
+ * Constructor.
+ *
+ * @param replicaService Replica service.
+ * @param localNode Local node.
+ * @param clockService Clock service.
+ * @param placementDriver Placement driver.
+ */
+ public PersistentTxStateVacuumizer(
+ ReplicaService replicaService,
+ ClusterNode localNode,
+ ClockService clockService,
+ PlacementDriver placementDriver
+ ) {
+ this.replicaService = replicaService;
+ this.localNode = localNode;
+ this.clockService = clockService;
+ this.placementDriver = placementDriver;
+ }
+
+ /**
+ * Vacuum persistent tx states.
+ *
+ * @param txIds Transaction ids to vacuum; map of commit partition ids to sets of tx ids.
+ * @return A future, result is the set of successfully vacuumized txn states.
+ */
+ public CompletableFuture<Set<UUID>> vacuumPersistentTxStates(Map<TablePartitionId, Set<UUID>> txIds) {
+ Set<UUID> successful = ConcurrentHashMap.newKeySet();
+ List<CompletableFuture<?>> futures = new ArrayList<>();
+ HybridTimestamp now = clockService.now();
+
+ txIds.forEach((commitPartitionId, txs) -> {
+ ReplicaMeta replicaMeta = placementDriver.getPrimaryReplica(commitPartitionId, now).join();
+
+ if (replicaMeta != null) {
+ VacuumTxStateReplicaRequest request = TX_MESSAGES_FACTORY.vacuumTxStateReplicaRequest()
+ .enlistmentConsistencyToken(replicaMeta.getStartTime().longValue())
+ .groupId(commitPartitionId)
+ .transactionIds(txs)
+ .build();
+
+ CompletableFuture<?> future;
+
+ if (localNode.id().equals(replicaMeta.getLeaseholderId())) {
+ future = replicaService.invoke(localNode, request).whenComplete((v, e) -> {
+ if (e == null) {
+ successful.addAll(txs);
+ } else if (!(unwrapCause(e) instanceof PrimaryReplicaMissException)) {
Review Comment:
added
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1578123209
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
Review Comment:
`igniteNode.txManager().vacuum()` - test only
But here I need to have this shortened vacuum interval and test methods waiting for vacuum because
- I can't be sure that the corresponding tx state meets the requirements to be vacuumized by the moment I call `txManager().vacuum()
- the vacuum is two step, so I would need more than 1 manual call and a time interval between calls
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1578244267
##########
modules/runner/src/testFixtures/java/org/apache/ignite/internal/table/NodeUtils.java:
##########
@@ -49,16 +50,16 @@ public class NodeUtils {
*
* @param nodes Nodes collection.
* @param groupId Group id.
- * @param preferablePrimary Primary replica name which is preferred for being primary or {@code null}.
+ * @param preferablePrimaryFilter Primary replica preferable nodes filter, accepts the node consistent id.
* @return New primary replica name.
* @throws InterruptedException If failed.
*/
public static String transferPrimary(
Collection<IgniteImpl> nodes,
ReplicationGroupId groupId,
- @Nullable String preferablePrimary
+ @Nullable Predicate<String> preferablePrimaryFilter
Review Comment:
I added a method with 2 parameters (nodes, group id) and returned the old one.
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1578374314
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/VolatileTxStateMetaStorage.java:
##########
@@ -118,35 +129,56 @@ public Collection<TxStateMeta> states() {
* @param vacuumObservationTimestamp Timestamp of the vacuum attempt.
* @param txnResourceTtl Transactional resource time to live in milliseconds.
*/
- public void vacuum(long vacuumObservationTimestamp, long txnResourceTtl) {
+ public void vacuum(
+ long vacuumObservationTimestamp,
+ long txnResourceTtl,
+ Function<Map<TablePartitionId, Set<UUID>>, CompletableFuture<IgniteBiTuple<Set<UUID>, Integer>>> beforeVacuum
+ ) {
LOG.info("Vacuum started [vacuumObservationTimestamp={}, txnResourceTtl={}].", vacuumObservationTimestamp, txnResourceTtl);
AtomicInteger vacuumizedTxnsCount = new AtomicInteger(0);
AtomicInteger markedAsInitiallyDetectedTxnsCount = new AtomicInteger(0);
AtomicInteger alreadyMarkedTxnsCount = new AtomicInteger(0);
AtomicInteger skippedFotFurtherProcessingUnfinishedTxnsCount = new AtomicInteger(0);
+ Map<TablePartitionId, Set<UUID>> txIds = new HashMap<>();
+ Map<UUID, Long> timestamps = new HashMap<>();
+
txStateMap.forEach((txId, meta) -> {
txStateMap.computeIfPresent(txId, (txId0, meta0) -> {
if (TxState.isFinalState(meta0.txState())) {
- if (txnResourceTtl == 0) {
- vacuumizedTxnsCount.incrementAndGet();
- return null;
- } else if (meta0.initialVacuumObservationTimestamp() == null) {
+ Long initialVacuumObservationTimestamp = meta0.initialVacuumObservationTimestamp();
+
+ if (initialVacuumObservationTimestamp == null) {
markedAsInitiallyDetectedTxnsCount.incrementAndGet();
- return new TxStateMeta(
- meta0.txState(),
- meta0.txCoordinatorId(),
- meta0.commitPartitionId(),
- meta0.commitTimestamp(),
- vacuumObservationTimestamp
- );
- } else if (meta0.initialVacuumObservationTimestamp() + txnResourceTtl < vacuumObservationTimestamp) {
- vacuumizedTxnsCount.incrementAndGet();
- return null;
+
+ return markInitialVacuumObservationTimestamp(meta0, vacuumObservationTimestamp);
} else {
- alreadyMarkedTxnsCount.incrementAndGet();
- return meta0;
+ Long cleanupCompletionTimestamp = meta0.cleanupCompletionTimestamp();
+
+ boolean shouldBeVacuumized = shouldBeVacuumized(requireNonNull(initialVacuumObservationTimestamp),
+ cleanupCompletionTimestamp, txnResourceTtl, vacuumObservationTimestamp);
+
+ if (shouldBeVacuumized) {
+ if (meta0.commitPartitionId() == null) {
Review Comment:
Here we cannot distinguish whether we are on the node of commit partition group or not. If the commitPartitionId is null, this means that we are not, and all we can do is vacuum of volatile state. Otherwise, we know that vacuum is still required (as defined in condition above) and we go to the persistent vacuumizer; there, if we are on the commit partition primary, then we send vacuum request, else we just consider this txId as successful and remove from volatile state.
This change would cause the failure of some test scenarios (for example #testVacuumPersistentStateAfterCleanupDelayAndVolatileStateVacuum ).
Btw, found a bug with nullification of cleanupCompletionTimestamp (fixed)
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1582618998
##########
modules/placement-driver/build.gradle:
##########
@@ -66,6 +66,7 @@ dependencies {
integrationTestImplementation(testFixtures(project(':ignite-distribution-zones')))
integrationTestImplementation(testFixtures(project(':ignite-runner')))
integrationTestImplementation(testFixtures(project(':ignite-replicator')))
+ integrationTestImplementation(testFixtures(project(':ignite-transactions')))
Review Comment:
Why? Same question for index/build.gradle and compute/build.gradle.
--
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-21763 [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1566231778
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/ResourceVacuumManager.java:
##########
@@ -50,7 +50,7 @@ public class ResourceVacuumManager implements IgniteComponent {
public static final String RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY = "RESOURCE_VACUUM_INTERVAL_MILLISECONDS";
private final int resourceVacuumIntervalMilliseconds = IgniteSystemProperties
- .getInteger(RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, 30_000);
+ .getInteger(RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, 1_000);
Review Comment:
debug, will be 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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1570173136
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/VolatileTxStateMetaStorage.java:
##########
@@ -155,14 +187,62 @@ public void vacuum(long vacuumObservationTimestamp, long txnResourceTtl) {
});
});
- LOG.info("Vacuum finished [vacuumObservationTimestamp={}, txnResourceTtl={}, vacuumizedTxnsCount={},"
- + " markedAsInitiallyDetectedTxnsCount={}, alreadyMarkedTxnsCount={}, skippedFotFurtherProcessingUnfinishedTxnsCount={}].",
- vacuumObservationTimestamp,
- txnResourceTtl,
- vacuumizedTxnsCount,
- markedAsInitiallyDetectedTxnsCount,
- alreadyMarkedTxnsCount,
- skippedFotFurtherProcessingUnfinishedTxnsCount
+ beforeVacuum.apply(txIds)
+ .thenAccept(tuple -> {
Review Comment:
kinda tricky, and we will have to pass the timestamps map to the persistent vacuum operation in order to compare the timestamps. Also, we'd better to have to count of successful persistent vacuums in log, so we cant just skip this future.
But I slightly revorked this part.
--
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-21763 [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1569196673
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/PersistentTxStateVacuumizer.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.impl;
+
+import static org.apache.ignite.internal.util.CompletableFutures.allOf;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.ignite.internal.lang.IgniteBiTuple;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.replicator.ReplicaService;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.tx.message.TxMessagesFactory;
+import org.apache.ignite.internal.tx.message.VacuumTxStateReplicaRequest;
+import org.apache.ignite.network.ClusterNode;
+
+public class PersistentTxStateVacuumizer {
+ private static final IgniteLogger LOG = Loggers.forClass(PersistentTxStateVacuumizer.class);
+
+ private static final TxMessagesFactory TX_MESSAGES_FACTORY = new TxMessagesFactory();
+
+ private final ReplicaService replicaService;
+
+ private final ClusterNode localNode;
+
+ public PersistentTxStateVacuumizer(
+ ReplicaService replicaService,
+ ClusterNode localNode) {
+ this.replicaService = replicaService;
+ this.localNode = localNode;
+ }
+
+ public CompletableFuture<IgniteBiTuple<Set<UUID>, Integer>> vacuumPersistentTxStates(Map<TablePartitionId, Set<UUID>> txIds) {
+ Set<UUID> successful = ConcurrentHashMap.newKeySet();
+ AtomicInteger unsuccessfulCount = new AtomicInteger(0);
+ List<CompletableFuture<?>> futures = new ArrayList<>();
+
+ txIds.forEach((commitPartitionId, txs) -> {
+ VacuumTxStateReplicaRequest request = TX_MESSAGES_FACTORY.vacuumTxStateReplicaRequest()
+ .groupId(commitPartitionId)
+ .transactionIds(txs)
+ .build();
+
+ CompletableFuture<?> future = replicaService.invoke(localNode, request).whenComplete((v, e) -> {
+ if (e == null) {
+ successful.addAll(txs);
+ } else {
+ LOG.warn("Failed to vacuum tx states from the persistent storage.", e);
+
+ unsuccessfulCount.incrementAndGet();
+ }
+ });
+
+ futures.add(future);
Review Comment:
it doesn't actually matter, because of `.handle` there, in the result there is a set of successfully vacuumized tx states that would be removed from the volatile storage
--
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-21763 [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1569183798
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/raft/PartitionListener.java:
##########
@@ -406,18 +413,18 @@ private UpdateCommandResult handleUpdateAllCommand(UpdateAllCommand cmd, long co
* Handler for the {@link WriteIntentSwitchCommand}.
*
* @param cmd Command.
- * @param commandIndex Index of the RAFT command.
- * @param commandTerm Term of the RAFT command.
+ * @param commandIndex Index of the RAFT cmd.
+ * @param commandTerm Term of the RAFT cmd.
*/
private void handleWriteIntentSwitchCommand(WriteIntentSwitchCommand cmd, long commandIndex, long commandTerm) {
- // Skips the write command because the storage has already executed it.
+ // Skips the write cmd because the storage has already executed it.
if (commandIndex <= storage.lastAppliedIndex()) {
return;
}
UUID txId = cmd.txId();
- markFinished(txId, cmd.commit(), cmd.commitTimestamp());
+ markFinished(txId, cmd.commit(), cmd.commitTimestamp(), null);
Review Comment:
To make sure the commit partition id would be present in the volatile tx state on all nodes of commit partition group.
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1580520355
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTransactionPrimaryChangeTest.java:
##########
@@ -87,7 +85,8 @@ protected void customizeInitParameters(InitParametersBuilder builder) {
builder.clusterConfiguration("{"
+ " transaction: {"
- + " implicitTransactionTimeout: 30000"
+ + " implicitTransactionTimeout: 30000,"
+ + " txnResourceTtl: 2"
Review Comment:
or 3, or 4, why it's 2?
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1578068201
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTransactionTestUtils.java:
##########
@@ -0,0 +1,204 @@
+/*
+ * 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.table;
+
+import static java.util.Objects.requireNonNull;
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.TestWrappers.unwrapIgniteTransaction;
+import static org.apache.ignite.internal.TestWrappers.unwrapRecordBinaryViewImpl;
+import static org.apache.ignite.internal.TestWrappers.unwrapTableImpl;
+import static org.apache.ignite.internal.distributionzones.rebalance.RebalanceUtil.stablePartAssignmentsKey;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.Function;
+import org.apache.ignite.internal.affinity.Assignment;
+import org.apache.ignite.internal.affinity.Assignments;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.lang.ByteArray;
+import org.apache.ignite.internal.metastorage.Entry;
+import org.apache.ignite.internal.metastorage.MetaStorageManager;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.ReplicationGroupId;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.schema.BinaryRowEx;
+import org.apache.ignite.internal.tx.impl.ReadWriteTransactionImpl;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Test utils for transaction integration tests.
+ */
+public class ItTransactionTestUtils {
+ /**
+ * Get the names of the nodes that are assignments of the given partition.
+ *
+ * @param node Any node in the cluster.
+ * @param grpId Group id.
+ * @return Node names.
+ */
+ public static Set<String> partitionAssignment(IgniteImpl node, TablePartitionId grpId) {
Review Comment:
any suggestions? I couldn't find a better place
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1578049130
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/raft/PartitionListener.java:
##########
@@ -406,18 +413,18 @@ private UpdateCommandResult handleUpdateAllCommand(UpdateAllCommand cmd, long co
* Handler for the {@link WriteIntentSwitchCommand}.
*
* @param cmd Command.
- * @param commandIndex Index of the RAFT command.
- * @param commandTerm Term of the RAFT command.
+ * @param commandIndex Index of the RAFT cmd.
+ * @param commandTerm Term of the RAFT cmd.
*/
private void handleWriteIntentSwitchCommand(WriteIntentSwitchCommand cmd, long commandIndex, long commandTerm) {
- // Skips the write command because the storage has already executed it.
+ // Skips the write cmd because the storage has already executed it.
if (commandIndex <= storage.lastAppliedIndex()) {
return;
}
UUID txId = cmd.txId();
- markFinished(txId, cmd.commit(), cmd.commitTimestamp());
+ markFinished(txId, cmd.commit(), cmd.commitTimestamp(), null);
Review Comment:
primary replica of the commit partition may change, and in this we need to have commit partition id in volatile state (together with cleanup completion timestamp) to be able to send the vacuum request on the commit partition.
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1578125303
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
+public class ItTxResourcesVacuumTest extends ClusterPerTestIntegrationTest {
+ /** Table name. */
+ private static final String TABLE_NAME = "test_table";
+
+ private static final Tuple INITIAL_TUPLE = Tuple.create().set("key", 1L).set("val", "1");
+
+ private static final Function<Tuple, Tuple> NEXT_TUPLE = t -> Tuple.create()
+ .set("key", t.longValue("key") + 1)
+ .set("val", "" + (t.longValue("key") + 1));
+
+ private static final int REPLICAS = 2;
+
+ /** Nodes bootstrap configuration pattern. */
+ private static final String NODE_BOOTSTRAP_CFG_TEMPLATE = "{\n"
+ + " network: {\n"
+ + " port: {},\n"
+ + " nodeFinder: {\n"
+ + " netClusterNodes: [ {} ]\n"
+ + " }\n"
+ + " },\n"
+ + " clientConnector: { port:{} },\n"
+ + " rest.port: {},\n"
+ + " raft: { responseTimeout: 30000 },"
+ + " compute.threadPoolSize: 1\n"
+ + "}";
+
+ private ExecutorService txStateStorageExecutor = Executors.newSingleThreadExecutor();
+
+ @BeforeEach
+ @Override
+ public void setup(TestInfo testInfo) throws Exception {
+ super.setup(testInfo);
+
+ String zoneSql = "create zone test_zone with partitions=20, replicas=" + REPLICAS
+ + ", storage_profiles='" + DEFAULT_STORAGE_PROFILE + "'";
Review Comment:
Does it matter? We have only one tx state storage production implementation, it's rocksdb
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1578123209
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
Review Comment:
`igniteNode.txManager().vacuum()` - test only
But here I need to have this shortened vacuum interval and test methods waiting for vacuum because
- I can't be sure that the corresponding tx state meets the requirements to be vacuumized by the moment I call `txManager().vacuum()
- the vacuum is two step, so I would need more than 1 manual call
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1578239484
##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItTxResourcesVacuumTest.java:
##########
@@ -0,0 +1,559 @@
+/*
+ * 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.table;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.internal.SessionUtils.executeUpdate;
+import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_STORAGE_PROFILE;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.findTupleToBeHostedOnNode;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionAssignment;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.partitionIdForTuple;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.table;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.tableId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.txId;
+import static org.apache.ignite.internal.table.ItTransactionTestUtils.waitAndGetPrimaryReplica;
+import static org.apache.ignite.internal.table.NodeUtils.transferPrimary;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.tx.TxState.COMMITTED;
+import static org.apache.ignite.internal.tx.impl.ResourceVacuumManager.RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY;
+import static org.apache.ignite.internal.util.IgniteUtils.shutdownAndAwaitTermination;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Iterator;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import org.apache.ignite.InitParametersBuilder;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.app.IgniteImpl;
+import org.apache.ignite.internal.placementdriver.ReplicaMeta;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.testframework.SystemPropertiesExtension;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.thread.IgniteThreadFactory;
+import org.apache.ignite.internal.thread.ThreadOperation;
+import org.apache.ignite.internal.tx.TransactionMeta;
+import org.apache.ignite.internal.tx.impl.TxManagerImpl;
+import org.apache.ignite.internal.tx.message.TxCleanupMessage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.table.RecordView;
+import org.apache.ignite.table.Tuple;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Integration tests for tx recources vacuum.
+ */
+@ExtendWith(SystemPropertiesExtension.class)
+@WithSystemProperty(key = RESOURCE_VACUUM_INTERVAL_MILLISECONDS_PROPERTY, value = "1000")
+public class ItTxResourcesVacuumTest extends ClusterPerTestIntegrationTest {
+ /** Table name. */
+ private static final String TABLE_NAME = "test_table";
+
+ private static final Tuple INITIAL_TUPLE = Tuple.create().set("key", 1L).set("val", "1");
+
+ private static final Function<Tuple, Tuple> NEXT_TUPLE = t -> Tuple.create()
+ .set("key", t.longValue("key") + 1)
+ .set("val", "" + (t.longValue("key") + 1));
+
+ private static final int REPLICAS = 2;
+
+ /** Nodes bootstrap configuration pattern. */
+ private static final String NODE_BOOTSTRAP_CFG_TEMPLATE = "{\n"
+ + " network: {\n"
+ + " port: {},\n"
+ + " nodeFinder: {\n"
+ + " netClusterNodes: [ {} ]\n"
+ + " }\n"
+ + " },\n"
+ + " clientConnector: { port:{} },\n"
+ + " rest.port: {},\n"
+ + " raft: { responseTimeout: 30000 },"
+ + " compute.threadPoolSize: 1\n"
+ + "}";
+
+ private ExecutorService txStateStorageExecutor = Executors.newSingleThreadExecutor();
+
+ @BeforeEach
+ @Override
+ public void setup(TestInfo testInfo) throws Exception {
+ super.setup(testInfo);
+
+ String zoneSql = "create zone test_zone with partitions=20, replicas=" + REPLICAS
+ + ", storage_profiles='" + DEFAULT_STORAGE_PROFILE + "'";
+ String sql = "create table " + TABLE_NAME + " (key bigint primary key, val varchar(20)) with primary_zone='TEST_ZONE'";
+
+ cluster.doInSession(0, session -> {
+ executeUpdate(zoneSql, session);
+ executeUpdate(sql, session);
+ });
+
+ txStateStorageExecutor = Executors.newSingleThreadExecutor(IgniteThreadFactory.create("test", "tx-state-storage-test-pool", log,
+ ThreadOperation.STORAGE_READ));
+ }
+
+ @Override
+ @AfterEach
+ public void tearDown() {
+ shutdownAndAwaitTermination(txStateStorageExecutor, 10, TimeUnit.SECONDS);
+
+ super.tearDown();
+ }
+
+ @Override
+ protected void customizeInitParameters(InitParametersBuilder builder) {
+ super.customizeInitParameters(builder);
+
+ builder.clusterConfiguration("{"
+ + " transaction: {"
+ + " implicitTransactionTimeout: 30000,"
+ + " txnResourceTtl: 2"
+ + " },"
+ + " replication: {"
+ + " rpcTimeout: 30000"
+ + " },"
+ + "}");
+ }
+
+ @Override
+ protected int initialNodes() {
+ return 3;
+ }
+
+ /**
+ * Returns node bootstrap config template.
+ *
+ * @return Node bootstrap config template.
+ */
+ @Override
+ protected String getNodeBootstrapConfigTemplate() {
+ return NODE_BOOTSTRAP_CFG_TEMPLATE;
+ }
+
+ @Test
+ public void testVacuum() throws InterruptedException {
+ IgniteImpl node = anyNode();
+
+ RecordView<Tuple> view = node.tables().table(TABLE_NAME).recordView();
+
+ // Put some value into the table.
+ Transaction tx = node.transactions().begin();
+ UUID txId = txId(tx);
+
+ log.info("Test: Loading the data [tx={}].", txId);
+
+ Tuple tuple = findTupleToBeHostedOnNode(node, TABLE_NAME, tx, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ int partId = partitionIdForTuple(node, TABLE_NAME, tuple, tx);
+
+ Set<String> nodes = partitionAssignment(node, new TablePartitionId(tableId(node, TABLE_NAME), partId));
+
+ view.upsert(tx, tuple);
+
+ tx.commit();
+
+ log.info("Test: Tx committed [tx={}].", txId);
+
+ checkVolatileTxStateOnNodes(nodes, txId);
+ waitForTxStateReplication(nodes, txId, partId, 10_000);
+
+ waitForTxStateVacuum(txId, partId, true, 10_000);
+ }
+
+ @Test
+ public void testVacuumWithCleanupDelay() throws InterruptedException {
+ IgniteImpl node = anyNode();
+
+ RecordView<Tuple> view = node.tables().table(TABLE_NAME).recordView();
+
+ // Put some value into the table.
+ Transaction tx = node.transactions().begin();
+ UUID txId = txId(tx);
+
+ log.info("Test: Loading the data [tx={}].", txId);
+
+ Tuple tuple0 = findTupleToBeHostedOnNode(node, TABLE_NAME, tx, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ int commitPartId = partitionIdForTuple(node, TABLE_NAME, tuple0, tx);
+
+ TablePartitionId commitPartGrpId = new TablePartitionId(tableId(node, TABLE_NAME), commitPartId);
+
+ ReplicaMeta replicaMeta = waitAndGetPrimaryReplica(node, commitPartGrpId);
+ IgniteImpl commitPartitionLeaseholder = findNode(n -> n.id().equals(replicaMeta.getLeaseholderId()));
+
+ Set<String> commitPartNodes = partitionAssignment(node, new TablePartitionId(tableId(node, TABLE_NAME), commitPartId));
+
+ log.info("Test: Commit partition [leaseholder={}, hostingNodes={}].", commitPartitionLeaseholder.name(), commitPartNodes);
+
+ // Some node that does not host the commit partition, will be the primary node for upserting another tuple.
+ IgniteImpl leaseholderForAnotherTuple = findNode(n -> !commitPartNodes.contains(n.name()));
+
+ log.info("Test: leaseholderForAnotherTuple={}", leaseholderForAnotherTuple.name());
+
+ Tuple tuple1 = findTupleToBeHostedOnNode(leaseholderForAnotherTuple, TABLE_NAME, tx, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ view.upsert(tx, tuple0);
+ view.upsert(tx, tuple1);
+
+ CompletableFuture<Void> cleanupStarted = new CompletableFuture<>();
+ CompletableFuture<Void> cleanupAllowed = new CompletableFuture<>();
+
+ commitPartitionLeaseholder.dropMessages((n, msg) -> {
+ if (msg instanceof TxCleanupMessage) {
+ cleanupStarted.complete(null);
+
+ log.info("Test: cleanup started.");
+
+ if (commitPartNodes.contains(n)) {
+ cleanupAllowed.join();
+ }
+ }
+
+ return false;
+ });
+
+ CompletableFuture<Void> commitFut = tx.commitAsync();
+
+ checkVolatileTxStateOnNodes(commitPartNodes, txId);
+ waitForTxStateReplication(commitPartNodes, txId, commitPartId, 10_000);
+
+ assertThat(cleanupStarted, willCompleteSuccessfully());
+
+ waitForTxStateVacuum(Set.of(leaseholderForAnotherTuple.name()), txId, 0, false, 10_000);
+
+ checkPersistentTxStateOnNodes(commitPartNodes, txId, commitPartId);
+
+ cleanupAllowed.complete(null);
+
+ assertThat(commitFut, willCompleteSuccessfully());
+
+ waitForTxStateVacuum(txId, commitPartId, true, 10_000);
+ }
+
+ @Test
+ public void testCommitPartitionPrimaryChangesBeforeVacuum() throws InterruptedException {
+ IgniteImpl node = anyNode();
+
+ RecordView<Tuple> view = node.tables().table(TABLE_NAME).recordView();
+
+ // Put some value into the table.
+ Transaction tx = node.transactions().begin();
+ UUID txId = txId(tx);
+
+ log.info("Test: Loading the data [tx={}].", txId);
+
+ Tuple tuple = findTupleToBeHostedOnNode(node, TABLE_NAME, tx, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ int commitPartId = partitionIdForTuple(node, TABLE_NAME, tuple, tx);
+
+ TablePartitionId commitPartGrpId = new TablePartitionId(tableId(node, TABLE_NAME), commitPartId);
+
+ ReplicaMeta replicaMeta = waitAndGetPrimaryReplica(node, commitPartGrpId);
+ IgniteImpl commitPartitionLeaseholder = findNode(n -> n.id().equals(replicaMeta.getLeaseholderId()));
+
+ Set<String> commitPartNodes = partitionAssignment(node, new TablePartitionId(tableId(node, TABLE_NAME), commitPartId));
+
+ log.info("Test: Commit partition [leaseholder={}, hostingNodes={}].", commitPartitionLeaseholder.name(), commitPartNodes);
+
+ view.upsert(tx, tuple);
+
+ CompletableFuture<Void> cleanupStarted = new CompletableFuture<>();
+ CompletableFuture<Void> cleanupAllowedFut = new CompletableFuture<>();
+ boolean[] cleanupAllowed = new boolean[1];
+
+ commitPartitionLeaseholder.dropMessages((n, msg) -> {
+ if (msg instanceof TxCleanupMessage && !cleanupAllowed[0]) {
+ cleanupStarted.complete(null);
+
+ cleanupAllowedFut.join();
+
+ return true;
+ }
+
+ return false;
+ });
+
+ CompletableFuture<Void> commitFut = tx.commitAsync();
+
+ assertThat(cleanupStarted, willCompleteSuccessfully());
+
+ transferPrimary(cluster.runningNodes().collect(toSet()), commitPartGrpId, commitPartNodes::contains);
+
+ cleanupAllowedFut.complete(null);
+
+ cleanupAllowed[0] = true;
+
+ assertThat(commitFut, willCompleteSuccessfully());
+
+ waitForTxStateVacuum(txId, commitPartId, true, 10_000);
+ }
+
+ @Test
+ public void testVacuumPersistentStateAfterCleanupDelayAndVolatileStateVacuum() throws InterruptedException {
+ IgniteImpl node = anyNode();
+
+ RecordView<Tuple> view = node.tables().table(TABLE_NAME).recordView();
+
+ // Put some value into the table.
+ Transaction tx = node.transactions().begin();
+ UUID txId = txId(tx);
+
+ log.info("Test: Loading the data [tx={}].", txId);
+
+ Tuple tuple = findTupleToBeHostedOnNode(node, TABLE_NAME, tx, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ int commitPartId = partitionIdForTuple(node, TABLE_NAME, tuple, tx);
+
+ TablePartitionId commitPartGrpId = new TablePartitionId(tableId(node, TABLE_NAME), commitPartId);
+
+ ReplicaMeta replicaMeta = waitAndGetPrimaryReplica(node, commitPartGrpId);
+ IgniteImpl commitPartitionLeaseholder = findNode(n -> n.id().equals(replicaMeta.getLeaseholderId()));
+
+ Set<String> commitPartNodes = partitionAssignment(node, new TablePartitionId(tableId(node, TABLE_NAME), commitPartId));
+
+ log.info("Test: Commit partition [leaseholder={}, hostingNodes={}].", commitPartitionLeaseholder.name(), commitPartNodes);
+
+ view.upsert(tx, tuple);
+
+ CompletableFuture<Void> cleanupStarted = new CompletableFuture<>();
+ CompletableFuture<Void> cleanupAllowedFut = new CompletableFuture<>();
+ boolean[] cleanupAllowed = new boolean[1];
+
+ commitPartitionLeaseholder.dropMessages((n, msg) -> {
+ if (msg instanceof TxCleanupMessage && !cleanupAllowed[0]) {
+ cleanupStarted.complete(null);
+
+ cleanupAllowedFut.join();
+
+ return true;
+ }
+
+ return false;
+ });
+
+ CompletableFuture<Void> commitFut = tx.commitAsync();
+
+ assertThat(cleanupStarted, willCompleteSuccessfully());
+
+ transferPrimary(cluster.runningNodes().collect(toSet()), commitPartGrpId, commitPartNodes::contains);
+
+ cleanupAllowedFut.complete(null);
+
+ cleanupAllowed[0] = true;
+
+ assertThat(commitFut, willCompleteSuccessfully());
+
+ waitForTxStateVacuum(txId, commitPartId, true, 10_000);
+ }
+
+ @Test
+ public void testRecoveryAfterPersistentStateVacuumized() throws InterruptedException {
+ // This node isn't going to be stopped, so let it be node 0.
+ IgniteImpl commitPartitionLeaseholder = cluster.runningNodes().collect(Collectors.toList()).get(0);
+
+ Tuple tuple0 = findTupleToBeHostedOnNode(commitPartitionLeaseholder, TABLE_NAME, null, INITIAL_TUPLE, NEXT_TUPLE, true);
+
+ int commitPartId = partitionIdForTuple(commitPartitionLeaseholder, TABLE_NAME, tuple0, null);
+
+ Set<String> commitPartitionNodes = partitionAssignment(commitPartitionLeaseholder,
+ new TablePartitionId(tableId(commitPartitionLeaseholder, TABLE_NAME), commitPartId));
+
+ // Choose some node that doesn't host the partition as a tx coordinator.
+ IgniteImpl coord0 = findNode(n -> !commitPartitionNodes.contains(n.name()));
+
+ RecordView<Tuple> view0 = coord0.tables().table(TABLE_NAME).recordView();
+
+ // Put some value into the table.
+ Transaction tx0 = coord0.transactions().begin();
+ UUID txId0 = txId(tx0);
+
+ log.info("Test: Transaction 0 [tx={}].", txId0);
+
+ log.info("Test: Commit partition of transaction 0 [leaseholder={}, hostingNodes={}].", commitPartitionLeaseholder.name(),
+ commitPartitionNodes);
+
+ view0.upsert(tx0, tuple0);
+
+ CompletableFuture<Void> cleanupStarted = new CompletableFuture<>();
+ boolean[] cleanupAllowed = new boolean[1];
+
+ commitPartitionLeaseholder.dropMessages((n, msg) -> {
+ if (msg instanceof TxCleanupMessage) {
+ cleanupStarted.complete(null);
+
+ return cleanupAllowed[0];
+ }
+
+ return false;
+ });
+
+ log.info("Test: Committing the transaction 0 [tx={}].", txId0);
+
+ tx0.commitAsync();
+
+ assertThat(cleanupStarted, willCompleteSuccessfully());
+
+ // Check that the final tx state COMMITTED is saved to the persistent tx storage.
+ assertTrue(waitForCondition(() -> cluster.runningNodes().filter(n -> commitPartitionNodes.contains(n.name())).allMatch(n -> {
+ TransactionMeta meta = persistentTxState(n, txId0, commitPartId);
+
+ return meta != null && meta.txState() == COMMITTED;
+ }), 10_000));
+
+ // Stop the first transaction coordinator.
+ stopNode(coord0.name());
+
+ // No cleanup happened, waiting for vacuum on the remaining nodes that participated on tx0.
+ waitForTxStateVacuum(txId0, commitPartId, true, 10_000);
+
+ // Preparing to run another tx.
+ IgniteImpl coord1 = anyNode();
+
+ RecordView<Tuple> view1 = coord1.tables().table(TABLE_NAME).recordView();
+
+ Transaction tx1 = coord1.transactions().begin();
+ UUID txId1 = txId(tx1);
+
+ log.info("Test: Transaction 1 [tx={}].", txId1);
+
+ // Tx 1 should get the data committed by tx 0.
+ Tuple keyTuple = Tuple.create().set("key", tuple0.longValue("key"));
+ Tuple tx0Data = view1.get(tx1, keyTuple);
+ assertEquals(tuple0.longValue("key"), tx0Data.longValue("key"));
+ assertEquals(tuple0.stringValue("val"), tx0Data.stringValue("val"));
+
+ tx1.commit();
+
+ waitForTxStateVacuum(txId0, commitPartId, true, 10_000);
+ waitForTxStateVacuum(txId0, commitPartId, true, 10_000);
+ }
+
+ private boolean checkVolatileTxStateOnNodes(Set<String> nodeConsistentIds, UUID txId) {
+ return cluster.runningNodes()
+ .filter(n -> nodeConsistentIds.contains(n.name()))
+ .allMatch(n -> volatileTxState(n, txId) != null);
+ }
+
+ private boolean checkPersistentTxStateOnNodes(Set<String> nodeConsistentIds, UUID txId, int partId) {
+ return cluster.runningNodes()
+ .filter(n -> nodeConsistentIds.contains(n.name()))
+ .allMatch(n -> persistentTxState(n, txId, partId) != null);
+ }
+
+ private void waitForTxStateReplication(Set<String> nodeConsistentIds, UUID txId, int partId, long timeMs)
+ throws InterruptedException {
+ assertTrue(waitForCondition(() -> checkPersistentTxStateOnNodes(nodeConsistentIds, txId, partId), timeMs));
+ }
+
+ private void waitForTxStateVacuum(UUID txId, int partId, boolean checkPersistent, long timeMs) throws InterruptedException {
Review Comment:
Added javadoc.
--
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-21763 Adjust TxnResourceVacuumTask in order to vacuum persistent txn state [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #3591:
URL: https://github.com/apache/ignite-3/pull/3591#discussion_r1578374314
##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/impl/VolatileTxStateMetaStorage.java:
##########
@@ -118,35 +129,56 @@ public Collection<TxStateMeta> states() {
* @param vacuumObservationTimestamp Timestamp of the vacuum attempt.
* @param txnResourceTtl Transactional resource time to live in milliseconds.
*/
- public void vacuum(long vacuumObservationTimestamp, long txnResourceTtl) {
+ public void vacuum(
+ long vacuumObservationTimestamp,
+ long txnResourceTtl,
+ Function<Map<TablePartitionId, Set<UUID>>, CompletableFuture<IgniteBiTuple<Set<UUID>, Integer>>> beforeVacuum
+ ) {
LOG.info("Vacuum started [vacuumObservationTimestamp={}, txnResourceTtl={}].", vacuumObservationTimestamp, txnResourceTtl);
AtomicInteger vacuumizedTxnsCount = new AtomicInteger(0);
AtomicInteger markedAsInitiallyDetectedTxnsCount = new AtomicInteger(0);
AtomicInteger alreadyMarkedTxnsCount = new AtomicInteger(0);
AtomicInteger skippedFotFurtherProcessingUnfinishedTxnsCount = new AtomicInteger(0);
+ Map<TablePartitionId, Set<UUID>> txIds = new HashMap<>();
+ Map<UUID, Long> timestamps = new HashMap<>();
+
txStateMap.forEach((txId, meta) -> {
txStateMap.computeIfPresent(txId, (txId0, meta0) -> {
if (TxState.isFinalState(meta0.txState())) {
- if (txnResourceTtl == 0) {
- vacuumizedTxnsCount.incrementAndGet();
- return null;
- } else if (meta0.initialVacuumObservationTimestamp() == null) {
+ Long initialVacuumObservationTimestamp = meta0.initialVacuumObservationTimestamp();
+
+ if (initialVacuumObservationTimestamp == null) {
markedAsInitiallyDetectedTxnsCount.incrementAndGet();
- return new TxStateMeta(
- meta0.txState(),
- meta0.txCoordinatorId(),
- meta0.commitPartitionId(),
- meta0.commitTimestamp(),
- vacuumObservationTimestamp
- );
- } else if (meta0.initialVacuumObservationTimestamp() + txnResourceTtl < vacuumObservationTimestamp) {
- vacuumizedTxnsCount.incrementAndGet();
- return null;
+
+ return markInitialVacuumObservationTimestamp(meta0, vacuumObservationTimestamp);
} else {
- alreadyMarkedTxnsCount.incrementAndGet();
- return meta0;
+ Long cleanupCompletionTimestamp = meta0.cleanupCompletionTimestamp();
+
+ boolean shouldBeVacuumized = shouldBeVacuumized(requireNonNull(initialVacuumObservationTimestamp),
+ cleanupCompletionTimestamp, txnResourceTtl, vacuumObservationTimestamp);
+
+ if (shouldBeVacuumized) {
+ if (meta0.commitPartitionId() == null) {
Review Comment:
changed; btw, found a bug with nullification of cleanupCompletionTimestamp (fixed)
--
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