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

rh客户端 发生 RemotingException 时,重试 #1135

Merged
merged 4 commits into from
Aug 7, 2024

Conversation

shihuili1218
Copy link
Collaborator

@shihuili1218 shihuili1218 commented Aug 5, 2024

Implementation of Issue #1131

Summary by CodeRabbit

  • New Features

    • Introduced new error constants, RPC_ERROR and RPC_CONNECTION_ERROR, to improve error handling for server communication issues.
    • Added a dedicated ConnectionFailureException to manage RPC connection-related errors.
  • Bug Fixes

    • Enhanced error handling logic to differentiate between various exception types related to remote procedure calls.
  • Style

    • Standardized the formatting of existing error messages by adding periods at the end for improved readability.
  • Refactor

    • Updated error checking logic to incorporate new error types for enhanced robustness in error handling.

Copy link
Contributor

coderabbitai bot commented Aug 5, 2024

Walkthrough

The recent modifications enhance error handling in the rheakv-core framework by introducing new error constants, RPC_ERROR and RPC_CONNECTION_ERROR, clarifying server availability issues during RPC operations. Additionally, existing error messages have been standardized for consistency and readability. These changes collectively strengthen the framework's robustness in managing remote procedure call errors by improving the specificity of error handling across various components.

Changes

Files Change Summary
.../rheakv-core/src/main/java/com/alipay/sofa/jraft/rhea/errors/Errors.java Added new RPC_ERROR and RPC_CONNECTION_ERROR constants; updated existing error messages for consistency by adding periods at the end.
.../rheakv-core/src/main/java/com/alipay/sofa/jraft/rhea/errors/ErrorsHelper.java Enhanced isInvalidPeer method to include checks for Errors.RPC_ERROR and Errors.RPC_CONNECTION_ERROR, broadening the criteria for invalid peers.
.../rheakv-core/src/main/java/com/alipay/sofa/jraft/rhea/client/DefaultRheaKVRpcService.java Modified error handling in the complete method to set Errors.RPC_CONNECTION_ERROR for RemotingException, improving clarity in error reporting.
.../rheakv-core/src/main/java/com/alipay/sofa/jraft/rhea/client/pd/DefaultPlacementDriverRpcService.java Added similar error handling for RemotingException in the complete method, enhancing feedback for RPC failures.
.../rheakv-core/src/main/java/com/alipay/sofa/jraft/rhea/errors/ConnectionFailureException.java Introduced ConnectionFailureException class to handle RPC connection errors, providing constructors for detailed exception reporting.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant DefaultRheaKVRpcService
    participant DefaultPlacementDriverRpcService
    participant Errors

    Caller->>DefaultRheaKVRpcService: Trigger RPC operation
    DefaultRheaKVRpcService->>Errors: Check for RemotingException
    alt RemotingException
        DefaultRheaKVRpcService->>Errors: setError(RPC_CONNECTION_ERROR)
        DefaultRheaKVRpcService->>Caller: Complete future with RPC_CONNECTION_ERROR
    else Other Error
        DefaultRheaKVRpcService->>Caller: Complete future with original error
    end
Loading

Poem

🐇 In the meadow where errors dance,
A new RPC_ERROR takes its chance.
With clearer paths and messages bright,
Our calls now sing with pure delight!
Let's hop along, improve and play,
For better code is here to stay! 🌼


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
Contributor

@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 38c0867 and 3652887.

Files selected for processing (3)
  • jraft-rheakv/rheakv-core/src/main/java/com/alipay/sofa/jraft/rhea/client/failover/impl/FailoverClosureImpl.java (2 hunks)
  • jraft-rheakv/rheakv-core/src/main/java/com/alipay/sofa/jraft/rhea/errors/Errors.java (2 hunks)
  • jraft-rheakv/rheakv-core/src/main/java/com/alipay/sofa/jraft/rhea/errors/ErrorsHelper.java (1 hunks)
Additional comments not posted (4)
jraft-rheakv/rheakv-core/src/main/java/com/alipay/sofa/jraft/rhea/errors/ErrorsHelper.java (1)

29-29: Inclusion of Errors.RPC_ERROR in isInvalidPeer method.

The addition of Errors.RPC_ERROR to the isInvalidPeer method broadens the criteria for identifying invalid peers, enhancing error handling for RPC issues. This change is appropriate and aligns with the PR objectives.

