Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.ignite.util.GridCommandHandlerBrokenIndexTest;
import org.apache.ignite.util.GridCommandHandlerCheckIncrementalSnapshotTest;
import org.apache.ignite.util.GridCommandHandlerCheckIndexesInlineSizeTest;
import org.apache.ignite.util.GridCommandHandlerCheckpointTest;
import org.apache.ignite.util.GridCommandHandlerClusterByClassTest;
import org.apache.ignite.util.GridCommandHandlerClusterByClassWithSSLTest;
import org.apache.ignite.util.GridCommandHandlerConsistencyRepairCorrectnessTransactionalTest;
Expand Down Expand Up @@ -80,7 +81,8 @@
BaselineEventsRemoteTest.class,

GridCommandHandlerConsistencyRepairCorrectnessTransactionalTest.class,
GridCommandHandlerWalTest.class
GridCommandHandlerWalTest.class,
GridCommandHandlerCheckpointTest.class
})
public class IgniteControlUtilityTestSuite {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/*
* 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.Objects;
import java.util.regex.Pattern;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.cluster.ClusterState;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.IgniteEx;
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;
import static org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_UNEXPECTED_ERROR;

/** Test for checkpoint in control.sh command. */
public class GridCommandHandlerCheckpointTest extends GridCommandHandlerAbstractTest {
/** */
private final ListeningTestLogger listeningLog = new ListeningTestLogger(log);

/** */
private final LogListener checkpointFinishedLsnr = LogListener.matches("Checkpoint finished").build();

/** */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

if (!persistenceEnable())
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, move this below to keep all storage configuration in one place

cfg.setDataStorageConfiguration(null);

listeningLog.registerListener(checkpointFinishedLsnr);

cfg.setGridLogger(listeningLog);

return cfg;
}

/** {@inheritDoc} */
@Override protected void beforeTest() throws Exception {
super.beforeTest();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a blank line after this.

stopAllGrids();
cleanPersistenceDir();
injectTestSystemOut();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a blank line after this.

}

/** Test checkpoint command with persistence enabled. */
@Test
public void testCheckpointPersistenceCluster() throws Exception {
persistenceEnable(true);

IgniteEx srv = startGrids(2);
IgniteEx cli = startClientGrid("client");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line after

srv.cluster().state(ClusterState.ACTIVE);

IgniteCache<Integer, Integer> cacheSrv = srv.getOrCreateCache(DEFAULT_CACHE_NAME);
IgniteCache<Integer, Integer> cacheCli = cli.getOrCreateCache(DEFAULT_CACHE_NAME);

cacheSrv.put(1, 1);
cacheCli.put(1, 1);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's enough to put from single cache instance, only.
Please, remove cacheSrv.put here and below.


assertEquals(EXIT_CODE_OK, execute("--checkpoint"));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no new line

outputContains("Checkpoint triggered on all nodes");
assertTrue(GridTestUtils.waitForCondition(checkpointFinishedLsnr::check, 10_000));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no new line

String out = testOut.toString();
assertFalse(out.contains(cli.localNode().id().toString()));
assertFalse(out.contains(Objects.toString(cli.localNode().consistentId())));

testOut.reset();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line after

checkpointFinishedLsnr.reset();

cacheSrv.put(2, 2);
cacheCli.put(2, 2);

assertEquals(EXIT_CODE_OK, execute("--checkpoint", "--reason", "test_reason"));

outputContains("Checkpoint triggered on all nodes");
Copy link
Copy Markdown
Contributor

@wernerdv wernerdv Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s add a check for the presence of reason=test_reason in the output.

assertTrue(GridTestUtils.waitForCondition(checkpointFinishedLsnr::check, 10_000));

testOut.reset();
checkpointFinishedLsnr.reset();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line after


cacheSrv.put(3, 3);
cacheCli.put(3, 3);

assertEquals(EXIT_CODE_OK, execute("--checkpoint", "--wait-for-finish"));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no new line

outputContains("Checkpoint triggered on all nodes");
assertTrue(GridTestUtils.waitForCondition(checkpointFinishedLsnr::check, 10_000));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we run the command with the --wait-for-finish flag, it seems there’s no need to wait here:
assertTrue(checkpointFinishedLsnr.check());


checkpointFinishedLsnr.reset();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add checkpointFinishedLsnr.reset(); in beforeTest() method and remove the last reset from each individual test.

}

/** Test checkpoint command with in-memory cluster. */
@Test
public void testCheckpointInMemoryCluster() throws Exception {
persistenceEnable(false);

IgniteEx srv = startGrids(2);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line after

IgniteEx cli = startClientGrid("client");
srv.cluster().state(ClusterState.ACTIVE);

srv.createCache("testCache");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line after

assertEquals(EXIT_CODE_UNEXPECTED_ERROR, execute("--checkpoint"));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no new line

outputContains("Can't checkpoint on in-memory node");
assertFalse(checkpointFinishedLsnr.check());

String out = testOut.toString();
assertFalse(out.contains(cli.localNode().id().toString()));
assertFalse(out.contains(Objects.toString(cli.localNode().consistentId())));

checkpointFinishedLsnr.reset();
}

/** Test checkpoint with timeout. */
@Test
public void testCheckpointTimeout() throws Exception {
persistenceEnable(true);

IgniteEx srv = startGrids(1);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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"));

outputContains("Checkpoint triggered on all nodes");
assertTrue(checkpointFinishedLsnr.check());

checkpointFinishedLsnr.reset();
}

/** */
private void outputContains(String regexp) {
assertTrue(Pattern.compile(regexp).matcher(testOut.toString()).find());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.ignite.internal.management.baseline.BaselineCommand;
import org.apache.ignite.internal.management.cache.CacheCommand;
import org.apache.ignite.internal.management.cdc.CdcCommand;
import org.apache.ignite.internal.management.checkpoint.CheckpointCommand;
import org.apache.ignite.internal.management.consistency.ConsistencyCommand;
import org.apache.ignite.internal.management.defragmentation.DefragmentationCommand;
import org.apache.ignite.internal.management.diagnostic.DiagnosticCommand;
Expand Down Expand Up @@ -58,6 +59,7 @@ public IgniteCommandRegistry() {
new TxCommand(),
new CacheCommand(),
new WalCommand(),
new CheckpointCommand(),
new DiagnosticCommand(),
new EncryptionCommand(),
new KillCommand(),
Expand Down
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 with optional parameters";
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's simplify this to "Trigger checkpoint" don't forget about tests.

}

/** {@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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* 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.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import org.apache.ignite.internal.dto.IgniteDataTransferObject;
import org.apache.ignite.internal.management.api.Argument;
import org.apache.ignite.internal.util.typedef.internal.U;

/** Checkpoint command arguments. */
public class CheckpointCommandArg extends IgniteDataTransferObject {
/** */
private static final long serialVersionUID = 0;

/** */
@Argument(description = "Reason for checkpoint", optional = true)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's simplify this to "Reason (visible in logs)" don't forget about tests.

private String reason;

/** */
@Argument(description = "Wait for checkpoint to finish", optional = true)
private boolean waitForFinish;

/** */
@Argument(description = "Timeout in milliseconds", optional = true)
private long timeout = -1;

/** {@inheritDoc} */
@Override protected void writeExternalData(ObjectOutput out) throws IOException {
U.writeString(out, reason);
out.writeBoolean(waitForFinish);
out.writeObject(timeout);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out.writeLong

}

/** {@inheritDoc} */
@Override protected void readExternalData(ObjectInput in) throws IOException, ClassNotFoundException {
reason = U.readString(in);
waitForFinish = in.readBoolean();
timeout = (long)in.readObject();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in.readLong

}

/** */
public String reason() {
return reason;
}

/** */
public void reason(String reason) {
this.reason = reason;
}

/** */
public boolean waitForFinish() {
return waitForFinish;
}

/** */
public void waitForFinish(boolean waitForFinish) {
this.waitForFinish = waitForFinish;
}

/** */
public long timeout() {
return timeout;
}

/** */
public void timeout(long timeout) {
this.timeout = timeout;
}
}
Loading
Loading