Skip to content

optimize : support multi-version codec & fix not returning client registration failure msg #7000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 32 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a3334d8
version check
Bughue Jul 27, 2024
a67a05a
Merge branch '2.x' of https://github.com/seata/seata into dev-registe…
Bughue Sep 25, 2024
492e5e6
register-fail-reason
Bughue Nov 1, 2024
2c40745
Merge branch '2.x' of https://github.com/seata/seata into dev-registe…
Bughue Nov 1, 2024
ff42508
undolog
Bughue Nov 1, 2024
b3456a6
Merge branch '2.x' of https://github.com/seata/seata into dev-registe…
Bughue Nov 6, 2024
8df9eb8
codec version
Bughue Nov 7, 2024
0853ece
codec version
Bughue Nov 7, 2024
bbec0c6
Merge branch '2.x' of https://github.com/seata/seata into dev-registe…
Bughue Nov 14, 2024
cca29e6
070 version
Bughue Nov 14, 2024
2826e7c
codec map match
Bughue Nov 14, 2024
8c2f73e
codec map match
Bughue Nov 14, 2024
2f3c8e3
codec map match
Bughue Nov 15, 2024
3b7edf4
version empty
Bughue Nov 26, 2024
d7838ff
Merge branch '2.x' of https://github.com/seata/seata into dev-registe…
Bughue Nov 26, 2024
bbf5c1c
sdk version to protocol version
Bughue Nov 30, 2024
cb93a9c
sdk version to protocol version
Bughue Nov 30, 2024
76d233a
v0
Bughue Dec 6, 2024
3e5cbfa
Merge branch '2.x' of https://github.com/seata/seata into dev-registe…
Bughue Feb 22, 2025
eec1cdc
SeataSerializerV2
Bughue Feb 22, 2025
708160c
SeataSerializerV2
Bughue Feb 22, 2025
559fcce
SeataSerializerV2
Bughue Feb 22, 2025
cbe4e1c
Merge branch '2.x' into dev-register-fail-reason
Bughue Mar 6, 2025
2461f18
style
Bughue Mar 11, 2025
ec0d313
Merge remote-tracking branch 'origin/dev-register-fail-reason' into d…
Bughue Mar 11, 2025
2c7aebd
Merge branch '2.x' of https://github.com/seata/seata into dev-registe…
Bughue Mar 11, 2025
303504e
style
Bughue Mar 11, 2025
5efc00a
style
Bughue Mar 11, 2025
b2e9392
test
Bughue Mar 14, 2025
58106ce
Merge branch '2.x' into dev-register-fail-reason
Bughue Mar 14, 2025
3d6bf10
test
Bughue Mar 14, 2025
74c01a2
Merge remote-tracking branch 'origin/dev-register-fail-reason' into d…
Bughue Mar 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/en-us/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Add changes here for all PR submitted to the 2.x branch.
- [[#7179](https://github.com/apache/incubator-seata/pull/7179)] Use shared EventLoop for TM and RM clients to reduce thread overhead and improve performance
- [[#7194](https://github.com/apache/incubator-seata/pull/7194)] automatically skipping proxy for datasource of type AbstractRoutingDataSource
- [[#7214](https://github.com/apache/incubator-seata/pull/7214)] upgrade jackson to 2.18.3
- [[#7000](https://github.com/apache/incubator-seata/pull/7000)] support multi-version codec & fix not returning client registration failure msg

### security:
- [[#6069](https://github.com/apache/incubator-seata/pull/6069)] Upgrade Guava dependencies to fix security vulnerabilities
Expand Down
1 change: 1 addition & 0 deletions changes/zh-cn/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
- [[#7179](https://github.com/apache/incubator-seata/pull/7179)] 使用共享的 EventLoop 来减少 TM 和 RM 客户端的线程开销并提高性能
- [[#7194](https://github.com/apache/incubator-seata/pull/7194)] 自动跳过对AbstractRoutingDataSource类型数据源的代理
- [[#7214](https://github.com/apache/incubator-seata/pull/7214)] 升级 jackson 至 2.18.3 版本
- [[#7000](https://github.com/apache/incubator-seata/pull/7000)] 支持多版本codec,修复不返回客户端注册失败消息的问题

### security:
- [[#6069](https://github.com/apache/incubator-seata/pull/6069)] 升级Guava依赖版本,修复安全漏洞
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,19 @@ public interface ProtocolConstants {
byte VERSION_0 = 0;

/**
* Protocol version
* Protocol version 1
*/
byte VERSION_1 = 1;

/**
* Protocol version 2
*/
byte VERSION_2 = 2;

/**
* Protocol version
*/
byte VERSION = VERSION_1;
byte VERSION = VERSION_2;

/**
* Max frame length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public RegisterRMResponse() {
public RegisterRMResponse(boolean result) {
super();
setIdentified(result);
setResultCode(result ? ResultCode.Success : ResultCode.Failed);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public RegisterTMResponse() {
public RegisterTMResponse(boolean result) {
super();
setIdentified(result);
setResultCode(result ? ResultCode.Success : ResultCode.Failed);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public class Version {
private static final String VERSION_0_7_1 = "0.7.1";
private static final String VERSION_1_5_0 = "1.5.0";
private static final String VERSION_2_3_0 = "2.3.0";

public static final String VERSION_0_7_0 = "0.7.0";

private static final int MAX_VERSION_DOT = 3;

/**
Expand Down Expand Up @@ -94,6 +97,10 @@ public static boolean isAboveOrEqualVersion230(String version) {
return isAboveOrEqualVersion(version, VERSION_2_3_0);
}

public static boolean isAboveOrEqualVersion071(String version) {
return isAboveOrEqualVersion(version, VERSION_0_7_1);
}

public static boolean isAboveOrEqualVersion(String clientVersion, String divideVersion) {
boolean isAboveOrEqualVersion = false;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.apache.seata.core.rpc.netty.v0.ProtocolEncoderV0;
import org.apache.seata.core.rpc.netty.v1.ProtocolDecoderV1;
import org.apache.seata.core.rpc.netty.v1.ProtocolEncoderV1;
import org.apache.seata.core.rpc.netty.v2.ProtocolDecoderV2;
import org.apache.seata.core.rpc.netty.v2.ProtocolEncoderV2;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -83,12 +85,16 @@ int lengthFieldLength, FullLength is int(4B). so values is 4
int initialBytesToStrip we will check magic code and version self, so do not strip any bytes. so values is 0
*/
super(maxFrameLength, 3, 4, -7, 0);
this.protocolDecoderMap =
ImmutableMap.<Byte, ProtocolDecoder>builder().put(ProtocolConstants.VERSION_0, new ProtocolDecoderV0())
.put(ProtocolConstants.VERSION_1, new ProtocolDecoderV1()).build();
this.protocolEncoderMap =
ImmutableMap.<Byte, ProtocolEncoder>builder().put(ProtocolConstants.VERSION_0, new ProtocolEncoderV0())
.put(ProtocolConstants.VERSION_1, new ProtocolEncoderV1()).build();
this.protocolDecoderMap = ImmutableMap.<Byte, ProtocolDecoder>builder()
.put(ProtocolConstants.VERSION_0, new ProtocolDecoderV0())
.put(ProtocolConstants.VERSION_1, new ProtocolDecoderV1())
.put(ProtocolConstants.VERSION_2, new ProtocolDecoderV2())
.build();
this.protocolEncoderMap = ImmutableMap.<Byte, ProtocolEncoder>builder()
.put(ProtocolConstants.VERSION_0, new ProtocolEncoderV0())
.put(ProtocolConstants.VERSION_1, new ProtocolEncoderV1())
.put(ProtocolConstants.VERSION_2, new ProtocolEncoderV2())
.build();
this.channelHandlers = channelHandlers;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
import org.apache.seata.core.rpc.RemotingBootstrap;
import org.apache.seata.core.rpc.netty.grpc.GrpcDecoder;
import org.apache.seata.core.rpc.netty.grpc.GrpcEncoder;
import org.apache.seata.core.rpc.netty.v1.ProtocolDecoderV1;
import org.apache.seata.core.rpc.netty.v1.ProtocolEncoderV1;
import org.apache.seata.core.rpc.netty.v2.ProtocolDecoderV2;
import org.apache.seata.core.rpc.netty.v2.ProtocolEncoderV2;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -157,8 +157,8 @@ public void initChannel(SocketChannel ch) {
pipeline.addLast(new IdleStateHandler(nettyClientConfig.getChannelMaxReadIdleSeconds(),
nettyClientConfig.getChannelMaxWriteIdleSeconds(),
nettyClientConfig.getChannelMaxAllIdleSeconds()));
pipeline.addLast(new ProtocolDecoderV1())
.addLast(new ProtocolEncoderV1());
pipeline.addLast(new ProtocolDecoderV2())
.addLast(new ProtocolEncoderV2());
if (channelHandlers != null) {
addChannelPipelineLast(ch, channelHandlers);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ public interface ProtocolDecoder {

RpcMessage decodeFrame(ByteBuf in);

byte protocolVersion();
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@
**/
public interface ProtocolEncoder {
void encode(RpcMessage rpcMessage, ByteBuf out);

byte protocolVersion();
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public RpcMessage decodeFrame(ByteBuf in) {
bs2[1] = (byte) (0x00FF & typeCode);
System.arraycopy(bs, 0, bs2, 2, length);
byte codecType = isSeataCodec ? SerializerType.SEATA.getCode() : SerializerType.HESSIAN.getCode();
Serializer serializer = SerializerServiceLoader.load(SerializerType.getByCode(codecType), ProtocolConstants.VERSION_0);
Serializer serializer = SerializerServiceLoader.load(SerializerType.getByCode(codecType), protocolVersion());
rpcMessage.setBody(serializer.deserialize(bs2));
} catch (Exception e) {
LOGGER.error("decode error", e);
Expand All @@ -151,4 +151,9 @@ protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception
throw new DecodeException(exx);
}
}

@Override
public byte protocolVersion() {
return ProtocolConstants.VERSION_0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void encode(RpcMessage message, ByteBuf out) {
}

byte[] bodyBytes = null;
Serializer serializer = SerializerServiceLoader.load(SerializerType.getByCode(codec), ProtocolConstants.VERSION_0);
Serializer serializer = SerializerServiceLoader.load(SerializerType.getByCode(codec), protocolVersion());
bodyBytes = serializer.serialize(msg.getBody());

if (msg.isSeataCodec()) {
Expand Down Expand Up @@ -118,4 +118,9 @@ protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws
LOGGER.error("Encode request error!", e);
}
}

@Override
public byte protocolVersion() {
return ProtocolConstants.VERSION_0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public RpcMessage decodeFrame(ByteBuf frame) {
bs = compressor.decompress(bs);
SerializerType protocolType = SerializerType.getByCode(rpcMessage.getCodec());
if (this.supportDeSerializerTypes.contains(protocolType)) {
Serializer serializer = SerializerServiceLoader.load(protocolType, ProtocolConstants.VERSION_1);
Serializer serializer = SerializerServiceLoader.load(protocolType, protocolVersion());
rpcMessage.setBody(serializer.deserialize(bs));
} else {
throw new IllegalArgumentException("SerializerType not match");
Expand Down Expand Up @@ -160,4 +160,8 @@ protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception
return decoded;
}

@Override
public byte protocolVersion() {
return ProtocolConstants.VERSION_1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void encode(RpcMessage message, ByteBuf out) {

byte messageType = rpcMessage.getMessageType();
out.writeBytes(ProtocolConstants.MAGIC_CODE_BYTES);
out.writeByte(ProtocolConstants.VERSION_1);
out.writeByte(protocolVersion());
// full Length(4B) and head length(2B) will fix in the end.
out.writerIndex(out.writerIndex() + 6);
out.writeByte(messageType);
Expand All @@ -94,7 +94,7 @@ public void encode(RpcMessage message, ByteBuf out) {
if (messageType != ProtocolConstants.MSGTYPE_HEARTBEAT_REQUEST
&& messageType != ProtocolConstants.MSGTYPE_HEARTBEAT_RESPONSE) {
// heartbeat has no body
Serializer serializer = SerializerServiceLoader.load(SerializerType.getByCode(rpcMessage.getCodec()), ProtocolConstants.VERSION_1);
Serializer serializer = SerializerServiceLoader.load(SerializerType.getByCode(rpcMessage.getCodec()), protocolVersion());
bodyBytes = serializer.serialize(rpcMessage.getBody());
Compressor compressor = CompressorFactory.getCompressor(rpcMessage.getCompressor());
bodyBytes = compressor.compress(bodyBytes);
Expand Down Expand Up @@ -134,4 +134,8 @@ protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws
}
}

@Override
public byte protocolVersion() {
return ProtocolConstants.VERSION_1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.seata.core.rpc.netty.v2;

import org.apache.seata.core.protocol.ProtocolConstants;
import org.apache.seata.core.rpc.netty.v1.ProtocolDecoderV1;

/**
* Decoder of protocol-v2
**/
public class ProtocolDecoderV2 extends ProtocolDecoderV1 {

@Override
public byte protocolVersion() {
return ProtocolConstants.VERSION_2;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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.seata.core.rpc.netty.v2;

import org.apache.seata.core.protocol.ProtocolConstants;
import org.apache.seata.core.rpc.netty.v1.ProtocolEncoderV1;

/**
* Encoder of protocol-v2
**/
public class ProtocolEncoderV2 extends ProtocolEncoderV1 {
@Override
public byte protocolVersion() {
return ProtocolConstants.VERSION_2;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ private void onRegRmMessage(ChannelHandlerContext ctx, RpcMessage rpcMessage) {
if (LOGGER.isWarnEnabled()) {
LOGGER.warn("RM checkAuth for client:{},vgroup:{},applicationId:{} is FAIL", ipAndPort, message.getTransactionServiceGroup(), message.getApplicationId());
}
errorInfo = "RM checkAuth fail";
}
} catch (Exception exx) {
isSuccess = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ private void onRegTmMessage(ChannelHandlerContext ctx, RpcMessage rpcMessage) {
LOGGER.warn("TM checkAuth for client:{},vgroup:{},applicationId:{} is FAIL",
ipAndPort, message.getTransactionServiceGroup(), message.getApplicationId());
}
errorInfo = "TM checkAuth fail";
}
} catch (Exception exx) {
isSuccess = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package org.apache.seata.mockserver.processor;

import io.netty.channel.ChannelHandlerContext;
import org.apache.commons.lang.StringUtils;
import org.apache.seata.core.protocol.AbstractResultMessage;
import org.apache.seata.core.protocol.RegisterRMRequest;
import org.apache.seata.core.protocol.RegisterRMResponse;
import org.apache.seata.core.protocol.RegisterTMRequest;
Expand Down Expand Up @@ -49,27 +51,31 @@ public MockRegisterProcessor(RemotingServer remotingServer, Role role) {

@Override
public void process(ChannelHandlerContext ctx, RpcMessage rpcMessage) throws Exception {
if (role == Role.TM) {
RegisterTMRequest message = (RegisterTMRequest) rpcMessage.getBody();
LOGGER.info("message = " + message);

ChannelManager.registerTMChannel(message, ctx.channel());
Version.putChannelVersion(ctx.channel(), message.getVersion());

RegisterTMResponse resp = new RegisterTMResponse();
remotingServer.sendAsyncResponse(rpcMessage, ctx.channel(), resp);
LOGGER.info("sendAsyncResponse: {}", resp);
} else if (role == Role.RM) {
RegisterRMRequest message = (RegisterRMRequest) rpcMessage.getBody();
LOGGER.info("message = " + message);

ChannelManager.registerRMChannel(message, ctx.channel());
Version.putChannelVersion(ctx.channel(), message.getVersion());

RegisterRMResponse resp = new RegisterRMResponse();
remotingServer.sendAsyncResponse(rpcMessage, ctx.channel(), resp);
LOGGER.info("sendAsyncResponse: {}", resp);
String errorInfo = StringUtils.EMPTY;
AbstractResultMessage response = null;
try {
if (role == Role.TM) {
RegisterTMRequest message = (RegisterTMRequest) rpcMessage.getBody();
LOGGER.info("reg message = " + message);
ChannelManager.registerTMChannel(message, ctx.channel());
Version.putChannelVersion(ctx.channel(), message.getVersion());
response = new RegisterTMResponse();
} else if (role == Role.RM) {
RegisterRMRequest message = (RegisterRMRequest) rpcMessage.getBody();
LOGGER.info("reg message = " + message);
ChannelManager.registerRMChannel(message, ctx.channel());
Version.putChannelVersion(ctx.channel(), message.getVersion());
response = new RegisterRMResponse();
}
} catch (Exception e) {
errorInfo = e.getMessage();
LOGGER.error(role + " register fail, error message:{}", errorInfo);
}
if (StringUtils.isNotEmpty(errorInfo)) {
response.setMsg(errorInfo);
}
remotingServer.sendAsyncResponse(rpcMessage, ctx.channel(), response);
LOGGER.info("sendAsyncResponse: {}", response);
}


Expand Down
Loading
Loading