-
Notifications
You must be signed in to change notification settings - Fork 1.9k
IGNITE-27033: Сheckpoint command added #12547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a9ff431
b641670
3b587c8
67f7e21
42fe06e
5743032
936dce1
d51ada4
ecfbe60
ccf2aca
4b5b778
3693820
d0c7142
63bc974
9c5b679
101b093
f112a29
a814c94
e93f9fb
7cc73a1
bfa8d17
95f42b5
0c7a20f
7bfd7f4
4b8e534
cdaddb8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,278 @@ | ||
| /* | ||
| * 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.util; | ||
|
|
||
| import java.util.concurrent.CountDownLatch; | ||
| import java.util.regex.Pattern; | ||
| 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.processors.cache.persistence.GridCacheDatabaseSharedManager; | ||
| import org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointListener; | ||
| import org.apache.ignite.testframework.GridTestUtils; | ||
| import org.apache.ignite.testframework.ListeningTestLogger; | ||
| import org.apache.ignite.testframework.LogListener; | ||
| import org.junit.Test; | ||
|
|
||
| import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK; | ||
|
|
||
| /** Test for checkpoint in control.sh command. */ | ||
| public class GridCommandHandlerCheckpointTest extends GridCommandHandlerAbstractTest { | ||
| /** */ | ||
| private static final String PERSISTENT_REGION_NAME = "pds-reg"; | ||
|
|
||
| /** */ | ||
| private final ListeningTestLogger listeningLog = new ListeningTestLogger(log); | ||
|
|
||
| /** */ | ||
| private final LogListener checkpointFinishedLsnr = LogListener.matches("Checkpoint finished").build(); | ||
|
|
||
| /** */ | ||
| private boolean mixedConfig; | ||
|
|
||
| /** Latch for blocking checkpoint in timeout test. */ | ||
| private CountDownLatch blockCheckpointLatch; | ||
|
|
||
| /** */ | ||
| @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { | ||
| IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); | ||
|
|
||
| listeningLog.registerListener(checkpointFinishedLsnr); | ||
|
|
||
| cfg.setGridLogger(listeningLog); | ||
|
|
||
| if (mixedConfig) { | ||
| DataStorageConfiguration storageCfg = new DataStorageConfiguration(); | ||
|
|
||
| storageCfg.setDefaultDataRegionConfiguration(new DataRegionConfiguration().setName("default_in_memory_region") | ||
| .setPersistenceEnabled(false)); | ||
|
|
||
| if (igniteInstanceName.contains("persistent_instance")) { | ||
| DataRegionConfiguration persistentRegionCfg = new DataRegionConfiguration(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new line after There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be inlined in setDataRegionConfiguration |
||
|
|
||
| storageCfg.setDataRegionConfigurations(persistentRegionCfg.setName(PERSISTENT_REGION_NAME) | ||
| .setPersistenceEnabled(true)); | ||
| } | ||
|
|
||
| cfg.setDataStorageConfiguration(storageCfg); | ||
| } | ||
| else if (!persistenceEnable()) { | ||
| cfg.setDataStorageConfiguration(null); | ||
| } | ||
|
Comment on lines
+77
to
+79
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, we don't use braces for one-line "if" statements, see Ignite codestyle |
||
|
|
||
| return cfg; | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override protected void beforeTest() throws Exception { | ||
| super.beforeTest(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a blank line after this. |
||
|
|
||
| stopAllGrids(); | ||
| cleanPersistenceDir(); | ||
| injectTestSystemOut(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a blank line after this. |
||
|
|
||
| checkpointFinishedLsnr.reset(); | ||
| blockCheckpointLatch = null; | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override protected void afterTest() throws Exception { | ||
| if (blockCheckpointLatch != null) { | ||
| blockCheckpointLatch.countDown(); | ||
| } | ||
|
|
||
| stopAllGrids(); | ||
| cleanPersistenceDir(); | ||
|
|
||
| super.afterTest(); | ||
| } | ||
|
|
||
| /** Test checkpoint command with persistence enabled. */ | ||
| @Test | ||
| public void testCheckpointPersistenceCluster() throws Exception { | ||
| persistenceEnable(true); | ||
|
|
||
| IgniteEx srv = startGrids(2); | ||
| IgniteEx cli = startClientGrid("client"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new line after |
||
|
|
||
| srv.cluster().state(ClusterState.ACTIVE); | ||
|
|
||
| IgniteCache<Integer, Integer> cacheCli = cli.getOrCreateCache(DEFAULT_CACHE_NAME); | ||
|
|
||
| cacheCli.put(1, 1); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's enough to put from single cache instance, only. |
||
|
|
||
| assertEquals(EXIT_CODE_OK, execute("--checkpoint")); | ||
| assertTrue(GridTestUtils.waitForCondition(checkpointFinishedLsnr::check, 10_000)); | ||
| assertFalse(testOut.toString().contains("persistence disabled")); | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no new line |
||
| outputContains(": Checkpoint started"); | ||
|
|
||
| testOut.reset(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new line after |
||
|
|
||
| checkpointFinishedLsnr.reset(); | ||
|
|
||
| cacheCli.put(2, 2); | ||
|
|
||
| assertEquals(EXIT_CODE_OK, execute("--checkpoint", "--reason", "test_reason")); | ||
|
|
||
| LogListener checkpointReasonLsnr = LogListener.matches("reason='test_reason'").build(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new line after |
||
|
|
||
| listeningLog.registerListener(checkpointReasonLsnr); | ||
|
|
||
| assertTrue(GridTestUtils.waitForCondition(checkpointFinishedLsnr::check, 10_000)); | ||
| assertTrue(GridTestUtils.waitForCondition(checkpointReasonLsnr::check, 10_000)); | ||
| assertFalse(testOut.toString().contains("persistence disabled")); | ||
|
|
||
| outputContains(": Checkpoint started"); | ||
|
|
||
| testOut.reset(); | ||
|
|
||
| checkpointFinishedLsnr.reset(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new line after |
||
|
|
||
| cacheCli.put(3, 3); | ||
|
|
||
| assertEquals(EXIT_CODE_OK, execute("--checkpoint", "--wait-for-finish")); | ||
| assertTrue(checkpointFinishedLsnr.check()); | ||
| assertFalse(testOut.toString().contains("persistence disabled")); | ||
| } | ||
|
|
||
| /** Test checkpoint command with in-memory cluster. */ | ||
| @Test | ||
| public void testCheckpointInMemoryCluster() throws Exception { | ||
| persistenceEnable(false); | ||
|
|
||
| IgniteEx srv = startGrids(2); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new line after |
||
|
|
||
| startClientGrid("client"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new line after |
||
|
|
||
| srv.cluster().state(ClusterState.ACTIVE); | ||
|
|
||
| srv.createCache("testCache"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new line after |
||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no new line |
||
| assertEquals(EXIT_CODE_OK, execute("--checkpoint")); | ||
| assertFalse(checkpointFinishedLsnr.check()); | ||
|
|
||
| outputContains("persistence disabled"); | ||
| } | ||
|
|
||
| /** Test checkpoint with timeout when checkpoint completes within timeout. */ | ||
| @Test | ||
| public void testCheckpointTimeout() throws Exception { | ||
| persistenceEnable(true); | ||
|
|
||
| IgniteEx srv = startGrids(1); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new line after |
||
|
|
||
| srv.cluster().state(ClusterState.ACTIVE); | ||
|
|
||
| assertEquals(EXIT_CODE_OK, execute("--checkpoint", "--wait-for-finish", "--timeout", "1000")); | ||
|
|
||
| assertTrue(checkpointFinishedLsnr.check()); | ||
|
|
||
| assertFalse(testOut.toString().contains("persistence disabled")); | ||
| } | ||
|
|
||
| /** Test checkpoint timeout when checkpoint doesn't complete within timeout. */ | ||
| @Test | ||
| public void testCheckpointTimeoutExceeded() throws Exception { | ||
| persistenceEnable(true); | ||
|
|
||
| IgniteEx srv = startGrids(1); | ||
|
|
||
| srv.cluster().state(ClusterState.ACTIVE); | ||
|
|
||
| blockCheckpointLatch = new CountDownLatch(1); | ||
|
|
||
| GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager)srv.context().cache().context().database(); | ||
|
|
||
| dbMgr.addCheckpointListener(new CheckpointListener() { | ||
| @Override public void onMarkCheckpointBegin(Context ctx) { | ||
| try { | ||
| blockCheckpointLatch.await(); | ||
| } | ||
| catch (InterruptedException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
|
|
||
| @Override public void onCheckpointBegin(Context ctx) { | ||
| // No-op | ||
| } | ||
|
|
||
| @Override public void beforeCheckpointBegin(Context ctx) { | ||
| // No-op | ||
| } | ||
| }); | ||
|
|
||
| assertEquals(EXIT_CODE_OK, execute("--checkpoint", "--wait-for-finish", "--timeout", "500")); | ||
|
|
||
| outputContains("Checkpoint started but not finished within timeout 500 ms"); | ||
|
|
||
| blockCheckpointLatch.countDown(); | ||
|
|
||
| assertTrue(GridTestUtils.waitForCondition(checkpointFinishedLsnr::check, 10_000)); | ||
| } | ||
|
|
||
| /** Mixed cluster test. */ | ||
| @Test | ||
| public void testMixedCluster() throws Exception { | ||
| mixedConfig = true; | ||
|
|
||
| IgniteEx node0 = startGrid("in-memory_instance"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new line after |
||
|
|
||
| node0.cluster().baselineAutoAdjustEnabled(false); | ||
|
|
||
| IgniteEx node1 = startGrid("persistent_instance"); | ||
|
|
||
| node0.cluster().state(ClusterState.ACTIVE); | ||
|
|
||
| assertEquals(2, node0.cluster().nodes().size()); | ||
|
|
||
| DataStorageConfiguration node0Storage = node0.configuration().getDataStorageConfiguration(); | ||
| DataStorageConfiguration node1Storage = node1.configuration().getDataStorageConfiguration(); | ||
|
|
||
| DataRegionConfiguration node0Dflt = node0Storage.getDefaultDataRegionConfiguration(); | ||
| DataRegionConfiguration node1Dflt = node1Storage.getDefaultDataRegionConfiguration(); | ||
|
|
||
| assertEquals(node0Dflt.getName(), node1Dflt.getName()); | ||
| assertEquals(node0Dflt.isPersistenceEnabled(), node1Dflt.isPersistenceEnabled()); | ||
| assertEquals(node0Dflt.getMaxSize(), node1Dflt.getMaxSize()); | ||
|
|
||
| DataRegionConfiguration[] node1Regions = node1Storage.getDataRegionConfigurations(); | ||
| assertEquals(1, node1Regions.length); | ||
|
|
||
| DataRegionConfiguration persistentRegion = node1Regions[0]; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new line after |
||
|
|
||
| assertEquals(PERSISTENT_REGION_NAME, persistentRegion.getName()); | ||
| assertEquals(true, persistentRegion.isPersistenceEnabled()); | ||
|
|
||
| assertEquals(EXIT_CODE_OK, execute("--checkpoint", "--wait-for-finish")); | ||
|
|
||
| assertTrue(checkpointFinishedLsnr.check()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new line after |
||
|
|
||
| outputContains("persistence disabled"); | ||
| outputContains("Checkpoint finished"); | ||
| } | ||
|
|
||
| /** */ | ||
| private void outputContains(String regexp) { | ||
| assertTrue(Pattern.compile(regexp).matcher(testOut.toString()).find()); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* | ||
| * 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.management.checkpoint; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.function.Consumer; | ||
| import org.apache.ignite.cluster.ClusterNode; | ||
| import org.apache.ignite.internal.management.api.CommandUtils; | ||
| import org.apache.ignite.internal.management.api.ComputeCommand; | ||
| import org.jetbrains.annotations.Nullable; | ||
|
|
||
| /** Checkpoint command. */ | ||
| public class CheckpointCommand implements ComputeCommand<CheckpointCommandArg, String> { | ||
| /** {@inheritDoc} */ | ||
| @Override public Class<CheckpointTask> taskClass() { | ||
| return CheckpointTask.class; | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override public String description() { | ||
| return "Trigger checkpoint"; | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override public Class<CheckpointCommandArg> argClass() { | ||
| return CheckpointCommandArg.class; | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override public @Nullable Collection<ClusterNode> nodes(Collection<ClusterNode> nodes, CheckpointCommandArg arg) { | ||
| return CommandUtils.servers(nodes); | ||
| } | ||
|
|
||
| /** {@inheritDoc} */ | ||
| @Override public void printResult(CheckpointCommandArg arg, String res, Consumer<String> printer) { | ||
| printer.accept(res); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use correct indent (4 spaces) next time