xtern commented on code in PR #4137: URL: https://github.com/apache/ignite-3/pull/4137#discussion_r1709016618
########## modules/catalog-compaction/src/integrationTest/java/org/apache/ignite/internal/catalog/compaction/ItCatalogCompactionTest.java: ########## @@ -0,0 +1,226 @@ +/* + * 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.catalog.compaction; + +import static org.apache.ignite.internal.lang.IgniteStringFormatter.format; +import static org.apache.ignite.internal.testframework.IgniteTestUtils.await; +import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.lessThanOrEqualTo; +import static org.hamcrest.Matchers.not; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import it.unimi.dsi.fastutil.ints.Int2IntMap; +import it.unimi.dsi.fastutil.ints.Int2IntMap.Entry; +import java.util.Collection; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Stream; +import org.apache.ignite.internal.ClusterPerClassIntegrationTest; +import org.apache.ignite.internal.app.IgniteImpl; +import org.apache.ignite.internal.catalog.Catalog; +import org.apache.ignite.internal.catalog.CatalogManagerImpl; +import org.apache.ignite.internal.catalog.compaction.CatalogCompactionRunner.TimeHolder; +import org.apache.ignite.internal.hlc.HybridTimestamp; +import org.apache.ignite.internal.raft.Loza; +import org.apache.ignite.internal.raft.Peer; +import org.apache.ignite.internal.raft.RaftNodeId; +import org.apache.ignite.internal.raft.server.impl.JraftServerImpl; +import org.apache.ignite.internal.raft.server.impl.JraftServerImpl.DelegatingStateMachine; +import org.apache.ignite.internal.replicator.TablePartitionId; +import org.apache.ignite.internal.table.distributed.raft.PartitionListener; +import org.apache.ignite.internal.testframework.IgniteTestUtils; +import org.apache.ignite.internal.tx.InternalTransaction; +import org.apache.ignite.network.ClusterNode; +import org.apache.ignite.raft.jraft.RaftGroupService; +import org.apache.ignite.tx.TransactionOptions; +import org.junit.jupiter.api.Test; + +/** + * Integration tests to verify catalog compaction. + */ +class ItCatalogCompactionTest extends ClusterPerClassIntegrationTest { + private static final int CLUSTER_SIZE = 3; + + @Override + protected int initialNodes() { + return CLUSTER_SIZE; + } + + @Test + void testRaftGroupsUpdate() throws InterruptedException { + IgniteImpl ignite = CLUSTER.aliveNode(); + CatalogManagerImpl catalogManager = ((CatalogManagerImpl) CLUSTER.aliveNode().catalogManager()); + + sql(format("create zone if not exists test with partitions=16, replicas={}, storage_profiles='default'", + initialNodes())); + sql("alter zone test set default"); + + // Latest active catalog contains all required tables. + { + sql("create table a(a int primary key)"); + + Catalog minRequiredCatalog = catalogManager.catalog(catalogManager.latestCatalogVersion()); + assertNotNull(minRequiredCatalog); + + sql("create table b(a int primary key)"); + + HybridTimestamp expectedTime = HybridTimestamp.hybridTimestamp(minRequiredCatalog.time()); + + CompletableFuture<Void> fut = ignite.catalogCompactionRunner() + .propagateTimeToReplicas(expectedTime.longValue()); + + assertThat(fut, willCompleteSuccessfully()); + + ensureTimestampStoredInAllReplicas(expectedTime, 2); + } + + // Latest active catalog does not contain all required tables. + // Replicas of dropped tables must also be updated. + long requiredTime = CLUSTER.aliveNode().clockService().nowLong(); + + { + sql("drop table a"); + sql("drop table b"); + + HybridTimestamp expectedTime = HybridTimestamp.hybridTimestamp(requiredTime); + + CompletableFuture<Void> fut = ignite.catalogCompactionRunner() + .propagateTimeToReplicas(expectedTime.longValue()); + + assertThat(fut, willCompleteSuccessfully()); + + ensureTimestampStoredInAllReplicas(expectedTime, 2); + } + + // Update to lower timestamp should not succeed. + { + HybridTimestamp expectedTime = HybridTimestamp.hybridTimestamp(requiredTime - 1); + + CompletableFuture<Void> fut = ignite.catalogCompactionRunner() + .propagateTimeToReplicas(expectedTime.longValue()); + + assertThat(fut, willCompleteSuccessfully()); + + ensureTimestampStoredInAllReplicas(HybridTimestamp.hybridTimestamp(requiredTime), 2); + } Review Comment: > 1. Infinitely dead assignment case is not covered. I mean the one when Assignment assignment = tokenizedAssignments.nodes().iterator().next(); is not present in topology and never will be. I added some tests on mocks for check this (`CatalogCompactionRunnerSelfTest`): * minTxTimePropagationSucceedWhenSomeAssignmentIsMissing * minTxTimePropagation * minTxTimePropagationAbortedIfNoAssignmentsPresentInTopology > 2. Table adjustments while invokeOnReplicas recursive calls is not covered. This test case needs more clarification, I don't quite understand what this test might look like. :thinking: > 3. Failover cases are not covered. E.g. temporary assignment death. Currently we don't have any failover :sunglasses: We just aborting the process (see `minTxTimePropagationAbortedIfNoAssignmentsPresentInTopology`). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
