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;
60 using SpaceIdName = std::pair<GraphSpaceID, std::string>;
61 using SpaceNameIdMap = std::unordered_map<std::string, GraphSpaceID>;
62 using SpaceEdgeNameTypeMap =
63 std::unordered_map<std::pair<GraphSpaceID, std::string>, EdgeType,
pair_hash>;
65 using SpaceTagNameTypeMap =
66 std::unordered_map<std::pair<GraphSpaceID, std::string>, TagID,
pair_hash>;
70 explicit MetaClient(
const std::vector<std::string> &metaAddrs,
75 std::pair<bool, GraphSpaceID> getSpaceIdByNameFromCache(
const std::string &name);
77 std::pair<bool, EdgeType> getEdgeTypeByNameFromCache(GraphSpaceID spaceId,
78 const std::string &name);
80 std::pair<bool, TagID> getTagIdByNameFromCache(GraphSpaceID spaceId,
const std::string &name);
82 std::pair<bool, std::vector<PartitionID>> getPartsFromCache(GraphSpaceID spaceId);
84 std::pair<bool, HostAddr> getPartLeaderFromCache(GraphSpaceID spaceId, PartitionID partId);
89 std::pair<bool, std::vector<SpaceIdName>> listSpaces();
91 std::pair<bool, std::vector<meta::cpp2::HostItem>> listHosts(meta::cpp2::ListHostType tp);
93 std::pair<bool, std::vector<meta::cpp2::EdgeItem>> listEdgeSchemas(GraphSpaceID spaceId);
95 std::pair<bool, std::vector<meta::cpp2::TagItem>> listTagSchemas(GraphSpaceID spaceId);
97 void loadLeader(
const std::vector<nebula::meta::cpp2::HostItem> &hostItems,
98 const SpaceNameIdMap &spaceIndexByName);
100 std::vector<SpaceIdName> toSpaceIdName(
const std::vector<meta::cpp2::IdName> &tIdNames);
102 template <
class Request,
105 class RpcResponse =
typename std::result_of<RemoteFunc(
106 std::shared_ptr<meta::cpp2::MetaServiceAsyncClient>, Request)>::type::value_type,
107 class Response =
typename std::result_of<RespGenerator(RpcResponse)>::type>
108 void getResponse(Request req,
109 RemoteFunc remoteFunc,
110 RespGenerator respGen,
114 std::vector<HostAddr> metaAddrs_;
116 SpaceNameIdMap spaceIndexByName_;
117 SpaceEdgeNameTypeMap spaceEdgeIndexByName_;
118 SpaceTagNameTypeMap spaceTagIndexByName_;
119 std::unordered_map<std::pair<GraphSpaceID, PartitionID>,
HostAddr,
pair_hash> spacePartLeaderMap_;
120 std::unordered_map<GraphSpaceID, std::vector<PartitionID>> spacePartsMap_;
121 std::shared_ptr<folly::IOThreadPoolExecutor> ioExecutor_;
122 std::shared_ptr<thrift::ThriftClientManager<meta::cpp2::MetaServiceAsyncClient>> clientsMan_;