You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "sashapolo (via GitHub)" <gi...@apache.org> on 2024/07/09 18:17:15 UTC

[PR] IGNITE-22619 Add `InternalTable#estimatedSize` method [ignite-3]

sashapolo opened a new pull request, #4065:
URL: https://github.com/apache/ignite-3/pull/4065

   https://issues.apache.org/jira/browse/IGNITE-22619
   
   Thank you for submitting the pull request.
   
   To streamline the review process of the patch and ensure better code quality
   we ask both an author and a reviewer to verify the following:
   
   ### The Review Checklist
   - [ ] **Formal criteria:** TC status, codestyle, mandatory documentation. Also make sure to complete the following:  
   \- There is a single JIRA ticket related to the pull request.  
   \- The web-link to the pull request is attached to the JIRA ticket.  
   \- The JIRA ticket has the Patch Available state.  
   \- The description of the JIRA ticket explains WHAT was made, WHY and HOW.  
   \- The pull request title is treated as the final commit message. The following pattern must be used: IGNITE-XXXX Change summary where XXXX - number of JIRA issue.
   - [ ] **Design:** new code conforms with the design principles of the components it is added to.
   - [ ] **Patch quality:** patch cannot be split into smaller pieces, its size must be reasonable.
   - [ ] **Code quality:** code is clean and readable, necessary developer documentation is added if needed.
   - [ ] **Tests code quality:** test set covers positive/negative scenarios, happy/edge cases. Tests are effective in terms of execution time and resources.
   
   ### Notes
   - [Apache Ignite Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Java+Code+Style+Guide)


-- 
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-22619 Add `InternalTable#estimatedSize` method [ignite-3]

Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
sashapolo commented on code in PR #4065:
URL: https://github.com/apache/ignite-3/pull/4065#discussion_r1671832950


