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

Commit

Permalink
init upload (#492)
Browse files Browse the repository at this point in the history
Co-authored-by: panda-sheep <59197347+panda-sheep@users.noreply.github.com>
Co-authored-by: CBS <56461666+bright-starry-sky@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 2, 2021
1 parent df7a638 commit 6b31073
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
29 changes: 26 additions & 3 deletions src/common/clients/meta/MetaClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ bool MetaClient::loadData() {

for (auto space : ret.value()) {
auto spaceId = space.first;
auto r = getPartsAlloc(spaceId).get();
MetaClient::PartTerms partTerms;
auto r = getPartsAlloc(spaceId, &partTerms).get();
if (!r.ok()) {
LOG(ERROR) << "Get parts allocation failed for spaceId " << spaceId
<< ", status " << r.status();
Expand All @@ -218,6 +219,7 @@ bool MetaClient::loadData() {
auto& spaceName = space.second;
spaceCache->partsOnHost_ = reverse(partsAlloc);
spaceCache->partsAlloc_ = std::move(partsAlloc);
spaceCache->termOfPartition_ = std::move(partTerms);
VLOG(2) << "Load space " << spaceId
<< ", parts num:" << spaceCache->partsAlloc_.size();

Expand Down Expand Up @@ -1169,7 +1171,7 @@ MetaClient::listParts(GraphSpaceID spaceId, std::vector<PartitionID> partIds) {


folly::Future<StatusOr<std::unordered_map<PartitionID, std::vector<HostAddr>>>>
MetaClient::getPartsAlloc(GraphSpaceID spaceId) {
MetaClient::getPartsAlloc(GraphSpaceID spaceId, PartTerms* partTerms) {
cpp2::GetPartsAllocReq req;
req.set_space_id(spaceId);
folly::Promise<StatusOr<std::unordered_map<PartitionID, std::vector<HostAddr>>>> promise;
Expand All @@ -1178,11 +1180,16 @@ MetaClient::getPartsAlloc(GraphSpaceID spaceId) {
[] (auto client, auto request) {
return client->future_getPartsAlloc(request);
},
[] (cpp2::GetPartsAllocResp&& resp) -> decltype(auto) {
[=] (cpp2::GetPartsAllocResp&& resp) -> decltype(auto) {
std::unordered_map<PartitionID, std::vector<HostAddr>> parts;
for (auto it = resp.get_parts().begin(); it != resp.get_parts().end(); it++) {
parts.emplace(it->first, it->second);
}
if (partTerms && resp.terms_ref().has_value()) {
for (auto& termOfPart : resp.terms_ref().value()) {
(*partTerms)[termOfPart.first] = termOfPart.second;
}
}
return parts;
},
std::move(promise));
Expand Down Expand Up @@ -2406,6 +2413,22 @@ bool MetaClient::checkShadowAccountFromCache(const std::string& account) const {
return false;
}

TermID MetaClient::getTermFromCache(GraphSpaceID spaceId, PartitionID partId) const {
static TermID notFound = -1;
folly::RWSpinLock::ReadHolder holder(localCacheLock_);
auto spaceInfo = localCache_.find(spaceId);
if (spaceInfo == localCache_.end()) {
return notFound;
}

auto termInfo = spaceInfo->second->termOfPartition_.find(partId);
if (termInfo == spaceInfo->second->termOfPartition_.end()) {
return notFound;
}

return termInfo->second;
}

StatusOr<std::vector<HostAddr>> MetaClient::getStorageHosts() const {
if (!ready_) {
return Status::Error("Not ready!");
Expand Down
6 changes: 5 additions & 1 deletion src/common/clients/meta/MetaClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ struct SpaceInfoCache {
Listeners listeners_;
// objPool used to decode when adding field
ObjectPool pool_;
std::unordered_map<PartitionID, TermID> termOfPartition_;
};

using LocalCache = std::unordered_map<GraphSpaceID, std::shared_ptr<SpaceInfoCache>>;
Expand Down Expand Up @@ -221,8 +222,9 @@ class MetaClient {
folly::Future<StatusOr<std::vector<cpp2::PartItem>>>
listParts(GraphSpaceID spaceId, std::vector<PartitionID> partIds);

using PartTerms = std::unordered_map<PartitionID, TermID>;
folly::Future<StatusOr<PartsAlloc>>
getPartsAlloc(GraphSpaceID spaceId);
getPartsAlloc(GraphSpaceID spaceId, MetaClient::PartTerms* partTerms = nullptr);

// Operations for schema
folly::Future<StatusOr<TagID>> createTagSchema(GraphSpaceID spaceId,
Expand Down Expand Up @@ -571,6 +573,8 @@ class MetaClient {

bool checkShadowAccountFromCache(const std::string& account) const;

TermID getTermFromCache(GraphSpaceID spaceId, PartitionID) const;

StatusOr<std::vector<HostAddr>> getStorageHosts() const;

StatusOr<HostAddr> getStorageLeaderFromCache(GraphSpaceID spaceId, PartitionID partId);
Expand Down
1 change: 1 addition & 0 deletions src/common/interface/meta.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ struct GetPartsAllocResp {
// Valid if ret equals E_LEADER_CHANGED.
2: common.HostAddr leader,
3: map<common.PartitionID, list<common.HostAddr>>(cpp.template = "std::unordered_map") parts,
4: optional map<common.PartitionID, i64>(cpp.template = "std::unordered_map") terms,
}

struct MultiPutReq {
Expand Down

0 comments on commit 6b31073

Please sign in to comment.