tkalkirill commented on code in PR #2814: URL: https://github.com/apache/ignite-3/pull/2814#discussion_r1386172458
########## modules/raft/src/main/java/org/apache/ignite/raft/jraft/rpc/ReadActionRequest.java: ########## @@ -0,0 +1,38 @@ +/* + * 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.raft.jraft.rpc; + +import org.apache.ignite.internal.raft.ReadCommand; +import org.apache.ignite.network.annotations.Transferable; +import org.apache.ignite.raft.jraft.RaftMessageGroup.RpcActionMessageGroup; + +/** + * Submit an action to a replication group. + */ +@Transferable(RpcActionMessageGroup.READ_ACTION_REQUEST) +public interface ReadActionRequest extends ActionRequest { + /** + * @return Action's command. + */ + ReadCommand command(); + + /** + * @return {@code True} for linearizable reading. Review Comment: I don't quite understand this description, could you expand on it? I see that there is a command for reading, can they be not only for reading? How can they **not** be safe reading? ########## modules/raft/src/main/java/org/apache/ignite/internal/raft/RaftGroupServiceImpl.java: ########## @@ -449,11 +449,20 @@ public <R> CompletableFuture<R> run(Command cmd) { return refreshLeader().thenCompose(res -> run(cmd)); } - Function<Peer, ActionRequest> requestFactory = targetPeer -> factory.actionRequest() - .command(cmd) - .groupId(groupId) - .readOnlySafe(true) - .build(); + Function<Peer, ActionRequest> requestFactory; Review Comment: Suggestion: How about creating a separate, understandable functional interface with a description? Even with implementations to make it clearer why this is. ########## modules/raft/src/main/java/org/apache/ignite/raft/jraft/rpc/ReadActionRequest.java: ########## @@ -0,0 +1,38 @@ +/* + * 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.raft.jraft.rpc; + +import org.apache.ignite.internal.raft.ReadCommand; +import org.apache.ignite.network.annotations.Transferable; +import org.apache.ignite.raft.jraft.RaftMessageGroup.RpcActionMessageGroup; + +/** + * Submit an action to a replication group. + */ +@Transferable(RpcActionMessageGroup.READ_ACTION_REQUEST) +public interface ReadActionRequest extends ActionRequest { + /** + * @return Action's command. + */ Review Comment: ```suggestion /** Returns read command. */ ``` ########## modules/raft/src/main/java/org/apache/ignite/raft/jraft/rpc/ReadActionRequest.java: ########## @@ -0,0 +1,38 @@ +/* + * 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.raft.jraft.rpc; + +import org.apache.ignite.internal.raft.ReadCommand; +import org.apache.ignite.network.annotations.Transferable; +import org.apache.ignite.raft.jraft.RaftMessageGroup.RpcActionMessageGroup; + +/** + * Submit an action to a replication group. + */ +@Transferable(RpcActionMessageGroup.READ_ACTION_REQUEST) +public interface ReadActionRequest extends ActionRequest { + /** + * @return Action's command. + */ + ReadCommand command(); + + /** + * @return {@code True} for linearizable reading. + */ Review Comment: ```suggestion /** Returns {@code True} for linearizable reading. */ ``` ########## modules/raft/src/main/java/org/apache/ignite/raft/jraft/rpc/ReadActionRequest.java: ########## @@ -0,0 +1,38 @@ +/* + * 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.raft.jraft.rpc; + +import org.apache.ignite.internal.raft.ReadCommand; +import org.apache.ignite.network.annotations.Transferable; +import org.apache.ignite.raft.jraft.RaftMessageGroup.RpcActionMessageGroup; + +/** + * Submit an action to a replication group. + */ Review Comment: ```suggestion /** Submit a read action to a replication group. */ ``` ########## modules/raft/src/main/java/org/apache/ignite/raft/jraft/rpc/WriteActionRequest.java: ########## @@ -0,0 +1,33 @@ +/* + * 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.raft.jraft.rpc; + +import org.apache.ignite.internal.raft.WriteCommand; +import org.apache.ignite.network.annotations.Transferable; +import org.apache.ignite.raft.jraft.RaftMessageGroup.RpcActionMessageGroup; + +/** + * Submit an action to a replication group. + */ Review Comment: ```suggestion /** Submit a write action to a replication group. */ ``` ########## modules/raft/src/main/java/org/apache/ignite/raft/jraft/rpc/impl/ActionRequestProcessor.java: ########## @@ -82,25 +84,30 @@ public void handleRequest(RpcContext rpcCtx, ActionRequest request) { JraftServerImpl.DelegatingStateMachine fsm = (JraftServerImpl.DelegatingStateMachine) node.getOptions().getFsm(); - if (request.command() instanceof WriteCommand) { + if (request instanceof WriteActionRequest) { if (fsm.getListener() instanceof BeforeApplyHandler) { synchronized (groupIdSyncMonitor(request.groupId())) { callOnBeforeApply(request, fsm); - applyWrite(node, request, rpcCtx); + applyWrite(node, (WriteActionRequest) request, rpcCtx); } } else { - applyWrite(node, request, rpcCtx); + applyWrite(node, (WriteActionRequest) request, rpcCtx); } } else { if (fsm.getListener() instanceof BeforeApplyHandler) { callOnBeforeApply(request, fsm); } - applyRead(node, request, rpcCtx); + applyRead(node, (ReadActionRequest) request, rpcCtx); } } + private static void callOnBeforeApply(ActionRequest request, DelegatingStateMachine fsm) { - ((BeforeApplyHandler) fsm.getListener()).onBeforeApply(request.command()); + Command command = request instanceof WriteActionRequest + ? ((WriteActionRequest) request).command() + : ((ReadActionRequest) request).command(); Review Comment: Can we create one common interface that will return a command so as not to use `instanceof`? ########## modules/raft/src/main/java/org/apache/ignite/raft/jraft/rpc/WriteActionRequest.java: ########## @@ -0,0 +1,33 @@ +/* + * 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.raft.jraft.rpc; + +import org.apache.ignite.internal.raft.WriteCommand; +import org.apache.ignite.network.annotations.Transferable; +import org.apache.ignite.raft.jraft.RaftMessageGroup.RpcActionMessageGroup; + +/** + * Submit an action to a replication group. + */ +@Transferable(RpcActionMessageGroup.WRITE_ACTION_REQUEST) +public interface WriteActionRequest extends ActionRequest { + /** + * @return Action's command. + */ Review Comment: ```suggestion /** Returns write action' command. */ ``` ########## modules/runner/src/integrationTest/java/org/apache/ignite/internal/raftsnapshot/ItTableRaftSnapshotsTest.java: ########## @@ -667,8 +667,8 @@ void snapshotInstallTimeoutDoesNotBreakSubsequentInstallsWhenSecondAttemptIsIden try { prepareClusterForInstallingSnapshotToNode2(DEFAULT_STORAGE_ENGINE, theCluster -> { BiPredicate<String, NetworkMessage> dropSafeTimeUntilSecondInstallSnapshotRequestIsProcessed = (recipientId, message) -> - message instanceof ActionRequest - && ((ActionRequest) message).command() instanceof SafeTimeSyncCommand + message instanceof WriteActionRequest Review Comment: Same about common interface. ########## modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItBuildIndexTest.java: ########## @@ -241,8 +241,8 @@ private static BiPredicate<String, NetworkMessage> waitSendBuildIndexCommand( boolean dropBuildIndexCommand ) { return (nodeConsistentId, networkMessage) -> { - if (networkMessage instanceof ActionRequest) { - Command command = ((ActionRequest) networkMessage).command(); + if (networkMessage instanceof WriteActionRequest) { Review Comment: Same ########## modules/raft/src/test/java/org/apache/ignite/internal/raft/RaftGroupServiceTest.java: ########## @@ -617,7 +618,7 @@ private void mockUserInput(boolean delay, @Nullable Peer peer) { argThat(new ArgumentMatcher<ActionRequest>() { @Override public boolean matches(ActionRequest arg) { - return arg.command() instanceof TestWriteCommand; + return arg instanceof WriteActionRequest && ((WriteActionRequest) arg).command() instanceof TestWriteCommand; Review Comment: It would be more convenient with a common interface that returns a command. ########## modules/raft/src/main/java/org/apache/ignite/raft/jraft/rpc/impl/IgniteRpcServer.java: ########## @@ -197,6 +191,26 @@ else if (prc.executor() != null) { LOG.warn("A request execution was rejected [sender={} req={} reason={}]", sender, S.toString(message), e.getMessage()); } } + + private @Nullable RpcProcessor<NetworkMessage> getProcessor(Class<?> cls) { + RpcProcessor<NetworkMessage> prc = processors.get(cls.getName()); + + if (prc != null) { + processors.putIfAbsent(cls.getName(), prc); Review Comment: Why `putIfAbsent` if it already exists above? -- 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]
