12 #include <unordered_map>
15 #include "common/datatypes/HostAddr.h"
16 #include "common/thrift/ThriftTypes.h"
17 #include "nebula/mclient/MConfig.h"
20 template <
class T1,
class T2>
21 std::size_t operator()(
const std::pair<T1, T2> &pair)
const {
22 return std::hash<T1>()(pair.first) ^ std::hash<T2>()(pair.second);
28 class IOThreadPoolExecutor;
38 template <
class ClientType>
46 enum class ListHostType;
48 class MetaServiceAsyncClient;
59 using SpaceIdName = std::pair<GraphSpaceID, std::string>;
60 using SpaceNameIdMap = std::unordered_map<std::string, GraphSpaceID>;
61 using SpaceEdgeNameTypeMap =
62 std::unordered_map<std::pair<GraphSpaceID, std::string>, EdgeType,
pair_hash>;
66 explicit MetaClient(
const std::vector<std::string> &metaAddrs,
71 std::pair<bool, GraphSpaceID> getSpaceIdByNameFromCache(
const std::string &name);
73 std::pair<bool, EdgeType> getEdgeTypeByNameFromCache(GraphSpaceID spaceId,
74 const std::string &name);
76 std::pair<bool, std::vector<PartitionID>> getPartsFromCache(GraphSpaceID spaceId);
78 std::pair<bool, HostAddr> getPartLeaderFromCache(GraphSpaceID spaceId, PartitionID partId);
83 std::pair<bool, std::vector<SpaceIdName>> listSpaces();
85 std::pair<bool, std::vector<meta::cpp2::HostItem>> listHosts(meta::cpp2::ListHostType tp);
87 std::pair<bool, std::vector<meta::cpp2::EdgeItem>> listEdgeSchemas(GraphSpaceID spaceId);
89 void loadLeader(
const std::vector<nebula::meta::cpp2::HostItem> &hostItems,
90 const SpaceNameIdMap &spaceIndexByName);
92 std::vector<SpaceIdName> toSpaceIdName(
const std::vector<meta::cpp2::IdName> &tIdNames);
94 template <
class Request,
97 class RpcResponse =
typename std::result_of<RemoteFunc(
98 std::shared_ptr<meta::cpp2::MetaServiceAsyncClient>, Request)>::type::value_type,
99 class Response =
typename std::result_of<RespGenerator(RpcResponse)>::type>
100 void getResponse(Request req,
101 RemoteFunc remoteFunc,
102 RespGenerator respGen,
106 std::vector<HostAddr> metaAddrs_;
108 SpaceNameIdMap spaceIndexByName_;
109 SpaceEdgeNameTypeMap spaceEdgeIndexByName_;
110 std::unordered_map<std::pair<GraphSpaceID, PartitionID>,
HostAddr,
pair_hash> spacePartLeaderMap_;
111 std::unordered_map<GraphSpaceID, std::vector<PartitionID>> spacePartsMap_;
112 std::shared_ptr<folly::IOThreadPoolExecutor> ioExecutor_;
113 std::shared_ptr<thrift::ThriftClientManager<meta::cpp2::MetaServiceAsyncClient>> clientsMan_;