Skip to content

Commit 870d275

Browse files
author
Tarunkumar Banda
committed
Changing concord_client_request.proto to concord_client_request.cmf
1 parent b8fc9eb commit 870d275

File tree

14 files changed

+82
-43
lines changed

14 files changed

+82
-43
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ CONCORD_BFT_RECONFIGURATION_CMF_PATHS?=${CONCORD_BFT_TARGET_SOURCE_PATH}/build/r
1111
CONCORD_BFT_BFTENGINE_CMF_PATHS?=${CONCORD_BFT_TARGET_SOURCE_PATH}/build/bftengine/cmf
1212
CONCORD_BFT_CCRON_CMF_PATHS?=${CONCORD_BFT_TARGET_SOURCE_PATH}/build/ccron/cmf
1313
CONCORD_BFT_SKVBC_CMF_PATHS?=${CONCORD_BFT_TARGET_SOURCE_PATH}/build/tests/simpleKVBC/cmf
14+
CONCORD_BFT_CONCORD_CLIENT_CMF_PATHS?=${CONCORD_BFT_TARGET_SOURCE_PATH}/build/client/concordclient/cmf
1415
CONCORD_BFT_CLIENT_PROTO_PATH?=${CONCORD_BFT_TARGET_SOURCE_PATH}/build/client/proto
1516
CONCORD_BFT_THIN_REPLICA_PROTO_PATH?=${CONCORD_BFT_TARGET_SOURCE_PATH}/build/thin-replica-server/proto
1617
CONCORD_BFT_KVBC_PROTO_PATH?=${CONCORD_BFT_TARGET_SOURCE_PATH}/build/kvbc/proto
@@ -197,6 +198,7 @@ tidy-check: gen_cmake ## Run clang-tidy
197198
make -C ${CONCORD_BFT_BFTENGINE_CMF_PATHS} &> /dev/null && \
198199
make -C ${CONCORD_BFT_CCRON_CMF_PATHS} &> /dev/null && \
199200
make -C ${CONCORD_BFT_SKVBC_CMF_PATHS} &> /dev/null && \
201+
make -C ${CONCORD_BFT_CONCORD_CLIENT_CMF_PATHS} &> /dev/null && \
200202
make -C ${CONCORD_BFT_CLIENT_PROTO_PATH} &> /dev/null && \
201203
make -C ${CONCORD_BFT_THIN_REPLICA_PROTO_PATH} &> /dev/null && \
202204
make -C ${CONCORD_BFT_KVBC_PROTO_PATH} &> /dev/null && \

bftengine/include/bftengine/SharedTypes.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,6 @@ enum class OperationResult : uint32_t {
2929
INTERNAL_ERROR
3030
};
3131

32+
enum class RequestType : uint32_t { RAW_MESSAGE, ANY_MESSAGE };
33+
3234
} // namespace bftEngine

client/bftclient/include/bftclient/config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "bftclient/base_types.h"
2323
#include "bftclient/quorums.h"
2424
#include "secret_data.h"
25+
#include "SharedTypes.hpp"
2526

2627
using namespace std::chrono_literals;
2728

@@ -81,6 +82,8 @@ struct RequestConfig {
8182
std::string span_context = "";
8283
bool key_exchange = false;
8384
bool reconfiguration = false;
85+
bftEngine::RequestType request_type = bftEngine::RequestType::RAW_MESSAGE;
86+
std::string client_service_id = "";
8487
};
8588

8689
// The configuration for a single write request.

client/client_pool/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ target_link_libraries(concord_client_pool PUBLIC
1111
bftclient
1212
bftclient_new
1313
corebft
14+
concord_client_request
1415
)
1516

1617
install (TARGETS concord_client_pool DESTINATION lib${LIB_SUFFIX})

client/client_pool/include/client/client_pool/concord_client_pool.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ class ConcordClientPool {
119119
uint64_t seq_num,
120120
std::string correlation_id = {},
121121
const std::string& span_context = std::string(),
122+
const bftEngine::RequestType request_type = bftEngine::RequestType::RAW_MESSAGE,
123+
const std::string& subscriptionId = std::string(),
122124
const bftEngine::RequestCallBack& callback = {});
123125

124126
// This method is responsible to get write requests with the new client

client/client_pool/include/client/client_pool/external_client.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "client_pool_config.hpp"
2222
#include "communication/StatusInfo.h"
2323
#include "external_client_exception.hpp"
24+
#include "concord_client_request.cmf.hpp"
2425

