Skip to content

Commit dfa9bed

Browse files
committed
IGNITE-27947 Add TX_ROLLBACK_USING_FIRST_REQUEST protocol feature
1 parent 52b8fe9 commit dfa9bed

File tree

6 files changed

+26
-6
lines changed

6 files changed

+26
-6
lines changed

modules/client-common/src/main/java/org/apache/ignite/internal/client/proto/ProtocolBitmaskFeature.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,12 @@ public enum ProtocolBitmaskFeature {
112112
/**
113113
* Send discard requests to directly mapped partitions.
114114
*/
115-
TX_DIRECT_MAPPING_SEND_DISCARD(17);
115+
TX_DIRECT_MAPPING_SEND_DISCARD(17),
116+
117+
/**
118+
* Allow rolling back direct transactions using the first request id.
119+
*/
120+
TX_ROLLBACK_USING_FIRST_REQUEST(18);
116121

117122
private static final EnumSet<ProtocolBitmaskFeature> ALL_FEATURES_AS_ENUM_SET =
118123
EnumSet.allOf(ProtocolBitmaskFeature.class);

modules/client-handler/src/integrationTest/java/org/apache/ignite/client/handler/ItClientHandlerTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,7 @@ public void testServerReturnsAllItsFeatures() throws IOException {
564564
expected.set(15);
565565
expected.set(16);
566566
expected.set(17);
567+
expected.set(18);
567568

568569
assertEquals(expected, supportedFeatures);
569570

modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientHandlerModule.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ public class ClientHandlerModule implements IgniteComponent, PlatformComputeTran
102102
ProtocolBitmaskFeature.COMPUTE_OBSERVABLE_TS,
103103
ProtocolBitmaskFeature.TX_DIRECT_MAPPING_SEND_REMOTE_WRITES,
104104
ProtocolBitmaskFeature.SQL_PARTITION_AWARENESS_TABLE_NAME,
105-
ProtocolBitmaskFeature.TX_DIRECT_MAPPING_SEND_DISCARD
105+
ProtocolBitmaskFeature.TX_DIRECT_MAPPING_SEND_DISCARD,
106+
ProtocolBitmaskFeature.TX_ROLLBACK_USING_FIRST_REQUEST
106107
));
107108

108109
/** Connection id generator.

modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientInboundMessageHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import static org.apache.ignite.internal.client.proto.ProtocolBitmaskFeature.TX_DIRECT_MAPPING;
2929
import static org.apache.ignite.internal.client.proto.ProtocolBitmaskFeature.TX_DIRECT_MAPPING_SEND_REMOTE_WRITES;
3030
import static org.apache.ignite.internal.client.proto.ProtocolBitmaskFeature.TX_PIGGYBACK;
31+
import static org.apache.ignite.internal.client.proto.ProtocolBitmaskFeature.TX_ROLLBACK_USING_FIRST_REQUEST;
3132
import static org.apache.ignite.internal.hlc.HybridTimestamp.NULL_HYBRID_TIMESTAMP;
3233
import static org.apache.ignite.internal.util.CompletableFutures.falseCompletedFuture;
3334
import static org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture;
@@ -573,6 +574,7 @@ private void handshakeSuccess(
573574
actualFeatures.clear(TX_DELAYED_ACKS.featureId());
574575
actualFeatures.clear(TX_PIGGYBACK.featureId());
575576
actualFeatures.clear(TX_ALLOW_NOOP_ENLIST.featureId());
577+
actualFeatures.clear(TX_ROLLBACK_USING_FIRST_REQUEST.featureId());
576578

577579
actualFeatures.clear(SQL_DIRECT_TX_MAPPING.featureId());
578580
} else {

modules/client/src/main/java/org/apache/ignite/internal/client/TcpClientChannel.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ class TcpClientChannel implements ClientChannel, ClientMessageHandler, ClientCon
106106
ProtocolBitmaskFeature.SQL_MULTISTATEMENT_SUPPORT,
107107
ProtocolBitmaskFeature.COMPUTE_OBSERVABLE_TS,
108108
ProtocolBitmaskFeature.TX_DIRECT_MAPPING_SEND_REMOTE_WRITES,
109-
ProtocolBitmaskFeature.TX_DIRECT_MAPPING_SEND_DISCARD
109+
ProtocolBitmaskFeature.TX_DIRECT_MAPPING_SEND_DISCARD,
110+
ProtocolBitmaskFeature.TX_ROLLBACK_USING_FIRST_REQUEST
110111
));
111112

112113
/** Minimum supported heartbeat interval. */

modules/client/src/main/java/org/apache/ignite/internal/client/tx/ClientLazyTransaction.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package org.apache.ignite.internal.client.tx;
1919

20+
import static java.util.concurrent.CompletableFuture.failedFuture;
21+
import static org.apache.ignite.internal.client.proto.ProtocolBitmaskFeature.TX_ROLLBACK_USING_FIRST_REQUEST;
2022
import static org.apache.ignite.internal.client.tx.ClientTransactions.USE_CONFIGURED_TIMEOUT_DEFAULT;
2123
import static org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture;
2224

@@ -41,6 +43,9 @@
4143
* Lazy client transaction. Will be actually started on the first operation.
4244
*/
4345
public class ClientLazyTransaction implements Transaction {
46+
private static final CompletableFuture<?> NOT_SUPPORTED_FUTURE =
47+
failedFuture(new UnsupportedOperationException("TX_ROLLBACK_USING_FIRST_REQUEST is not supported"));
48+
4449
private final long observableTimestamp;
4550

4651
private final @Nullable TransactionOptions options;
@@ -109,9 +114,14 @@ public CompletableFuture<Void> rollbackAsync() {
109114
// If the transaction is not started. Issue the rollback and wait for the server response.
110115
if (!tx0.isDone() && cancelled.compareAndSet(false, true)) {
111116
return requestInfoFuture
112-
.thenCompose(reqInfo ->
113-
reqInfo.ch.serviceAsync(ClientOp.TX_ROLLBACK, w -> w.out().packLong(-reqInfo.firstReqId), r -> null)
114-
)
117+
.thenCompose(reqInfo -> {
118+
ClientChannel ch = reqInfo.ch;
119+
if (ch.protocolContext().isFeatureSupported(TX_ROLLBACK_USING_FIRST_REQUEST)) {
120+
return ch.serviceAsync(ClientOp.TX_ROLLBACK, w -> w.out().packLong(-reqInfo.firstReqId), r -> null);
121+
} else {
122+
return NOT_SUPPORTED_FUTURE;
123+
}
124+
})
115125
.handle((res, e) -> {
116126
// If ok, we don't need to wait for the response. If error, let's block.
117127
if (e == null) {

0 commit comments

Comments
 (0)