-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add heartbeat processor #343
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* Copyright (c) 2018 - present, VE Software Inc. All rights reserved | ||
* | ||
* This source code is licensed under Apache 2.0 License | ||
* (found in the LICENSE.Apache file in the root directory) | ||
*/ | ||
|
||
|
||
#include "meta/processors/HBProcessor.h" | ||
|
||
DEFINE_int32(expired_hosts_check_interval_sec, 20, | ||
"Check the expired hosts at the interval"); | ||
DEFINE_int32(expired_threshold_sec, 10 * 60, | ||
"Hosts will be expired in this time if no heartbeat received"); | ||
|
||
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. Would a parameter check be better? for example : 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. Sounds good. |
||
namespace nebula { | ||
namespace meta { | ||
|
||
|
||
} // namespace meta | ||
} // namespace nebula | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* Copyright (c) 2018 - present, VE Software Inc. All rights reserved | ||
* | ||
* This source code is licensed under Apache 2.0 License | ||
* (found in the LICENSE.Apache file in the root directory) | ||
*/ | ||
|
||
#ifndef META_HBPROCESSOR_H_ | ||
#define META_HBPROCESSOR_H_ | ||
|
||
#include <gtest/gtest_prod.h> | ||
#include "meta/processors/BaseProcessor.h" | ||
#include "meta/ActiveHostsMan.h" | ||
#include "time/TimeUtils.h" | ||
|
||
DECLARE_int32(expired_hosts_check_interval_sec); | ||
DECLARE_int32(expired_threshold_sec); | ||
|
||
namespace nebula { | ||
namespace meta { | ||
|
||
class HBProcessor : public BaseProcessor<cpp2::HBResp> { | ||
FRIEND_TEST(HBProcessorTest, HBTest); | ||
|
||
public: | ||
static HBProcessor* instance(kvstore::KVStore* kvstore) { | ||
return new HBProcessor(kvstore); | ||
} | ||
|
||
void process(const cpp2::HBReq& req) { | ||
HostAddr host(req.host.ip, req.host.port); | ||
if (hostExist(MetaServiceUtils::hostKey(host.first, host.second)) | ||
== Status::HostNotFound()) { | ||
LOG(INFO) << "Reject unregistered host " << host << "!"; | ||
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. I think we should add a interface to handler the situation uniformly. 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. Output HostAddr to stream has been supported. |
||
resp_.set_code(cpp2::ErrorCode::E_INVALID_HOST); | ||
onFinished(); | ||
return; | ||
} | ||
|
||
LOG(INFO) << "Receive heartbeat from " << host; | ||
HostInfo info; | ||
info.lastHBTimeInSec_ = time::TimeUtils::nowInSeconds(); | ||
hostsMan()->updateHostInfo(host, info); | ||
onFinished(); | ||
} | ||
|
||
private: | ||
explicit HBProcessor(kvstore::KVStore* kvstore) | ||
: BaseProcessor<cpp2::HBResp>(kvstore) {} | ||
|
||
static ActiveHostsMan* hostsMan() { | ||
static auto hostsMan | ||
= std::make_unique<ActiveHostsMan>(FLAGS_expired_hosts_check_interval_sec, | ||
FLAGS_expired_threshold_sec); | ||
return hostsMan.get(); | ||
} | ||
}; | ||
|
||
} // namespace meta | ||
} // namespace nebula | ||
|
||
#endif // META_HBPROCESSOR_H_ |
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.
timestamp ?
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.
For what?
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.
when a storage node offline, could get the final reporting time.
Or recorded it in logs
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.
We have recorded its last hb-timestamp