Skip to content
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

feat: support fury serializer #356

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Conversation

funky-eyes
Copy link
Contributor

@funky-eyes funky-eyes commented Jul 31, 2024

个人认为apache fury已经进入apache孵化器,未来的迭代,稳定性也会更高,性能根据其测试报告非常优秀,并且目前sofa-bolt自带的序列化器只有hessian,应该扩充一些序列化器避免用户自行实现.
目前pr中遗留2个问题需要跟社区讨论下:

  1. 是否将fury的白名单关闭?(dubbo侧是直接关闭的,用户不需要手动注册类,但是有安全风险),目前的实现是开启白名单,也就是用户在使用fury序列化器时,需要在应用初始化时将需要rpc用到的类手动注册到fury中(专门为此开了一个静态方法以便使用)
  2. 是否将hessian也开启白名单,如果二者都要开启白名单,那么应该抽象出一个专门用作白名单的类,在初始化二者时,自动将白名单涉及的类注册进去.(如果需要该能力,可以通过额外的pr来实现,该pr先只做fury的序列化支持)

Summary by CodeRabbit

  • New Features

    • Introduced a new serializer, FurySerializer, enhancing serialization capabilities within the application.
    • Added support for version management of the Apache Fury library.
  • Bug Fixes

    • Improved error handling in the serialization process to provide clearer messages for exceptions.
  • Tests

    • Implemented a comprehensive suite of unit tests for the FurySerializer, validating successful and concurrent serialization scenarios.
    • Enhanced clarity and consistency in assertion methods within existing tests.
  • Chores

    • Updated build configuration to include support for the latest Java version (17) in the CI workflow.

Copy link

coderabbitai bot commented Jul 31, 2024

Warning

Rate limit exceeded

@funky-eyes has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 6 minutes and 40 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 7adb1f1 and ff900b9.

Walkthrough

The recent changes integrate the Apache Fury serialization framework into the project, enhancing serialization capabilities with the addition of the FurySerializer. Updates include modifications to the SerializerManager to support this new serializer, the introduction of unit tests to validate its functionality, and the expansion of the Java version matrix in the CI workflow to include Java 17, ensuring compatibility with newer features.

Changes

File Path Change Summary
pom.xml Added property fury.version set to 0.6.0 and new dependency for fury-core with scope provided.
src/main/java/com/alipay/remoting/serialization/SerializerManager.java Introduced FurySerializer with a new constant Fury for extended serialization support.
src/test/java/com/alipay/remoting/serialization/fury/FurySerializerTest.java Added unit tests for FurySerializer to validate serialization under concurrent conditions and error handling.
.github/workflows/maven.yml Updated Java version matrix to include Java 17.
src/test/java/com/alipay/remoting/rpc/protocol/RpcCommandHandlerTest.java Improved assertions in testHandleCommand and preHandleRequest methods for better clarity.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant SerializerManager
    participant FurySerializer

    Client->>SerializerManager: Request Serializer (Fury)
    SerializerManager->>FurySerializer: Instantiate FurySerializer
    FurySerializer-->>SerializerManager: Return FurySerializer Instance
    SerializerManager-->>Client: Return FurySerializer

    Client->>FurySerializer: Serialize Object
    FurySerializer-->>Client: Return Serialized Data
Loading
sequenceDiagram
    participant Client
    participant FurySerializer

    Client->>FurySerializer: Serialize Invalid Object
    FurySerializer-->>Client: Throw CodecException
Loading

Poem

🐰 In fields of code, a new friend hops,
With Fury's might, our data never stops.
Threads dance in joy, as serialize sings,
Bugs flee in fright, while our rabbit heart springs.
Let's cheer for the changes, so bright and so bold,
In the world of serialization, new stories unfold! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 12ef565 and 8157507.

Files selected for processing (5)
  • pom.xml (2 hunks)
  • src/main/java/com/alipay/remoting/serialization/HessianSerializer.java (1 hunks)
  • src/main/java/com/alipay/remoting/serialization/SerializerManager.java (2 hunks)
  • src/main/java/com/alipay/remoting/serialization/fury/FurySerializer.java (1 hunks)
  • src/test/java/com/alipay/remoting/serialization/fury/FurySerializerTest.java (1 hunks)
Files skipped from review due to trivial changes (1)
  • src/main/java/com/alipay/remoting/serialization/HessianSerializer.java
Additional comments not posted (15)
src/main/java/com/alipay/remoting/serialization/fury/FurySerializer.java (4)

32-39: LGTM! Class members are well-defined.

The static list REGISTRY_LIST and the ThreadSafeFury instance are appropriately defined for the class functionality.


41-47: LGTM! Proper error handling in serialize method.

The serialize method correctly handles serialization errors by wrapping them in a CodecException.


55-57: LGTM! Simple and effective registry method.

The registry method correctly adds classes to the REGISTRY_LIST.


34-39: LGTM! Proper initialization in constructor.

The constructor correctly initializes the fury instance with a custom class loader and registers classes from the REGISTRY_LIST.

src/main/java/com/alipay/remoting/serialization/SerializerManager.java (4)

39-39: LGTM! New constant Fury is well-defined.

The addition of the new constant Fury is appropriate for adding support for FurySerializer.


20-20: LGTM! Updated serializers array is well-defined.

The updated serializers array is appropriate for adding support for FurySerializer.


45-56: LGTM! Proper support for FurySerializer in getSerializer method.

The getSerializer method correctly implements support for FurySerializer with proper locking and initialization.


Line range hint 58-69:
LGTM! addSerializer method is well-implemented.

The addSerializer method correctly supports dynamic addition of serializers.

src/test/java/com/alipay/remoting/serialization/fury/FurySerializerTest.java (5)

38-43: LGTM! Class members are well-defined for testing.

The static serializer instance and the static block for initialization are appropriate for testing purposes.


45-55: LGTM! Proper concurrency test in concurrentSerializeTest method.

The concurrentSerializeTest method correctly tests the thread safety of the FurySerializer with proper concurrency handling using CountDownLatch.


57-65: LGTM! Proper error handling test in testSerializeError method.

The testSerializeError method correctly verifies that the FurySerializer throws a CodecException with the expected cause.


67-75: LGTM! Successful serialization test in testSerialize method.

The testSerialize method correctly verifies that the FurySerializer successfully serializes an object.


77-99: LGTM! Proper implementation of MyThread class for concurrency testing.

The MyThread class correctly tests the concurrent serialization and deserialization capabilities of the FurySerializer.

pom.xml (2)

90-90: LGTM! Adding the fury.version property.

The addition of the fury.version property is consistent with the existing version management strategy.


100-105: LGTM! Adding the fury-core dependency.

The addition of the fury-core dependency with a scope of provided is appropriate and follows the existing pattern for adding dependencies.

Comment on lines +50 to +53
@Override
public <T> T deserialize(byte[] data, String classOfT) throws CodecException {
return (T)fury.deserialize(data);
}
Copy link

@coderabbitai coderabbitai bot Jul 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add type safety to deserialize method.

The deserialize method uses unchecked casting which can lead to ClassCastException. Consider adding type safety.

