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

meta-server: re-implement returning forward address in configuration_query_b… #217

Merged
merged 1 commit into from
Jan 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 1 addition & 12 deletions include/dsn/cpp/serialization_helper/dsn.layer2_types.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 0 additions & 24 deletions src/core/core/dsn.layer2_types.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 25 additions & 18 deletions src/dist/replication/meta_server/meta_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,23 +361,6 @@ int meta_service::check_leader(dsn::message_ex *req, dsn::rpc_address *forward_a
return; \
}

#define RPC_CHECK_STATUS_WITH_FORWARD(dsn_msg, response_struct) \
dinfo("rpc %s called", __FUNCTION__); \
int result = check_leader(dsn_msg, &response_struct.forward_address); \
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; \
}

// table operations
void meta_service::on_create_app(dsn::message_ex *req)
{
Expand Down Expand Up @@ -507,7 +490,31 @@ void meta_service::on_query_configuration_by_node(dsn::message_ex *msg)
void meta_service::on_query_configuration_by_index(dsn::message_ex *msg)
{
configuration_query_by_index_response response;
RPC_CHECK_STATUS_WITH_FORWARD(msg, response);

// here we do not use RPC_CHECK_STATUS macro, but specially handle it
// to response forward address.
dinfo("rpc %s called", __FUNCTION__);
Copy link
Member

Choose a reason for hiding this comment

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

__FUNCTION__ 在这里不是固定的 on_query_configuration_by_index 这个函数吗?

Copy link
Member Author

Choose a reason for hiding this comment

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

是的,这里一方面是为了让代码和宏保持一致,一方面如果以后改了函数名,这里也不用改

rpc_address forward_address;
int result = check_leader(msg, &forward_address);
if (result == 0)
return;
if (result == -1 || !_started) {
if (result == -1) {
response.err = ERR_FORWARD_TO_OTHERS;
if (!forward_address.is_invalid()) {
partition_configuration config;
config.primary = forward_address;
response.partitions.push_back(std::move(config));
}
} else if (_recovering) {
response.err = ERR_UNDER_RECOVERY;
} else {
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);
Expand Down
3 changes: 2 additions & 1 deletion src/dsn.layer2.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ struct configuration_query_by_index_request
2:list<i32> partition_indices;
}

// for server version > 1.11.2, if err == ERR_FORWARD_TO_OTHERS,
// then the forward address will be put in partitions[0].primary if exist.
struct configuration_query_by_index_response
{
1:dsn.error_code err;
2:i32 app_id;
3:i32 partition_count;
4:bool is_stateful;
5:list<partition_configuration> partitions;
6:dsn.rpc_address forward_address;
}

enum app_status
Expand Down