You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2022/02/17 15:44:54 UTC

[GitHub] [ignite] xtern opened a new pull request #9833: IGNITE-16072 Add configurable transfer rate limit for the spanshot process.

xtern opened a new pull request #9833:
URL: https://github.com/apache/ignite/pull/9833


   Thank you for submitting the pull request to the Apache Ignite.
   
   In order to streamline the review of the contribution 
   we ask you to ensure the following steps have been taken:
   
   ### The Contribution Checklist
   - [ ] 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 pull request body describes changes that have been made. 
   The description explains _WHAT_ and _WHY_ was made instead of _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.
   - [ ] A reviewer has been mentioned through the JIRA comments 
   (see [the Maintainers list](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute#HowtoContribute-ReviewProcessandMaintainers)) 
   - [ ] The pull request has been checked by the Teamcity Bot and 
   the `green visa` attached to the JIRA ticket (see [TC.Bot: Check PR](https://mtcga.gridgain.com/prs.html))
   
   ### Notes
   - [How to Contribute](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute)
   - [Coding abbreviation rules](https://cwiki.apache.org/confluence/display/IGNITE/Abbreviation+Rules)
   - [Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Coding+Guidelines)
   - [Apache Ignite Teamcity Bot](https://cwiki.apache.org/confluence/display/IGNITE/Apache+Ignite+Teamcity+Bot)
   
   If you need any help, please email dev@ignite.apache.org or ask anу advice on http://asf.slack.com _#ignite_ channel.
   


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



[GitHub] [ignite] alex-plekhanov commented on a change in pull request #9833: IGNITE-16072 Add configurable transfer rate limit for the spanshot process.

Posted by GitBox <gi...@apache.org>.
alex-plekhanov commented on a change in pull request #9833:
URL: https://github.com/apache/ignite/pull/9833#discussion_r818590851



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java
##########
@@ -282,7 +279,10 @@
      * <p>
      * Default value is {@code 256Kb}.
      */
-    private static final int DFLT_CHUNK_SIZE_BYTES = 256 * 1024;

Review comment:
       Redundant change




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



[GitHub] [ignite] xtern commented on a change in pull request #9833: IGNITE-16072 Add configurable transfer rate limit for the spanshot process.

Posted by GitBox <gi...@apache.org>.
xtern commented on a change in pull request #9833:
URL: https://github.com/apache/ignite/pull/9833#discussion_r815642067



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteSnapshotManager.java
##########
@@ -427,6 +451,38 @@ public static String partDeltaFileName(int partId) {
         U.ensureDirectory(locSnpDir, "snapshot work directory", log);
         U.ensureDirectory(tmpWorkDir, "temp directory for snapshot creation", log);
 
+        ctx.internalSubscriptionProcessor().registerDistributedConfigurationListener(
+            new DistributedConfigurationLifecycleListener() {
+                @Override public void onReadyToRegister(DistributedPropertyDispatcher dispatcher) {
+                    snapshotTransferRate.addListener((name, oldVal, newVal) -> {
+                        if (!Objects.equals(oldVal, newVal)) {
+                            if (newVal < 0) {
+                                log.warning("The snapshot transfer rate cannot be negative, " +
+                                    "the value '" + newVal + "' is ignored.");
+
+                                return;
+                            }
+
+                            ioFactory.setRate(newVal);
+
+                            if (log.isInfoEnabled()) {
+                                log.info("The snapshot transfer rate " + (newVal == 0 ? "is not limited." :
+                                    "has been changed from '" + oldVal + "' to '" + newVal + "' KB/s."));

Review comment:
       Done, thanks!

##########
File path: modules/core/src/test/java/org/apache/ignite/internal/util/io/LimitedWriteRateFileIOTest.java
##########
@@ -0,0 +1,302 @@
+/*
+ * 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.util.io;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.channels.Channel;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
+import java.nio.file.OpenOption;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.TimeUnit;
+import org.apache.commons.io.FileUtils;
+import org.apache.ignite.internal.processors.cache.persistence.file.FileIO;
+import org.apache.ignite.internal.processors.cache.persistence.file.LimitedWriteRateFileIO;
+import org.apache.ignite.internal.processors.cache.persistence.file.LimitedWriteRateFileIOFactory;
+import org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import static java.nio.file.StandardOpenOption.APPEND;
+import static java.nio.file.StandardOpenOption.CREATE;
+import static java.nio.file.StandardOpenOption.READ;
+import static java.nio.file.StandardOpenOption.WRITE;
+import static org.junit.Assert.assertArrayEquals;
+
+/**
+ * Test {@link LimitedWriteRateFileIO}.
+ */
+@RunWith(Parameterized.class)
+public class LimitedWriteRateFileIOTest extends GridCommonAbstractTest {
+    /** Estimated duration of an I/O operation. */
+    private static final int DURATION_SEC = 4;
+
+    /** Temp directory name. */
+    private static final String TMP_DIR_NAME = "temp";
+
+    /** Temp file. */
+    private static File tempFile;
+
+    /** Write rate. */
+    @Parameterized.Parameter(0)
+    public int rate;
+
+    /** Destination buffer length. */
+    @Parameterized.Parameter(1)
+    public int bufLen;
+
+    /** Flag for writing only part of the data to check the write with an offset. */
+    @Parameterized.Parameter(2)
+    public boolean checkOffset;
+
+    /** Binary data. */
+    private byte[] data;
+
+    /** File offset. */
+    private int offset;
+
+    /** Parameters. */
+    @Parameterized.Parameters(name = "rate={0}, bufLen={1}, checkOffset={2}")
+    public static Iterable<Object[]> parameters() {
+        List<Object[]> params = new ArrayList<>();
+
+        params.add(new Object[] {4096, 65536, true});
+        params.add(new Object[] {4096, 65536, false});
+        params.add(new Object[] {4096, 1, true});
+        params.add(new Object[] {4096, 1, false});
+        params.add(new Object[] {1, 1, true});
+        params.add(new Object[] {1, 1, false});
+
+        return params;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        super.beforeTestsStarted();
+
+        File tmpDir = new File(U.defaultWorkDirectory(), TMP_DIR_NAME);
+
+        if (!tmpDir.exists())
+            tmpDir.mkdirs();
+
+        tempFile = new File(new File(U.defaultWorkDirectory(), TMP_DIR_NAME),
+            U.maskForFileName(getClass().getSimpleName()) + ".tmp.1");
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        U.delete(new File(U.defaultWorkDirectory(), TMP_DIR_NAME));
+
+        super.afterTestsStopped();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        super.beforeTest();
+
+        tempFile.delete();
+
+        int len = DURATION_SEC * rate + 1;;

Review comment:
       Done, thanks!




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



[GitHub] [ignite] alex-plekhanov commented on a change in pull request #9833: IGNITE-16072 Add configurable transfer rate limit for the spanshot process.

Posted by GitBox <gi...@apache.org>.
alex-plekhanov commented on a change in pull request #9833:
URL: https://github.com/apache/ignite/pull/9833#discussion_r818487906



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/util/BasicRateLimiter.java
##########
@@ -136,7 +143,7 @@ public void acquire(int permits) throws IgniteInterruptedCheckedException {
      * @param permits The number of permits.
      * @return Time in microseconds to wait until the resource can be acquired, never negative.
      */
-    private long reserve(int permits) {
+    private long reserve(long permits) {

Review comment:
       It's only one usage of this method and this usage with `int` parameter. So, we should make parameter as long in  `acquire` method (also remove one cast from long to int in in `acquire` method usage) or revert this change. 

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteSnapshotManager.java
##########
@@ -258,6 +266,19 @@
     /** Prefix for snapshot threads. */
     public static final String SNAPSHOT_RUNNER_THREAD_PREFIX = "snapshot-runner";
 
+    /** Snapshot transfer rate distributed configuration key */
+    public static final String SNAPSHOT_TRANSFER_RATE_DMS_KEY = "snapshotTransferRate";
+
+    /** Snapshot transfer rate is unlimited by default. */
+    public static final long DFLT_SNAPSHOT_TRANSFER_RATE = 0L;
+
+    /** Minimum block size for limited snapshot transfer. */
+    @SystemProperty(value = "Sets the minimum block size for limited snapshot transfer")
+    public static final String SNAPSHOT_LIMITED_TRANSFER_BLOCK_SIZE = "SNAPSHOT_LIMITED_TRANSFER_BLOCK_SIZE";

Review comment:
       Property name should be started with "IGNITE_".
   Do we really need to configure this property? Why don't just set some reasonable constant value?

##########
File path: modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java
##########
@@ -2994,6 +2997,44 @@ public void testMasterKeyChangeOnInactiveCluster() throws Exception {
         assertContains(log, testOut.toString(), "Master key change was rejected. The cluster is inactive.");
     }
 
+    /** @throws Exception If failed. */
+    @Test
+    @WithSystemProperty(key = SNAPSHOT_LIMITED_TRANSFER_BLOCK_SIZE, value = "1")

Review comment:
       Since `SNAPSHOT_TRANSFER_BLOCK_SIZE_BYTES` is static, this `WithSystemProperty` does nothing (unless this test is the first after JVM start).  

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteSnapshotManager.java
##########
@@ -258,6 +267,20 @@
     /** Prefix for snapshot threads. */
     public static final String SNAPSHOT_RUNNER_THREAD_PREFIX = "snapshot-runner";
 
+    /** Snapshot transfer rate distributed configuration key */
+    public static final String SNAPSHOT_TRANSFER_RATE_DMS_KEY = "snapshotTransferRate";
+
+    /** Snapshot transfer rate is unlimited by default. */
+    public static final long DFLT_SNAPSHOT_TRANSFER_RATE_BYTES = 0L;
+
+    /** Minimum block size for limited snapshot transfer. */
+    @SystemProperty(value = "Sets the minimum block size for limited snapshot transfer")
+    public static final String SNAPSHOT_LIMITED_TRANSFER_BLOCK_SIZE = "SNAPSHOT_LIMITED_TRANSFER_BLOCK_SIZE";
+
+    /** Snapshot limited transfer block size (in bytes). */
+    private static final int SNAPSHOT_TRANSFER_BLOCK_SIZE_BYTES =

Review comment:
       Why it's bounded to IO chunk size? Currently, this property is only used for local copy.




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



[GitHub] [ignite] xtern commented on a change in pull request #9833: IGNITE-16072 Add configurable transfer rate limit for the spanshot process.

Posted by GitBox <gi...@apache.org>.
xtern commented on a change in pull request #9833:
URL: https://github.com/apache/ignite/pull/9833#discussion_r815634967



##########
File path: modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java
##########
@@ -2989,6 +2994,47 @@ public void testMasterKeyChangeOnInactiveCluster() throws Exception {
         assertContains(log, testOut.toString(), "Master key change was rejected. The cluster is inactive.");
     }
 
+    /** @throws Exception If failed. */
+    @Test
+    @WithSystemProperty(key = SNAPSHOT_LIMITED_TRANSFER_BLOCK_SIZE, value = "1")
+    public void testChangeSnapshotTransferRateInRuntime() throws Exception {
+        int keysCnt = 10_000;
+        String snpName = "snapshot_02052020";
+
+        StopNodeFailureHandler failHnd = new StopNodeFailureHandler();
+        failHnd.setIgnoredFailureTypes(Collections.emptySet());
+
+        IgniteConfiguration cfg = optimize(getConfiguration(getTestIgniteInstanceName(0)))
+            .setFailureHandler(failHnd)
+            .setFailureDetectionTimeout(5_000);
+
+        IgniteEx ignite = startGrid(cfg);
+
+        ignite.cluster().state(ACTIVE);
+
+        createCacheAndPreload(ignite, keysCnt);
+
+        // Set transfer rate to 1 byte/sec.
+        assertEquals(EXIT_CODE_OK, execute("--property", "set", "--name", SNAPSHOT_TRANSFER_RATE_DMS_KEY, "--val", "1"));
+
+        IgniteFuture<Void> snpFut = ignite.snapshot().createSnapshot(snpName);
+
+        // Make sure there are no blocks in critical sections.
+        U.sleep(cfg.getFailureDetectionTimeout());
+
+        assertFalse(snpFut.isDone());
+
+        // Set transfer rate to unlimited.
+        assertEquals(EXIT_CODE_OK, execute("--property", "set", "--name", SNAPSHOT_TRANSFER_RATE_DMS_KEY, "--val", "0"));
+
+        long totalPartsSize = ((PageStoreCollection)ignite.context().cache().context().pageStore())
+            .getStores(CU.cacheId(DEFAULT_CACHE_NAME)).stream().mapToLong(PageStore::size).sum();
+
+        assertTrue(totalPartsSize > TimeUnit.MILLISECONDS.toSeconds(getTestTimeout()));

Review comment:
       Didn't quite get the idea.
   This test checks that we can change the speed limit at runtime.
   Specifically, this check is needed so that the test fails by timeout if the speed is not changed (ie if the limit remains 1 byte per second).




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



[GitHub] [ignite] xtern commented on a change in pull request #9833: IGNITE-16072 Add configurable transfer rate limit for the spanshot process.

Posted by GitBox <gi...@apache.org>.
xtern commented on a change in pull request #9833:
URL: https://github.com/apache/ignite/pull/9833#discussion_r815642020



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/LimitedWriteRateFileIO.java
##########
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.persistence.file;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
+import org.apache.ignite.IgniteInterruptedException;
+import org.apache.ignite.internal.IgniteInterruptedCheckedException;
+import org.apache.ignite.internal.util.BasicRateLimiter;
+
+/**
+ * File I/O providing the ability to limit the write rate.
+ * <p>
+ * Note: read operations are not limited, only write and transfer operations are limited.
+ */
+public class LimitedWriteRateFileIO extends FileIODecorator {

Review comment:
       Done, thanks!




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



[GitHub] [ignite] xtern commented on a change in pull request #9833: IGNITE-16072 Add configurable transfer rate limit for the spanshot process.

Posted by GitBox <gi...@apache.org>.
xtern commented on a change in pull request #9833:
URL: https://github.com/apache/ignite/pull/9833#discussion_r818583147



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteSnapshotManager.java
##########
@@ -258,6 +266,19 @@
     /** Prefix for snapshot threads. */
     public static final String SNAPSHOT_RUNNER_THREAD_PREFIX = "snapshot-runner";
 
+    /** Snapshot transfer rate distributed configuration key */
+    public static final String SNAPSHOT_TRANSFER_RATE_DMS_KEY = "snapshotTransferRate";
+
+    /** Snapshot transfer rate is unlimited by default. */
+    public static final long DFLT_SNAPSHOT_TRANSFER_RATE = 0L;
+
+    /** Minimum block size for limited snapshot transfer. */
+    @SystemProperty(value = "Sets the minimum block size for limited snapshot transfer")
+    public static final String SNAPSHOT_LIMITED_TRANSFER_BLOCK_SIZE = "SNAPSHOT_LIMITED_TRANSFER_BLOCK_SIZE";

Review comment:
       System property removed.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] xtern commented on a change in pull request #9833: IGNITE-16072 Add configurable transfer rate limit for the spanshot process.

Posted by GitBox <gi...@apache.org>.
xtern commented on a change in pull request #9833:
URL: https://github.com/apache/ignite/pull/9833#discussion_r818583315



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/util/BasicRateLimiter.java
##########
@@ -136,7 +143,7 @@ public void acquire(int permits) throws IgniteInterruptedCheckedException {
      * @param permits The number of permits.
      * @return Time in microseconds to wait until the resource can be acquired, never negative.
      */
-    private long reserve(int permits) {
+    private long reserve(long permits) {

Review comment:
       done




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



[GitHub] [ignite] ololo3000 commented on a change in pull request #9833: IGNITE-16072 Add configurable transfer rate limit for the spanshot process.

Posted by GitBox <gi...@apache.org>.
ololo3000 commented on a change in pull request #9833:
URL: https://github.com/apache/ignite/pull/9833#discussion_r815318241



##########
File path: modules/core/src/test/java/org/apache/ignite/internal/util/io/LimitedWriteRateFileIOTest.java
##########
@@ -0,0 +1,302 @@
+/*
+ * 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.util.io;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.channels.Channel;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
+import java.nio.file.OpenOption;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.TimeUnit;
+import org.apache.commons.io.FileUtils;
+import org.apache.ignite.internal.processors.cache.persistence.file.FileIO;
+import org.apache.ignite.internal.processors.cache.persistence.file.LimitedWriteRateFileIO;
+import org.apache.ignite.internal.processors.cache.persistence.file.LimitedWriteRateFileIOFactory;
+import org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import static java.nio.file.StandardOpenOption.APPEND;
+import static java.nio.file.StandardOpenOption.CREATE;
+import static java.nio.file.StandardOpenOption.READ;
+import static java.nio.file.StandardOpenOption.WRITE;
+import static org.junit.Assert.assertArrayEquals;
+
+/**
+ * Test {@link LimitedWriteRateFileIO}.
+ */
+@RunWith(Parameterized.class)
+public class LimitedWriteRateFileIOTest extends GridCommonAbstractTest {
+    /** Estimated duration of an I/O operation. */
+    private static final int DURATION_SEC = 4;
+
+    /** Temp directory name. */
+    private static final String TMP_DIR_NAME = "temp";
+
+    /** Temp file. */
+    private static File tempFile;
+
+    /** Write rate. */
+    @Parameterized.Parameter(0)
+    public int rate;
+
+    /** Destination buffer length. */
+    @Parameterized.Parameter(1)
+    public int bufLen;
+
+    /** Flag for writing only part of the data to check the write with an offset. */
+    @Parameterized.Parameter(2)
+    public boolean checkOffset;
+
+    /** Binary data. */
+    private byte[] data;
+
+    /** File offset. */
+    private int offset;
+
+    /** Parameters. */
+    @Parameterized.Parameters(name = "rate={0}, bufLen={1}, checkOffset={2}")
+    public static Iterable<Object[]> parameters() {
+        List<Object[]> params = new ArrayList<>();
+
+        params.add(new Object[] {4096, 65536, true});
+        params.add(new Object[] {4096, 65536, false});
+        params.add(new Object[] {4096, 1, true});
+        params.add(new Object[] {4096, 1, false});
+        params.add(new Object[] {1, 1, true});
+        params.add(new Object[] {1, 1, false});
+
+        return params;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        super.beforeTestsStarted();
+
+        File tmpDir = new File(U.defaultWorkDirectory(), TMP_DIR_NAME);
+
+        if (!tmpDir.exists())
+            tmpDir.mkdirs();
+
+        tempFile = new File(new File(U.defaultWorkDirectory(), TMP_DIR_NAME),
+            U.maskForFileName(getClass().getSimpleName()) + ".tmp.1");
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        U.delete(new File(U.defaultWorkDirectory(), TMP_DIR_NAME));
+
+        super.afterTestsStopped();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        super.beforeTest();
+
+        tempFile.delete();
+
+        int len = DURATION_SEC * rate + 1;;

Review comment:
       Extra semicolon.

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/LimitedWriteRateFileIO.java
##########
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.persistence.file;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
+import org.apache.ignite.IgniteInterruptedException;
+import org.apache.ignite.internal.IgniteInterruptedCheckedException;
+import org.apache.ignite.internal.util.BasicRateLimiter;
+
+/**
+ * File I/O providing the ability to limit the write rate.
+ * <p>
+ * Note: read operations are not limited, only write and transfer operations are limited.
+ */
+public class LimitedWriteRateFileIO extends FileIODecorator {

Review comment:
       It might be worth trying to override the `writeFully` methods and just call them in the `write`. It more clearly depicts what is really going on here.
   
   

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteSnapshotManager.java
##########
@@ -427,6 +451,38 @@ public static String partDeltaFileName(int partId) {
         U.ensureDirectory(locSnpDir, "snapshot work directory", log);
         U.ensureDirectory(tmpWorkDir, "temp directory for snapshot creation", log);
 
+        ctx.internalSubscriptionProcessor().registerDistributedConfigurationListener(
+            new DistributedConfigurationLifecycleListener() {
+                @Override public void onReadyToRegister(DistributedPropertyDispatcher dispatcher) {
+                    snapshotTransferRate.addListener((name, oldVal, newVal) -> {
+                        if (!Objects.equals(oldVal, newVal)) {
+                            if (newVal < 0) {
+                                log.warning("The snapshot transfer rate cannot be negative, " +
+                                    "the value '" + newVal + "' is ignored.");
+
+                                return;
+                            }
+
+                            ioFactory.setRate(newVal);
+
+                            if (log.isInfoEnabled()) {
+                                log.info("The snapshot transfer rate " + (newVal == 0 ? "is not limited." :
+                                    "has been changed from '" + oldVal + "' to '" + newVal + "' KB/s."));

Review comment:
       It seems that KB/s should be changed to B/s

##########
File path: modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java
##########
@@ -2989,6 +2994,47 @@ public void testMasterKeyChangeOnInactiveCluster() throws Exception {
         assertContains(log, testOut.toString(), "Master key change was rejected. The cluster is inactive.");
     }
 
+    /** @throws Exception If failed. */
+    @Test
+    @WithSystemProperty(key = SNAPSHOT_LIMITED_TRANSFER_BLOCK_SIZE, value = "1")
+    public void testChangeSnapshotTransferRateInRuntime() throws Exception {
+        int keysCnt = 10_000;
+        String snpName = "snapshot_02052020";
+
+        StopNodeFailureHandler failHnd = new StopNodeFailureHandler();
+        failHnd.setIgnoredFailureTypes(Collections.emptySet());
+
+        IgniteConfiguration cfg = optimize(getConfiguration(getTestIgniteInstanceName(0)))
+            .setFailureHandler(failHnd)
+            .setFailureDetectionTimeout(5_000);
+
+        IgniteEx ignite = startGrid(cfg);
+
+        ignite.cluster().state(ACTIVE);
+
+        createCacheAndPreload(ignite, keysCnt);
+
+        // Set transfer rate to 1 byte/sec.
+        assertEquals(EXIT_CODE_OK, execute("--property", "set", "--name", SNAPSHOT_TRANSFER_RATE_DMS_KEY, "--val", "1"));
+
+        IgniteFuture<Void> snpFut = ignite.snapshot().createSnapshot(snpName);
+
+        // Make sure there are no blocks in critical sections.
+        U.sleep(cfg.getFailureDetectionTimeout());
+
+        assertFalse(snpFut.isDone());
+
+        // Set transfer rate to unlimited.
+        assertEquals(EXIT_CODE_OK, execute("--property", "set", "--name", SNAPSHOT_TRANSFER_RATE_DMS_KEY, "--val", "0"));
+
+        long totalPartsSize = ((PageStoreCollection)ignite.context().cache().context().pageStore())
+            .getStores(CU.cacheId(DEFAULT_CACHE_NAME)).stream().mapToLong(PageStore::size).sum();
+
+        assertTrue(totalPartsSize > TimeUnit.MILLISECONDS.toSeconds(getTestTimeout()));

Review comment:
       Why can't we use the same approach as in ` LimitedWriteRateFileIOTest` - measure the operation time and compare it with the expected execution time calculated from the rate value?
   
   Frankly, this check looks to me not so obvious.




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



[GitHub] [ignite] xtern merged pull request #9833: IGNITE-16072 Add configurable transfer rate limit for the spanshot process.

Posted by GitBox <gi...@apache.org>.
xtern merged pull request #9833:
URL: https://github.com/apache/ignite/pull/9833


   


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



[GitHub] [ignite] xtern commented on a change in pull request #9833: IGNITE-16072 Add configurable transfer rate limit for the spanshot process.

Posted by GitBox <gi...@apache.org>.
xtern commented on a change in pull request #9833:
URL: https://github.com/apache/ignite/pull/9833#discussion_r818583473



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/snapshot/IgniteSnapshotManager.java
##########
@@ -258,6 +267,20 @@
     /** Prefix for snapshot threads. */
     public static final String SNAPSHOT_RUNNER_THREAD_PREFIX = "snapshot-runner";
 
+    /** Snapshot transfer rate distributed configuration key */
+    public static final String SNAPSHOT_TRANSFER_RATE_DMS_KEY = "snapshotTransferRate";
+
+    /** Snapshot transfer rate is unlimited by default. */
+    public static final long DFLT_SNAPSHOT_TRANSFER_RATE_BYTES = 0L;
+
+    /** Minimum block size for limited snapshot transfer. */
+    @SystemProperty(value = "Sets the minimum block size for limited snapshot transfer")
+    public static final String SNAPSHOT_LIMITED_TRANSFER_BLOCK_SIZE = "SNAPSHOT_LIMITED_TRANSFER_BLOCK_SIZE";
+
+    /** Snapshot limited transfer block size (in bytes). */
+    private static final int SNAPSHOT_TRANSFER_BLOCK_SIZE_BYTES =

Review comment:
       System property removed.

##########
File path: modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java
##########
@@ -2994,6 +2997,44 @@ public void testMasterKeyChangeOnInactiveCluster() throws Exception {
         assertContains(log, testOut.toString(), "Master key change was rejected. The cluster is inactive.");
     }
 
+    /** @throws Exception If failed. */
+    @Test
+    @WithSystemProperty(key = SNAPSHOT_LIMITED_TRANSFER_BLOCK_SIZE, value = "1")

Review comment:
       System property removed.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org