-    public <T> T deserialize(byte[] data, String classOfT) throws CodecException {
-        return (T)fury.deserialize(data);
+    public <T> T deserialize(byte[] data, Class<T> classOfT) throws CodecException {
+        return classOfT.cast(fury.deserialize(data));
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@Override
public <T> T deserialize(byte[] data, String classOfT) throws CodecException {
return (T)fury.deserialize(data);
}
@Override
public <T> T deserialize(byte[] data, Class<T> classOfT) throws CodecException {
return classOfT.cast(fury.deserialize(data));

Copy link
Contributor Author

@funky-eyes funky-eyes Jul 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个问题我无法决定是否如此修改,因为会涉及改动上层序列化接口

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@funky-eyes, I understand that changing the deserialize method's signature might involve modifications to the upper-level serialization interface and other dependent classes. The method is used in several places across the codebase, including FurySerializerTest.java, HessianSerializerTest.java, RpcResponseCommand.java, and more.

Given the widespread usage, this change would require careful consideration and testing. It might be best to discuss this further or address it in a separate PR to ensure all dependencies are handled properly. Let me know how you would like to proceed.

Analysis chain
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for all invocations of the `deserialize` method in the codebase to understand its usage and potential impact of changing its signature.
rg --context 5 'deserialize\('

Length of output: 18313

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8157507 and 199b787.

Files selected for processing (3)
  • pom.xml (2 hunks)
  • src/main/java/com/alipay/remoting/serialization/SerializerManager.java (2 hunks)
  • src/test/java/com/alipay/remoting/serialization/fury/FurySerializerTest.java (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • pom.xml
  • src/main/java/com/alipay/remoting/serialization/SerializerManager.java
  • src/test/java/com/alipay/remoting/serialization/fury/FurySerializerTest.java

@funky-eyes funky-eyes closed this Aug 1, 2024
@funky-eyes funky-eyes reopened this Aug 1, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 199b787 and eed4b2b.

Files selected for processing (2)
  • .github/workflows/maven.yml (1 hunks)
  • src/test/java/com/alipay/remoting/rpc/protocol/RpcCommandHandlerTest.java (2 hunks)
Additional comments not posted (4)
.github/workflows/maven.yml (1)

35-35: LGTM! Verify compatibility with Java 17.

The addition of Java 17 to the Java version matrix is a good step to ensure compatibility with newer Java features. Ensure that the codebase is compatible with Java 17.

src/test/java/com/alipay/remoting/rpc/protocol/RpcCommandHandlerTest.java (3)

69-69: LGTM! Improved assertion clarity.

The change from Assert.assertTrue(remotingContextList.size() == 2) to Assert.assertEquals(2, remotingContextList.size()) improves the clarity and consistency of the assertion.


92-92: LGTM! Improved assertion specificity.

The change from Assert.assertTrue(remotingCtx != remotingContext) to Assert.assertNotSame(remotingCtx, remotingContext) more accurately conveys the intent of checking that the two references are not the same object in memory.


68-68: Verify the impact of removing the timeout parameter.

The removal of the timeout parameter from countDownLatch.await() may affect how long the test waits for the latch to count down. Ensure that this change does not cause the test to hang indefinitely.

Verification successful

The removal of the timeout parameter from countDownLatch.await() does not cause the test to hang indefinitely.

  • The countDownLatch.countDown() method is called within the test file, ensuring the latch is decremented and the test proceeds.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of removing the timeout parameter from `countDownLatch.await()`.

# Test: Run the test suite. Expect: No hanging tests.
./mvnw test

Length of output: 133


Script:

#!/bin/bash
# Search for all instances of `countDownLatch.await()` in the test file to analyze their usage.
rg 'countDownLatch.await' src/test/java/com/alipay/remoting/rpc/protocol/RpcCommandHandlerTest.java -A 5

Length of output: 377


Script:

#!/bin/bash
# Search for all instances of `countDownLatch.countDown()` in the test file to ensure the latch is properly decremented.
rg 'countDownLatch.countDown' src/test/java/com/alipay/remoting/rpc/protocol/RpcCommandHandlerTest.java -A 5

Length of output: 296

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between eed4b2b and 7adb1f1.

Files selected for processing (1)
  • pom.xml (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • pom.xml

@chuailiwu
Copy link
Collaborator

Great, I'll spend some time to check this PR.

return new ByteArrayOutputStream();
}
};
private static ThreadLocal<ByteArrayOutputStream> localOutputByteArray = ThreadLocal.withInitial(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bolt用于多个基础组件,最好不要用高版本的用法保持线下兼容

//public static final byte Json = 2;

public static final byte Fury = 3;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

另,bolt作为底层组件需要考虑引入依赖版本的兼容性,如现在rpc里使用fury版本是0.4,如果和当前0.6版本不兼容就会有问题

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

另,bolt作为底层组件需要考虑引入依赖版本的兼容性,如现在rpc里使用fury版本是0.4,如果和当前0.6版本不兼容就会有问题

这个不太好改,因为fury捐给apache后,对老的包全部做了迁移,没有做向下兼容,导致0.6跟0.4不兼容,0.4跟0.6也不兼容。
当然序列化后的数据是兼容的,但是包和类都不同了,可以说0.4和0.6压根就不是一个依赖,相当于引入了2个依赖,实际上应该不会有冲突,因为各自用的各自的类,在序列化反序列化方面是兼容的即可。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是否考虑rpc先把版本提升上来,统一维护一个版本就好了

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是否考虑rpc先把版本提升上来,统一维护一个版本就好了

好的,我去看看rpc那块的实现,考虑先提交到sofa-rpc侧.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants