-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
1,111 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* Copyright (c) 2021 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. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <functional> | ||
#include <memory> | ||
#include <string> | ||
#include <thread> | ||
#include <unordered_map> | ||
#include <vector> | ||
|
||
#include "common/datatypes/HostAddr.h" | ||
#include "common/thrift/ThriftTypes.h" | ||
#include "nebula/sclient/ScanEdgeIter.h" | ||
|
||
struct pair_hash { | ||
template <class T1, class T2> | ||
std::size_t operator()(const std::pair<T1, T2> &pair) const { | ||
return std::hash<T1>()(pair.first) ^ std::hash<T2>()(pair.second); | ||
} | ||
}; | ||
|
||
namespace folly { | ||
|
||
class IOThreadPoolExecutor; | ||
template <class T> | ||
class Promise; | ||
|
||
} // namespace folly | ||
|
||
namespace nebula { | ||
|
||
namespace thrift { | ||
|
||
template <class ClientType> | ||
class ThriftClientManager; | ||
|
||
} // namespace thrift | ||
|
||
namespace meta { | ||
namespace cpp2 { | ||
|
||
enum class ListHostType; | ||
class HostItem; | ||
class MetaServiceAsyncClient; | ||
class ListSpacesReq; | ||
class ListSpacesResp; | ||
class IdName; | ||
class EdgeItem; | ||
class ListEdgesReq; | ||
class ListEdgesResp; | ||
|
||
} // namespace cpp2 | ||
} // namespace meta | ||
|
||
using SpaceIdName = std::pair<GraphSpaceID, std::string>; | ||
using SpaceNameIdMap = std::unordered_map<std::string, GraphSpaceID>; | ||
using SpaceEdgeNameTypeMap = | ||
std::unordered_map<std::pair<GraphSpaceID, std::string>, EdgeType, pair_hash>; | ||
|
||
class MetaClient { | ||
public: | ||
explicit MetaClient(const std::vector<std::string> &metaAddrs); | ||
|
||
~MetaClient(); | ||
|
||
std::pair<bool, GraphSpaceID> getSpaceIdByNameFromCache(const std::string &name); | ||
|
||
std::pair<bool, EdgeType> getEdgeTypeByNameFromCache(GraphSpaceID spaceId, | ||
const std::string &name); | ||
|
||
std::pair<bool, std::vector<PartitionID>> getPartsFromCache(GraphSpaceID spaceId); | ||
|
||
std::pair<bool, HostAddr> getPartLeaderFromCache(GraphSpaceID spaceId, PartitionID partId); | ||
|
||
private: | ||
bool loadData(); | ||
|
||
std::pair<bool, std::vector<SpaceIdName>> listSpaces(); | ||
|
||
std::pair<bool, std::vector<meta::cpp2::HostItem>> listHosts(meta::cpp2::ListHostType tp); | ||
|
||
std::pair<bool, std::vector<meta::cpp2::EdgeItem>> listEdgeSchemas(GraphSpaceID spaceId); | ||
|
||
void loadLeader(const std::vector<nebula::meta::cpp2::HostItem> &hostItems, | ||
const SpaceNameIdMap &spaceIndexByName); | ||
|
||
std::vector<SpaceIdName> toSpaceIdName(const std::vector<meta::cpp2::IdName> &tIdNames); | ||
|
||
template <class Request, | ||
class RemoteFunc, | ||
class RespGenerator, | ||
class RpcResponse = typename std::result_of<RemoteFunc( | ||
std::shared_ptr<meta::cpp2::MetaServiceAsyncClient>, Request)>::type::value_type, | ||
class Response = typename std::result_of<RespGenerator(RpcResponse)>::type> | ||
void getResponse(Request req, | ||
RemoteFunc remoteFunc, | ||
RespGenerator respGen, | ||
folly::Promise<std::pair<bool, Response>> pro); | ||
|
||
private: | ||
std::vector<HostAddr> metaAddrs_; | ||
SpaceNameIdMap spaceIndexByName_; | ||
SpaceEdgeNameTypeMap spaceEdgeIndexByName_; | ||
std::unordered_map<std::pair<GraphSpaceID, PartitionID>, HostAddr, pair_hash> spacePartLeaderMap_; | ||
std::unordered_map<GraphSpaceID, std::vector<PartitionID>> spacePartsMap_; | ||
std::shared_ptr<folly::IOThreadPoolExecutor> ioExecutor_; | ||
std::shared_ptr<thrift::ThriftClientManager<meta::cpp2::MetaServiceAsyncClient>> clientsMan_; | ||
}; | ||
|
||
} // 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,13 @@ | ||
/* Copyright (c) 2021 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. | ||
*/ | ||
|
||
#pragma once | ||
|
||
namespace nebula { | ||
|
||
void init(int *argc, char **argv[]); | ||
|
||
} // 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,40 @@ | ||
/* Copyright (c) 2021 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. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include "common/datatypes/DataSet.h" | ||
|
||
namespace nebula { | ||
class StorageClient; | ||
|
||
namespace storage { | ||
namespace cpp2 { | ||
class ScanEdgeRequest; | ||
} // namespace cpp2 | ||
} // namespace storage | ||
|
||
struct ScanEdgeIter { | ||
ScanEdgeIter(StorageClient* client, | ||
storage::cpp2::ScanEdgeRequest* req, | ||
bool hasNext = true); | ||
|
||
~ScanEdgeIter(); | ||
|
||
bool hasNext(); | ||
|
||
DataSet next(); | ||
|
||
StorageClient* client_; | ||
storage::cpp2::ScanEdgeRequest* req_; | ||
bool hasNext_; | ||
std::string nextCursor_; | ||
}; | ||
|
||
} // 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,94 @@ | ||
/* Copyright (c) 2018 vesoft inc. All rights reserved. | ||
* | ||
* This source code is licensed under Apache 2.0 License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <thread> | ||
#include <unordered_map> | ||
#include <vector> | ||
|
||
#include "ScanEdgeIter.h" | ||
#include "common/datatypes/HostAddr.h" | ||
#include "common/thrift/ThriftTypes.h" | ||
#include "nebula/mclient/MetaClient.h" | ||
#include "nebula/sclient/ScanEdgeIter.h" | ||
|
||
namespace folly { | ||
class IOThreadPoolExecutor; | ||
template <class T> | ||
class Promise; | ||
} // namespace folly | ||
|
||
namespace nebula { | ||
|
||
namespace thrift { | ||
|
||
template <class ClientType> | ||
class ThriftClientManager; | ||
|
||
} // namespace thrift | ||
|
||
namespace meta { | ||
namespace cpp2 { | ||
|
||
class MetaServiceAsyncClient; | ||
|
||
} // namespace cpp2 | ||
} // namespace meta | ||
|
||
namespace storage { | ||
namespace cpp2 { | ||
|
||
class GraphStorageServiceAsyncClient; | ||
class ScanCursor; | ||
class ScanEdgeRequest; | ||
class ScanEdgeResponse; | ||
|
||
} // namespace cpp2 | ||
} // namespace storage | ||
|
||
#define DEFAULT_LIMIT 1000 | ||
#define DEFAULT_START_TIME 0 | ||
#define DEFAULT_END_TIME std::numeric_limits<int64_t>::max() | ||
|
||
class StorageClient { | ||
friend class ScanEdgeIter; | ||
public: | ||
explicit StorageClient(const std::vector<std::string>& metaAddrs); | ||
|
||
~StorageClient(); | ||
|
||
std::vector<PartitionID> getParts(const std::string& spaceName); // plato needed | ||
|
||
ScanEdgeIter scanEdgeWithPart(std::string spaceName, | ||
int32_t partID, | ||
std::string edgeName, | ||
std::vector<std::string> propNames, | ||
int64_t limit = DEFAULT_LIMIT, | ||
int64_t startTime = DEFAULT_START_TIME, | ||
int64_t endTime = DEFAULT_END_TIME, | ||
std::string filter = "", | ||
bool onlyLatestVersion = false, | ||
bool enableReadFromFollower = true); // plato needed | ||
|
||
private: | ||
std::pair<bool, storage::cpp2::ScanEdgeResponse> doScanEdge( | ||
const storage::cpp2::ScanEdgeRequest& req); | ||
|
||
template <typename Request, typename RemoteFunc, typename Response> | ||
void getResponse(std::pair<HostAddr, Request>&& request, | ||
RemoteFunc&& remoteFunc, | ||
folly::Promise<std::pair<bool, Response>> pro); | ||
|
||
private: | ||
std::unique_ptr<MetaClient> mClient_; | ||
std::shared_ptr<folly::IOThreadPoolExecutor> ioExecutor_; | ||
std::shared_ptr<thrift::ThriftClientManager<storage::cpp2::GraphStorageServiceAsyncClient>> | ||
clientsMan_; | ||
}; | ||
|
||
} // 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
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
Oops, something went wrong.