tkalkirill commented on code in PR #2450: URL: https://github.com/apache/ignite-3/pull/2450#discussion_r1301241925
########## modules/core/src/test/java/org/apache/ignite/internal/util/VarIntUtilsTest.java: ########## @@ -0,0 +1,72 @@ +/* + * 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.util; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + +import java.nio.ByteBuffer; +import java.util.stream.Stream; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +class VarIntUtilsTest { Review Comment: I think that we need a test that will honestly check `VarIntUtils#varIntLength`. ########## modules/core/src/main/java/org/apache/ignite/internal/util/VarIntUtils.java: ########## @@ -0,0 +1,93 @@ +/* + * 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.util; + +import java.nio.ByteBuffer; + +/** + * Utilities to work with general-purpose varints. + */ +public class VarIntUtils { + /** + * Returns number of bytes that are needed to represent the given integer as a varint. + * + * @param val Int value. + * @return Number of bytes that are needed to represent the given integer as a varint. Review Comment: ```suggestion * @param val Int value. ``` ########## modules/raft/src/main/java/org/apache/ignite/internal/raft/server/impl/JraftServerImpl.java: ########## @@ -122,10 +125,12 @@ public class JraftServerImpl implements RaftServer { private ExecutorService requestExecutor; /** Marshaller for RAFT commands. */ - private final Marshaller commandsMarshaller; + private final Marshaller defaultCommandsMarshaller; Review Comment: why default? ########## modules/raft/src/main/java/org/apache/ignite/raft/jraft/rpc/impl/AppendEntriesRequestInterceptor.java: ########## @@ -0,0 +1,41 @@ +/* + * 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.impl; + +import org.apache.ignite.raft.jraft.rpc.Message; +import org.apache.ignite.raft.jraft.rpc.RaftServerService; +import org.apache.ignite.raft.jraft.rpc.RpcRequestClosure; +import org.apache.ignite.raft.jraft.rpc.RpcRequests.AppendEntriesRequest; +import org.jetbrains.annotations.Nullable; + +/** + * Intercepts {@link AppendEntriesRequest}s as they come in. It might be used to handle such a request in a non-standard + * way (like returning EBUSY under special circumstances instead of the standard behavior). + */ +public interface AppendEntriesRequestInterceptor { + /** + * Intercepts handling of an incoming request. If non-null message is returned, the standard handling is omitted. + * + * @param service Server service. + * @param request Request in question. + * @param done Done closure. + * @return A message to return to the caller, or {@code null} if standard handling should be used. + */ + @Nullable + Message intercept(RaftServerService service, AppendEntriesRequest request, RpcRequestClosure done); Review Comment: ```suggestion @Nullable Message intercept(RaftServerService service, AppendEntriesRequest request, RpcRequestClosure done); ``` ########## modules/runner/src/integrationTest/java/org/apache/ignite/internal/schemasync/ItSchemaSyncAndReplicationTest.java: ########## @@ -0,0 +1,173 @@ +/* + * 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.schemasync; + +import static org.apache.ignite.internal.SessionUtils.executeUpdate; +import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.function.BooleanSupplier; +import java.util.logging.LogRecord; +import java.util.logging.Logger; +import org.apache.ignite.internal.ClusterPerTestIntegrationTest; +import org.apache.ignite.internal.ReplicationGroupsUtils; +import org.apache.ignite.internal.app.IgniteImpl; +import org.apache.ignite.internal.metastorage.server.raft.MetastorageGroupId; +import org.apache.ignite.internal.storage.MvPartitionStorage; +import org.apache.ignite.internal.storage.RowId; +import org.apache.ignite.internal.table.TableImpl; +import org.apache.ignite.internal.table.distributed.schema.CheckCatalogVersionOnAppendEntries; +import org.apache.ignite.internal.test.WatchListenerInhibitor; +import org.apache.ignite.internal.testframework.jul.NoOpHandler; +import org.apache.ignite.table.KeyValueView; +import org.apache.ignite.table.Tuple; +import org.junit.jupiter.api.Test; + +/** + * Tests about interaction between Schema Synchronization and Replication. + */ +@SuppressWarnings("resource") +class ItSchemaSyncAndReplicationTest extends ClusterPerTestIntegrationTest { + @Override + protected int initialNodes() { + return 3; + } + + /** + * The replication mechanism must not replicate commands for which schemas are not yet available on the node + * to which replication happens (in Raft, it means that followers/learners cannot receive commands that they + * cannot execute without waiting for schemas). This method tests this scenario. + */ + @Test + void laggingSchemasPreventPartitionDataReplication() throws Exception { + createTestTableWith3Replicas(); + + final int notInhibitedNodeIndex = 0; + transferLeadershipsTo(notInhibitedNodeIndex); + + IgniteImpl nodeToInhibitMetaStorage = cluster.node(1); + + WatchListenerInhibitor listenerInhibitor = WatchListenerInhibitor.metastorageEventsInhibitor(nodeToInhibitMetaStorage); + listenerInhibitor.startInhibit(); + + try { + CountDownLatch rejectionTriggered = rejectionDueToMetadataLagTriggered(); + + updateTableSchemaAt(notInhibitedNodeIndex); + putToTableAt(notInhibitedNodeIndex); + + assertTrue(rejectionTriggered.await(10, TimeUnit.SECONDS), "Did not see rejections due to lagging metadata"); + + assertTrue(solePartitionIsEmpty(nodeToInhibitMetaStorage), "Something was written to the partition"); + + listenerInhibitor.stopInhibit(); + + assertTrue( + waitForCondition(() -> !solePartitionIsEmpty(nodeToInhibitMetaStorage), 10_000), + "Nothing was written to partition even after inhibiting was cancelled" + ); + } finally { + listenerInhibitor.stopInhibit(); + } + } + + private void createTestTableWith3Replicas() throws InterruptedException { + String zoneSql = "create zone test_zone with partitions=1, replicas=3"; + String sql = "create table test (key int primary key, value varchar(20))" + + " with primary_zone='TEST_ZONE'"; + + cluster.doInSession(0, session -> { + executeUpdate(zoneSql, session); + executeUpdate(sql, session); + }); + + waitForTableToStart(); + } + + private void waitForTableToStart() throws InterruptedException { + // TODO: IGNITE-18733 - remove this wait because when a table creation query is executed, the table must be fully ready. + + BooleanSupplier tableStarted = () -> { + int numberOfStartedRaftNodes = cluster.runningNodes() + .map(ReplicationGroupsUtils::tablePartitionIds) + .mapToInt(List::size) + .sum(); + return numberOfStartedRaftNodes == 3; + }; + + assertTrue(waitForCondition(tableStarted, 10_000), "Did not see all table RAFT nodes started"); + } + + private void transferLeadershipsTo(int nodeIndex) throws InterruptedException { + cluster.transferLeadershipTo(nodeIndex, MetastorageGroupId.INSTANCE); + cluster.transferLeadershipTo(nodeIndex, cluster.solePartitionId()); + } + + private static CountDownLatch rejectionDueToMetadataLagTriggered() { + Logger interceptorLogger = Logger.getLogger(CheckCatalogVersionOnAppendEntries.class.getName()); + + CountDownLatch rejectionTriggered = new CountDownLatch(1); Review Comment: Maybe CompletableFuture? ########## modules/table/src/main/java/org/apache/ignite/internal/table/distributed/command/CatalogVersionAware.java: ########## @@ -0,0 +1,28 @@ +/* + * 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.table.distributed.command; + +/** + * A command that requires certain level of catalog version to be locally available just to be accepted on the node. + */ +public interface CatalogVersionAware { Review Comment: Please add `@FunctionalInterface` ########## modules/table/src/main/java/org/apache/ignite/internal/table/distributed/schema/ThreadLocalPartitionCommandsMarshaller.java: ########## @@ -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.table.distributed.schema; + +import java.nio.ByteBuffer; +import org.apache.ignite.network.serialization.MessageSerializationRegistry; + +/** + * Thread-safe variant of {@link PartitionCommandsMarshaller}. Review Comment: `Thread-local` i guess =) ########## modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/PartitionReplicaListener.java: ########## @@ -1158,25 +1169,31 @@ private CompletableFuture<Object> finishTransaction(List<TablePartitionId> aggre HybridTimestamp currentTimestamp = hybridClock.now(); HybridTimestamp commitTimestamp = commit ? currentTimestamp : null; - FinishTxCommandBuilder finishTxCmdBldr = MSG_FACTORY.finishTxCommand() - .txId(txId) - .commit(commit) - .safeTimeLong(currentTimestamp.longValue()) - .tablePartitionIds( - aggregatedGroupIds.stream() - .map(PartitionReplicaListener::tablePartitionId) - .collect(toList()) - ); - - if (commit) { - finishTxCmdBldr.commitTimestampLong(commitTimestamp.longValue()); - } + return catalogVersionFor(currentTimestamp) + .thenApply(catalogVersion -> { Review Comment: Good comment from Vanya, of the same opinion. ########## modules/core/src/main/java/org/apache/ignite/internal/util/VarIntUtils.java: ########## @@ -0,0 +1,93 @@ +/* + * 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.util; + +import java.nio.ByteBuffer; + +/** + * Utilities to work with general-purpose varints. Review Comment: I think we should reveal what "**varints**" is. And in what format will it be presented. ########## modules/runner/src/integrationTest/java/org/apache/ignite/internal/schemasync/ItSchemaSyncAndReplicationTest.java: ########## @@ -0,0 +1,173 @@ +/* + * 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.schemasync; + +import static org.apache.ignite.internal.SessionUtils.executeUpdate; +import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.function.BooleanSupplier; +import java.util.logging.LogRecord; +import java.util.logging.Logger; +import org.apache.ignite.internal.ClusterPerTestIntegrationTest; +import org.apache.ignite.internal.ReplicationGroupsUtils; +import org.apache.ignite.internal.app.IgniteImpl; +import org.apache.ignite.internal.metastorage.server.raft.MetastorageGroupId; +import org.apache.ignite.internal.storage.MvPartitionStorage; +import org.apache.ignite.internal.storage.RowId; +import org.apache.ignite.internal.table.TableImpl; +import org.apache.ignite.internal.table.distributed.schema.CheckCatalogVersionOnAppendEntries; +import org.apache.ignite.internal.test.WatchListenerInhibitor; +import org.apache.ignite.internal.testframework.jul.NoOpHandler; +import org.apache.ignite.table.KeyValueView; +import org.apache.ignite.table.Tuple; +import org.junit.jupiter.api.Test; + +/** + * Tests about interaction between Schema Synchronization and Replication. + */ +@SuppressWarnings("resource") +class ItSchemaSyncAndReplicationTest extends ClusterPerTestIntegrationTest { + @Override + protected int initialNodes() { + return 3; + } + + /** + * The replication mechanism must not replicate commands for which schemas are not yet available on the node + * to which replication happens (in Raft, it means that followers/learners cannot receive commands that they + * cannot execute without waiting for schemas). This method tests this scenario. + */ + @Test + void laggingSchemasPreventPartitionDataReplication() throws Exception { + createTestTableWith3Replicas(); + + final int notInhibitedNodeIndex = 0; + transferLeadershipsTo(notInhibitedNodeIndex); + + IgniteImpl nodeToInhibitMetaStorage = cluster.node(1); + + WatchListenerInhibitor listenerInhibitor = WatchListenerInhibitor.metastorageEventsInhibitor(nodeToInhibitMetaStorage); + listenerInhibitor.startInhibit(); + + try { + CountDownLatch rejectionTriggered = rejectionDueToMetadataLagTriggered(); + + updateTableSchemaAt(notInhibitedNodeIndex); + putToTableAt(notInhibitedNodeIndex); + + assertTrue(rejectionTriggered.await(10, TimeUnit.SECONDS), "Did not see rejections due to lagging metadata"); + + assertTrue(solePartitionIsEmpty(nodeToInhibitMetaStorage), "Something was written to the partition"); + + listenerInhibitor.stopInhibit(); + + assertTrue( + waitForCondition(() -> !solePartitionIsEmpty(nodeToInhibitMetaStorage), 10_000), + "Nothing was written to partition even after inhibiting was cancelled" + ); + } finally { + listenerInhibitor.stopInhibit(); + } + } + + private void createTestTableWith3Replicas() throws InterruptedException { + String zoneSql = "create zone test_zone with partitions=1, replicas=3"; + String sql = "create table test (key int primary key, value varchar(20))" + + " with primary_zone='TEST_ZONE'"; + + cluster.doInSession(0, session -> { + executeUpdate(zoneSql, session); + executeUpdate(sql, session); + }); + + waitForTableToStart(); + } + + private void waitForTableToStart() throws InterruptedException { + // TODO: IGNITE-18733 - remove this wait because when a table creation query is executed, the table must be fully ready. + + BooleanSupplier tableStarted = () -> { + int numberOfStartedRaftNodes = cluster.runningNodes() + .map(ReplicationGroupsUtils::tablePartitionIds) + .mapToInt(List::size) + .sum(); + return numberOfStartedRaftNodes == 3; Review Comment: Maybe instead 3 use constant or method argument? ########## modules/raft/src/main/java/org/apache/ignite/raft/jraft/option/NodeOptions.java: ########## @@ -704,4 +705,16 @@ public TimeoutStrategy getElectionTimeoutStrategy() { public void setElectionTimeoutStrategy(TimeoutStrategy electionTimeoutStrategy) { this.electionTimeoutStrategy = electionTimeoutStrategy; } + + public Marshaller getCommandsMarshaller() { Review Comment: Nullable? ########## modules/core/src/test/java/org/apache/ignite/internal/util/VarIntUtilsTest.java: ########## @@ -0,0 +1,72 @@ +/* + * 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.util; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + +import java.nio.ByteBuffer; +import java.util.stream.Stream; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +class VarIntUtilsTest { + private final byte[] array = new byte[10]; Review Comment: I suggest using it as a local variable, it's easier to read the code. ########## modules/runner/src/testFixtures/java/org/apache/ignite/internal/Cluster.java: ########## @@ -523,6 +531,74 @@ public void removeNetworkPartitionOf(int nodeIndex) { LOG.info("Reanimated node " + nodeIndex + " by removing an artificial network partition"); } + /** + * Transfers leadsership over a replication group to a node identified by the given index. + * + * @param nodeIndex Node index of the new leader. + * @param groupId ID of the replication group. + * @throws InterruptedException If interrupted while waiting. + */ + public void transferLeadershipTo(int nodeIndex, ReplicationGroupId groupId) throws InterruptedException { + String nodeConsistentId = node(nodeIndex).node().name(); + + int maxAttempts = 3; + + for (int attempt = 1; attempt <= maxAttempts; attempt++) { + boolean transferred = tryTransferLeadershipTo(nodeConsistentId, groupId); + + if (transferred) { + break; + } + + if (attempt < maxAttempts) { + LOG.info("Did not transfer leadership after " + attempt + " attempts, going to retry..."); + } else { + fail("Did not transfer leadership in time after " + maxAttempts + " attempts"); Review Comment: ```suggestion fail("Did not transfer leadership in time after {} attempts", maxAttempts); ``` ########## modules/raft/src/main/java/org/apache/ignite/internal/raft/server/impl/JraftServerImpl.java: ########## @@ -122,10 +125,12 @@ public class JraftServerImpl implements RaftServer { private ExecutorService requestExecutor; /** Marshaller for RAFT commands. */ - private final Marshaller commandsMarshaller; + private final Marshaller defaultCommandsMarshaller; /** Raft service event interceptor. */ - private RaftServiceEventInterceptor serviceEventInterceptor; + private final RaftServiceEventInterceptor serviceEventInterceptor; + + private AppendEntriesRequestInterceptor appendEntriesRequestInterceptor = new NullAppendEntriesRequestInterceptor(); Review Comment: Needs `volatile`? ########## modules/runner/src/integrationTest/java/org/apache/ignite/internal/schemasync/ItSchemaSyncAndReplicationTest.java: ########## @@ -0,0 +1,173 @@ +/* + * 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.schemasync; + +import static org.apache.ignite.internal.SessionUtils.executeUpdate; +import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.function.BooleanSupplier; +import java.util.logging.LogRecord; +import java.util.logging.Logger; +import org.apache.ignite.internal.ClusterPerTestIntegrationTest; +import org.apache.ignite.internal.ReplicationGroupsUtils; +import org.apache.ignite.internal.app.IgniteImpl; +import org.apache.ignite.internal.metastorage.server.raft.MetastorageGroupId; +import org.apache.ignite.internal.storage.MvPartitionStorage; +import org.apache.ignite.internal.storage.RowId; +import org.apache.ignite.internal.table.TableImpl; +import org.apache.ignite.internal.table.distributed.schema.CheckCatalogVersionOnAppendEntries; +import org.apache.ignite.internal.test.WatchListenerInhibitor; +import org.apache.ignite.internal.testframework.jul.NoOpHandler; +import org.apache.ignite.table.KeyValueView; +import org.apache.ignite.table.Tuple; +import org.junit.jupiter.api.Test; + +/** + * Tests about interaction between Schema Synchronization and Replication. + */ +@SuppressWarnings("resource") +class ItSchemaSyncAndReplicationTest extends ClusterPerTestIntegrationTest { + @Override + protected int initialNodes() { + return 3; + } + + /** + * The replication mechanism must not replicate commands for which schemas are not yet available on the node + * to which replication happens (in Raft, it means that followers/learners cannot receive commands that they + * cannot execute without waiting for schemas). This method tests this scenario. + */ + @Test + void laggingSchemasPreventPartitionDataReplication() throws Exception { + createTestTableWith3Replicas(); + + final int notInhibitedNodeIndex = 0; + transferLeadershipsTo(notInhibitedNodeIndex); + + IgniteImpl nodeToInhibitMetaStorage = cluster.node(1); + + WatchListenerInhibitor listenerInhibitor = WatchListenerInhibitor.metastorageEventsInhibitor(nodeToInhibitMetaStorage); + listenerInhibitor.startInhibit(); + + try { + CountDownLatch rejectionTriggered = rejectionDueToMetadataLagTriggered(); + + updateTableSchemaAt(notInhibitedNodeIndex); + putToTableAt(notInhibitedNodeIndex); + + assertTrue(rejectionTriggered.await(10, TimeUnit.SECONDS), "Did not see rejections due to lagging metadata"); + + assertTrue(solePartitionIsEmpty(nodeToInhibitMetaStorage), "Something was written to the partition"); + + listenerInhibitor.stopInhibit(); + + assertTrue( + waitForCondition(() -> !solePartitionIsEmpty(nodeToInhibitMetaStorage), 10_000), + "Nothing was written to partition even after inhibiting was cancelled" + ); + } finally { + listenerInhibitor.stopInhibit(); + } + } + + private void createTestTableWith3Replicas() throws InterruptedException { + String zoneSql = "create zone test_zone with partitions=1, replicas=3"; + String sql = "create table test (key int primary key, value varchar(20))" + + " with primary_zone='TEST_ZONE'"; + + cluster.doInSession(0, session -> { + executeUpdate(zoneSql, session); + executeUpdate(sql, session); + }); + + waitForTableToStart(); + } + + private void waitForTableToStart() throws InterruptedException { + // TODO: IGNITE-18733 - remove this wait because when a table creation query is executed, the table must be fully ready. + + BooleanSupplier tableStarted = () -> { + int numberOfStartedRaftNodes = cluster.runningNodes() + .map(ReplicationGroupsUtils::tablePartitionIds) + .mapToInt(List::size) + .sum(); + return numberOfStartedRaftNodes == 3; + }; + + assertTrue(waitForCondition(tableStarted, 10_000), "Did not see all table RAFT nodes started"); + } + + private void transferLeadershipsTo(int nodeIndex) throws InterruptedException { + cluster.transferLeadershipTo(nodeIndex, MetastorageGroupId.INSTANCE); + cluster.transferLeadershipTo(nodeIndex, cluster.solePartitionId()); + } + + private static CountDownLatch rejectionDueToMetadataLagTriggered() { + Logger interceptorLogger = Logger.getLogger(CheckCatalogVersionOnAppendEntries.class.getName()); + + CountDownLatch rejectionTriggered = new CountDownLatch(1); + + interceptorLogger.addHandler(new NoOpHandler() { + @Override + public void publish(LogRecord record) { + if (record.getMessage().startsWith("Metadata not yet available")) { + rejectionTriggered.countDown(); + } + } + }); + + return rejectionTriggered; + } + + private void putToTableAt(int nodeIndex) { + KeyValueView<Tuple, Tuple> kvView = cluster.node(nodeIndex) + .tables() + .table("test") + .keyValueView(); + kvView.put(null, Tuple.create().set("key", 1), Tuple.create().set("value", "one")); Review Comment: ```suggestion cluster.node(nodeIndex) .tables() .table("test") .keyValueView() .put(null, Tuple.create().set("key", 1), Tuple.create().set("value", "one")); ``` ########## modules/table/src/main/java/org/apache/ignite/internal/table/distributed/schema/PartitionCommandsMarshallerImpl.java: ########## @@ -0,0 +1,65 @@ +/* + * 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.table.distributed.schema; + +import java.nio.ByteBuffer; +import org.apache.ignite.internal.raft.util.OptimizedMarshaller; +import org.apache.ignite.internal.table.distributed.command.CatalogVersionAware; +import org.apache.ignite.internal.util.VarIntUtils; +import org.apache.ignite.network.serialization.MessageSerializationRegistry; + +/** + * Default {@link PartitionCommandsMarshaller} implementation. + */ +public class PartitionCommandsMarshallerImpl extends OptimizedMarshaller implements PartitionCommandsMarshaller { + public PartitionCommandsMarshallerImpl(MessageSerializationRegistry serializationRegistry) { + super(serializationRegistry); + } + + @Override + public byte[] marshall(Object o) { + int requiredCatalogVersion = o instanceof CatalogVersionAware ? ((CatalogVersionAware) o).requiredCatalogVersion() : -1; Review Comment: did not notice where it is said about `-1` and its meaning. ########## modules/runner/src/testFixtures/java/org/apache/ignite/internal/Cluster.java: ########## @@ -523,6 +531,74 @@ public void removeNetworkPartitionOf(int nodeIndex) { LOG.info("Reanimated node " + nodeIndex + " by removing an artificial network partition"); } + /** + * Transfers leadsership over a replication group to a node identified by the given index. + * + * @param nodeIndex Node index of the new leader. + * @param groupId ID of the replication group. + * @throws InterruptedException If interrupted while waiting. + */ + public void transferLeadershipTo(int nodeIndex, ReplicationGroupId groupId) throws InterruptedException { + String nodeConsistentId = node(nodeIndex).node().name(); + + int maxAttempts = 3; + + for (int attempt = 1; attempt <= maxAttempts; attempt++) { + boolean transferred = tryTransferLeadershipTo(nodeConsistentId, groupId); + + if (transferred) { + break; + } + + if (attempt < maxAttempts) { + LOG.info("Did not transfer leadership after " + attempt + " attempts, going to retry..."); Review Comment: ```suggestion LOG.info("Did not transfer leadership after {} attempts, going to retry...", attempt); ``` ########## modules/runner/src/integrationTest/java/org/apache/ignite/internal/schemasync/ItSchemaSyncAndReplicationTest.java: ########## @@ -0,0 +1,173 @@ +/* + * 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.schemasync; + +import static org.apache.ignite.internal.SessionUtils.executeUpdate; +import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.function.BooleanSupplier; +import java.util.logging.LogRecord; +import java.util.logging.Logger; +import org.apache.ignite.internal.ClusterPerTestIntegrationTest; +import org.apache.ignite.internal.ReplicationGroupsUtils; +import org.apache.ignite.internal.app.IgniteImpl; +import org.apache.ignite.internal.metastorage.server.raft.MetastorageGroupId; +import org.apache.ignite.internal.storage.MvPartitionStorage; +import org.apache.ignite.internal.storage.RowId; +import org.apache.ignite.internal.table.TableImpl; +import org.apache.ignite.internal.table.distributed.schema.CheckCatalogVersionOnAppendEntries; +import org.apache.ignite.internal.test.WatchListenerInhibitor; +import org.apache.ignite.internal.testframework.jul.NoOpHandler; +import org.apache.ignite.table.KeyValueView; +import org.apache.ignite.table.Tuple; +import org.junit.jupiter.api.Test; + +/** + * Tests about interaction between Schema Synchronization and Replication. + */ +@SuppressWarnings("resource") +class ItSchemaSyncAndReplicationTest extends ClusterPerTestIntegrationTest { + @Override + protected int initialNodes() { + return 3; + } + + /** + * The replication mechanism must not replicate commands for which schemas are not yet available on the node + * to which replication happens (in Raft, it means that followers/learners cannot receive commands that they + * cannot execute without waiting for schemas). This method tests this scenario. + */ + @Test + void laggingSchemasPreventPartitionDataReplication() throws Exception { + createTestTableWith3Replicas(); + + final int notInhibitedNodeIndex = 0; + transferLeadershipsTo(notInhibitedNodeIndex); + + IgniteImpl nodeToInhibitMetaStorage = cluster.node(1); + + WatchListenerInhibitor listenerInhibitor = WatchListenerInhibitor.metastorageEventsInhibitor(nodeToInhibitMetaStorage); + listenerInhibitor.startInhibit(); + + try { + CountDownLatch rejectionTriggered = rejectionDueToMetadataLagTriggered(); + + updateTableSchemaAt(notInhibitedNodeIndex); + putToTableAt(notInhibitedNodeIndex); + + assertTrue(rejectionTriggered.await(10, TimeUnit.SECONDS), "Did not see rejections due to lagging metadata"); + + assertTrue(solePartitionIsEmpty(nodeToInhibitMetaStorage), "Something was written to the partition"); + + listenerInhibitor.stopInhibit(); + + assertTrue( + waitForCondition(() -> !solePartitionIsEmpty(nodeToInhibitMetaStorage), 10_000), + "Nothing was written to partition even after inhibiting was cancelled" + ); + } finally { + listenerInhibitor.stopInhibit(); + } + } + + private void createTestTableWith3Replicas() throws InterruptedException { + String zoneSql = "create zone test_zone with partitions=1, replicas=3"; + String sql = "create table test (key int primary key, value varchar(20))" + + " with primary_zone='TEST_ZONE'"; + + cluster.doInSession(0, session -> { + executeUpdate(zoneSql, session); + executeUpdate(sql, session); + }); + + waitForTableToStart(); + } + + private void waitForTableToStart() throws InterruptedException { + // TODO: IGNITE-18733 - remove this wait because when a table creation query is executed, the table must be fully ready. + + BooleanSupplier tableStarted = () -> { + int numberOfStartedRaftNodes = cluster.runningNodes() + .map(ReplicationGroupsUtils::tablePartitionIds) + .mapToInt(List::size) + .sum(); + return numberOfStartedRaftNodes == 3; + }; + + assertTrue(waitForCondition(tableStarted, 10_000), "Did not see all table RAFT nodes started"); + } + + private void transferLeadershipsTo(int nodeIndex) throws InterruptedException { + cluster.transferLeadershipTo(nodeIndex, MetastorageGroupId.INSTANCE); + cluster.transferLeadershipTo(nodeIndex, cluster.solePartitionId()); + } + + private static CountDownLatch rejectionDueToMetadataLagTriggered() { + Logger interceptorLogger = Logger.getLogger(CheckCatalogVersionOnAppendEntries.class.getName()); + + CountDownLatch rejectionTriggered = new CountDownLatch(1); + + interceptorLogger.addHandler(new NoOpHandler() { + @Override + public void publish(LogRecord record) { + if (record.getMessage().startsWith("Metadata not yet available")) { + rejectionTriggered.countDown(); + } + } + }); + + return rejectionTriggered; + } + + private void putToTableAt(int nodeIndex) { + KeyValueView<Tuple, Tuple> kvView = cluster.node(nodeIndex) + .tables() + .table("test") + .keyValueView(); + kvView.put(null, Tuple.create().set("key", 1), Tuple.create().set("value", "one")); + } + + private void updateTableSchemaAt(int nodeIndex) { + cluster.doInSession(nodeIndex, session -> { + session.execute(null, "alter table test add column added int"); + }); + } + + private static boolean solePartitionIsEmpty(IgniteImpl node) { + MvPartitionStorage mvPartitionStorage = solePartitionStorage(node); + RowId rowId = mvPartitionStorage.closestRowId(RowId.lowestRowId(0)); + return rowId == null; + } + + private static MvPartitionStorage solePartitionStorage(IgniteImpl node) { + TableImpl table = (TableImpl) node.tables().table("test"); Review Comment: Let's move "table" to constant. ########## modules/table/src/main/java/org/apache/ignite/internal/table/distributed/schema/CheckCatalogVersionOnAppendEntries.java: ########## @@ -0,0 +1,104 @@ +/* + * 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.table.distributed.schema; + +import java.nio.ByteBuffer; +import org.apache.ignite.internal.catalog.CatalogService; +import org.apache.ignite.internal.logger.IgniteLogger; +import org.apache.ignite.internal.logger.Loggers; +import org.apache.ignite.raft.jraft.Node; +import org.apache.ignite.raft.jraft.entity.EnumOutter.EntryType; +import org.apache.ignite.raft.jraft.entity.RaftOutter; +import org.apache.ignite.raft.jraft.entity.RaftOutter.EntryMeta; +import org.apache.ignite.raft.jraft.error.RaftError; +import org.apache.ignite.raft.jraft.rpc.Message; +import org.apache.ignite.raft.jraft.rpc.RaftRpcFactory; +import org.apache.ignite.raft.jraft.rpc.RaftServerService; +import org.apache.ignite.raft.jraft.rpc.RpcRequestClosure; +import org.apache.ignite.raft.jraft.rpc.RpcRequests.AppendEntriesRequest; +import org.apache.ignite.raft.jraft.rpc.impl.AppendEntriesRequestInterceptor; +import org.apache.ignite.raft.jraft.util.Marshaller; +import org.jetbrains.annotations.Nullable; + +/** + * An {@link AppendEntriesRequestInterceptor} that rejects requests (by returning EBUSY error code) if any of the + * incoming commands requires catalog version that is not available locally yet. + */ +public class CheckCatalogVersionOnAppendEntries implements AppendEntriesRequestInterceptor { + private static final IgniteLogger LOG = Loggers.forClass(CheckCatalogVersionOnAppendEntries.class); + + private static final int NO_VERSION_REQUIREMENT = Integer.MIN_VALUE; + + private final CatalogService catalogService; + + public CheckCatalogVersionOnAppendEntries(CatalogService catalogService) { + this.catalogService = catalogService; + } + + @Override + @Nullable + public Message intercept(RaftServerService service, AppendEntriesRequest request, RpcRequestClosure done) { + if (request.entriesList() == null || request.data() == null) { + return null; + } + + Node node = (Node) service; + + ByteBuffer allData = request.data().asReadOnlyByteBuffer(); + int offset = 0; + + for (RaftOutter.EntryMeta entry : request.entriesList()) { + int requiredCatalogVersion = readRequiredCatalogVersionForMeta(allData, entry, node.getOptions().requiredCommandsMarshaller()); + + if (requiredCatalogVersion != NO_VERSION_REQUIREMENT && !isMetadataAvailableFor(requiredCatalogVersion)) { + LOG.warn("Metadata not yet available, group {}, required level {}.", request.groupId(), requiredCatalogVersion); + return RaftRpcFactory.DEFAULT // + .newResponse(node.getRaftOptions().getRaftMessagesFactory(), RaftError.EBUSY, + "Metadata not yet available, group '%s', required level %d.", request.groupId(), requiredCatalogVersion); + } + + offset += (int) entry.dataLen(); + allData.position(offset); + } + + return null; + } + + private static int readRequiredCatalogVersionForMeta(ByteBuffer allData, final EntryMeta entry, Marshaller commandsMarshaller) { + if (entry.type() != EntryType.ENTRY_TYPE_DATA) { + return NO_VERSION_REQUIREMENT; + } + + if (!(commandsMarshaller instanceof PartitionCommandsMarshaller)) { + return NO_VERSION_REQUIREMENT; + } + + PartitionCommandsMarshaller partitionCommandsMarshaller = (PartitionCommandsMarshaller) commandsMarshaller; + + long dataLen = entry.dataLen(); + if (dataLen > 0) { + return partitionCommandsMarshaller.readRequiredCatalogVersion(allData); + } + + return NO_VERSION_REQUIREMENT; + } + + private boolean isMetadataAvailableFor(int catalogVersion) { Review Comment: Maybe `catalogVersion` -> `requiredCatalogVersion` ? ########## modules/table/src/main/java/org/apache/ignite/internal/table/distributed/schema/PartitionCommandsMarshaller.java: ########## @@ -0,0 +1,35 @@ +/* + * 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.table.distributed.schema; + +import java.nio.ByteBuffer; +import org.apache.ignite.raft.jraft.util.Marshaller; + +/** + * {@link Marshaller} that first writes some metadata about an object and then it writes the actual serialized + * representation of the object. + */ +public interface PartitionCommandsMarshaller extends Marshaller { Review Comment: Maybe add `@FunctionalInterface` ? ########## modules/raft/src/main/java/org/apache/ignite/raft/jraft/rpc/impl/AppendEntriesRequestInterceptor.java: ########## @@ -0,0 +1,41 @@ +/* + * 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.impl; + +import org.apache.ignite.raft.jraft.rpc.Message; +import org.apache.ignite.raft.jraft.rpc.RaftServerService; +import org.apache.ignite.raft.jraft.rpc.RpcRequestClosure; +import org.apache.ignite.raft.jraft.rpc.RpcRequests.AppendEntriesRequest; +import org.jetbrains.annotations.Nullable; + +/** + * Intercepts {@link AppendEntriesRequest}s as they come in. It might be used to handle such a request in a non-standard + * way (like returning EBUSY under special circumstances instead of the standard behavior). + */ +public interface AppendEntriesRequestInterceptor { Review Comment: Maybe add `@FunctionalInterface` ########## modules/table/src/test/java/org/apache/ignite/internal/table/distributed/replication/PartitionReplicaListenerTest.java: ########## @@ -1590,6 +1602,82 @@ public void failsWhenFullScanReadsTupleWithIncompatibleSchemaFromFuture() { ); } + @ParameterizedTest + @MethodSource("singleRowWriteRequestTypes") + public void singleRowWritesAreSuppliedWithRequiredCatalogVersion(RequestType requestType) { + testWritesAreSuppliedWithRequiredCatalogVersion(requestType, (targetTxId, key) -> { + return doSingleRowRequest(targetTxId, marshalKeyOrKeyValue(requestType, key), requestType); + }); + } + + private static Stream<Arguments> singleRowWriteRequestTypes() { + return Arrays.stream(RequestType.values()) + .filter(RequestType::isSingleRowWrite) + .map(Arguments::of); + } + + private void testWritesAreSuppliedWithRequiredCatalogVersion(RequestType requestType, ListenerInvocation listenerInvocation) { + TestKey key = nextKey(); + + if (requestType.looksUpFirst()) { + UUID tx0 = beginTx(); + upsert(tx0, binaryRow(key, someValue)); + cleanup(tx0); + + // While handling the upsert, our mocks were touched, let's reset them to prevent false-positives during verification. + Mockito.reset(schemaSyncService); + } + + when(catalogService.activeCatalogVersion(anyLong())).thenReturn(42); + + UUID targetTxId = beginTx(); + + CompletableFuture<?> future = listenerInvocation.invoke(targetTxId, key); + + assertThat(future, willCompleteSuccessfully()); + + // Make sure metadata completeness is awaited for. + InOrder inOrder = inOrder(schemaSyncService, catalogService); + Review Comment: ```suggestion ``` ########## modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/action/RequestType.java: ########## @@ -79,6 +79,13 @@ public boolean isSingleRow() { } } + /** + * Returns {@code true} if the operation works with a single row and it's a write. + */ + public boolean isSingleRowWrite() { Review Comment: Maybe add a test utility class for this in `testFixtures`? ########## modules/table/src/test/java/org/apache/ignite/internal/table/distributed/replication/PartitionReplicaListenerTest.java: ########## @@ -1423,30 +1451,22 @@ private static List<FullTableSchema> incompatibleSchemaVersions(int fromSchemaVe @MethodSource("singleRowRequestTypes") public void failsWhenReadingSingleRowFromFutureIncompatibleSchema(RequestType requestType) { testFailsWhenReadingFromFutureIncompatibleSchema((targetTxId, key) -> { - try { - switch (requestType) { - case RW_GET: - case RW_DELETE: - case RW_GET_AND_DELETE: - return doSingleRowRequest(targetTxId, kvMarshaller.marshal(key), requestType); - - case RW_DELETE_EXACT: - case RW_INSERT: - case RW_UPSERT: - case RW_GET_AND_UPSERT: - case RW_GET_AND_REPLACE: - case RW_REPLACE_IF_EXIST: - return doSingleRowRequest(targetTxId, kvMarshaller.marshal(key, new TestValue(1, "v1")), requestType); - - default: - throw new AssertionError("Unexpected operation type: " + requestType); - } - } catch (MarshallerException e) { - throw new AssertionError(e); - } + return doSingleRowRequest(targetTxId, marshalKeyOrKeyValue(requestType, key), requestType); }); } + private BinaryRow marshalKeyOrKeyValue(RequestType requestType, TestKey key) { + try { + if (requestType.isKeyOnly()) { + return kvMarshaller.marshal(key); + } else { + return kvMarshaller.marshal(key, someValue); + } Review Comment: ```suggestion return requestType.isKeyOnly() ? kvMarshaller.marshal(key) : kvMarshaller.marshal(key, someValue); ``` -- 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]
