NebulaGraph CPP Client  release-3.4
StorageClient.h
1 /* Copyright (c) 2018 vesoft inc. All rights reserved.
2  *
3  * This source code is licensed under Apache 2.0 License.
4  */
5 
6 #pragma once
7 
8 #include <memory>
9 #include <string>
10 #include <thread>
11 #include <unordered_map>
12 #include <vector>
13 
14 #include "ScanEdgeIter.h"
15 #include "common/datatypes/HostAddr.h"
16 #include "common/thrift/ThriftTypes.h"
17 #include "nebula/mclient/MetaClient.h"
18 #include "nebula/sclient/SConfig.h"
19 #include "nebula/sclient/ScanEdgeIter.h"
20 
21 namespace folly {
22 class IOThreadPoolExecutor;
23 template <class T>
24 class Promise;
25 } // namespace folly
26 
27 namespace nebula {
28 
29 namespace thrift {
30 
31 template <class ClientType>
32 class ThriftClientManager;
33 
34 } // namespace thrift
35 
36 namespace meta {
37 namespace cpp2 {
38 
39 class MetaServiceAsyncClient;
40 
41 } // namespace cpp2
42 } // namespace meta
43 
44 namespace storage {
45 namespace cpp2 {
46 
47 class GraphStorageServiceAsyncClient;
48 class ScanCursor;
49 class ScanEdgeRequest;
50 class ScanResponse;
51 
52 } // namespace cpp2
53 } // namespace storage
54 
55 #define DEFAULT_LIMIT std::numeric_limits<int64_t>::max()
56 #define DEFAULT_START_TIME 0
57 #define DEFAULT_END_TIME std::numeric_limits<int64_t>::max()
58 
60  friend struct ScanEdgeIter;
61 
62  public:
63  explicit StorageClient(const std::vector<std::string>& metaAddrs,
64  const MConfig& mConfig = MConfig{},
65  const SConfig& sConfig = SConfig{});
66 
67  ~StorageClient();
68 
69  std::vector<PartitionID> getParts(const std::string& spaceName); // plato needed
70 
71  ScanEdgeIter scanEdgeWithPart(std::string spaceName,
72  int32_t partID,
73  std::string edgeName,
74  std::vector<std::string> propNames,
75  int64_t limit = DEFAULT_LIMIT,
76  int64_t startTime = DEFAULT_START_TIME,
77  int64_t endTime = DEFAULT_END_TIME,
78  std::string filter = "",
79  bool onlyLatestVersion = false,
80  bool enableReadFromFollower = true); // plato needed
81 
82  MetaClient* getMetaClient() {
83  return mClient_.get();
84  }
85 
86  private:
87  std::pair<bool, storage::cpp2::ScanResponse> doScanEdge(
88  const storage::cpp2::ScanEdgeRequest& req);
89 
90  template <typename Request, typename RemoteFunc, typename Response>
91  void getResponse(std::pair<HostAddr, Request>&& request,
92  RemoteFunc&& remoteFunc,
93  folly::Promise<std::pair<bool, Response>> pro);
94 
95  std::unique_ptr<MetaClient> mClient_;
96  SConfig sConfig_;
97  std::shared_ptr<folly::IOThreadPoolExecutor> ioExecutor_;
98  std::shared_ptr<thrift::ThriftClientManager<storage::cpp2::GraphStorageServiceAsyncClient>>
99  clientsMan_;
100 };
101 
102 } // namespace nebula