Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable kv interface in 2.0 #3282

Merged
merged 4 commits into from
Nov 26, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/clients/storage/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ nebula_add_library(
)


nebula_add_library(
general_storage_client_obj OBJECT
GeneralStorageClient.cpp
)


nebula_add_library(
storage_client_base_obj OBJECT
StorageClientBase.cpp
Expand Down
90 changes: 0 additions & 90 deletions src/clients/storage/GeneralStorageClient.cpp

This file was deleted.

50 changes: 0 additions & 50 deletions src/clients/storage/GeneralStorageClient.h

This file was deleted.

76 changes: 76 additions & 0 deletions src/clients/storage/GraphStorageClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,82 @@ StorageRpcRespFuture<cpp2::ScanVertexResponse> GraphStorageClient::scanVertex(
});
}

folly::SemiFuture<StorageRpcResponse<cpp2::KVGetResponse>> GraphStorageClient::get(
critical27 marked this conversation as resolved.
Show resolved Hide resolved
GraphSpaceID space, std::vector<std::string>&& keys, bool returnPartly, folly::EventBase* evb) {
auto status = clusterIdsToHosts(
space, std::move(keys), [](const std::string& v) -> const std::string& { return v; });

if (!status.ok()) {
return folly::makeFuture<StorageRpcResponse<cpp2::KVGetResponse>>(
std::runtime_error(status.status().toString()));
}

auto& clusters = status.value();
std::unordered_map<HostAddr, cpp2::KVGetRequest> requests;
for (auto& c : clusters) {
auto& host = c.first;
auto& req = requests[host];
req.set_space_id(space);
req.set_parts(std::move(c.second));
req.set_return_partly(returnPartly);
}

return collectResponse(evb,
std::move(requests),
[](cpp2::GraphStorageServiceAsyncClient* client,
const cpp2::KVGetRequest& r) { return client->future_get(r); });
}

folly::SemiFuture<StorageRpcResponse<cpp2::ExecResponse>> GraphStorageClient::put(
GraphSpaceID space, std::vector<KeyValue> kvs, folly::EventBase* evb) {
auto status = clusterIdsToHosts(
space, std::move(kvs), [](const KeyValue& v) -> const std::string& { return v.key; });

if (!status.ok()) {
return folly::makeFuture<StorageRpcResponse<cpp2::ExecResponse>>(
std::runtime_error(status.status().toString()));
}

auto& clusters = status.value();
std::unordered_map<HostAddr, cpp2::KVPutRequest> requests;
for (auto& c : clusters) {
auto& host = c.first;
auto& req = requests[host];
req.set_space_id(space);
req.set_parts(std::move(c.second));
}

return collectResponse(evb,
std::move(requests),
[](cpp2::GraphStorageServiceAsyncClient* client,
const cpp2::KVPutRequest& r) { return client->future_put(r); });
}

folly::SemiFuture<StorageRpcResponse<cpp2::ExecResponse>> GraphStorageClient::remove(
GraphSpaceID space, std::vector<std::string> keys, folly::EventBase* evb) {
auto status = clusterIdsToHosts(
space, std::move(keys), [](const std::string& v) -> const std::string& { return v; });

if (!status.ok()) {
return folly::makeFuture<StorageRpcResponse<cpp2::ExecResponse>>(
std::runtime_error(status.status().toString()));
}

auto& clusters = status.value();
std::unordered_map<HostAddr, cpp2::KVRemoveRequest> requests;
for (auto& c : clusters) {
auto& host = c.first;
auto& req = requests[host];
req.set_space_id(space);
req.set_parts(std::move(c.second));
}

return collectResponse(evb,
std::move(requests),
[](cpp2::GraphStorageServiceAsyncClient* client,
const cpp2::KVRemoveRequest& r) { return client->future_remove(r); });
}

StatusOr<std::function<const VertexID&(const Row&)>> GraphStorageClient::getIdFromRow(
GraphSpaceID space, bool isEdgeProps) const {
auto vidTypeStatus = metaClient_->getSpaceVidType(space);
Expand Down
13 changes: 13 additions & 0 deletions src/clients/storage/GraphStorageClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,19 @@ class GraphStorageClient : public StorageClientBase<cpp2::GraphStorageServiceAsy
int64_t limit,
const Expression* filter);

folly::SemiFuture<StorageRpcResponse<cpp2::KVGetResponse>> get(GraphSpaceID space,
std::vector<std::string>&& keys,
bool returnPartly = false,
folly::EventBase* evb = nullptr);

folly::SemiFuture<StorageRpcResponse<cpp2::ExecResponse>> put(GraphSpaceID space,
std::vector<KeyValue> kvs,
folly::EventBase* evb = nullptr);