2526
namespace concord {
2627

@@ -104,6 +105,12 @@ class ConcordClient {
104105

105106
std::string messageSignature(bft::client::Msg&);
106107

108+
static void createConcordClientRequest(bft::client::Msg& request,
109+
bftEngine::RequestType typed_request,
110+
const std::string& subscriptionId);
111+
112+
static void createConcordClientResponse(bft::client::Msg& response);
113+
107114
private:
108115
void CreateClient(std::shared_ptr<concordMetrics::Aggregator> aggregator);
109116

client/client_pool/src/concord_client_pool.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ SubmitResult ConcordClientPool::SendRequest(std::vector<uint8_t> &&request,
4444
uint64_t seq_num,
4545
std::string correlation_id,
4646
const std::string &span_context,
47+
const bftEngine::RequestType request_type,
48+
const std::string &subscriptionId,
4749
const bftEngine::RequestCallBack &callback) {
4850
if (callback && timeout_ms.count() == 0) {
4951
callback(bftEngine::SendResult{static_cast<uint32_t>(OperationResult::INVALID_REQUEST)});
@@ -56,6 +58,7 @@ SubmitResult ConcordClientPool::SendRequest(std::vector<uint8_t> &&request,
5658

5759
while (!clients_.empty() && serving_candidates != 0) {
5860
auto client = clients_.front();
61+
external_client::ConcordClient::createConcordClientRequest(request, request_type, subscriptionId);
5962
client_id = client->getClientId();
6063
if (is_overloaded_) {
6164
is_overloaded_ = false;
@@ -224,6 +227,8 @@ SubmitResult ConcordClientPool::SendRequest(const bft::client::WriteConfig &conf
224227
config.request.sequence_number,
225228
config.request.correlation_id,
226229
config.request.span_context,
230+
config.request.request_type,
231+
config.request.client_service_id,
227232
callback);
228233
}
229234

@@ -245,6 +250,8 @@ SubmitResult ConcordClientPool::SendRequest(const bft::client::ReadConfig &confi
245250
config.request.sequence_number,
246251
config.request.correlation_id,
247252
config.request.span_context,
253+
config.request.request_type,
254+
config.request.client_service_id,
248255
callback);
249256
}
250257

@@ -487,10 +494,13 @@ void SingleRequestProcessingJob::execute() {
487494
OperationResult operation_result = processing_client_->getRequestExecutionResult();
488495
reply_size = res.matched_data.size();
489496
if (callback_) {
490-
if (operation_result == OperationResult::SUCCESS)
497+
if (operation_result == OperationResult::SUCCESS) {
498+
external_client::ConcordClient::createConcordClientResponse(res.matched_data);
499+
reply_size = res.matched_data.size();
491500
callback_(res);
492-
else
501+
} else {
493502
callback_(static_cast<uint32_t>(operation_result));
503+
}
494504
}
495505
external_client::ConcordClient::PendingReplies replies;
496506
replies.push_back(ClientReply{static_cast<uint32_t>(request_.size()),

client/client_pool/src/external_client.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ std::pair<int32_t, ConcordClient::PendingReplies> ConcordClient::SendPendingRequ
184184
try {
185185
LOG_INFO(logger_, "Batch processing started" << KVLOG(client_id_, batch_cid));
186186
auto received_replies_map = new_client_->sendBatch(request_queue, batch_cid);
187-
for (const auto& received_reply_entry : received_replies_map) {
187+
for (auto& received_reply_entry : received_replies_map) {
188188
const auto received_reply_seq_num = received_reply_entry.first;
189189
const auto& pending_seq_num_to_cid_entry = seq_num_to_cid.find(received_reply_seq_num);
190190
if (pending_seq_num_to_cid_entry == seq_num_to_cid.end()) {
@@ -195,6 +195,7 @@ std::pair<int32_t, ConcordClient::PendingReplies> ConcordClient::SendPendingRequ
195195
}
196196
auto cid = pending_seq_num_to_cid_entry->second;
197197
cid_response_map_[cid] = std::chrono::steady_clock::now();
198+
createConcordClientResponse(received_reply_entry.second.matched_data);
198199
auto data_size = received_reply_entry.second.matched_data.size();
199200
for (auto& pending_reply : pending_replies_) {
200201
if (pending_reply.cid != cid) continue;
@@ -392,6 +393,24 @@ OperationResult ConcordClient::getRequestExecutionResult() { return clientReques
392393

393394
std::string ConcordClient::messageSignature(bft::client::Msg& message) { return new_client_->signMessage(message); }
394395

396+
void ConcordClient::createConcordClientRequest(bft::client::Msg& request,
397+
bftEngine::RequestType typed_request,
398+
const std::string& subscriptionId) {
399+
concord::client::request::messages::ConcordClientRequest concord_request;
400+
concord_request.type = static_cast<decltype(concord_request.type)>(typed_request);
401+
concord_request.client_id = static_cast<decltype(concord_request.client_id)>(subscriptionId);
402+
concord_request.application_request = std::vector<uint8_t>(request.begin(), request.end());
403+
request.clear();
404+
concord::client::request::messages::serialize(request, concord_request);
405+
}
406+
407+
void ConcordClient::createConcordClientResponse(bft::client::Msg& response) {
408+
concord::client::request::messages::ConcordClientResponse concord_response;
409+
concord::client::request::messages::deserialize(response, concord_response);
410+
response.clear();
411+
response.assign(concord_response.application_response.begin(), concord_response.application_response.end());
412+
}
413+
395414
void ConcordClient::stopClientComm() { new_client_->stop(); }
396415

397416
} // namespace concord::external_client

client/clientservice/src/request_service.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414

1515
#include "client/clientservice/request_service.hpp"
1616
#include "client/concordclient/concord_client.hpp"
17-
#include "concord_client_request.pb.h"
1817
#include "client/thin-replica-client/trace_contexts.hpp"
1918

2019
using namespace client::thin_replica_client;
21-
using namespace vmware::concord::client::concord_client_request::v1;
2220

2321
namespace concord::client::clientservice {
2422

@@ -75,12 +73,9 @@ void RequestServiceCallData::sendToConcordClient() {
7573
bool is_any_request_type = false;
7674
bft::client::Msg msg;
7775
if (request_.has_typed_request()) {
78-
ConcordClientRequest concord_request;
79-
concord_request.set_client_service_id(client_->getSubscriptionId());
80-
concord_request.mutable_application_request()->CopyFrom(request_.typed_request());
81-
size_t request_size = concord_request.ByteSizeLong();
76+
size_t request_size = request_.typed_request().ByteSizeLong();
8277
std::string request(request_size, '\0');
83-
concord_request.SerializeToArray(request.data(), request_size);
78+
request_.typed_request().SerializeToArray(request.data(), request_size);
8479
msg = bft::client::Msg(request.begin(), request.end());
8580
is_any_request_type = true;
8681
} else {
@@ -95,6 +90,12 @@ void RequestServiceCallData::sendToConcordClient() {
9590
req_config.pre_execute = request_.pre_execute();
9691
req_config.timeout = timeout;
9792
req_config.correlation_id = request_.correlation_id();
93+
if (request_.has_typed_request()) {
94+
req_config.request_type = bftEngine::RequestType::ANY_MESSAGE;
95+
} else {
96+
req_config.request_type = bftEngine::RequestType::RAW_MESSAGE;
97+
}
98+
req_config.client_service_id = client_->getSubscriptionId();
9899

99100
auto callback = [this, req_config, is_any_request_type](concord::client::concordclient::SendResult&& send_result) {
100101
grpc::Status status;
@@ -163,13 +164,12 @@ void RequestServiceCallData::sendToConcordClient() {
163164

164165
// Check if the application response is of Any Type then set it to Any response.
165166
if (is_any_request_type) {
166-
ConcordClientResponse concord_response;
167-
if (!concord_response.ParseFromArray(data.c_str(), data.size())) {
167+
google::protobuf::Any* app_response = this->response_.mutable_typed_response();
168+
if (!app_response->ParseFromArray(data.c_str(), data.size())) {
168169
status = grpc::Status(grpc::StatusCode::INTERNAL, "Internal error in parsing typed response");
169170
this->populateResult(status);
170171
return;
171172
}
172-
this->response_.mutable_typed_response()->CopyFrom(concord_response.application_response());
173173
} else {
174174
this->response_.set_raw_response(std::move(data));
175175
}

client/concordclient/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
add_library(concordclient "src/concord_client.cpp")
22
target_include_directories(concordclient PUBLIC include)
33
# TODO: Mark libraries as PRIVATE once the interface is selfcontained
4+
5+
add_subdirectory("cmf")
6+
47
target_link_libraries(concordclient PUBLIC
58
thin_replica_client_lib
9+
concord_client_request
610
concord_client_pool
711
concordclient-event-api
812
util

0 commit comments

Comments
 (0)