-
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.
update storage client for plato (#68)
Add meta/storage client. Co-authored-by: Shylock Hg <33566796+Shylock-Hg@users.noreply.github.com>
- Loading branch information
1 parent
41052df
commit 630d9f5
Showing
46 changed files
with
1,483 additions
and
44 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
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 |
---|---|---|
|
@@ -37,3 +37,6 @@ modules | |
|
||
# IDE | ||
.vscode/ | ||
|
||
# Coredump | ||
core.* |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* Copyright (c) 2020 vesoft inc. All rights reserved. | ||
* | ||
* This source code is licensed under Apache 2.0 License. | ||
*/ | ||
|
||
#include <atomic> | ||
#include <chrono> | ||
#include <limits> | ||
#include <thread> | ||
|
||
#include <nebula/sclient/ScanEdgeIter.h> | ||
#include <common/Init.h> | ||
#include <nebula/sclient/StorageClient.h> | ||
|
||
int main(int argc, char* argv[]) { | ||
nebula::init(&argc, &argv); | ||
|
||
nebula::StorageClient c({"127.0.0.1:9559"}); | ||
|
||
nebula::ScanEdgeIter scanEdgeIter = c.scanEdgeWithPart("nba", | ||
1, | ||
"like", | ||
std::vector<std::string>{"likeness"}, | ||
10, | ||
0, | ||
std::numeric_limits<int64_t>::max(), | ||
"", | ||
true, | ||
true); | ||
std::cout << "scan edge..." << std::endl; | ||
while (scanEdgeIter.hasNext()) { | ||
std::cout << "-------------------------" << std::endl; | ||
nebula::DataSet ds = scanEdgeIter.next(); | ||
std::cout << ds << std::endl; | ||
std::cout << "+++++++++++++++++++++++++" << std::endl; | ||
} | ||
|
||
return 0; | ||
} |
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
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,3 @@ enum class ByteOrder : uint8_t { | |
|
||
} // namespace geo | ||
} // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* Copyright (c) 2020 vesoft inc. All rights reserved. | ||
* | ||
* This source code is licensed under Apache 2.0 License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <string> | ||
|
||
namespace nebula { | ||
|
||
struct MConfig { | ||
// It's as same as FLAGS_conn_timeout_ms in nebula | ||
int32_t connTimeoutInMs_{1000}; | ||
// It's as same as FLAG_meta_client_timeout_ms in nebula | ||
int32_t clientTimeoutInMs_{60 * 1000}; | ||
bool enableSSL_{false}; | ||
std::string CAPath_; | ||
}; | ||
|
||
} // 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,116 @@ | ||
/* Copyright (c) 2020 vesoft inc. All rights reserved. | ||
* | ||
* This source code is licensed under Apache 2.0 License. | ||
*/ | ||
|
||
#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/mclient/MConfig.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, | ||
const MConfig &mConfig = MConfig{}); | ||
|
||
~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_; | ||
MConfig mConfig_; | ||
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,22 @@ | ||
/* Copyright (c) 2020 vesoft inc. All rights reserved. | ||
* | ||
* This source code is licensed under Apache 2.0 License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <string> | ||
|
||
namespace nebula { | ||
|
||
struct SConfig { | ||
// It's as same as FLAGS_conn_timeout_ms in nebula | ||
int32_t connTimeoutInMs_{1000}; | ||
// It's as same as FLAG_meta_client_timeout_ms in nebula | ||
int32_t clientTimeoutInMs_{60 * 1000}; | ||
bool enableSSL_{false}; | ||
std::string CAPath_; | ||
}; | ||
|
||
} // 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,37 @@ | ||
/* Copyright (c) 2020 vesoft inc. All rights reserved. | ||
* | ||
* This source code is licensed under Apache 2.0 License. | ||
*/ | ||
|
||
#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 |
Oops, something went wrong.