##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItEstimatedSizeTest.java:
##########
@@ -0,0 +1,182 @@
+/*
+ * 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 org.apache.ignite.internal.TestDefaultProfilesNames.DEFAULT_TEST_PROFILE_NAME;
+import static org.apache.ignite.internal.TestWrappers.unwrapTableViewInternal;
+import static org.apache.ignite.internal.catalog.commands.CatalogUtils.IMMEDIATE_TIMER_VALUE;
+import static org.apache.ignite.internal.distributionzones.rebalance.RebalanceUtil.STABLE_ASSIGNMENTS_PREFIX;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.flow.TestFlowUtils.subscribeToList;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willBe;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.affinity.Assignments;
+import org.apache.ignite.internal.lang.ByteArray;
+import org.apache.ignite.internal.metastorage.Entry;
+import org.apache.ignite.internal.metastorage.MetaStorageManager;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Integration tests for {@link InternalTable#estimatedSize()} method.
+ *
+ * <p>This class doesn't use the Parameterized Test approach in order to reduce the number of created clusters.
+ */
+public class ItEstimatedSizeTest extends ClusterPerTestIntegrationTest {
+    private static final String TEST_ZONE_NAME = "TestZone";
+
+    private static final String TEST_TABLE_NAME_PREFIX = "Test_";
+
+    private static final long NUM_ROWS = 100;
+
+    private static final String[] ALL_STORAGE_PROFILES = {
+            DEFAULT_TEST_PROFILE_NAME,
+            // TODO: https://issues.apache.org/jira/browse/IGNITE-22616
+            // DEFAULT_AIPERSIST_PROFILE_NAME,
+            // TODO: https://issues.apache.org/jira/browse/IGNITE-22616
+            // DEFAULT_AIMEM_PROFILE_NAME,
+            // TODO: https://issues.apache.org/jira/browse/IGNITE-22617
+            // DEFAULT_ROCKSDB_PROFILE_NAME
+    };
+
+    @BeforeEach
+    void setUp() {
+        executeSql(String.format(
+                "CREATE ZONE %s WITH "
+                        + "REPLICAS=%d, "
+                        + "DATA_NODES_AUTO_ADJUST_SCALE_UP=%d, "
+                        + "DATA_NODES_AUTO_ADJUST_SCALE_DOWN=%d, "
+                        + "STORAGE_PROFILES='%s'",
+                TEST_ZONE_NAME,
+                initialNodes(),
+                IMMEDIATE_TIMER_VALUE,
+                IMMEDIATE_TIMER_VALUE,
+                String.join(", ", ALL_STORAGE_PROFILES)
+        ));
+    }
+
+    @Test
+    void testEstimatedSize() {
+        for (String profile : ALL_STORAGE_PROFILES) {
+            String tableName = createTableWithData(profile);
+
+            assertThat(tableSize(tableName), willBe(NUM_ROWS));
+
+            for (int i = 0; i < NUM_ROWS / 2; i++) {
+                executeSql(String.format("DELETE FROM %s WHERE key = %d", tableName, i));
+            }
+
+            assertThat(tableSize(tableName), willBe(NUM_ROWS / 2));
+
+            executeSql(String.format("DELETE FROM %s", tableName));
+
+            assertThat(tableSize(tableName), willBe(0L));
+        }
+    }
+
+    @Test
+    void testEstimatedSizeAfterScaleUp() throws InterruptedException {
+        for (String profile : ALL_STORAGE_PROFILES) {
+            String tableName = createTableWithData(profile);
+
+            assertThat(tableSize(tableName), willBe(NUM_ROWS));
+        }
+
+        cluster.startNode(initialNodes());

Review Comment:
   These are integration tests for the logic of applying snapshots to partition storages. So here I try to test a lower-level issue: that `MvPartitionStorage#size` returns a correct value after a partition was rebalanced.



-- 
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-22619 Add `InternalTable#estimatedSize` method [ignite-3]

Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #4065:
URL: https://github.com/apache/ignite-3/pull/4065#discussion_r1671000478


##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/network/replication/GetEstimatedSizeRequest.java:
##########
@@ -0,0 +1,29 @@
+/*
+ * 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.partition.replicator.network.replication;
+
+import org.apache.ignite.internal.network.annotations.Transferable;
+import org.apache.ignite.internal.partition.replicator.network.PartitionReplicationMessageGroup;
+import org.apache.ignite.internal.replicator.message.ReplicaRequest;
+
+/**
+ * Request for getting an estimated size of a partition.
+ */
+@Transferable(PartitionReplicationMessageGroup.GET_ESTIMATED_SIZE_MESSAGE)
+public interface GetEstimatedSizeRequest extends ReplicaRequest {

Review Comment:
   It might be useful in some cases: e.g. in order to gather statistics for sql and to ease failure analysis. However within given ticket I'd expect the request to be primary only and thus I'd rather add `extends PrimaryReplicaRequest`



-- 
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-22619 Add `InternalTable#estimatedSize` method [ignite-3]

Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #4065:
URL: https://github.com/apache/ignite-3/pull/4065#discussion_r1670995838


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/storage/InternalTableImpl.java:
##########
@@ -2231,6 +2232,27 @@ public ScheduledExecutorService streamerFlushExecutor() {
         return streamerFlushExecutor.get();
     }
 
+    @Override
+    public CompletableFuture<Long> estimatedSize() {
+        var invokeFutures = new CompletableFuture<?>[partitions];
+
+        for (int partId = 0; partId < partitions; partId++) {
+            var replicaGroupId = new TablePartitionId(tableId, partId);
+
+            invokeFutures[partId] = partitionLocation(replicaGroupId)

Review Comment:
   I'd rather implement it in a bit different manner. For each partition I'd call awaitPrimaryReplica() in order to define the location. Just like we do for any other 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-22619 Add `InternalTable#estimatedSize` method [ignite-3]

Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
sashapolo commented on code in PR #4065:
URL: https://github.com/apache/ignite-3/pull/4065#discussion_r1671793606


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/storage/InternalTableImpl.java:
##########
@@ -2231,6 +2232,27 @@ public ScheduledExecutorService streamerFlushExecutor() {
         return streamerFlushExecutor.get();
     }
 
+    @Override
+    public CompletableFuture<Long> estimatedSize() {
+        var invokeFutures = new CompletableFuture<?>[partitions];
+
+        for (int partId = 0; partId < partitions; partId++) {
+            var replicaGroupId = new TablePartitionId(tableId, partId);
+
+            invokeFutures[partId] = partitionLocation(replicaGroupId)

Review Comment:
   But `partitionLocation` already does call `awaitPrimaryReplica`



##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/storage/InternalTableImpl.java:
##########
@@ -2231,6 +2232,27 @@ public ScheduledExecutorService streamerFlushExecutor() {
         return streamerFlushExecutor.get();
     }
 
+    @Override
+    public CompletableFuture<Long> estimatedSize() {
+        var invokeFutures = new CompletableFuture<?>[partitions];
+
+        for (int partId = 0; partId < partitions; partId++) {
+            var replicaGroupId = new TablePartitionId(tableId, partId);
+
+            invokeFutures[partId] = partitionLocation(replicaGroupId)

Review Comment:
   But `partitionLocation` already calls `awaitPrimaryReplica`



-- 
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-22619 Add `InternalTable#estimatedSize` method [ignite-3]

Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #4065:
URL: https://github.com/apache/ignite-3/pull/4065#discussion_r1671007487


##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItEstimatedSizeTest.java:
##########
@@ -0,0 +1,182 @@
+/*
+ * 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 org.apache.ignite.internal.TestDefaultProfilesNames.DEFAULT_TEST_PROFILE_NAME;
+import static org.apache.ignite.internal.TestWrappers.unwrapTableViewInternal;
+import static org.apache.ignite.internal.catalog.commands.CatalogUtils.IMMEDIATE_TIMER_VALUE;
+import static org.apache.ignite.internal.distributionzones.rebalance.RebalanceUtil.STABLE_ASSIGNMENTS_PREFIX;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.flow.TestFlowUtils.subscribeToList;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willBe;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.affinity.Assignments;
+import org.apache.ignite.internal.lang.ByteArray;
+import org.apache.ignite.internal.metastorage.Entry;
+import org.apache.ignite.internal.metastorage.MetaStorageManager;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Integration tests for {@link InternalTable#estimatedSize()} method.
+ *
+ * <p>This class doesn't use the Parameterized Test approach in order to reduce the number of created clusters.
+ */
+public class ItEstimatedSizeTest extends ClusterPerTestIntegrationTest {
+    private static final String TEST_ZONE_NAME = "TestZone";
+
+    private static final String TEST_TABLE_NAME_PREFIX = "Test_";
+
+    private static final long NUM_ROWS = 100;
+
+    private static final String[] ALL_STORAGE_PROFILES = {
+            DEFAULT_TEST_PROFILE_NAME,
+            // TODO: https://issues.apache.org/jira/browse/IGNITE-22616
+            // DEFAULT_AIPERSIST_PROFILE_NAME,
+            // TODO: https://issues.apache.org/jira/browse/IGNITE-22616
+            // DEFAULT_AIMEM_PROFILE_NAME,
+            // TODO: https://issues.apache.org/jira/browse/IGNITE-22617
+            // DEFAULT_ROCKSDB_PROFILE_NAME
+    };
+
+    @BeforeEach
+    void setUp() {
+        executeSql(String.format(
+                "CREATE ZONE %s WITH "
+                        + "REPLICAS=%d, "
+                        + "DATA_NODES_AUTO_ADJUST_SCALE_UP=%d, "
+                        + "DATA_NODES_AUTO_ADJUST_SCALE_DOWN=%d, "
+                        + "STORAGE_PROFILES='%s'",
+                TEST_ZONE_NAME,
+                initialNodes(),
+                IMMEDIATE_TIMER_VALUE,
+                IMMEDIATE_TIMER_VALUE,
+                String.join(", ", ALL_STORAGE_PROFILES)
+        ));
+    }
+
+    @Test
+    void testEstimatedSize() {
+        for (String profile : ALL_STORAGE_PROFILES) {
+            String tableName = createTableWithData(profile);
+
+            assertThat(tableSize(tableName), willBe(NUM_ROWS));
+
+            for (int i = 0; i < NUM_ROWS / 2; i++) {
+                executeSql(String.format("DELETE FROM %s WHERE key = %d", tableName, i));
+            }
+
+            assertThat(tableSize(tableName), willBe(NUM_ROWS / 2));
+
+            executeSql(String.format("DELETE FROM %s", tableName));
+
+            assertThat(tableSize(tableName), willBe(0L));
+        }
+    }
+
+    @Test
+    void testEstimatedSizeAfterScaleUp() throws InterruptedException {
+        for (String profile : ALL_STORAGE_PROFILES) {
+            String tableName = createTableWithData(profile);
+
+            assertThat(tableSize(tableName), willBe(NUM_ROWS));
+        }
+
+        cluster.startNode(initialNodes());

Review Comment:
   In case of primary-only logic that test is almost meaningless.



##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItEstimatedSizeTest.java:
##########
@@ -0,0 +1,182 @@
+/*
+ * 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 org.apache.ignite.internal.TestDefaultProfilesNames.DEFAULT_TEST_PROFILE_NAME;
+import static org.apache.ignite.internal.TestWrappers.unwrapTableViewInternal;
+import static org.apache.ignite.internal.catalog.commands.CatalogUtils.IMMEDIATE_TIMER_VALUE;
+import static org.apache.ignite.internal.distributionzones.rebalance.RebalanceUtil.STABLE_ASSIGNMENTS_PREFIX;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.flow.TestFlowUtils.subscribeToList;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willBe;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.affinity.Assignments;
+import org.apache.ignite.internal.lang.ByteArray;
+import org.apache.ignite.internal.metastorage.Entry;
+import org.apache.ignite.internal.metastorage.MetaStorageManager;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Integration tests for {@link InternalTable#estimatedSize()} method.
+ *
+ * <p>This class doesn't use the Parameterized Test approach in order to reduce the number of created clusters.
+ */
+public class ItEstimatedSizeTest extends ClusterPerTestIntegrationTest {
+    private static final String TEST_ZONE_NAME = "TestZone";
+
+    private static final String TEST_TABLE_NAME_PREFIX = "Test_";
+
+    private static final long NUM_ROWS = 100;
+
+    private static final String[] ALL_STORAGE_PROFILES = {
+            DEFAULT_TEST_PROFILE_NAME,
+            // TODO: https://issues.apache.org/jira/browse/IGNITE-22616
+            // DEFAULT_AIPERSIST_PROFILE_NAME,
+            // TODO: https://issues.apache.org/jira/browse/IGNITE-22616
+            // DEFAULT_AIMEM_PROFILE_NAME,
+            // TODO: https://issues.apache.org/jira/browse/IGNITE-22617
+            // DEFAULT_ROCKSDB_PROFILE_NAME
+    };
+
+    @BeforeEach
+    void setUp() {
+        executeSql(String.format(
+                "CREATE ZONE %s WITH "
+                        + "REPLICAS=%d, "
+                        + "DATA_NODES_AUTO_ADJUST_SCALE_UP=%d, "
+                        + "DATA_NODES_AUTO_ADJUST_SCALE_DOWN=%d, "
+                        + "STORAGE_PROFILES='%s'",
+                TEST_ZONE_NAME,
+                initialNodes(),
+                IMMEDIATE_TIMER_VALUE,
+                IMMEDIATE_TIMER_VALUE,
+                String.join(", ", ALL_STORAGE_PROFILES)
+        ));
+    }
+
+    @Test
+    void testEstimatedSize() {
+        for (String profile : ALL_STORAGE_PROFILES) {
+            String tableName = createTableWithData(profile);
+
+            assertThat(tableSize(tableName), willBe(NUM_ROWS));
+
+            for (int i = 0; i < NUM_ROWS / 2; i++) {
+                executeSql(String.format("DELETE FROM %s WHERE key = %d", tableName, i));
+            }
+
+            assertThat(tableSize(tableName), willBe(NUM_ROWS / 2));
+
+            executeSql(String.format("DELETE FROM %s", tableName));
+
+            assertThat(tableSize(tableName), willBe(0L));
+        }
+    }
+
+    @Test
+    void testEstimatedSizeAfterScaleUp() throws InterruptedException {
+        for (String profile : ALL_STORAGE_PROFILES) {
+            String tableName = createTableWithData(profile);
+
+            assertThat(tableSize(tableName), willBe(NUM_ROWS));
+        }
+
+        cluster.startNode(initialNodes());
+
+        for (String profile : ALL_STORAGE_PROFILES) {
+            waitForRebalance(initialNodes() + 1);
+
+            assertThat(tableSize(tableName(profile)), willBe(NUM_ROWS));
+        }
+    }
+
+    @Test
+    void testEstimatedAfterScaleDown() throws InterruptedException {

Review Comment:
   Same as above.



-- 
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-22619 Add `InternalTable#estimatedSize` method [ignite-3]

Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
sashapolo merged PR #4065:
URL: https://github.com/apache/ignite-3/pull/4065


-- 
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-22619 Add `InternalTable#estimatedSize` method [ignite-3]

Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #4065:
URL: https://github.com/apache/ignite-3/pull/4065#discussion_r1671018873


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/storage/InternalTableImpl.java:
##########
@@ -2231,6 +2232,27 @@ public ScheduledExecutorService streamerFlushExecutor() {
         return streamerFlushExecutor.get();
     }
 
+    @Override
+    public CompletableFuture<Long> estimatedSize() {
+        var invokeFutures = new CompletableFuture<?>[partitions];
+
+        for (int partId = 0; partId < partitions; partId++) {

Review Comment:
   What if some partitions are unavailable? Is it intended to await all of them or we should also have best effort solution?



-- 
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-22619 Add `InternalTable#estimatedSize` method [ignite-3]

Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #4065:
URL: https://github.com/apache/ignite-3/pull/4065#discussion_r1678271523


##########
modules/table/build.gradle:
##########
@@ -64,6 +64,7 @@ dependencies {
     testImplementation project(':ignite-page-memory')
     testImplementation project(':ignite-storage-rocksdb')
     testImplementation project(':ignite-placement-driver-api')
+    testImplementation project(':ignite-placement-driver')

Review Comment:
   Curious why placement-driver-api is not enough? 



##########
modules/table/src/test/java/org/apache/ignite/internal/table/distributed/storage/InternalTableEstimatedSizeTest.java:
##########
@@ -0,0 +1,471 @@
+/*
+ * 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.distributed.storage;
+
+import static java.util.concurrent.CompletableFuture.completedFuture;
+import static java.util.concurrent.CompletableFuture.failedFuture;
+import static java.util.stream.Collectors.toList;
+import static org.apache.ignite.internal.network.utils.ClusterServiceTestUtils.clusterService;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willBe;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture;
+import static org.apache.ignite.internal.util.IgniteUtils.startAsync;
+import static org.apache.ignite.internal.util.IgniteUtils.stopAsync;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.lenient;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ForkJoinPool;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.TimeoutException;
+import java.util.stream.IntStream;
+import org.apache.ignite.internal.catalog.CatalogService;
+import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension;
+import org.apache.ignite.internal.configuration.testframework.InjectConfiguration;
+import org.apache.ignite.internal.hlc.ClockService;
+import org.apache.ignite.internal.hlc.ClockServiceImpl;
+import org.apache.ignite.internal.hlc.ClockWaiter;
+import org.apache.ignite.internal.hlc.HybridClockImpl;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.manager.ComponentContext;
+import org.apache.ignite.internal.manager.IgniteComponent;
+import org.apache.ignite.internal.metastorage.MetaStorageManager;
+import org.apache.ignite.internal.metastorage.impl.StandaloneMetaStorageManager;
+import org.apache.ignite.internal.metastorage.server.SimpleInMemoryKeyValueStorage;
+import org.apache.ignite.internal.network.ClusterNodeResolver;
+import org.apache.ignite.internal.network.ClusterService;
+import org.apache.ignite.internal.network.MessagingService;
+import org.apache.ignite.internal.network.StaticNodeFinder;
+import org.apache.ignite.internal.placementdriver.PlacementDriver;
+import org.apache.ignite.internal.placementdriver.leases.Lease;
+import org.apache.ignite.internal.raft.Command;
+import org.apache.ignite.internal.raft.service.RaftCommandRunner;
+import org.apache.ignite.internal.replicator.ReplicaService;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.replicator.configuration.ReplicationConfiguration;
+import org.apache.ignite.internal.replicator.message.ReplicaMessagesFactory;
+import org.apache.ignite.internal.replicator.message.ReplicaRequest;
+import org.apache.ignite.internal.schema.SchemaRegistry;
+import org.apache.ignite.internal.storage.MvPartitionStorage;
+import org.apache.ignite.internal.storage.engine.MvTableStorage;
+import org.apache.ignite.internal.table.InternalTable;
+import org.apache.ignite.internal.table.distributed.StorageUpdateHandler;
+import org.apache.ignite.internal.table.distributed.index.IndexMetaStorage;
+import org.apache.ignite.internal.table.distributed.replicator.PartitionReplicaListener;
+import org.apache.ignite.internal.table.distributed.replicator.TransactionStateResolver;
+import org.apache.ignite.internal.table.distributed.schema.SchemaSyncService;
+import org.apache.ignite.internal.table.distributed.schema.ValidationSchemasSource;
+import org.apache.ignite.internal.testframework.BaseIgniteAbstractTest;
+import org.apache.ignite.internal.tx.HybridTimestampTracker;
+import org.apache.ignite.internal.tx.LockManager;
+import org.apache.ignite.internal.tx.TxManager;
+import org.apache.ignite.internal.tx.impl.RemotelyTriggeredResourceRegistry;
+import org.apache.ignite.internal.tx.impl.TransactionInflights;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.internal.tx.storage.state.TxStateTableStorage;
+import org.apache.ignite.internal.util.Lazy;
+import org.apache.ignite.internal.util.PendingComparableValuesTracker;
+import org.apache.ignite.network.ClusterNode;
+import org.apache.ignite.network.NetworkAddress;
+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;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+/**
+ * Tests for distributed aspects of the {@link InternalTable#estimatedSize} method.
+ */
+@ExtendWith(MockitoExtension.class)
+@ExtendWith(ConfigurationExtension.class)
+public class InternalTableEstimatedSizeTest extends BaseIgniteAbstractTest {
+    private static final String TABLE_NAME = "TEST";
+
+    private static final int TABLE_ID = 1;
+
+    private static final int PARTITIONS_NUM = 3;
+
+    private static final List<TablePartitionId> TABLE_PARTITION_IDS = IntStream.range(0, PARTITIONS_NUM)
+            .mapToObj(i -> new TablePartitionId(TABLE_ID, i))
+            .collect(toList());
+
+    private ClusterNode node;
+
+    private InternalTableImpl table;
+
+    private MessagingService messagingService;
+
+    @Mock
+    private PlacementDriver placementDriver;
+
+    private final HybridClockImpl clock = new HybridClockImpl();
+
+    private final ComponentContext componentContext = new ComponentContext();
+
+    private final List<MvPartitionStorage> partitionStorages = new ArrayList<>(PARTITIONS_NUM);
+
+    private final List<IgniteComponent> components = new ArrayList<>();
+
+    @BeforeEach
+    void setUp(

Review Comment:
   Great work first of all. However given test seems to be very fragile because it mainly tests mocks. Did you consider using real ignite nodes with some message blocking and transferPrimary/killing nodes? Such tests will be longer but more robust, WDYT?



##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/storage/InternalTableImpl.java:
##########
@@ -1918,43 +1913,39 @@ protected CompletableFuture<IgniteBiTuple<ClusterNode, Long>> enlist(int partId,
             TablePartitionId partGroupId = new TablePartitionId(tableId, partId);
 
             return tx.enlist(partGroupId, new IgniteBiTuple<>(
-                    getClusterNode(meta.getLeaseholder()),
-                    meta.getStartTime().longValue())
+                    getClusterNode(meta),
+                    enlistmentConsistencyToken(meta))
             );
         });
     }
 
     @Override
     public CompletableFuture<ClusterNode> partitionLocation(TablePartitionId tablePartitionId) {
-        return partitionMeta(tablePartitionId).thenApply(meta -> getClusterNode(meta.getLeaseholder()));
+        return partitionMeta(tablePartitionId).thenApply(this::getClusterNode);
     }
 
     private CompletableFuture<ReplicaMeta> partitionMeta(TablePartitionId tablePartitionId) {
         HybridTimestamp now = clock.now();
 
-        CompletableFuture<ReplicaMeta> primaryReplicaFuture = placementDriver.awaitPrimaryReplica(
-                tablePartitionId,
-                now,
-                AWAIT_PRIMARY_REPLICA_TIMEOUT,
-                SECONDS
-        );
-
-        return primaryReplicaFuture.handle((primaryReplica, e) -> {
-            if (e != null) {
-                throw withCause(TransactionException::new, REPLICA_UNAVAILABLE_ERR, "Failed to get the primary replica"
-                        + " [tablePartitionId=" + tablePartitionId + ", awaitTimestamp=" + now + ']', e);
-            }
-
-            return primaryReplica;
-        });
+        return awaitPrimaryReplica(tablePartitionId, now)
+                .exceptionally(e -> {
+                    throw withCause(
+                            TransactionException::new,
+                            REPLICA_UNAVAILABLE_ERR,
+                            "Failed to get the primary replica [tablePartitionId=" + tablePartitionId + ", awaitTimestamp=" + now + ']',
+                            e
+                    );
+                });
     }
 
-    private ClusterNode getClusterNode(@Nullable String leaserHolder) {
-        ClusterNode node = clusterNodeResolver.getByConsistentId(leaserHolder);
+    private ClusterNode getClusterNode(ReplicaMeta replicaMeta) {
+        String leaseHolder = replicaMeta.getLeaseholder();

Review Comment:
   Seems that using getLeaseholderId will be more robust.



##########
modules/table/src/test/java/org/apache/ignite/internal/table/distributed/storage/InternalTableEstimatedSizeTest.java:
##########
@@ -0,0 +1,471 @@
+/*
+ * 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.distributed.storage;
+
+import static java.util.concurrent.CompletableFuture.completedFuture;
+import static java.util.concurrent.CompletableFuture.failedFuture;
+import static java.util.stream.Collectors.toList;
+import static org.apache.ignite.internal.network.utils.ClusterServiceTestUtils.clusterService;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willBe;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture;
+import static org.apache.ignite.internal.util.IgniteUtils.startAsync;
+import static org.apache.ignite.internal.util.IgniteUtils.stopAsync;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.lenient;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ForkJoinPool;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.TimeoutException;
+import java.util.stream.IntStream;
+import org.apache.ignite.internal.catalog.CatalogService;
+import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension;
+import org.apache.ignite.internal.configuration.testframework.InjectConfiguration;
+import org.apache.ignite.internal.hlc.ClockService;
+import org.apache.ignite.internal.hlc.ClockServiceImpl;
+import org.apache.ignite.internal.hlc.ClockWaiter;
+import org.apache.ignite.internal.hlc.HybridClockImpl;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.manager.ComponentContext;
+import org.apache.ignite.internal.manager.IgniteComponent;
+import org.apache.ignite.internal.metastorage.MetaStorageManager;
+import org.apache.ignite.internal.metastorage.impl.StandaloneMetaStorageManager;
+import org.apache.ignite.internal.metastorage.server.SimpleInMemoryKeyValueStorage;
+import org.apache.ignite.internal.network.ClusterNodeResolver;
+import org.apache.ignite.internal.network.ClusterService;
+import org.apache.ignite.internal.network.MessagingService;
+import org.apache.ignite.internal.network.StaticNodeFinder;
+import org.apache.ignite.internal.placementdriver.PlacementDriver;
+import org.apache.ignite.internal.placementdriver.leases.Lease;
+import org.apache.ignite.internal.raft.Command;
+import org.apache.ignite.internal.raft.service.RaftCommandRunner;
+import org.apache.ignite.internal.replicator.ReplicaService;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.replicator.configuration.ReplicationConfiguration;
+import org.apache.ignite.internal.replicator.message.ReplicaMessagesFactory;
+import org.apache.ignite.internal.replicator.message.ReplicaRequest;
+import org.apache.ignite.internal.schema.SchemaRegistry;
+import org.apache.ignite.internal.storage.MvPartitionStorage;
+import org.apache.ignite.internal.storage.engine.MvTableStorage;
+import org.apache.ignite.internal.table.InternalTable;
+import org.apache.ignite.internal.table.distributed.StorageUpdateHandler;
+import org.apache.ignite.internal.table.distributed.index.IndexMetaStorage;
+import org.apache.ignite.internal.table.distributed.replicator.PartitionReplicaListener;
+import org.apache.ignite.internal.table.distributed.replicator.TransactionStateResolver;
+import org.apache.ignite.internal.table.distributed.schema.SchemaSyncService;
+import org.apache.ignite.internal.table.distributed.schema.ValidationSchemasSource;
+import org.apache.ignite.internal.testframework.BaseIgniteAbstractTest;
+import org.apache.ignite.internal.tx.HybridTimestampTracker;
+import org.apache.ignite.internal.tx.LockManager;
+import org.apache.ignite.internal.tx.TxManager;
+import org.apache.ignite.internal.tx.impl.RemotelyTriggeredResourceRegistry;
+import org.apache.ignite.internal.tx.impl.TransactionInflights;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.internal.tx.storage.state.TxStateTableStorage;
+import org.apache.ignite.internal.util.Lazy;
+import org.apache.ignite.internal.util.PendingComparableValuesTracker;
+import org.apache.ignite.network.ClusterNode;
+import org.apache.ignite.network.NetworkAddress;
+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;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+/**
+ * Tests for distributed aspects of the {@link InternalTable#estimatedSize} method.
+ */
+@ExtendWith(MockitoExtension.class)
+@ExtendWith(ConfigurationExtension.class)
+public class InternalTableEstimatedSizeTest extends BaseIgniteAbstractTest {
+    private static final String TABLE_NAME = "TEST";
+
+    private static final int TABLE_ID = 1;
+
+    private static final int PARTITIONS_NUM = 3;
+
+    private static final List<TablePartitionId> TABLE_PARTITION_IDS = IntStream.range(0, PARTITIONS_NUM)
+            .mapToObj(i -> new TablePartitionId(TABLE_ID, i))
+            .collect(toList());
+
+    private ClusterNode node;
+
+    private InternalTableImpl table;
+
+    private MessagingService messagingService;
+
+    @Mock
+    private PlacementDriver placementDriver;
+
+    private final HybridClockImpl clock = new HybridClockImpl();
+
+    private final ComponentContext componentContext = new ComponentContext();
+
+    private final List<MvPartitionStorage> partitionStorages = new ArrayList<>(PARTITIONS_NUM);
+
+    private final List<IgniteComponent> components = new ArrayList<>();
+
+    @BeforeEach
+    void setUp(
+            TestInfo testInfo,
+            @Mock TxManager txManager,
+            @Mock LockManager lockManager,
+            @Mock MvTableStorage tableStorage,
+            @Mock TxStateTableStorage txStateTableStorage,
+            @Mock TxStateStorage txStateStorage,
+            @Mock TableRaftServiceImpl tableRaftService,
+            @Mock TransactionStateResolver transactionStateResolver,
+            @Mock StorageUpdateHandler storageUpdateHandler,
+            @Mock ValidationSchemasSource validationSchemasSource,
+            @Mock SchemaSyncService schemaSyncService,
+            @Mock CatalogService catalogService,
+            @Mock RemotelyTriggeredResourceRegistry remotelyTriggeredResourceRegistry,
+            @Mock SchemaRegistry schemaRegistry,
+            @Mock IndexMetaStorage indexMetaStorage,
+            @InjectConfiguration ReplicationConfiguration replicationConfiguration
+    ) {
+        String nodeName = testNodeName(testInfo, 0);
+
+        var addr = new NetworkAddress("localhost", 10_000);
+
+        ClusterService clusterService = spy(clusterService(nodeName, addr.port(), new StaticNodeFinder(List.of(addr))));
+
+        messagingService = spy(clusterService.messagingService());
+
+        when(clusterService.messagingService()).thenReturn(messagingService);
+
+        components.add(clusterService);
+
+        var clockWaiter = new ClockWaiter(nodeName, clock);
+
+        components.add(clockWaiter);
+
+        MetaStorageManager metaStorageManager = StandaloneMetaStorageManager.create(
+                new SimpleInMemoryKeyValueStorage(nodeName),
+                clock
+        );
+
+        components.add(metaStorageManager);
+
+        assertThat(startAsync(componentContext, components), willCompleteSuccessfully());
+
+        assertThat(metaStorageManager.deployWatches(), willCompleteSuccessfully());
+
+        node = clusterService.topologyService().localMember();
+
+        var clockService = new ClockServiceImpl(clock, clockWaiter, () -> 0);
+
+        table = new InternalTableImpl(
+                TABLE_NAME,
+                TABLE_ID,
+                PARTITIONS_NUM,
+                clusterService.topologyService(),
+                txManager,
+                tableStorage,
+                txStateTableStorage,
+                new ReplicaService(clusterService.messagingService(), clock, replicationConfiguration),
+                clock,
+                new HybridTimestampTracker(),
+                placementDriver,
+                tableRaftService,
+                new TransactionInflights(placementDriver, clockService),
+                0,
+                0,
+                () -> null
+        );
+
+        List<PartitionReplicaListener> partitionReplicaListeners = IntStream.range(0, PARTITIONS_NUM)
+                .mapToObj(partId -> createPartitionReplicaListener(
+                        partId,
+                        txManager,
+                        lockManager,
+                        clockService,
+                        txStateStorage,
+                        transactionStateResolver,
+                        storageUpdateHandler,
+                        validationSchemasSource,
+                        node,
+                        schemaSyncService,
+                        catalogService,
+                        placementDriver,
+                        clusterService.topologyService(),
+                        remotelyTriggeredResourceRegistry,
+                        schemaRegistry,
+                        indexMetaStorage
+                ))
+                .collect(toList());
+
+        lenient().doAnswer(invocation -> {
+            ReplicaRequest request = invocation.getArgument(1);
+
+            var tablePartitionId = (TablePartitionId) request.groupId().asReplicationGroupId();
+
+            return partitionReplicaListeners.get(tablePartitionId.partitionId())
+                    .invoke(request, node.id())
+                    .thenApply(replicaResult -> new ReplicaMessagesFactory()
+                            .replicaResponse()
+                            .result(replicaResult.result())
+                            .build()
+                    );
+        }).when(messagingService).invoke(eq(nodeName), any(ReplicaRequest.class), anyLong());
+    }
+
+    @AfterEach
+    void tearDown() {
+        Collections.reverse(components);
+
+        assertThat(stopAsync(componentContext, components), willCompleteSuccessfully());

Review Comment:
   beforeNodeStop is missing.



-- 
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-22619 Add `InternalTable#estimatedSize` method [ignite-3]

Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
sashapolo commented on code in PR #4065:
URL: https://github.com/apache/ignite-3/pull/4065#discussion_r1671793606


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/storage/InternalTableImpl.java:
##########
@@ -2231,6 +2232,27 @@ public ScheduledExecutorService streamerFlushExecutor() {
         return streamerFlushExecutor.get();
     }
 
+    @Override
+    public CompletableFuture<Long> estimatedSize() {
+        var invokeFutures = new CompletableFuture<?>[partitions];
+
+        for (int partId = 0; partId < partitions; partId++) {
+            var replicaGroupId = new TablePartitionId(tableId, partId);
+
+            invokeFutures[partId] = partitionLocation(replicaGroupId)

Review Comment:
   But `partitionLocation` already calls `awaitPrimaryReplica`



-- 
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-22619 Add `InternalTable#estimatedSize` method [ignite-3]

Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #4065:
URL: https://github.com/apache/ignite-3/pull/4065#discussion_r1671793242


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/PartitionReplicaListener.java:
##########
@@ -517,6 +522,10 @@ private CompletableFuture<?> processRequest(ReplicaRequest request, @Nullable Bo
                         processOperationRequestWithTxRwCounter(senderId, request, isPrimary, opTsIfDirectRo, leaseStartTime));
     }
 
+    private CompletableFuture<Long> processGetEstimatedSizeRequest() {
+        return completedFuture(mvDataStorage.estimatedSize());

Review Comment:
   Sounds reasonable while we retrieving data from primary.



-- 
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-22619 Add `InternalTable#estimatedSize` method [ignite-3]

Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #4065:
URL: https://github.com/apache/ignite-3/pull/4065#discussion_r1671794538


##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItEstimatedSizeTest.java:
##########
@@ -0,0 +1,182 @@
+/*
+ * 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 org.apache.ignite.internal.TestDefaultProfilesNames.DEFAULT_TEST_PROFILE_NAME;
+import static org.apache.ignite.internal.TestWrappers.unwrapTableViewInternal;
+import static org.apache.ignite.internal.catalog.commands.CatalogUtils.IMMEDIATE_TIMER_VALUE;
+import static org.apache.ignite.internal.distributionzones.rebalance.RebalanceUtil.STABLE_ASSIGNMENTS_PREFIX;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.flow.TestFlowUtils.subscribeToList;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willBe;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.affinity.Assignments;
+import org.apache.ignite.internal.lang.ByteArray;
+import org.apache.ignite.internal.metastorage.Entry;
+import org.apache.ignite.internal.metastorage.MetaStorageManager;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Integration tests for {@link InternalTable#estimatedSize()} method.
+ *
+ * <p>This class doesn't use the Parameterized Test approach in order to reduce the number of created clusters.
+ */
+public class ItEstimatedSizeTest extends ClusterPerTestIntegrationTest {
+    private static final String TEST_ZONE_NAME = "TestZone";
+
+    private static final String TEST_TABLE_NAME_PREFIX = "Test_";
+
+    private static final long NUM_ROWS = 100;
+
+    private static final String[] ALL_STORAGE_PROFILES = {
+            DEFAULT_TEST_PROFILE_NAME,
+            // TODO: https://issues.apache.org/jira/browse/IGNITE-22616
+            // DEFAULT_AIPERSIST_PROFILE_NAME,
+            // TODO: https://issues.apache.org/jira/browse/IGNITE-22616
+            // DEFAULT_AIMEM_PROFILE_NAME,
+            // TODO: https://issues.apache.org/jira/browse/IGNITE-22617
+            // DEFAULT_ROCKSDB_PROFILE_NAME
+    };
+
+    @BeforeEach
+    void setUp() {
+        executeSql(String.format(
+                "CREATE ZONE %s WITH "
+                        + "REPLICAS=%d, "
+                        + "DATA_NODES_AUTO_ADJUST_SCALE_UP=%d, "
+                        + "DATA_NODES_AUTO_ADJUST_SCALE_DOWN=%d, "
+                        + "STORAGE_PROFILES='%s'",
+                TEST_ZONE_NAME,
+                initialNodes(),
+                IMMEDIATE_TIMER_VALUE,
+                IMMEDIATE_TIMER_VALUE,
+                String.join(", ", ALL_STORAGE_PROFILES)
+        ));
+    }
+
+    @Test
+    void testEstimatedSize() {
+        for (String profile : ALL_STORAGE_PROFILES) {
+            String tableName = createTableWithData(profile);
+
+            assertThat(tableSize(tableName), willBe(NUM_ROWS));
+
+            for (int i = 0; i < NUM_ROWS / 2; i++) {
+                executeSql(String.format("DELETE FROM %s WHERE key = %d", tableName, i));
+            }
+
+            assertThat(tableSize(tableName), willBe(NUM_ROWS / 2));
+
+            executeSql(String.format("DELETE FROM %s", tableName));
+
+            assertThat(tableSize(tableName), willBe(0L));
+        }
+    }
+
+    @Test
+    void testEstimatedSizeAfterScaleUp() throws InterruptedException {
+        for (String profile : ALL_STORAGE_PROFILES) {
+            String tableName = createTableWithData(profile);
+
+            assertThat(tableSize(tableName), willBe(NUM_ROWS));
+        }
+
+        cluster.startNode(initialNodes());
+
+        for (String profile : ALL_STORAGE_PROFILES) {
+            waitForRebalance(initialNodes() + 1);
+
+            assertThat(tableSize(tableName(profile)), willBe(NUM_ROWS));
+        }
+    }
+
+    @Test
+    void testEstimatedAfterScaleDown() throws InterruptedException {
+        for (String profile : ALL_STORAGE_PROFILES) {
+            String tableName = createTableWithData(profile);
+
+            assertThat(tableSize(tableName), willBe(NUM_ROWS));
+        }
+
+        cluster.stopNode(initialNodes() - 1);
+
+        for (String profile : ALL_STORAGE_PROFILES) {
+            waitForRebalance(initialNodes() - 1);
+
+            assertThat(tableSize(tableName(profile)), willBe(NUM_ROWS));
+        }
+    }
+

Review Comment:
   Yep, makes sense.



-- 
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-22619 Add `InternalTable#estimatedSize` method [ignite-3]

Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #4065:
URL: https://github.com/apache/ignite-3/pull/4065#discussion_r1671859951


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/storage/InternalTableImpl.java:
##########
@@ -2231,6 +2232,27 @@ public ScheduledExecutorService streamerFlushExecutor() {
         return streamerFlushExecutor.get();
     }
 
+    @Override
+    public CompletableFuture<Long> estimatedSize() {
+        var invokeFutures = new CompletableFuture<?>[partitions];
+
+        for (int partId = 0; partId < partitions; partId++) {

Review Comment:
   Implicit `Select *` is an RO wrapped operation, thus it might be executed on backup even without majority - in that case, behavior will differ. All in all that sounds like a follow up ticket that will add an ability to retrieve size from backups.



-- 
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-22619 Add `InternalTable#estimatedSize` method [ignite-3]

Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #4065:
URL: https://github.com/apache/ignite-3/pull/4065#discussion_r1671000478


##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/network/replication/GetEstimatedSizeRequest.java:
##########
@@ -0,0 +1,29 @@
+/*
+ * 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.partition.replicator.network.replication;
+
+import org.apache.ignite.internal.network.annotations.Transferable;
+import org.apache.ignite.internal.partition.replicator.network.PartitionReplicationMessageGroup;
+import org.apache.ignite.internal.replicator.message.ReplicaRequest;
+
+/**
+ * Request for getting an estimated size of a partition.
+ */
+@Transferable(PartitionReplicationMessageGroup.GET_ESTIMATED_SIZE_MESSAGE)
+public interface GetEstimatedSizeRequest extends ReplicaRequest {

Review Comment:
   It might be useful in some cases: e.g. in order to gather statistics for sql and to ease failure analysis. However within given ticket I'd expect give request to be primary only and thus I'd rather add `extends PrimaryReplicaRequest`



-- 
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-22619 Add `InternalTable#estimatedSize` method [ignite-3]

Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #4065:
URL: https://github.com/apache/ignite-3/pull/4065#discussion_r1671004848


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/PartitionReplicaListener.java:
##########
@@ -517,6 +522,10 @@ private CompletableFuture<?> processRequest(ReplicaRequest request, @Nullable Bo
                         processOperationRequestWithTxRwCounter(senderId, request, isPrimary, opTsIfDirectRo, leaseStartTime));
     }
 
+    private CompletableFuture<Long> processGetEstimatedSizeRequest() {
+        return completedFuture(mvDataStorage.estimatedSize());

Review Comment:
   Curious whether estimatedSize evaluates writeIntent as +1? 



-- 
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-22619 Add `InternalTable#estimatedSize` method [ignite-3]

Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
sashapolo commented on code in PR #4065:
URL: https://github.com/apache/ignite-3/pull/4065#discussion_r1678933616


##########
modules/table/build.gradle:
##########
@@ -64,6 +64,7 @@ dependencies {
     testImplementation project(':ignite-page-memory')
     testImplementation project(':ignite-storage-rocksdb')
     testImplementation project(':ignite-placement-driver-api')
+    testImplementation project(':ignite-placement-driver')

Review Comment:
   Because I need the `Lease` class



-- 
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-22619 Add `InternalTable#estimatedSize` method [ignite-3]

Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
sashapolo commented on code in PR #4065:
URL: https://github.com/apache/ignite-3/pull/4065#discussion_r1672695105


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/storage/InternalTableImpl.java:
##########
@@ -2231,6 +2232,27 @@ public ScheduledExecutorService streamerFlushExecutor() {
         return streamerFlushExecutor.get();
     }
 
+    @Override
+    public CompletableFuture<Long> estimatedSize() {
+        var invokeFutures = new CompletableFuture<?>[partitions];
+
+        for (int partId = 0; partId < partitions; partId++) {

Review Comment:
   Discussed this in person: there's no need for a best-effort approach, we will wait for the partition to appear



-- 
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-22619 Add `InternalTable#estimatedSize` method [ignite-3]

Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
sashapolo commented on code in PR #4065:
URL: https://github.com/apache/ignite-3/pull/4065#discussion_r1671032467


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/PartitionReplicaListener.java:
##########
@@ -517,6 +522,10 @@ private CompletableFuture<?> processRequest(ReplicaRequest request, @Nullable Bo
                         processOperationRequestWithTxRwCounter(senderId, request, isPrimary, opTsIfDirectRo, leaseStartTime));
     }
 
+    private CompletableFuture<Long> processGetEstimatedSizeRequest() {
+        return completedFuture(mvDataStorage.estimatedSize());

Review Comment:
   No, Write Intents are going to be omitted, only committed entries change the size



-- 
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-22619 Add `InternalTable#estimatedSize` method [ignite-3]

Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
sashapolo commented on code in PR #4065:
URL: https://github.com/apache/ignite-3/pull/4065#discussion_r1671034172


##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/storage/InternalTableImpl.java:
##########
@@ -2231,6 +2232,27 @@ public ScheduledExecutorService streamerFlushExecutor() {
         return streamerFlushExecutor.get();
     }
 
+    @Override
+    public CompletableFuture<Long> estimatedSize() {
+        var invokeFutures = new CompletableFuture<?>[partitions];
+
+        for (int partId = 0; partId < partitions; partId++) {

Review Comment:
   How do we usually handle this? What will happen to the `SELECT *` query in this case? I think we should mimic the full scan behaviour 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-22619 Add `InternalTable#estimatedSize` method [ignite-3]

Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #4065:
URL: https://github.com/apache/ignite-3/pull/4065#discussion_r1671009329


##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItEstimatedSizeTest.java:
##########
@@ -0,0 +1,182 @@
+/*
+ * 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 org.apache.ignite.internal.TestDefaultProfilesNames.DEFAULT_TEST_PROFILE_NAME;
+import static org.apache.ignite.internal.TestWrappers.unwrapTableViewInternal;
+import static org.apache.ignite.internal.catalog.commands.CatalogUtils.IMMEDIATE_TIMER_VALUE;
+import static org.apache.ignite.internal.distributionzones.rebalance.RebalanceUtil.STABLE_ASSIGNMENTS_PREFIX;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.flow.TestFlowUtils.subscribeToList;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willBe;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.affinity.Assignments;
+import org.apache.ignite.internal.lang.ByteArray;
+import org.apache.ignite.internal.metastorage.Entry;
+import org.apache.ignite.internal.metastorage.MetaStorageManager;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Integration tests for {@link InternalTable#estimatedSize()} method.
+ *
+ * <p>This class doesn't use the Parameterized Test approach in order to reduce the number of created clusters.
+ */
+public class ItEstimatedSizeTest extends ClusterPerTestIntegrationTest {
+    private static final String TEST_ZONE_NAME = "TestZone";
+
+    private static final String TEST_TABLE_NAME_PREFIX = "Test_";
+
+    private static final long NUM_ROWS = 100;
+
+    private static final String[] ALL_STORAGE_PROFILES = {
+            DEFAULT_TEST_PROFILE_NAME,
+            // TODO: https://issues.apache.org/jira/browse/IGNITE-22616
+            // DEFAULT_AIPERSIST_PROFILE_NAME,
+            // TODO: https://issues.apache.org/jira/browse/IGNITE-22616
+            // DEFAULT_AIMEM_PROFILE_NAME,
+            // TODO: https://issues.apache.org/jira/browse/IGNITE-22617
+            // DEFAULT_ROCKSDB_PROFILE_NAME
+    };
+
+    @BeforeEach
+    void setUp() {
+        executeSql(String.format(
+                "CREATE ZONE %s WITH "
+                        + "REPLICAS=%d, "
+                        + "DATA_NODES_AUTO_ADJUST_SCALE_UP=%d, "
+                        + "DATA_NODES_AUTO_ADJUST_SCALE_DOWN=%d, "
+                        + "STORAGE_PROFILES='%s'",
+                TEST_ZONE_NAME,
+                initialNodes(),
+                IMMEDIATE_TIMER_VALUE,
+                IMMEDIATE_TIMER_VALUE,
+                String.join(", ", ALL_STORAGE_PROFILES)
+        ));
+    }
+
+    @Test
+    void testEstimatedSize() {
+        for (String profile : ALL_STORAGE_PROFILES) {
+            String tableName = createTableWithData(profile);
+
+            assertThat(tableSize(tableName), willBe(NUM_ROWS));
+
+            for (int i = 0; i < NUM_ROWS / 2; i++) {
+                executeSql(String.format("DELETE FROM %s WHERE key = %d", tableName, i));
+            }
+
+            assertThat(tableSize(tableName), willBe(NUM_ROWS / 2));
+
+            executeSql(String.format("DELETE FROM %s", tableName));
+
+            assertThat(tableSize(tableName), willBe(0L));
+        }
+    }
+
+    @Test
+    void testEstimatedSizeAfterScaleUp() throws InterruptedException {
+        for (String profile : ALL_STORAGE_PROFILES) {
+            String tableName = createTableWithData(profile);
+
+            assertThat(tableSize(tableName), willBe(NUM_ROWS));
+        }
+
+        cluster.startNode(initialNodes());
+
+        for (String profile : ALL_STORAGE_PROFILES) {
+            waitForRebalance(initialNodes() + 1);
+
+            assertThat(tableSize(tableName(profile)), willBe(NUM_ROWS));
+        }
+    }
+
+    @Test
+    void testEstimatedAfterScaleDown() throws InterruptedException {
+        for (String profile : ALL_STORAGE_PROFILES) {
+            String tableName = createTableWithData(profile);
+
+            assertThat(tableSize(tableName), willBe(NUM_ROWS));
+        }
+
+        cluster.stopNode(initialNodes() - 1);
+
+        for (String profile : ALL_STORAGE_PROFILES) {
+            waitForRebalance(initialNodes() - 1);
+
+            assertThat(tableSize(tableName(profile)), willBe(NUM_ROWS));
+        }
+    }
+

Review Comment:
   - I'd rather add test that will check whether pending transactions (that not yet committed) effect the size.



##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItEstimatedSizeTest.java:
##########
@@ -0,0 +1,182 @@
+/*
+ * 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 org.apache.ignite.internal.TestDefaultProfilesNames.DEFAULT_TEST_PROFILE_NAME;
+import static org.apache.ignite.internal.TestWrappers.unwrapTableViewInternal;
+import static org.apache.ignite.internal.catalog.commands.CatalogUtils.IMMEDIATE_TIMER_VALUE;
+import static org.apache.ignite.internal.distributionzones.rebalance.RebalanceUtil.STABLE_ASSIGNMENTS_PREFIX;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.flow.TestFlowUtils.subscribeToList;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willBe;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.affinity.Assignments;
+import org.apache.ignite.internal.lang.ByteArray;
+import org.apache.ignite.internal.metastorage.Entry;
+import org.apache.ignite.internal.metastorage.MetaStorageManager;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Integration tests for {@link InternalTable#estimatedSize()} method.
+ *
+ * <p>This class doesn't use the Parameterized Test approach in order to reduce the number of created clusters.
+ */
+public class ItEstimatedSizeTest extends ClusterPerTestIntegrationTest {
+    private static final String TEST_ZONE_NAME = "TestZone";
+
+    private static final String TEST_TABLE_NAME_PREFIX = "Test_";
+
+    private static final long NUM_ROWS = 100;
+
+    private static final String[] ALL_STORAGE_PROFILES = {
+            DEFAULT_TEST_PROFILE_NAME,
+            // TODO: https://issues.apache.org/jira/browse/IGNITE-22616
+            // DEFAULT_AIPERSIST_PROFILE_NAME,
+            // TODO: https://issues.apache.org/jira/browse/IGNITE-22616
+            // DEFAULT_AIMEM_PROFILE_NAME,
+            // TODO: https://issues.apache.org/jira/browse/IGNITE-22617
+            // DEFAULT_ROCKSDB_PROFILE_NAME
+    };
+
+    @BeforeEach
+    void setUp() {
+        executeSql(String.format(
+                "CREATE ZONE %s WITH "
+                        + "REPLICAS=%d, "
+                        + "DATA_NODES_AUTO_ADJUST_SCALE_UP=%d, "
+                        + "DATA_NODES_AUTO_ADJUST_SCALE_DOWN=%d, "
+                        + "STORAGE_PROFILES='%s'",
+                TEST_ZONE_NAME,
+                initialNodes(),
+                IMMEDIATE_TIMER_VALUE,
+                IMMEDIATE_TIMER_VALUE,
+                String.join(", ", ALL_STORAGE_PROFILES)
+        ));
+    }
+
+    @Test
+    void testEstimatedSize() {
+        for (String profile : ALL_STORAGE_PROFILES) {
+            String tableName = createTableWithData(profile);
+
+            assertThat(tableSize(tableName), willBe(NUM_ROWS));
+
+            for (int i = 0; i < NUM_ROWS / 2; i++) {
+                executeSql(String.format("DELETE FROM %s WHERE key = %d", tableName, i));
+            }
+
+            assertThat(tableSize(tableName), willBe(NUM_ROWS / 2));
+
+            executeSql(String.format("DELETE FROM %s", tableName));
+
+            assertThat(tableSize(tableName), willBe(0L));
+        }
+    }
+
+    @Test
+    void testEstimatedSizeAfterScaleUp() throws InterruptedException {
+        for (String profile : ALL_STORAGE_PROFILES) {
+            String tableName = createTableWithData(profile);
+
+            assertThat(tableSize(tableName), willBe(NUM_ROWS));
+        }
+
+        cluster.startNode(initialNodes());
+
+        for (String profile : ALL_STORAGE_PROFILES) {
+            waitForRebalance(initialNodes() + 1);
+
+            assertThat(tableSize(tableName(profile)), willBe(NUM_ROWS));
+        }
+    }
+
+    @Test
+    void testEstimatedAfterScaleDown() throws InterruptedException {
+        for (String profile : ALL_STORAGE_PROFILES) {
+            String tableName = createTableWithData(profile);
+
+            assertThat(tableSize(tableName), willBe(NUM_ROWS));
+        }
+
+        cluster.stopNode(initialNodes() - 1);
+
+        for (String profile : ALL_STORAGE_PROFILES) {
+            waitForRebalance(initialNodes() - 1);
+
+            assertThat(tableSize(tableName(profile)), willBe(NUM_ROWS));
+        }
+    }
+

Review Comment:
   I'd rather add test that will check whether pending transactions (that not yet committed) effect the size.



-- 
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-22619 Add `InternalTable#estimatedSize` method [ignite-3]

Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
sashapolo commented on code in PR #4065:
URL: https://github.com/apache/ignite-3/pull/4065#discussion_r1670983364


##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/network/replication/GetEstimatedSizeRequest.java:
##########
@@ -0,0 +1,29 @@
+/*
+ * 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.partition.replicator.network.replication;
+
+import org.apache.ignite.internal.network.annotations.Transferable;
+import org.apache.ignite.internal.partition.replicator.network.PartitionReplicationMessageGroup;
+import org.apache.ignite.internal.replicator.message.ReplicaRequest;
+
+/**
+ * Request for getting an estimated size of a partition.
+ */
+@Transferable(PartitionReplicationMessageGroup.GET_ESTIMATED_SIZE_MESSAGE)
+public interface GetEstimatedSizeRequest extends ReplicaRequest {

Review Comment:
   yes (I think). Does it make sense to retrieve the size of the partition from a non-primary replica? Will it bring any performance improvements?



##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/network/replication/GetEstimatedSizeRequest.java:
##########
@@ -0,0 +1,29 @@
+/*
+ * 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.partition.replicator.network.replication;
+
+import org.apache.ignite.internal.network.annotations.Transferable;
+import org.apache.ignite.internal.partition.replicator.network.PartitionReplicationMessageGroup;
+import org.apache.ignite.internal.replicator.message.ReplicaRequest;
+
+/**
+ * Request for getting an estimated size of a partition.
+ */
+@Transferable(PartitionReplicationMessageGroup.GET_ESTIMATED_SIZE_MESSAGE)
+public interface GetEstimatedSizeRequest extends ReplicaRequest {

Review Comment:
   yes (I think). Does it make sense to retrieve the size of a partition from a non-primary replica? Will it bring any performance improvements?



-- 
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-22619 Add `InternalTable#estimatedSize` method [ignite-3]

Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #4065:
URL: https://github.com/apache/ignite-3/pull/4065#discussion_r1670979920


##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/network/replication/GetEstimatedSizeRequest.java:
##########
@@ -0,0 +1,29 @@
+/*
+ * 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.partition.replicator.network.replication;
+
+import org.apache.ignite.internal.network.annotations.Transferable;
+import org.apache.ignite.internal.partition.replicator.network.PartitionReplicationMessageGroup;
+import org.apache.ignite.internal.replicator.message.ReplicaRequest;
+
+/**
+ * Request for getting an estimated size of a partition.
+ */
+@Transferable(PartitionReplicationMessageGroup.GET_ESTIMATED_SIZE_MESSAGE)
+public interface GetEstimatedSizeRequest extends ReplicaRequest {

Review Comment:
   Do you expect to process given request on primary 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-22619 Add `InternalTable#estimatedSize` method [ignite-3]

Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
sashapolo commented on code in PR #4065:
URL: https://github.com/apache/ignite-3/pull/4065#discussion_r1671033319


##########
modules/table/src/integrationTest/java/org/apache/ignite/internal/table/ItEstimatedSizeTest.java:
##########
@@ -0,0 +1,182 @@
+/*
+ * 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 org.apache.ignite.internal.TestDefaultProfilesNames.DEFAULT_TEST_PROFILE_NAME;
+import static org.apache.ignite.internal.TestWrappers.unwrapTableViewInternal;
+import static org.apache.ignite.internal.catalog.commands.CatalogUtils.IMMEDIATE_TIMER_VALUE;
+import static org.apache.ignite.internal.distributionzones.rebalance.RebalanceUtil.STABLE_ASSIGNMENTS_PREFIX;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
+import static org.apache.ignite.internal.testframework.flow.TestFlowUtils.subscribeToList;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willBe;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.ClusterPerTestIntegrationTest;
+import org.apache.ignite.internal.affinity.Assignments;
+import org.apache.ignite.internal.lang.ByteArray;
+import org.apache.ignite.internal.metastorage.Entry;
+import org.apache.ignite.internal.metastorage.MetaStorageManager;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Integration tests for {@link InternalTable#estimatedSize()} method.
+ *
+ * <p>This class doesn't use the Parameterized Test approach in order to reduce the number of created clusters.
+ */
+public class ItEstimatedSizeTest extends ClusterPerTestIntegrationTest {
+    private static final String TEST_ZONE_NAME = "TestZone";
+
+    private static final String TEST_TABLE_NAME_PREFIX = "Test_";
+
+    private static final long NUM_ROWS = 100;
+
+    private static final String[] ALL_STORAGE_PROFILES = {
+            DEFAULT_TEST_PROFILE_NAME,
+            // TODO: https://issues.apache.org/jira/browse/IGNITE-22616
+            // DEFAULT_AIPERSIST_PROFILE_NAME,
+            // TODO: https://issues.apache.org/jira/browse/IGNITE-22616
+            // DEFAULT_AIMEM_PROFILE_NAME,
+            // TODO: https://issues.apache.org/jira/browse/IGNITE-22617
+            // DEFAULT_ROCKSDB_PROFILE_NAME
+    };
+
+    @BeforeEach
+    void setUp() {
+        executeSql(String.format(
+                "CREATE ZONE %s WITH "
+                        + "REPLICAS=%d, "
+                        + "DATA_NODES_AUTO_ADJUST_SCALE_UP=%d, "
+                        + "DATA_NODES_AUTO_ADJUST_SCALE_DOWN=%d, "
+                        + "STORAGE_PROFILES='%s'",
+                TEST_ZONE_NAME,
+                initialNodes(),
+                IMMEDIATE_TIMER_VALUE,
+                IMMEDIATE_TIMER_VALUE,
+                String.join(", ", ALL_STORAGE_PROFILES)
+        ));
+    }
+
+    @Test
+    void testEstimatedSize() {
+        for (String profile : ALL_STORAGE_PROFILES) {
+            String tableName = createTableWithData(profile);
+
+            assertThat(tableSize(tableName), willBe(NUM_ROWS));
+
+            for (int i = 0; i < NUM_ROWS / 2; i++) {
+                executeSql(String.format("DELETE FROM %s WHERE key = %d", tableName, i));
+            }
+
+            assertThat(tableSize(tableName), willBe(NUM_ROWS / 2));
+
+            executeSql(String.format("DELETE FROM %s", tableName));
+
+            assertThat(tableSize(tableName), willBe(0L));
+        }
+    }
+
+    @Test
+    void testEstimatedSizeAfterScaleUp() throws InterruptedException {
+        for (String profile : ALL_STORAGE_PROFILES) {
+            String tableName = createTableWithData(profile);
+
+            assertThat(tableSize(tableName), willBe(NUM_ROWS));
+        }
+
+        cluster.startNode(initialNodes());
+
+        for (String profile : ALL_STORAGE_PROFILES) {
+            waitForRebalance(initialNodes() + 1);
+
+            assertThat(tableSize(tableName(profile)), willBe(NUM_ROWS));
+        }
+    }
+
+    @Test
+    void testEstimatedAfterScaleDown() throws InterruptedException {
+        for (String profile : ALL_STORAGE_PROFILES) {
+            String tableName = createTableWithData(profile);
+
+            assertThat(tableSize(tableName), willBe(NUM_ROWS));
+        }
+
+        cluster.stopNode(initialNodes() - 1);
+
+        for (String profile : ALL_STORAGE_PROFILES) {
+            waitForRebalance(initialNodes() - 1);
+
+            assertThat(tableSize(tableName(profile)), willBe(NUM_ROWS));
+        }
+    }
+

Review Comment:
   I already have such tests on the Partition Storage level, I think writing full integration tests for that is not needed



-- 
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-22619 Add `InternalTable#estimatedSize` method [ignite-3]

Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
sashapolo commented on code in PR #4065:
URL: https://github.com/apache/ignite-3/pull/4065#discussion_r1678944946


##########
modules/table/src/test/java/org/apache/ignite/internal/table/distributed/storage/InternalTableEstimatedSizeTest.java:
##########
@@ -0,0 +1,471 @@
+/*
+ * 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.distributed.storage;
+
+import static java.util.concurrent.CompletableFuture.completedFuture;
+import static java.util.concurrent.CompletableFuture.failedFuture;
+import static java.util.stream.Collectors.toList;
+import static org.apache.ignite.internal.network.utils.ClusterServiceTestUtils.clusterService;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willBe;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture;
+import static org.apache.ignite.internal.util.IgniteUtils.startAsync;
+import static org.apache.ignite.internal.util.IgniteUtils.stopAsync;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.lenient;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ForkJoinPool;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.TimeoutException;
+import java.util.stream.IntStream;
+import org.apache.ignite.internal.catalog.CatalogService;
+import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension;
+import org.apache.ignite.internal.configuration.testframework.InjectConfiguration;
+import org.apache.ignite.internal.hlc.ClockService;
+import org.apache.ignite.internal.hlc.ClockServiceImpl;
+import org.apache.ignite.internal.hlc.ClockWaiter;
+import org.apache.ignite.internal.hlc.HybridClockImpl;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.manager.ComponentContext;
+import org.apache.ignite.internal.manager.IgniteComponent;
+import org.apache.ignite.internal.metastorage.MetaStorageManager;
+import org.apache.ignite.internal.metastorage.impl.StandaloneMetaStorageManager;
+import org.apache.ignite.internal.metastorage.server.SimpleInMemoryKeyValueStorage;
+import org.apache.ignite.internal.network.ClusterNodeResolver;
+import org.apache.ignite.internal.network.ClusterService;
+import org.apache.ignite.internal.network.MessagingService;
+import org.apache.ignite.internal.network.StaticNodeFinder;
+import org.apache.ignite.internal.placementdriver.PlacementDriver;
+import org.apache.ignite.internal.placementdriver.leases.Lease;
+import org.apache.ignite.internal.raft.Command;
+import org.apache.ignite.internal.raft.service.RaftCommandRunner;
+import org.apache.ignite.internal.replicator.ReplicaService;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.replicator.configuration.ReplicationConfiguration;
+import org.apache.ignite.internal.replicator.message.ReplicaMessagesFactory;
+import org.apache.ignite.internal.replicator.message.ReplicaRequest;
+import org.apache.ignite.internal.schema.SchemaRegistry;
+import org.apache.ignite.internal.storage.MvPartitionStorage;
+import org.apache.ignite.internal.storage.engine.MvTableStorage;
+import org.apache.ignite.internal.table.InternalTable;
+import org.apache.ignite.internal.table.distributed.StorageUpdateHandler;
+import org.apache.ignite.internal.table.distributed.index.IndexMetaStorage;
+import org.apache.ignite.internal.table.distributed.replicator.PartitionReplicaListener;
+import org.apache.ignite.internal.table.distributed.replicator.TransactionStateResolver;
+import org.apache.ignite.internal.table.distributed.schema.SchemaSyncService;
+import org.apache.ignite.internal.table.distributed.schema.ValidationSchemasSource;
+import org.apache.ignite.internal.testframework.BaseIgniteAbstractTest;
+import org.apache.ignite.internal.tx.HybridTimestampTracker;
+import org.apache.ignite.internal.tx.LockManager;
+import org.apache.ignite.internal.tx.TxManager;
+import org.apache.ignite.internal.tx.impl.RemotelyTriggeredResourceRegistry;
+import org.apache.ignite.internal.tx.impl.TransactionInflights;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.internal.tx.storage.state.TxStateTableStorage;
+import org.apache.ignite.internal.util.Lazy;
+import org.apache.ignite.internal.util.PendingComparableValuesTracker;
+import org.apache.ignite.network.ClusterNode;
+import org.apache.ignite.network.NetworkAddress;
+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;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+/**
+ * Tests for distributed aspects of the {@link InternalTable#estimatedSize} method.
+ */
+@ExtendWith(MockitoExtension.class)
+@ExtendWith(ConfigurationExtension.class)
+public class InternalTableEstimatedSizeTest extends BaseIgniteAbstractTest {
+    private static final String TABLE_NAME = "TEST";
+
+    private static final int TABLE_ID = 1;
+
+    private static final int PARTITIONS_NUM = 3;
+
+    private static final List<TablePartitionId> TABLE_PARTITION_IDS = IntStream.range(0, PARTITIONS_NUM)
+            .mapToObj(i -> new TablePartitionId(TABLE_ID, i))
+            .collect(toList());
+
+    private ClusterNode node;
+
+    private InternalTableImpl table;
+
+    private MessagingService messagingService;
+
+    @Mock
+    private PlacementDriver placementDriver;
+
+    private final HybridClockImpl clock = new HybridClockImpl();
+
+    private final ComponentContext componentContext = new ComponentContext();
+
+    private final List<MvPartitionStorage> partitionStorages = new ArrayList<>(PARTITIONS_NUM);
+
+    private final List<IgniteComponent> components = new ArrayList<>();
+
+    @BeforeEach
+    void setUp(

Review Comment:
   > Did you consider using real ignite nodes with some message blocking
   
   I did, bu writing such tests and validating exact conditions that I want is a nightmare. I don't fully agree that it mainly tests mocks. My main goal was to see what exceptions are thrown by the `ReplicaService` in different conditions in order to check the exception types and these tests helped me achieve that



##########
modules/table/src/test/java/org/apache/ignite/internal/table/distributed/storage/InternalTableEstimatedSizeTest.java:
##########
@@ -0,0 +1,471 @@
+/*
+ * 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.distributed.storage;
+
+import static java.util.concurrent.CompletableFuture.completedFuture;
+import static java.util.concurrent.CompletableFuture.failedFuture;
+import static java.util.stream.Collectors.toList;
+import static org.apache.ignite.internal.network.utils.ClusterServiceTestUtils.clusterService;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willBe;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture;
+import static org.apache.ignite.internal.util.IgniteUtils.startAsync;
+import static org.apache.ignite.internal.util.IgniteUtils.stopAsync;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.lenient;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ForkJoinPool;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.TimeoutException;
+import java.util.stream.IntStream;
+import org.apache.ignite.internal.catalog.CatalogService;
+import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension;
+import org.apache.ignite.internal.configuration.testframework.InjectConfiguration;
+import org.apache.ignite.internal.hlc.ClockService;
+import org.apache.ignite.internal.hlc.ClockServiceImpl;
+import org.apache.ignite.internal.hlc.ClockWaiter;
+import org.apache.ignite.internal.hlc.HybridClockImpl;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.manager.ComponentContext;
+import org.apache.ignite.internal.manager.IgniteComponent;
+import org.apache.ignite.internal.metastorage.MetaStorageManager;
+import org.apache.ignite.internal.metastorage.impl.StandaloneMetaStorageManager;
+import org.apache.ignite.internal.metastorage.server.SimpleInMemoryKeyValueStorage;
+import org.apache.ignite.internal.network.ClusterNodeResolver;
+import org.apache.ignite.internal.network.ClusterService;
+import org.apache.ignite.internal.network.MessagingService;
+import org.apache.ignite.internal.network.StaticNodeFinder;
+import org.apache.ignite.internal.placementdriver.PlacementDriver;
+import org.apache.ignite.internal.placementdriver.leases.Lease;
+import org.apache.ignite.internal.raft.Command;
+import org.apache.ignite.internal.raft.service.RaftCommandRunner;
+import org.apache.ignite.internal.replicator.ReplicaService;
+import org.apache.ignite.internal.replicator.TablePartitionId;
+import org.apache.ignite.internal.replicator.configuration.ReplicationConfiguration;
+import org.apache.ignite.internal.replicator.message.ReplicaMessagesFactory;
+import org.apache.ignite.internal.replicator.message.ReplicaRequest;
+import org.apache.ignite.internal.schema.SchemaRegistry;
+import org.apache.ignite.internal.storage.MvPartitionStorage;
+import org.apache.ignite.internal.storage.engine.MvTableStorage;
+import org.apache.ignite.internal.table.InternalTable;
+import org.apache.ignite.internal.table.distributed.StorageUpdateHandler;
+import org.apache.ignite.internal.table.distributed.index.IndexMetaStorage;
+import org.apache.ignite.internal.table.distributed.replicator.PartitionReplicaListener;
+import org.apache.ignite.internal.table.distributed.replicator.TransactionStateResolver;
+import org.apache.ignite.internal.table.distributed.schema.SchemaSyncService;
+import org.apache.ignite.internal.table.distributed.schema.ValidationSchemasSource;
+import org.apache.ignite.internal.testframework.BaseIgniteAbstractTest;
+import org.apache.ignite.internal.tx.HybridTimestampTracker;
+import org.apache.ignite.internal.tx.LockManager;
+import org.apache.ignite.internal.tx.TxManager;
+import org.apache.ignite.internal.tx.impl.RemotelyTriggeredResourceRegistry;
+import org.apache.ignite.internal.tx.impl.TransactionInflights;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import org.apache.ignite.internal.tx.storage.state.TxStateTableStorage;
+import org.apache.ignite.internal.util.Lazy;
+import org.apache.ignite.internal.util.PendingComparableValuesTracker;
+import org.apache.ignite.network.ClusterNode;
+import org.apache.ignite.network.NetworkAddress;
+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;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+/**
+ * Tests for distributed aspects of the {@link InternalTable#estimatedSize} method.
+ */
+@ExtendWith(MockitoExtension.class)
+@ExtendWith(ConfigurationExtension.class)
+public class InternalTableEstimatedSizeTest extends BaseIgniteAbstractTest {
+    private static final String TABLE_NAME = "TEST";
+
+    private static final int TABLE_ID = 1;
+
+    private static final int PARTITIONS_NUM = 3;
+
+    private static final List<TablePartitionId> TABLE_PARTITION_IDS = IntStream.range(0, PARTITIONS_NUM)
+            .mapToObj(i -> new TablePartitionId(TABLE_ID, i))
+            .collect(toList());
+
+    private ClusterNode node;
+
+    private InternalTableImpl table;
+
+    private MessagingService messagingService;
+
+    @Mock
+    private PlacementDriver placementDriver;
+
+    private final HybridClockImpl clock = new HybridClockImpl();
+
+    private final ComponentContext componentContext = new ComponentContext();
+
+    private final List<MvPartitionStorage> partitionStorages = new ArrayList<>(PARTITIONS_NUM);
+
+    private final List<IgniteComponent> components = new ArrayList<>();
+
+    @BeforeEach
+    void setUp(

Review Comment:
   > Did you consider using real ignite nodes with some message blocking
   
   I did, but writing such tests and validating exact conditions that I want is a nightmare. I don't fully agree that it mainly tests mocks. My main goal was to see what exceptions are thrown by the `ReplicaService` in different conditions in order to check the exception types and these tests helped me achieve that



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