This repository has been archived by the owner on Jun 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
rpc: remove uri resolver; move partition resolver to replication/client #205
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
39d6b1f
replication: remove uri resolver, move feature to replication client
shengofsun b1eb86f
Merge branch 'master' into refactor-resolver
9b1ef23
Merge branch 'master' into refactor-resolver
qinzuoyan 09d0452
fix code format
0900b9e
fix based on comments
shengofsun b95ba2a
fix based on comments
shengofsun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2015 Microsoft Corporation | ||
* | ||
* -=- Robust Distributed System Nucleus (rDSN) -=- | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <dsn/utility/autoref_ptr.h> | ||
#include <dsn/utility/error_code.h> | ||
#include <dsn/tool-api/gpid.h> | ||
#include <dsn/tool-api/rpc_address.h> | ||
#include <dsn/tool-api/rpc_message.h> | ||
#include <dsn/tool-api/async_calls.h> | ||
|
||
namespace dsn { | ||
namespace replication { | ||
|
||
class partition_resolver : public ref_counter | ||
{ | ||
public: | ||
static dsn::ref_ptr<partition_resolver> | ||
get_resolver(const char *cluster_name, | ||
const std::vector<dsn::rpc_address> &meta_list, | ||
const char *app_name); | ||
|
||
template <typename TReq, typename TCallback> | ||
dsn::rpc_response_task_ptr call_op(dsn::task_code code, | ||
TReq &&request, | ||
dsn::task_tracker *tracker, | ||
TCallback &&callback, | ||
std::chrono::milliseconds timeout, | ||
uint64_t partition_hash, | ||
int reply_hash = 0) | ||
{ | ||
dsn::message_ex *msg = dsn::message_ex::create_request( | ||
code, static_cast<int>(timeout.count()), 0, partition_hash); | ||
marshall(msg, std::forward<TReq>(request)); | ||
dsn::rpc_response_task_ptr response_task = rpc::create_rpc_response_task( | ||
msg, tracker, std::forward<TCallback>(callback), reply_hash); | ||
call_task(response_task); | ||
return response_task; | ||
} | ||
|
||
void call_task(const dsn::rpc_response_task_ptr &task); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 建议对public的方法都增加注释,表名这个函数是做什么的,产生什么效果。 |
||
|
||
std::string get_app_name() const { return _app_name; } | ||
|
||
dsn::rpc_address get_meta_server() const { return _meta_server; } | ||
|
||
protected: | ||
partition_resolver(rpc_address meta_server, const char *app_name) | ||
: _app_name(app_name), _meta_server(meta_server) | ||
{ | ||
} | ||
|
||
virtual ~partition_resolver() {} | ||
|
||
struct resolve_result | ||
{ | ||
///< ERR_OK | ||
///< ERR_SERVICE_NOT_FOUND if resolver or app is missing | ||
///< ERR_IO_PENDING if resolve in is progress, callers | ||
///< should call resolve_async in this case | ||
error_code err; | ||
///< IPv4 of the target to send request to | ||
rpc_address address; | ||
///< global partition indentity | ||
dsn::gpid pid; | ||
}; | ||
|
||
/** | ||
* resolve partition_hash into IP or group addresses to know what to connect next | ||
* | ||
* \param partition_hash the partition hash | ||
* \param callback callback invoked on completion or timeout | ||
* \param timeout_ms timeout to execute the callback | ||
* | ||
* \return see \ref resolve_result for details | ||
*/ | ||
virtual void resolve(uint64_t partition_hash, | ||
std::function<void(resolve_result &&)> &&callback, | ||
int timeout_ms) = 0; | ||
|
||
/*! | ||
failure handler when access failed for certain partition | ||
|
||
\param partition_index zero-based index of the partition. | ||
\param err error code | ||
|
||
this is usually to trigger new round of address resolve | ||
*/ | ||
virtual void on_access_failure(int partition_index, error_code err) = 0; | ||
|
||
/** | ||
* get zero-based partition index | ||
* | ||
* \param partition_count number of partitions. | ||
* \param partition_hash the partition hash. | ||
* | ||
* \return zero-based partition index. | ||
*/ | ||
|
||
virtual int get_partition_index(int partition_count, uint64_t partition_hash) = 0; | ||
|
||
std::string _cluster_name; | ||
std::string _app_name; | ||
rpc_address _meta_server; | ||
}; | ||
|
||
typedef ref_ptr<partition_resolver> partition_resolver_ptr; | ||
|
||
} // namespace replication | ||
} // namespace dsn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个改名叫 call_replica 是不是合适一点。call_op 还不如简单叫 call。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
java那边叫operate,叫call_op是为了蹭那边的“operate”……
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我觉得 java 叫 operator 这个名字也很一般...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我觉得叫op也挺好的啊,各种操作,不就是个op嘛……
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
其实叫什么真的无所谓了。
不过我个人觉得呢,连同下面的call_task,都叫call得了(反正函数重载)。
就没这么多纠结了,哈哈哈...