jraft-rheakv/rheakv-core/src/main/java/com/alipay/sofa/jraft/rhea/client/failover/impl/FailoverClosureImpl.java (1)

95-100: Enhanced error handling in failure method for RemotingException.

The updated failure method now checks if the cause is an instance of RemotingException. If so, it sets an error state with Errors.RPC_ERROR and runs a new status. This change improves the granularity of error handling by distinguishing between different types of exceptions.

jraft-rheakv/rheakv-core/src/main/java/com/alipay/sofa/jraft/rhea/errors/Errors.java (2)

39-41: Addition of new error constant RPC_ERROR.

The new error constant RPC_ERROR represents a specific server availability issue due to a disconnected RPC connection. This addition enhances the granularity of error handling related to server communication issues.


70-76: Standardization of error messages.

The error messages for INVALID_STORE_STATS, INVALID_REGION_STATS, STORE_HEARTBEAT_OUT_OF_DATE, and REGION_HEARTBEAT_OUT_OF_DATE have been updated to include a period at the end. This change improves readability and consistency across the error handling framework.

Copy link
Contributor

@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 3652887 and e6f0a6d.

Files selected for processing (1)
  • jraft-rheakv/rheakv-core/src/main/java/com/alipay/sofa/jraft/rhea/errors/ErrorsHelper.java (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • jraft-rheakv/rheakv-core/src/main/java/com/alipay/sofa/jraft/rhea/errors/ErrorsHelper.java

@sofastack-cla sofastack-cla bot added size/M and removed size/S labels Aug 6, 2024
Copy link
Contributor

@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 e6f0a6d and 608b174.

Files selected for processing (4)
  • jraft-rheakv/rheakv-core/src/main/java/com/alipay/sofa/jraft/rhea/client/DefaultRheaKVRpcService.java (2 hunks)
  • jraft-rheakv/rheakv-core/src/main/java/com/alipay/sofa/jraft/rhea/client/pd/DefaultPlacementDriverRpcService.java (2 hunks)
  • jraft-rheakv/rheakv-core/src/main/java/com/alipay/sofa/jraft/rhea/errors/Errors.java (2 hunks)
  • jraft-rheakv/rheakv-core/src/main/java/com/alipay/sofa/jraft/rhea/errors/ErrorsHelper.java (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • jraft-rheakv/rheakv-core/src/main/java/com/alipay/sofa/jraft/rhea/errors/Errors.java
  • jraft-rheakv/rheakv-core/src/main/java/com/alipay/sofa/jraft/rhea/errors/ErrorsHelper.java
Additional comments not posted (4)
jraft-rheakv/rheakv-core/src/main/java/com/alipay/sofa/jraft/rhea/client/pd/DefaultPlacementDriverRpcService.java (2)

27-27: Import statement addition is appropriate.

The import statement for RemotingException is necessary for the new error handling mechanism.


114-119: Enhanced error handling is well-implemented.

The new error handling mechanism improves the specificity of error handling by distinguishing between different types of errors.

However, ensure that Errors.RPC_CONNECTION_ERROR is correctly defined and used throughout the codebase.

Verification successful

Errors.RPC_CONNECTION_ERROR is correctly defined and used.

The error code Errors.RPC_CONNECTION_ERROR is properly defined in Errors.java and used consistently in DefaultRheaKVRpcService.java, DefaultPlacementDriverRpcService.java, and ErrorsHelper.java to handle RPC connection issues.

  • Errors.java: Defined with the value -2 and the message "RPC connection disconnected."
  • DefaultRheaKVRpcService.java: Used to handle RemotingException.
  • ErrorsHelper.java: Checked within the isInvalidPeer method.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of Errors.RPC_CONNECTION_ERROR in the codebase.

# Test: Search for the usage of Errors.RPC_CONNECTION_ERROR. Expect: Correct definition and usage.
rg --type java 'Errors.RPC_CONNECTION_ERROR'

Length of output: 551


Script:

#!/bin/bash
# Locate the definition of Errors.RPC_CONNECTION_ERROR
rg --type java 'RPC_CONNECTION_ERROR' -A 5

# Inspect the context of its usage in DefaultRheaKVRpcService.java
rg --type java -A 5 -B 5 'Errors.RPC_CONNECTION_ERROR' jraft-rheakv/rheakv-core/src/main/java/com/alipay/sofa/jraft/rhea/client/DefaultRheaKVRpcService.java

# Inspect the context of its usage in ErrorsHelper.java
rg --type java -A 5 -B 5 'Errors.RPC_CONNECTION_ERROR' jraft-rheakv/rheakv-core/src/main/java/com/alipay/sofa/jraft/rhea/errors/ErrorsHelper.java

Length of output: 4823

jraft-rheakv/rheakv-core/src/main/java/com/alipay/sofa/jraft/rhea/client/DefaultRheaKVRpcService.java (2)

27-27: Import statement addition is appropriate.

The import statement for RemotingException is necessary for the new error handling mechanism.


143-148: Enhanced error handling is well-implemented.

The new error handling mechanism improves the specificity of error handling by distinguishing between different types of errors.

However, ensure that Errors.RPC_CONNECTION_ERROR is correctly defined and used throughout the codebase.

Verification successful

Enhanced error handling is well-implemented.

The new error handling mechanism improves the specificity of error handling by distinguishing between different types of errors. The Errors.RPC_CONNECTION_ERROR is correctly defined and consistently used across the codebase.

  • Errors.java: Definition of RPC_CONNECTION_ERROR
  • DefaultRheaKVRpcService.java: Usage of RPC_CONNECTION_ERROR
  • DefaultPlacementDriverRpcService.java: Usage of RPC_CONNECTION_ERROR
  • ErrorsHelper.java: Usage of RPC_CONNECTION_ERROR
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of Errors.RPC_CONNECTION_ERROR in the codebase.

# Test: Search for the usage of Errors.RPC_CONNECTION_ERROR. Expect: Correct definition and usage.
rg --type java 'Errors.RPC_CONNECTION_ERROR'

Length of output: 551


Script:

#!/bin/bash
# Description: Verify the definition of Errors.RPC_CONNECTION_ERROR in the codebase.

# Test: Search for the definition of RPC_CONNECTION_ERROR in the Errors class. Expect: Correct definition.
rg --type java 'RPC_CONNECTION_ERROR' -A 5

Length of output: 3456

Copy link
Contributor

@fengjiachun fengjiachun left a comment

Choose a reason for hiding this comment

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

LGTM, Thank you!

Copy link
Contributor

@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 608b174 and df43824.

Files selected for processing (2)
  • jraft-rheakv/rheakv-core/src/main/java/com/alipay/sofa/jraft/rhea/errors/ConnectionFailureException.java (1 hunks)
  • jraft-rheakv/rheakv-core/src/main/java/com/alipay/sofa/jraft/rhea/errors/Errors.java (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • jraft-rheakv/rheakv-core/src/main/java/com/alipay/sofa/jraft/rhea/errors/Errors.java
Additional comments not posted (5)
jraft-rheakv/rheakv-core/src/main/java/com/alipay/sofa/jraft/rhea/errors/ConnectionFailureException.java (5)

1-17: Package declaration and license information are correct.

The package declaration and license information are standard and do not contain any issues.


19-21: Class-level documentation is clear and concise.

The documentation provides a brief description of the ConnectionFailureException.


22-24: Class declaration and serialVersionUID are correct.

The class extends ApiException and includes a serialVersionUID.


25-38: Constructors are correctly implemented.

The class includes four constructors: a default constructor, a constructor with a message, a constructor with a message and cause, and a constructor with a cause. All are correctly implemented and follow standard practices.


39-39: Class is correctly closed.

The class ends correctly with a closing brace.

@en-hui
Copy link

en-hui commented Aug 12, 2024

您好,我尝试使用1.3.15,好像问题并没有修复

@shihuili1218
Copy link
Collaborator Author

shihuili1218 commented Aug 12, 2024

您好,我尝试使用1.3.15,好像问题并没有修复

回顾你贴出的异常:https://github.com/sofastack/sofa-jraft/issues/1131#issuecomment-2255066719。
这是bolt心跳重连,对应节点已经下掉,与put失败无关。可以通过参数来关闭重连。

你说的未修复的问题,可以再提供一些详细信息吗?

@en-hui
Copy link

en-hui commented Aug 12, 2024

您好,我尝试使用1.3.15,好像问题并没有修复

回顾你贴出的异常:https://github.com/sofastack/sofa-jraft/issues/1131#issuecomment-2255066719。 这是bolt心跳重连,对应节点已经下掉,与put失败无关。可以通过参数来关闭重连。

你说的未修复的问题,可以再提供一些详细信息吗?

您的修改为:在rpc回调的complete中添加了异常处理,我复现发现当出现RemotingException的时候,并未进入complete,而是在这里直接异常处理了。所以没有进到closure.run(new Status(-1, "RPC failed with address: %s, response: %s", endpoint, response));
try {
this.rpcClient.invokeAsync(endpoint, request, invokeCtx, invokeCallback, this.rpcTimeoutMillis);
} catch (final Throwable t) {
closure.failure(t);
}

@shihuili1218
Copy link
Collaborator Author

您好,我尝试使用1.3.15,好像问题并没有修复

回顾你贴出的异常:https://github.com/sofastack/sofa-jraft/issues/1131#issuecomment-2255066719。 这是bolt心跳重连,对应节点已经下掉,与put失败无关。可以通过参数来关闭重连。
你说的未修复的问题,可以再提供一些详细信息吗?

您的修改为:在rpc回调的complete中添加了异常处理,我复现发现当出现RemotingException的时候,并未进入complete,而是在这里直接异常处理了。所以没有进到closure.run(new Status(-1, "RPC failed with address: %s, response: %s", endpoint, response)); try { this.rpcClient.invokeAsync(endpoint, request, invokeCtx, invokeCallback, this.rpcTimeoutMillis); } catch (final Throwable t) { closure.failure(t); }

你是对的,我测试了一下,确实直接抛异常出去了

@en-hui
Copy link

en-hui commented Aug 12, 2024

您好,我尝试使用1.3.15,好像问题并没有修复

回顾你贴出的异常:https://github.com/sofastack/sofa-jraft/issues/1131#issuecomment-2255066719。 这是bolt心跳重连,对应节点已经下掉,与put失败无关。可以通过参数来关闭重连。
你说的未修复的问题,可以再提供一些详细信息吗?

您的修改为:在rpc回调的complete中添加了异常处理,我复现发现当出现RemotingException的时候,并未进入complete,而是在这里直接异常处理了。所以没有进到closure.run(new Status(-1, "RPC failed with address: %s, response: %s", endpoint, response)); try { this.rpcClient.invokeAsync(endpoint, request, invokeCtx, invokeCallback, this.rpcTimeoutMillis); } catch (final Throwable t) { closure.failure(t); }

你是对的,我测试了一下,确实直接抛异常出去了

最近还能在发一次版本吗,或者这个版本从发?
关于关闭bolt心跳重连这个参数,能大概说下有哪些不利影响吗?

@shihuili1218
Copy link
Collaborator Author

您好,我尝试使用1.3.15,好像问题并没有修复

回顾你贴出的异常:https://github.com/sofastack/sofa-jraft/issues/1131#issuecomment-2255066719。 这是bolt心跳重连,对应节点已经下掉,与put失败无关。可以通过参数来关闭重连。
你说的未修复的问题,可以再提供一些详细信息吗?

您的修改为:在rpc回调的complete中添加了异常处理,我复现发现当出现RemotingException的时候,并未进入complete,而是在这里直接异常处理了。所以没有进到closure.run(new Status(-1, "RPC failed with address: %s, response: %s", endpoint, response)); try { this.rpcClient.invokeAsync(endpoint, request, invokeCtx, invokeCallback, this.rpcTimeoutMillis); } catch (final Throwable t) { closure.failure(t); }

你是对的,我测试了一下,确实直接抛异常出去了

最近还能在发一次版本吗,或者这个版本从发? 关于关闭bolt心跳重连这个参数,能大概说下有哪些不利影响吗?

应该会发一个fix版本

@en-hui
Copy link

en-hui commented Aug 12, 2024

在使用RheaKV的时候,RpcOption指定blot心跳关闭,应该如何设置呢?我使用了下面的第一种方式,2、3我没有找到参数和rheaKVStore结合使用的方法

// 1、直接这样使用是正确方式吗
SystemPropertyUtil.setProperty("jraft.bolt.conn.reconnect", "false");
// 2、rhea 中的rpcOption没有该参数
final com.alipay.sofa.jraft.rhea.options.RpcOptions config = RpcOptionsConfigured.newConfigured().config();
// 3、这个包有,但是无法给rheaKVStore使用
final com.alipay.sofa.jraft.option.RpcOptions rpcOptions = new com.alipay.sofa.jraft.option.RpcOptions();
rpcOptions.setEnableBoltReconnect(false);

@shihuili1218
Copy link
Collaborator Author

@en-hui 我们准备发一个fix版本 #1141

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.

3 participants