nizhikov commented on a change in pull request #8928: URL: https://github.com/apache/ignite/pull/8928#discussion_r612153523
########## File path: modules/core/src/test/java/org/apache/ignite/internal/processors/performancestatistics/CheckpointTest.java ########## @@ -0,0 +1,273 @@ +/* + * 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.performancestatistics; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.file.OpenOption; +import java.util.UUID; +import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.locks.LockSupport; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.cluster.ClusterState; +import org.apache.ignite.configuration.DataRegionConfiguration; +import org.apache.ignite.configuration.DataStorageConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.IgniteInternalFuture; +import org.apache.ignite.internal.processors.cache.persistence.file.FileIO; +import org.apache.ignite.internal.processors.cache.persistence.file.FileIODecorator; +import org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory; +import org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory; +import org.apache.ignite.internal.processors.metric.MetricRegistry; +import org.apache.ignite.internal.processors.metric.impl.AtomicLongMetric; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.junits.WithSystemProperty; +import org.junit.Test; + +import static org.apache.ignite.IgniteSystemProperties.IGNITE_OVERRIDE_WRITE_THROTTLING_ENABLED; +import static org.apache.ignite.internal.processors.cache.persistence.DataStorageMetricsImpl.DATASTORAGE_METRIC_PREFIX; +import static org.apache.ignite.testframework.GridTestUtils.waitForCondition; + +/** + * Tests checkpoint performance statistics. + */ +public class CheckpointTest extends AbstractPerformanceStatisticsTest { + /** Slow checkpoint enabled. */ + private static final AtomicBoolean slowCheckpointEnabled = new AtomicBoolean(false); + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); + + cfg.setCacheConfiguration(defaultCacheConfiguration()); + cfg.setDataStorageConfiguration(new DataStorageConfiguration() + .setMetricsEnabled(true) + .setDefaultDataRegionConfiguration(new DataRegionConfiguration() + .setMaxSize(10 * 1024 * 1024) + .setCheckpointPageBufferSize(1024 * 1024) + .setMetricsEnabled(true) + .setPersistenceEnabled(true)) + .setWriteThrottlingEnabled(true) + .setFileIOFactory(new SlowCheckpointFileIOFactory()) + .setCheckpointThreads(1)); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + super.beforeTestsStarted(); + + cleanPersistenceDir(); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + slowCheckpointEnabled.set(false); + + stopAllGrids(); + + cleanPersistenceDir(); + } + + /** @throws Exception If failed. */ + @Test + public void testCheckpoint() throws Exception { + IgniteEx srv = startGrid(); + + srv.cluster().state(ClusterState.ACTIVE); + + MetricRegistry mreg = srv.context().metric().registry(DATASTORAGE_METRIC_PREFIX); + + AtomicLongMetric lastBeforeLockDuration = mreg.findMetric("LastCheckpointBeforeLockDuration"); + AtomicLongMetric lastLockWaitDuration = mreg.findMetric("LastCheckpointLockWaitDuration"); + AtomicLongMetric lastListenersExecDuration = mreg.findMetric("LastCheckpointListenersExecuteDuration"); + AtomicLongMetric lastMarcDuration = mreg.findMetric("LastCheckpointMarkDuration"); + AtomicLongMetric lastLockHoldDuration = mreg.findMetric("LastCheckpointLockHoldDuration"); + AtomicLongMetric lastPagesWriteDuration = mreg.findMetric("LastCheckpointPagesWriteDuration"); + AtomicLongMetric lastFsyncDuration = mreg.findMetric("LastCheckpointFsyncDuration"); + AtomicLongMetric lastWalRecordFsyncDuration = mreg.findMetric("LastCheckpointWalRecordFsyncDuration"); + AtomicLongMetric lastWriteEntryDuration = mreg.findMetric("LastCheckpointWriteEntryDuration"); + AtomicLongMetric lastSplitAndSortPagesDuration = + mreg.findMetric("LastCheckpointSplitAndSortPagesDuration"); + AtomicLongMetric lastDuration = mreg.findMetric("LastCheckpointDuration"); + AtomicLongMetric lastStart = mreg.findMetric("LastCheckpointStart"); + AtomicLongMetric lastTotalPages = mreg.findMetric("LastCheckpointTotalPagesNumber"); + AtomicLongMetric lastDataPages = mreg.findMetric("LastCheckpointDataPagesNumber"); + AtomicLongMetric lastCOWPages = mreg.findMetric("LastCheckpointCopiedOnWritePagesNumber"); + + // wait for checkpoint to finish on node start + assertTrue(waitForCondition(() -> 0 < lastStart.value(), TIMEOUT)); + + startCollectStatisticsWithImmediatelyFlush(); + + forceCheckpoint(); + + assertTrue(waitForCondition(() -> { Review comment: Let's rewrite test as follows: 1. Start psproc 2. forceCheckpoint 3. Wait for checkpoint finish (based on metric value or similar) 4. Stop psproc. 5. Check is there checkpoint data in statistics (no multiple read of statistics). -- 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. For queries about this service, please contact Infrastructure at: [email protected]
