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/26 16:26:05 UTC

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

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