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

task_tracker: refactor on task_tracker #41

Merged
merged 4 commits into from May 7, 2018

Conversation

shengofsun
Copy link
Contributor

  1. remove c interface of task tracker
  2. remove task tracker from clientlet and fix all the
    misusing of task tracker as it shouldn't be stored
    in a base class

@@ -159,8 +149,7 @@ class serverlet : public virtual clientlet

// ------------- inline implementation ----------------
template <typename T>
inline serverlet<T>::serverlet(const char *nm, int task_bucket_count)
: clientlet(task_bucket_count), _name(nm)
inline serverlet<T>::serverlet(const char *nm) : clientlet(), _name(nm)
Copy link
Contributor

Choose a reason for hiding this comment

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

默认构造函数就不需要写 clientlet() 了

@@ -224,7 +224,7 @@ void provider_recursively_create_delete_test(const service_creator_func &creator
const service_deleter_func &deleter)
{
meta_state_service *service = creator();
clientlet tracker;
dsn::task_tracker tracker(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

把 1 删掉

Copy link
Member

Choose a reason for hiding this comment

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

还不止一处,默认是1的地方都删掉吧

task_ptr
call(::dsn::rpc_address server, clientlet *svc, TCallback &&callback, int reply_thread_hash = 0)
task_ptr call(::dsn::rpc_address server,
dsn::task_tracker *svc,
Copy link
Member

Choose a reason for hiding this comment

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

变量名改一下,改成tracker

@@ -273,7 +275,7 @@ namespace rpc {
template <typename TCallback, typename TRpcHolder>
task_ptr call(::dsn::rpc_address server,
TRpcHolder rpc,
clientlet *svc,
dsn::task_tracker *svc,
Copy link
Member

Choose a reason for hiding this comment

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

变量名改一下,改成tracker

@@ -117,7 +107,7 @@ template <typename T> // where T : serverlet<T>
class serverlet : public virtual clientlet
{
public:
serverlet(const char *nm, int task_bucket_count = 1);
serverlet(const char *nm);
Copy link
Member

Choose a reason for hiding this comment

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

加explicit关键字

@@ -218,6 +218,8 @@ class failure_detector : public failure_detector_service,
mutable service::zlock _lock;
// subClass can rewrite these method.
virtual void send_beacon(::dsn::rpc_address node, uint64_t time);

dsn::task_tracker _tracker;
Copy link
Member

Choose a reason for hiding this comment

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

变量和_lock放在一起吧,别变量和方法混着放。

另外,在析构函数也需要调用 cancel_outstanding_tasks() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这个是在子类里面调用的

// task_tracker is the base class for RPC service and client
// there can be multiple task_tracker in the system, mostly
// defined during set_tracker in main
// task_tracker mainly used to prevent a task from visit a deleted object. For example:
Copy link
Member

Choose a reason for hiding this comment

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

task_tracker is mainly used to prevent a task from visiting a deleted object.

@@ -193,6 +195,8 @@ class meta_service : public serverlet<meta_service>

perf_counter_wrapper _recent_disconnect_count;
perf_counter_wrapper _unalive_nodes_count;

dsn::task_tracker _tracker;
Copy link
Member

Choose a reason for hiding this comment

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

忘记在析构函数调用 cancel_outstanding_tasks() ?

clientlet *tracker() { return &_tracker; }
void wait_all_task() { dsn_task_tracker_wait_all(_tracker.tracker()); }
task_tracker *tracker() { return &_tracker; }
void wait_all_task() { _tracker.wait_outstanding_tasks(); }
Copy link
Member

Choose a reason for hiding this comment

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

这两个方法没啥用,去掉吧

Copy link
Contributor Author

Choose a reason for hiding this comment

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

测试用的

@@ -301,7 +302,7 @@ class server_state

// ATTENTION:
// DO NOT use this tracker to track timer task
clientlet _tracker;
dsn::task_tracker _tracker;
Copy link
Member

Choose a reason for hiding this comment

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

这个ATTENTION分析一下,还有没有必要保留?如果有必要,把注释写详细写,为什么不能track timer task。

另外忘记在析构函数调用 cancel_outstanding_tasks() ?

@@ -269,7 +266,7 @@ task_ptr meta_state_service_zookeeper::delete_node(const std::string &node,
bind_and_enqueue(tsk, err);
else if (children.empty())
delete_empty_node(
node, cb_code, [tsk](error_code err) { bind_and_enqueue(tsk, err); }, this);
node, cb_code, [tsk](error_code err) { bind_and_enqueue(tsk, err); }, nullptr);
Copy link
Member

Choose a reason for hiding this comment

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

这里用null没有问题吗?

@@ -224,7 +224,7 @@ void provider_recursively_create_delete_test(const service_creator_func &creator
const service_deleter_func &deleter)
{
meta_state_service *service = creator();
clientlet tracker;
dsn::task_tracker tracker(1);
Copy link
Member

Choose a reason for hiding this comment

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

还不止一处,默认是1的地方都删掉吧

@shengofsun
Copy link
Contributor Author

已修改

return ::dsn::ERR_OK;
}

virtual ::dsn::error_code stop(bool cleanup = false)
{
_tracker.cancel_outstanding_tasks();
Copy link
Member

Choose a reason for hiding this comment

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

下面的 _timer->cancel(true); 是不是没必要了?

@@ -125,6 +125,8 @@ class partition_resolver_simple : public partition_resolver, public virtual clie
dsn_message_t request,
dsn_message_t response,
int partition_index);

dsn::task_tracker _tracker;
Copy link
Member

Choose a reason for hiding this comment

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

放在变量一起吧。
整理一下,把私有方法都放在一个单独的private段里面。
public:
// public methods
private:
// private methods
private:
// attributes

partition_resolver_simple::~partition_resolver_simple() { clear_all_pending_requests(); }
partition_resolver_simple::~partition_resolver_simple()
{
_tracker.cancel_outstanding_tasks();
Copy link
Member

Choose a reason for hiding this comment

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

考虑下是放在clear_all_pending_requests()前面还是后面更合适

_checkpoint_timer->cancel(true);
_checkpoint_timer = nullptr;
}
// TODO: assert _checkpoint_timer.is_cancelled_or_finished
Copy link
Member

Choose a reason for hiding this comment

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

别TODO了,直接:
dassert(_checkpoint_timer->cancel(false), "checkpoint_timer should already been canceled");

@@ -101,6 +99,7 @@ void replica::init_checkpoint(bool is_emergency)
return;
}

::dsn::service::zauto_lock l(_async_checkpoint_lock);
Copy link
Member

Choose a reason for hiding this comment

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

如果用了tracker,就不需要 _async_checkpoint_task 和 _async_checkpoint_lock 变量了,相关代码都可以干掉

@@ -300,8 +301,9 @@ class server_state
friend class ::meta_service_test_app;

// ATTENTION:
// DO NOT use this tracker to track timer task
clientlet _tracker;
// when use tracker to track timer task, please make sure not to wait the timer task.
Copy link
Member

Choose a reason for hiding this comment

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

感觉这个注释放在 task_tracker::wait_outstanding_tasks() 那里更合适?

@@ -339,6 +339,8 @@ class mutation_log : public ref_counter, public virtual clientlet
int64_t _min_log_file_size_in_bytes;
bool _force_flush;

dsn::task_tracker _tracker;
Copy link
Member

Choose a reason for hiding this comment

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

感觉在 mutation_log::close() 函数里面的 flush() 后面调用下 _tracker->cancel_outstanding_tasks() 更妥当:

// make all data is on disk
flush();

_tracker->cancel_outstanding_tasks() 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

在flush的时候调过wait了

// int value;
// task_tracker _tracker;
// };
//
Copy link
Member

Choose a reason for hiding this comment

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

直接写个Attention列表,包括不能wait timer task,都写到这里。

另外 so that to ensure all tasks.. 改为 to ensure that all tasks.. 比较好。

qinzuoyan
qinzuoyan previously approved these changes May 7, 2018
Copy link
Member

@qinzuoyan qinzuoyan left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -303,7 +295,7 @@ struct rpc_message_helper
explicit rpc_message_helper(dsn_message_t request) : request(request) {}
template <typename TCallback>
task_ptr call(::dsn::rpc_address server,
clientlet *owner,
dsn::task_tracker *owner,
Copy link
Contributor

Choose a reason for hiding this comment

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

这里名字也改成 tracker ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

改了

// task_tracker is used to track one ore more unfinished tasks, you may use it to
// wait or cancel the tasks tracked by the tracker.
//
// A classical situation is use tracker to prevent a task from visiting a delete object.
Copy link
Contributor

Choose a reason for hiding this comment

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

deleted, not delete

Copy link
Contributor Author

Choose a reason for hiding this comment

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

改了

@@ -78,7 +78,7 @@ class cli_client : public virtual ::dsn::clientlet
return ::dsn::rpc::call(server_addr.unwrap_or(_server),
RPC_CLI_CLI_CALL,
args,
this,
nullptr,
Copy link
Contributor

Choose a reason for hiding this comment

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

最好还是加上 tracker,方便以后可能的测试

Copy link
Contributor Author

Choose a reason for hiding this comment

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

测试的时候加?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

加了

1. remove c interface of task tracker
2. remove task tracker from clientlet and fix all the
   misusing of task tracker as it shouldn't be stored
   in a base class
Copy link
Member

@qinzuoyan qinzuoyan left a comment

Choose a reason for hiding this comment

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

LGTM

@shengofsun shengofsun merged commit f187c7b into XiaoMi:master May 7, 2018
@qinzuoyan qinzuoyan mentioned this pull request Aug 20, 2018
28 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants