You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "rpuch (via GitHub)" <gi...@apache.org> on 2026/03/12 06:59:58 UTC
[PR] IGNITE-28202 Advance last applied index for each Metastorage command [ignite-3]
rpuch opened a new pull request, #7763:
URL: https://github.com/apache/ignite-3/pull/7763
https://issues.apache.org/jira/browse/IGNITE-28202
--
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
Re: [PR] IGNITE-28202 Advance last applied index for each Metastorage command [ignite-3]
Posted by "rpuch (via GitHub)" <gi...@apache.org>.
rpuch commented on code in PR #7763:
URL: https://github.com/apache/ignite-3/pull/7763#discussion_r2923748870
##########
modules/metastorage/src/integrationTest/java/org/apache/ignite/internal/metastorage/impl/ItIdempotentCommandCacheTest.java:
##########
@@ -607,4 +650,34 @@ private void startCluster(TestInfo testInfo) {
nodes.forEach(Node::deployWatches);
}
+
+ @Target(ElementType.METHOD)
+ @Retention(RetentionPolicy.RUNTIME)
+ private @interface DisableIdleSafeTimePropagation {
+ }
+
+ private enum Invoker {
+ INVOKE {
+ @Override
+ CompletableFuture<Boolean> invokeOn(MetaStorageManager metaStorageManager) {
+ return metaStorageManager.invoke(
+ notExists(TEST_KEY),
+ put(TEST_KEY, TEST_VALUE),
+ put(TEST_KEY, ANOTHER_VALUE)
+ );
+ }
+ },
+ MULTI_INVOKE {
Review Comment:
The command is called MultiInvokeCommand. What name would you suggest instead for this enum constant?
--
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
Re: [PR] IGNITE-28202 Advance last applied index for each Metastorage command [ignite-3]
Posted by "rpuch (via GitHub)" <gi...@apache.org>.
rpuch commented on code in PR #7763:
URL: https://github.com/apache/ignite-3/pull/7763#discussion_r2923901585
##########
modules/metastorage/src/integrationTest/java/org/apache/ignite/internal/metastorage/impl/ItMetaStorageServiceTest.java:
##########
@@ -395,7 +401,7 @@ public void testGetWithUpperBoundRevision() {
public void testGetAll() {
Node node = prepareNodes(1).get(0);
- when(node.mockStorage.getAll(anyList())).thenReturn(EXPECTED_SRV_RESULT_COLL);
+ doReturn(EXPECTED_SRV_RESULT_COLL).when(node.mockStorage).getAll(anyList());
Review Comment:
It's simply easier this way. Using the real storage API would require even more changes. Current approach doesn't seem to cause any problems; I think we can live with it
--
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
Re: [PR] IGNITE-28202 Advance last applied index for each Metastorage command [ignite-3]
Posted by "rpuch (via GitHub)" <gi...@apache.org>.
rpuch commented on code in PR #7763:
URL: https://github.com/apache/ignite-3/pull/7763#discussion_r2923755013
##########
modules/metastorage/src/integrationTest/java/org/apache/ignite/internal/metastorage/impl/ItIdempotentCommandCacheTest.java:
##########
@@ -329,23 +339,63 @@ boolean checkValueInStorage(byte[] testKey, byte[] testValueExpected) {
@BeforeEach
void setUp(TestInfo testInfo) {
- startCluster(testInfo);
+ this.testInfo = testInfo;
+
+ if (testInfo.getTestMethod().orElseThrow().isAnnotationPresent(DisableIdleSafeTimePropagation.class)) {
+ assertThat(
+ systemDistributedConfiguration.idleSafeTimeSyncIntervalMillis().update(HOURS.toMillis(1)),
+ willCompleteSuccessfully()
+ );
+ }
+
+ startCluster();
}
@AfterEach
void tearDown() throws Exception {
- closeAll(nodes.stream());
+ closeAllManually(nodes.stream());
}
- @Test
- public void testIdempotentInvoke() throws InterruptedException {
+ @ParameterizedTest
+ @EnumSource(Invoker.class)
+ void testIdempotentInvoke(Invoker invoker) {
+ Node leader = leader(raftClient());
+
+ boolean result = doRetriedInvoke(invoker, leader);
+
+ assertTrue(result);
+ assertTrue(leader.checkValueInStorage(TEST_KEY.bytes(), TEST_VALUE));
+ }
+
+ private boolean doRetriedInvoke(Invoker invoker, Node leader) {
AtomicInteger writeActionReqCount = new AtomicInteger();
CompletableFuture<Void> retryBlockingFuture = new CompletableFuture<>();
log.info("Test: blocking messages.");
- Node leader = leader(raftClient());
+ dropResponseToFirstInvoke(leader, writeActionReqCount, retryBlockingFuture);
+
+ MetaStorageManager metaStorageManager = leader.metaStorageManager;
+
+ CompletableFuture<Boolean> fut = invoker.invokeOn(metaStorageManager);
+
+ await().until(() -> leader.checkValueInStorage(TEST_KEY.bytes(), TEST_VALUE));
+
+ log.info("Test: value appeared in storage.");
+
+ assertTrue(retryBlockingFuture.complete(null));
Review Comment:
I just refactored this code, but I suppose that it's because `complete()` will return `false` if it's already completed (in this case, by an exception), and it makes sense to check for it, I guess
--
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
Re: [PR] IGNITE-28202 Advance last applied index for each Metastorage command [ignite-3]
Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
sashapolo commented on code in PR #7763:
URL: https://github.com/apache/ignite-3/pull/7763#discussion_r2923777409
##########
modules/metastorage/src/integrationTest/java/org/apache/ignite/internal/metastorage/impl/ItIdempotentCommandCacheTest.java:
##########
@@ -607,4 +650,34 @@ private void startCluster(TestInfo testInfo) {
nodes.forEach(Node::deployWatches);
}
+
+ @Target(ElementType.METHOD)
+ @Retention(RetentionPolicy.RUNTIME)
+ private @interface DisableIdleSafeTimePropagation {
+ }
+
+ private enum Invoker {
+ INVOKE {
+ @Override
+ CompletableFuture<Boolean> invokeOn(MetaStorageManager metaStorageManager) {
+ return metaStorageManager.invoke(
+ notExists(TEST_KEY),
+ put(TEST_KEY, TEST_VALUE),
+ put(TEST_KEY, ANOTHER_VALUE)
+ );
+ }
+ },
+ MULTI_INVOKE {
Review Comment:
I would call it `IFF_INVOKE`, but whatever, up to you
--
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
Re: [PR] IGNITE-28202 Advance last applied index for each Metastorage command [ignite-3]
Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
sashapolo commented on code in PR #7763:
URL: https://github.com/apache/ignite-3/pull/7763#discussion_r2922994497
##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/server/raft/MetaStorageWriteHandler.java:
##########
@@ -114,6 +115,14 @@ public class MetaStorageWriteHandler {
* Processes a given {@link WriteCommand}.
*/
void handleWriteCommand(CommandClosure<WriteCommand> clo) {
+ handleWriteCommandInternal(clo);
+
+ assert lastAppliedIndex() == clo.index() : "Last applied index after command application is not equal to the command index "
Review Comment:
Can we use `String.format` here?
##########
modules/metastorage/src/integrationTest/java/org/apache/ignite/internal/metastorage/impl/ItMetaStorageServiceTest.java:
##########
@@ -395,7 +401,7 @@ public void testGetWithUpperBoundRevision() {
public void testGetAll() {
Node node = prepareNodes(1).get(0);
- when(node.mockStorage.getAll(anyList())).thenReturn(EXPECTED_SRV_RESULT_COLL);
+ doReturn(EXPECTED_SRV_RESULT_COLL).when(node.mockStorage).getAll(anyList());
Review Comment:
Since we are now using real storage implementation, why do we need to mock this? Can we just insert the values?
##########
modules/metastorage/src/test/java/org/apache/ignite/internal/metastorage/server/raft/MetaStorageListenerTest.java:
##########
@@ -0,0 +1,306 @@
+/*
+ * 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.metastorage.server.raft;
+
+import static org.apache.ignite.internal.metastorage.dsl.Conditions.notExists;
+import static org.apache.ignite.internal.metastorage.dsl.Operations.noop;
+import static org.apache.ignite.internal.metastorage.dsl.Operations.ops;
+import static org.apache.ignite.internal.util.IgniteUtils.closeAllManually;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+
+import java.io.Serializable;
+import java.nio.ByteBuffer;
+import java.util.List;
+import java.util.UUID;
+import org.apache.ignite.internal.hlc.HybridClock;
+import org.apache.ignite.internal.hlc.HybridClockImpl;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.lang.ByteArray;
+import org.apache.ignite.internal.metastorage.command.InvokeCommand;
+import org.apache.ignite.internal.metastorage.command.MetaStorageCommandsFactory;
+import org.apache.ignite.internal.metastorage.command.MetaStorageWriteCommand;
+import org.apache.ignite.internal.metastorage.command.MultiInvokeCommand;
+import org.apache.ignite.internal.metastorage.command.PutCommand;
+import org.apache.ignite.internal.metastorage.dsl.MetaStorageMessagesFactory;
+import org.apache.ignite.internal.metastorage.dsl.Statements;
+import org.apache.ignite.internal.metastorage.server.KeyValueStorage;
+import org.apache.ignite.internal.metastorage.server.SimpleInMemoryKeyValueStorage;
+import org.apache.ignite.internal.metastorage.server.time.ClusterTimeImpl;
+import org.apache.ignite.internal.raft.Command;
+import org.apache.ignite.internal.raft.IndexWithTerm;
+import org.apache.ignite.internal.raft.RaftGroupConfiguration;
+import org.apache.ignite.internal.raft.WriteCommand;
+import org.apache.ignite.internal.raft.service.CommandClosure;
+import org.apache.ignite.internal.util.IgniteSpinBusyLock;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+
+class MetaStorageListenerTest {
+ private static final MetaStorageCommandsFactory commandsFactory = new MetaStorageCommandsFactory();
+ private static final MetaStorageMessagesFactory messagesFactory = new MetaStorageMessagesFactory();
+
+ private static final long COMMAND_TERM = 3;
+
+ private static final long PRE_TARGET_COMMAND_INDEX = 1;
+ private static final long TARGET_COMMAND_INDEX = 2;
+
+ private static final HybridClock clock = new HybridClockImpl();
+
+ private KeyValueStorage storage;
+ private ClusterTimeImpl clusterTime;
+
+ private MetaStorageListener listener;
+
+ @BeforeEach
+ void setUp() {
+ storage = new SimpleInMemoryKeyValueStorage("test");
+ clusterTime = new ClusterTimeImpl("test", new IgniteSpinBusyLock(), clock);
+
+ listener = new MetaStorageListener(storage, clock, clusterTime);
+
+ storage.start();
+ }
+
+ @AfterEach
+ void cleanup() throws Exception {
+ if (listener != null) {
+ listener.onShutdown();
+ }
+
+ closeAllManually(clusterTime, storage);
+ }
+
+ @ParameterizedTest
+ @MethodSource("commandsVariationsForIndexAdvanceTesting")
+ void commandsAdvanceLastAppliedIndex(MetaStorageWriteCommand command) {
+ testCommandAdvancedLastAppliedIndex(command);
+ }
+
+ private static List<MetaStorageWriteCommand> commandsVariationsForIndexAdvanceTesting() {
+ return List.of(
+ somePutCommand(),
+ commandsFactory.putAllCommand()
+ .keys(List.of(ByteBuffer.allocate(3)))
+ .values(List.of(ByteBuffer.allocate(3)))
+ .initiatorTime(clock.now())
Review Comment:
Minor nitpick, but I think we can extract `clock.now` into a variable)
##########
modules/metastorage/src/integrationTest/java/org/apache/ignite/internal/metastorage/impl/ItMetaStorageServiceTest.java:
##########
@@ -736,7 +754,12 @@ public void testInvoke() {
byte[] expVal = {2};
- when(node.mockStorage.invoke(any(), any(), any(), any(), any())).thenReturn(true);
+ doAnswer(invocation -> {
Review Comment:
What's the point of this mocking?
##########
modules/metastorage/src/integrationTest/java/org/apache/ignite/internal/metastorage/impl/ItIdempotentCommandCacheTest.java:
##########
@@ -329,23 +339,63 @@ boolean checkValueInStorage(byte[] testKey, byte[] testValueExpected) {
@BeforeEach
void setUp(TestInfo testInfo) {
- startCluster(testInfo);
+ this.testInfo = testInfo;
+
+ if (testInfo.getTestMethod().orElseThrow().isAnnotationPresent(DisableIdleSafeTimePropagation.class)) {
+ assertThat(
+ systemDistributedConfiguration.idleSafeTimeSyncIntervalMillis().update(HOURS.toMillis(1)),
+ willCompleteSuccessfully()
+ );
+ }
+
+ startCluster();
}
@AfterEach
void tearDown() throws Exception {
- closeAll(nodes.stream());
+ closeAllManually(nodes.stream());
}
- @Test
- public void testIdempotentInvoke() throws InterruptedException {
+ @ParameterizedTest
+ @EnumSource(Invoker.class)
+ void testIdempotentInvoke(Invoker invoker) {
+ Node leader = leader(raftClient());
+
+ boolean result = doRetriedInvoke(invoker, leader);
+
+ assertTrue(result);
+ assertTrue(leader.checkValueInStorage(TEST_KEY.bytes(), TEST_VALUE));
+ }
+
+ private boolean doRetriedInvoke(Invoker invoker, Node leader) {
AtomicInteger writeActionReqCount = new AtomicInteger();
CompletableFuture<Void> retryBlockingFuture = new CompletableFuture<>();
log.info("Test: blocking messages.");
- Node leader = leader(raftClient());
+ dropResponseToFirstInvoke(leader, writeActionReqCount, retryBlockingFuture);
+
+ MetaStorageManager metaStorageManager = leader.metaStorageManager;
+
+ CompletableFuture<Boolean> fut = invoker.invokeOn(metaStorageManager);
+
+ await().until(() -> leader.checkValueInStorage(TEST_KEY.bytes(), TEST_VALUE));
+
+ log.info("Test: value appeared in storage.");
+
+ assertTrue(retryBlockingFuture.complete(null));
Review Comment:
Why do we need an assertion here?
##########
modules/metastorage/src/integrationTest/java/org/apache/ignite/internal/metastorage/impl/ItMetaStorageServiceTest.java:
##########
@@ -685,7 +691,19 @@ public void testMultiInvoke() {
var ifCaptor = ArgumentCaptor.forClass(If.class);
- when(node.mockStorage.invoke(any(), any(), any())).thenReturn(ops().yield(true).result(), null, null);
+ doAnswer(new Answer() {
Review Comment:
and this?
##########
modules/metastorage/src/integrationTest/java/org/apache/ignite/internal/metastorage/impl/ItIdempotentCommandCacheTest.java:
##########
@@ -329,23 +339,63 @@ boolean checkValueInStorage(byte[] testKey, byte[] testValueExpected) {
@BeforeEach
void setUp(TestInfo testInfo) {
- startCluster(testInfo);
+ this.testInfo = testInfo;
+
+ if (testInfo.getTestMethod().orElseThrow().isAnnotationPresent(DisableIdleSafeTimePropagation.class)) {
Review Comment:
Could you please leave a comment about why this is needed?
##########
modules/metastorage/src/integrationTest/java/org/apache/ignite/internal/metastorage/impl/ItIdempotentCommandCacheTest.java:
##########
@@ -582,7 +625,7 @@ private static IdempotentCommand buildKeyNotExistsMultiInvokeCommand(
.build();
}
- private void startCluster(TestInfo testInfo) {
+ private void startCluster() {
Review Comment:
Not related to this PR, but I think making `Node` class non-static may make the code shorter and simpler
##########
modules/metastorage/src/integrationTest/java/org/apache/ignite/internal/metastorage/impl/ItIdempotentCommandCacheTest.java:
##########
@@ -607,4 +650,34 @@ private void startCluster(TestInfo testInfo) {
nodes.forEach(Node::deployWatches);
}
+
+ @Target(ElementType.METHOD)
+ @Retention(RetentionPolicy.RUNTIME)
+ private @interface DisableIdleSafeTimePropagation {
+ }
+
+ private enum Invoker {
+ INVOKE {
+ @Override
+ CompletableFuture<Boolean> invokeOn(MetaStorageManager metaStorageManager) {
+ return metaStorageManager.invoke(
+ notExists(TEST_KEY),
+ put(TEST_KEY, TEST_VALUE),
+ put(TEST_KEY, ANOTHER_VALUE)
+ );
+ }
+ },
+ MULTI_INVOKE {
Review Comment:
Why is this a "multi-invoke"? It does the same thing just through a different API. Or do we call that API "multi-invoke"?
--
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
Re: [PR] IGNITE-28202 Advance last applied index for each Metastorage command [ignite-3]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #7763:
URL: https://github.com/apache/ignite-3/pull/7763#discussion_r2922748257
##########
modules/metastorage/src/test/java/org/apache/ignite/internal/metastorage/server/raft/MetaStorageListenerTest.java:
##########
@@ -0,0 +1,289 @@
+/*
+ * 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.metastorage.server.raft;
+
+import static org.apache.ignite.internal.metastorage.dsl.Conditions.notExists;
+import static org.apache.ignite.internal.metastorage.dsl.Operations.noop;
+import static org.apache.ignite.internal.metastorage.dsl.Operations.ops;
+import static org.apache.ignite.internal.util.IgniteUtils.closeAllManually;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+
+import java.io.Serializable;
+import java.nio.ByteBuffer;
+import java.util.List;
+import java.util.UUID;
+import org.apache.ignite.internal.hlc.HybridClock;
+import org.apache.ignite.internal.hlc.HybridClockImpl;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.lang.ByteArray;
+import org.apache.ignite.internal.metastorage.command.InvokeCommand;
+import org.apache.ignite.internal.metastorage.command.MetaStorageCommandsFactory;
+import org.apache.ignite.internal.metastorage.command.MetaStorageWriteCommand;
+import org.apache.ignite.internal.metastorage.command.MultiInvokeCommand;
+import org.apache.ignite.internal.metastorage.command.PutCommand;
+import org.apache.ignite.internal.metastorage.dsl.MetaStorageMessagesFactory;
+import org.apache.ignite.internal.metastorage.dsl.Statements;
+import org.apache.ignite.internal.metastorage.server.KeyValueStorage;
+import org.apache.ignite.internal.metastorage.server.SimpleInMemoryKeyValueStorage;
+import org.apache.ignite.internal.metastorage.server.time.ClusterTimeImpl;
+import org.apache.ignite.internal.raft.IndexWithTerm;
+import org.apache.ignite.internal.raft.WriteCommand;
+import org.apache.ignite.internal.raft.service.CommandClosure;
+import org.apache.ignite.internal.util.IgniteSpinBusyLock;
+import org.jetbrains.annotations.Nullable;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+
+class MetaStorageListenerTest {
+ private static final MetaStorageCommandsFactory commandsFactory = new MetaStorageCommandsFactory();
+ private static final MetaStorageMessagesFactory messagesFactory = new MetaStorageMessagesFactory();
+
+ private static final long COMMAND_TERM = 3;
+
+ private static final long PRE_TARGET_COMMAND_INDEX = 1;
+ private static final long TARGET_COMMAND_INDEX = 2;
+
+ private static final HybridClock clock = new HybridClockImpl();
+
+ private KeyValueStorage storage;
+ private ClusterTimeImpl clusterTime;
+
+ private MetaStorageListener listener;
+
+ @BeforeEach
+ void setUp() {
+ storage = new SimpleInMemoryKeyValueStorage("test");
+ clusterTime = new ClusterTimeImpl("test", new IgniteSpinBusyLock(), clock);
+
+ listener = new MetaStorageListener(storage, clock, clusterTime);
+
+ storage.start();
+ }
+
+ @AfterEach
+ void cleanup() throws Exception {
+ if (listener != null) {
+ listener.onShutdown();
+ }
+
+ closeAllManually(clusterTime, storage);
+ }
+
+ @ParameterizedTest
+ @MethodSource("commandsVariationsForIndexAdvanceTesting")
+ void commandsAdvanceLastAppliedIndex(MetaStorageWriteCommand command) {
+ testCommandAdvancedLastAppliedIndex(command);
+ }
+
+ private static List<MetaStorageWriteCommand> commandsVariationsForIndexAdvanceTesting() {
+ return List.of(
+ somePutCommand(),
+ commandsFactory.putAllCommand()
+ .keys(List.of(ByteBuffer.allocate(3)))
+ .values(List.of(ByteBuffer.allocate(3)))
+ .initiatorTime(clock.now())
+ .safeTime(clock.now())
+ .build(),
+ commandsFactory.removeCommand()
+ .key(ByteBuffer.allocate(3))
+ .initiatorTime(clock.now())
+ .safeTime(clock.now())
+ .build(),
+ commandsFactory.removeAllCommand()
+ .keys(List.of(ByteBuffer.allocate(3)))
+ .initiatorTime(clock.now())
+ .safeTime(clock.now())
+ .build(),
+ commandsFactory.removeByPrefixCommand()
+ .prefix(ByteBuffer.allocate(3))
+ .initiatorTime(clock.now())
+ .safeTime(clock.now())
+ .build(),
+ someInvokeCommand(),
+ someMultiInvokeCommand(),
+
+ // Normal command that gets applied.
+ commandsFactory.syncTimeCommand()
+ .initiatorTime(clock.now())
+ .safeTime(clock.now())
+ .initiatorTerm(COMMAND_TERM)
+ .build(),
+
+ // Command that gets discarded.
+ commandsFactory.syncTimeCommand()
+ .initiatorTime(clock.now())
+ .safeTime(clock.now())
+ .initiatorTerm(COMMAND_TERM - 1)
+ .build()
+ );
+ }
+
+ private void testCommandAdvancedLastAppliedIndex(MetaStorageWriteCommand command) {
+ applySingleCommand(command, TARGET_COMMAND_INDEX, COMMAND_TERM);
+
+ IndexWithTerm indexWithTerm = storage.getIndexWithTerm();
+
+ assertThat(indexWithTerm, is(notNullValue()));
+ assertThat(indexWithTerm.index(), is(TARGET_COMMAND_INDEX));
+ assertThat(indexWithTerm.term(), is(COMMAND_TERM));
+ }
+
+ private void applySingleCommand(MetaStorageWriteCommand command, long index, long term) {
+ listener.onBeforeApply(command);
+ listener.onWrite(List.of(commandClosure(command, index, term)).iterator());
+ }
Review Comment:
In applySingleCommand, the return value of listener.onBeforeApply(command) is ignored. In real Raft flow the (potentially cloned/modified) command returned from onBeforeApply is what gets applied in onWrite; skipping it makes the test diverge from production behavior (e.g., safeTime adjustment/clone semantics). Consider using the returned Command (cast back to MetaStorageWriteCommand) when building the CommandClosure.
##########
modules/metastorage/src/main/java/org/apache/ignite/internal/metastorage/server/raft/MetaStorageWriteHandler.java:
##########
@@ -114,6 +115,14 @@ public class MetaStorageWriteHandler {
* Processes a given {@link WriteCommand}.
*/
void handleWriteCommand(CommandClosure<WriteCommand> clo) {
+ handleWriteCommandInternal(clo);
+
+ assert lastAppliedIndex() == clo.index() : "Last applied index after command application is not equal to the command index "
+ + "[lastAppliedIndex=" + lastAppliedIndex() + ", commandIndex=" + clo.index()
Review Comment:
The assertion message computes lastAppliedIndex() again, which can produce a different value than the one used in the assert condition (and does an extra storage read). Consider storing lastAppliedIndex() in a local variable and using it both for the condition and for the message to keep diagnostics consistent and avoid duplicate work when assertions are enabled.
```suggestion
long lastAppliedIndex = lastAppliedIndex();
assert lastAppliedIndex == clo.index() : "Last applied index after command application is not equal to the command index "
+ "[lastAppliedIndex=" + lastAppliedIndex + ", commandIndex=" + clo.index()
```
--
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
Re: [PR] IGNITE-28202 Advance last applied index for each Metastorage command [ignite-3]
Posted by "rpuch (via GitHub)" <gi...@apache.org>.
rpuch commented on code in PR #7763:
URL: https://github.com/apache/ignite-3/pull/7763#discussion_r2923913861
##########
modules/metastorage/src/integrationTest/java/org/apache/ignite/internal/metastorage/impl/ItMetaStorageServiceTest.java:
##########
@@ -685,7 +691,19 @@ public void testMultiInvoke() {
var ifCaptor = ArgumentCaptor.forClass(If.class);
- when(node.mockStorage.invoke(any(), any(), any())).thenReturn(ops().yield(true).result(), null, null);
+ doAnswer(new Answer() {
Review Comment:
Here, we need to first and subsequent invocations to return different results, hence the mocking
--
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
Re: [PR] IGNITE-28202 Advance last applied index for each Metastorage command [ignite-3]
Posted by "rpuch (via GitHub)" <gi...@apache.org>.
rpuch merged PR #7763:
URL: https://github.com/apache/ignite-3/pull/7763
--
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