Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

fix: fix RPC_CHECK_STATUS incorrect usage in meta_service #497

Merged
merged 25 commits into from
Jun 15, 2020

Conversation

levy5307
Copy link
Contributor

@levy5307 levy5307 commented Jun 10, 2020

In meta_service, there are some rpc interfaces which are using rpc_holder. And they use RPC_CHECK_STATUS to do some check work. But it will cause the response to be sent repeatedly, for example:

  1. A response will replied in RPC_CHECK_STATUS, and another response will be sent in the dstor of rpc_holder. So one response is sent repeatedly here.

  2. If this node is not a master, a forward message will send in this macro, And this situation is same as above.

The implementation of RPC_CHECK_STATUS:

#define RPC_CHECK_STATUS(dsn_msg, response_struct)                                                 \
    dinfo("rpc %s called", __FUNCTION__);                                                          \
    int result = check_leader(dsn_msg, nullptr);                                                   \
    if (result == 0)                                                                               \
        return;                                                                                    \
    if (result == -1 || !_started) {                                                               \
        if (result == -1)                                                                          \
            response_struct.err = ERR_FORWARD_TO_OTHERS;                                           \
        else if (_recovering)                                                                      \
            response_struct.err = ERR_UNDER_RECOVERY;                                              \
        else                                                                                       \
            response_struct.err = ERR_SERVICE_NOT_ACTIVE;                                          \
        ddebug("reject request with %s", response_struct.err.to_string());                         \
        reply(dsn_msg, response_struct);                                                           \
        return;                                                                                    \
    }

zhaoliwei added 3 commits June 10, 2020 17:00
@neverchanje neverchanje changed the title fix: fix bug in meta_service fix: fix bug in meta_service RPC_CHECK_STATUS Jun 10, 2020
@levy5307 levy5307 changed the title fix: fix bug in meta_service RPC_CHECK_STATUS fix: fix RPC_CHECK_STATUS use error in meta_service Jun 10, 2020
@neverchanje neverchanje changed the title fix: fix RPC_CHECK_STATUS use error in meta_service fix: fix RPC_CHECK_STATUS incorrect usage in meta_service Jun 10, 2020
@levy5307 levy5307 marked this pull request as draft June 10, 2020 10:41
@levy5307 levy5307 marked this pull request as ready for review June 10, 2020 10:53
zhaoliwei added 2 commits June 10, 2020 19:00
}

template <typename TRpcHolder>
bool meta_service::check_status(TRpcHolder rpc, rpc_address *forward_address)
Copy link
Contributor

Choose a reason for hiding this comment

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

This function name is not self-descriptive enough. Call it try_forward_if_not_leader

I highly recommend you add a unit test here, btw. It seems slightly difficult to mock the case where this meta is not the leader. But since it's necessary, you can add a fail_point to meta_server_failure_detector::get_leader

Copy link
Contributor Author

@levy5307 levy5307 Jun 11, 2020

Choose a reason for hiding this comment

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

I don't think try_forward_if_not_leader is a good name. Because the main purpose for this function is to do some check work, but not forward

src/dist/replication/meta_server/meta_service.cpp Outdated Show resolved Hide resolved
include/dsn/cpp/rpc_holder.h Outdated Show resolved Hide resolved
zhaoliwei added 7 commits June 11, 2020 15:32
acelyc111
acelyc111 previously approved these changes Jun 12, 2020
template <typename TRpcHolder>
int check_leader(TRpcHolder rpc, /*out*/ rpc_address *forward_address);
template <typename TRpcHolder>
bool check_status(TRpcHolder rpc, /*out*/ rpc_address *forward_address = nullptr);
Copy link
Contributor

Choose a reason for hiding this comment

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

I checked all the callers of check_status. None is using the parameter forward_address . It's useless I think.

Suggested change
bool check_status(TRpcHolder rpc, /*out*/ rpc_address *forward_address = nullptr);
bool check_status(TRpcHolder 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.

I will use it in the later pull request, which needs the forward_address.

neverchanje
neverchanje previously approved these changes Jun 12, 2020
@levy5307 levy5307 marked this pull request as draft June 12, 2020 04:12
@levy5307 levy5307 marked this pull request as ready for review June 12, 2020 06:15
neverchanje
neverchanje previously approved these changes Jun 12, 2020
@neverchanje neverchanje merged commit 33afe0e into XiaoMi:master Jun 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants