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

Commit

Permalink
refactor: use rpc_holder to reimplement on_query_configuration_by_ind…
Browse files Browse the repository at this point in the history
…ex (#474)
  • Loading branch information
zhao liwei authored and neverchanje committed May 28, 2020
1 parent 87194af commit 667b3d7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
3 changes: 3 additions & 0 deletions include/dsn/cpp/rpc_holder.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ class rpc_holder
return rpc;
}

// disable auto reply which is performed in the destructor of _i
void disable_auto_reply() { _i->auto_reply = false; }

// Only use this function when testing.
// In mock mode, all messages will be dropped into mail_box without going through network,
// and response callbacks will never be called.
Expand Down
29 changes: 17 additions & 12 deletions src/dist/replication/meta_server/meta_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <dsn/tool-api/command_manager.h>
#include <algorithm> // for std::remove_if
#include <cctype> // for ::isspace
#include <dsn/dist/fmt_logging.h>

#include "meta_service.h"
#include "server_state.h"
Expand Down Expand Up @@ -345,9 +346,9 @@ void meta_service::register_rpc_handlers()
"query_configuration_by_node",
&meta_service::on_query_configuration_by_node);
register_rpc_handler(RPC_CM_CONFIG_SYNC, "config_sync", &meta_service::on_config_sync);
register_rpc_handler(RPC_CM_QUERY_PARTITION_CONFIG_BY_INDEX,
"query_configuration_by_index",
&meta_service::on_query_configuration_by_index);
register_rpc_handler_with_rpc_holder(RPC_CM_QUERY_PARTITION_CONFIG_BY_INDEX,
"query_configuration_by_index",
&meta_service::on_query_configuration_by_index);
register_rpc_handler(RPC_CM_UPDATE_PARTITION_CONFIGURATION,
"update_configuration",
&meta_service::on_update_configuration);
Expand Down Expand Up @@ -567,17 +568,19 @@ void meta_service::on_query_configuration_by_node(dsn::message_ex *msg)
reply(msg, response);
}

void meta_service::on_query_configuration_by_index(dsn::message_ex *msg)
void meta_service::on_query_configuration_by_index(configuration_query_by_index_rpc rpc)
{
configuration_query_by_index_response response;
configuration_query_by_index_response &response = rpc.response();

// here we do not use RPC_CHECK_STATUS macro, but specially handle it
// to response forward address.
dinfo("rpc %s called", __FUNCTION__);
rpc_address forward_address;
int result = check_leader(msg, &forward_address);
if (result == 0)
int result = check_leader(rpc.dsn_request(), &forward_address);
if (result == 0) {
rpc.disable_auto_reply();
return;
}
if (result == -1 || !_started) {
if (result == -1) {
response.err = ERR_FORWARD_TO_OTHERS;
Expand All @@ -592,14 +595,16 @@ void meta_service::on_query_configuration_by_index(dsn::message_ex *msg)
response.err = ERR_SERVICE_NOT_ACTIVE;
}
ddebug("reject request with %s", response.err.to_string());
reply(msg, response);
return;
}

configuration_query_by_index_request request;
dsn::unmarshall(msg, request);
_state->query_configuration_by_index(request, response);
reply(msg, response);
_state->query_configuration_by_index(rpc.request(), response);
if (ERR_OK == response.err) {
ddebug_f("client {} queried an available app {} with appid {}",
rpc.dsn_request()->header->from_address.to_string(),
rpc.request().app_name,
response.app_id);
}
}

// partition sever => meta sever
Expand Down
4 changes: 3 additions & 1 deletion src/dist/replication/meta_server/meta_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ typedef rpc_holder<configuration_update_app_env_request, configuration_update_ap
typedef rpc_holder<ddd_diagnose_request, ddd_diagnose_response> ddd_diagnose_rpc;
typedef rpc_holder<app_partition_split_request, app_partition_split_response>
app_partition_split_rpc;
typedef rpc_holder<configuration_query_by_index_request, configuration_query_by_index_response>
configuration_query_by_index_rpc;

class meta_service : public serverlet<meta_service>
{
Expand Down Expand Up @@ -139,7 +141,7 @@ class meta_service : public serverlet<meta_service>
// client => meta server
// query partition configuration
void on_query_configuration_by_node(dsn::message_ex *req);
void on_query_configuration_by_index(dsn::message_ex *req);
void on_query_configuration_by_index(configuration_query_by_index_rpc rpc);

// partition server => meta server
void on_config_sync(dsn::message_ex *req);
Expand Down

0 comments on commit 667b3d7

Please sign in to comment.