forked from vesoft-inc/nebula
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
16 changed files
with
282 additions
and
2 deletions.
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* Copyright (c) 2019 vesoft inc. All rights reserved. | ||
* | ||
* This source code is licensed under Apache 2.0 License, | ||
* attached with Common Clause Condition 1.0, found in the LICENSES directory. | ||
*/ | ||
|
||
#include "meta/processors/partsMan/ListPartsProcessor.h" | ||
#include "meta/processors/admin/AdminClient.h" | ||
|
||
namespace nebula { | ||
namespace meta { | ||
|
||
void ListPartsProcessor::process(const cpp2::ListPartsReq& req) { | ||
spaceId_ = req.get_space_id(); | ||
std::unordered_map<PartitionID, std::vector<nebula::cpp2::HostAddr>> partHostsMap; | ||
{ | ||
folly::SharedMutex::ReadHolder rHolder(LockUtils::spaceLock()); | ||
auto status = getAllParts(); | ||
if (!status.ok()) { | ||
onFinished(); | ||
return; | ||
} | ||
partHostsMap = std::move(status.value()); | ||
} | ||
std::vector<cpp2::PartItem> partItems; | ||
getLeaderDist(partItems, partHostsMap); | ||
// TODO(zhangguoqing) getAllLosts() of parts | ||
resp_.set_parts(std::move(partItems)); | ||
onFinished(); | ||
} | ||
|
||
|
||
StatusOr<std::unordered_map<PartitionID, std::vector<nebula::cpp2::HostAddr>>> | ||
ListPartsProcessor::getAllParts() { | ||
std::unordered_map<PartitionID, std::vector<nebula::cpp2::HostAddr>> partHostsMap; | ||
|
||
folly::SharedMutex::ReadHolder rHolder(LockUtils::spaceLock()); | ||
auto prefix = MetaServiceUtils::partPrefix(spaceId_); | ||
std::unique_ptr<kvstore::KVIterator> iter; | ||
auto kvRet = kvstore_->prefix(kDefaultSpaceId, kDefaultPartId, prefix, &iter); | ||
if (kvRet != kvstore::ResultCode::SUCCEEDED) { | ||
LOG(ERROR) << "List Parts Failed: No parts"; | ||
resp_.set_code(cpp2::ErrorCode::E_NOT_FOUND); | ||
return Status::Error("Can't access kvstore, ret = %d", static_cast<int32_t>(kvRet)); | ||
} | ||
|
||
while (iter->valid()) { | ||
auto key = iter->key(); | ||
PartitionID partId; | ||
memcpy(&partId, key.data() + prefix.size(), sizeof(PartitionID)); | ||
std::vector<nebula::cpp2::HostAddr> partHosts = MetaServiceUtils::parsePartVal(iter->val()); | ||
partHostsMap.emplace(partId, std::move(partHosts)); | ||
iter->next(); | ||
} | ||
|
||
return partHostsMap; | ||
} | ||
|
||
|
||
void ListPartsProcessor::getLeaderDist( | ||
std::vector<cpp2::PartItem>& partItems, | ||
std::unordered_map<PartitionID, std::vector<nebula::cpp2::HostAddr>>& partHostsMap) { | ||
if (adminClient_ == nullptr) { | ||
return; | ||
} | ||
|
||
HostLeaderMap hostLeaderMap; | ||
auto ret = adminClient_->getLeaderDist(&hostLeaderMap).get(); | ||
if (!ret.ok()) { | ||
LOG(ERROR) << "Get leader distribution failed"; | ||
return; | ||
} | ||
|
||
for (auto& hostEntry : hostLeaderMap) { | ||
auto leader = hostEntry.first; | ||
auto spaceIter = hostEntry.second.find(spaceId_); | ||
if (spaceIter != hostEntry.second.end()) { | ||
for (auto& partId : spaceIter->second) { | ||
cpp2::PartItem partItem; | ||
partItem.set_part_id(partId); | ||
partItem.set_leader(this->toThriftHost(leader)); | ||
auto hostsIt = partHostsMap.find(partId); | ||
if (hostsIt != partHostsMap.end()) { | ||
partItem.set_peers(std::move(hostsIt->second)); | ||
} | ||
partItems.emplace_back(std::move(partItem)); | ||
} | ||
} | ||
} | ||
|
||
if (partItems.size() != partHostsMap.size()) { | ||
LOG(ERROR) << "Maybe lost some partitions!"; | ||
} | ||
} | ||
|
||
} // namespace meta | ||
} // namespace nebula | ||
|
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,47 @@ | ||
/* Copyright (c) 2019 vesoft inc. All rights reserved. | ||
* | ||
* This source code is licensed under Apache 2.0 License, | ||
* attached with Common Clause Condition 1.0, found in the LICENSES directory. | ||
*/ | ||
|
||
#ifndef META_LISTPARTSPROCESSOR_H_ | ||
#define META_LISTPARTSPROCESSOR_H_ | ||
|
||
#include "meta/processors/BaseProcessor.h" | ||
#include "meta/processors/admin/AdminClient.h" | ||
|
||
namespace nebula { | ||
namespace meta { | ||
|
||
class ListPartsProcessor : public BaseProcessor<cpp2::ListPartsResp> { | ||
public: | ||
static ListPartsProcessor* instance(kvstore::KVStore* kvstore, | ||
AdminClient* adminClient = nullptr) { | ||
return new ListPartsProcessor(kvstore, adminClient); | ||
} | ||
|
||
void process(const cpp2::ListPartsReq& req); | ||
|
||
private: | ||
explicit ListPartsProcessor(kvstore::KVStore* kvstore, AdminClient* adminClient) | ||
: BaseProcessor<cpp2::ListPartsResp>(kvstore) | ||
, adminClient_(adminClient) {} | ||
|
||
|
||
// Get parts alloc information | ||
StatusOr<std::unordered_map<PartitionID, std::vector<nebula::cpp2::HostAddr>>> getAllParts(); | ||
|
||
// Get all parts with storage leader distribution | ||
void getLeaderDist(std::vector<cpp2::PartItem>& partItems, | ||
std::unordered_map<PartitionID, | ||
std::vector<nebula::cpp2::HostAddr>>& partHostsMap); | ||
|
||
private: | ||
AdminClient* adminClient_; | ||
GraphSpaceID spaceId_; | ||
}; | ||
|
||
} // namespace meta | ||
} // namespace nebula | ||
|
||
#endif // META_LISTPARTSPROCESSOR_H_ |
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
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.