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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]