folly::SemiFuture<StorageRpcResponse<cpp2::ExecResponse>> remove(GraphSpaceID space,
std::vector<std::string> keys,
folly::EventBase* evb = nullptr);

private:
StatusOr<std::function<const VertexID&(const Row&)>> getIdFromRow(GraphSpaceID space,
bool isEdgeProps) const;
Expand Down
2 changes: 1 addition & 1 deletion src/interface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ thrift_generate("raftex" "RaftexService" ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CUR
# Target object name : storage_thrift_obj
thrift_generate(
"storage"
"GraphStorageService;StorageAdminService;GeneralStorageService;InternalStorageService"
"GraphStorageService;StorageAdminService;InternalStorageService"
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
"interface"
Expand Down
101 changes: 47 additions & 54 deletions src/interface/storage.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -630,18 +630,37 @@ struct TaskPara {
3: optional list<binary> task_specific_paras
}

struct AddAdminTaskRequest {
// rebuild index / flush / compact / stats
1: meta.AdminCmd cmd
2: i32 job_id
3: i32 task_id
4: TaskPara para
5: optional i32 concurrency
//////////////////////////////////////////////////////////
//
// Requests, responses for the kv interfaces
//
//////////////////////////////////////////////////////////
struct KVGetRequest {
1: common.GraphSpaceID space_id,
2: map<common.PartitionID, list<binary>>(
cpp.template = "std::unordered_map") parts,
// When return_partly is true and some of the keys not found, will return the keys
// which exist
3: bool return_partly
}

struct StopAdminTaskRequest {
1: i32 job_id
2: i32 task_id
struct KVGetResponse {
1: required ResponseCommon result,
2: map<binary, binary>(cpp.template = "std::unordered_map") key_values,
}

struct KVPutRequest {
1: common.GraphSpaceID space_id,
// part -> key/value
2: map<common.PartitionID, list<common.KeyValue>>(
cpp.template = "std::unordered_map") parts,
}

struct KVRemoveRequest {
1: common.GraphSpaceID space_id,
// part -> key
2: map<common.PartitionID, list<binary>>(
cpp.template = "std::unordered_map") parts,
}

service GraphStorageService {
Expand Down Expand Up @@ -672,6 +691,10 @@ service GraphStorageService {

UpdateResponse chainUpdateEdge(1: UpdateEdgeRequest req);
ExecResponse chainAddEdges(1: AddEdgesRequest req);

KVGetResponse get(1: KVGetRequest req);
ExecResponse put(1: KVPutRequest req);
ExecResponse remove(1: KVRemoveRequest req);
}


Expand Down Expand Up @@ -790,6 +813,20 @@ struct ListClusterInfoResp {
struct ListClusterInfoReq {
}

struct AddAdminTaskRequest {
// rebuild index / flush / compact / statis
1: meta.AdminCmd cmd
2: i32 job_id
3: i32 task_id
4: TaskPara para
5: optional i32 concurrency
}

struct StopAdminTaskRequest {
1: i32 job_id
2: i32 task_id
}

service StorageAdminService {
// Interfaces for admin operations
AdminExecResp transLeader(1: TransLeaderReq req);
Expand Down Expand Up @@ -820,50 +857,6 @@ service StorageAdminService {
}


//////////////////////////////////////////////////////////
//
// Requests, responses for the GeneralStorageService
//
//////////////////////////////////////////////////////////
struct KVGetRequest {
1: common.GraphSpaceID space_id,
2: map<common.PartitionID, list<binary>>(
cpp.template = "std::unordered_map") parts,
// When return_partly is true and some of the keys not found, will return the keys
// which exist
3: bool return_partly
}


struct KVGetResponse {
1: required ResponseCommon result,
2: map<binary, binary>(cpp.template = "std::unordered_map") key_values,
}


struct KVPutRequest {
1: common.GraphSpaceID space_id,
// part -> key/value
2: map<common.PartitionID, list<common.KeyValue>>(
cpp.template = "std::unordered_map") parts,
}


struct KVRemoveRequest {
1: common.GraphSpaceID space_id,
// part -> key
2: map<common.PartitionID, list<binary>>(
cpp.template = "std::unordered_map") parts,
}


service GeneralStorageService {
// Interfaces for key-value storage
KVGetResponse get(1: KVGetRequest req);
ExecResponse put(1: KVPutRequest req);
ExecResponse remove(1: KVRemoveRequest req);
}

//////////////////////////////////////////////////////////
//
// Requests, responses for the InternalStorageService
Expand Down
Loading