Fixes the timeout parameter and some improvements to find non-standard installed deps.
Signed-off-by: Tao He <sighingnow@gmail.com>
This commit is contained in:
parent
62884c7e38
commit
5d1769a344
|
|
@ -117,6 +117,7 @@ find_package(gRPC QUIET)
|
|||
if(gRPC_FOUND)
|
||||
set(GRPC_LIBRARIES gRPC::gpr gRPC::grpc gRPC::grpc++)
|
||||
get_target_property(GRPC_CPP_PLUGIN gRPC::grpc_cpp_plugin LOCATION)
|
||||
get_target_property(GRPC_INCLUDE_DIR gRPC::grpc INTERFACE_INCLUDE_DIRECTORIES)
|
||||
else()
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindGRPC.cmake)
|
||||
set(GRPC_LIBRARIES ${GPR_LIBRARY} ${GRPC_LIBRARY} ${GRPC_GRPC++_LIBRARY})
|
||||
|
|
@ -137,6 +138,7 @@ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/proto)
|
|||
include_directories(SYSTEM ${Boost_INCLUDE_DIR}
|
||||
${CPPREST_INCLUDE_DIR}
|
||||
${PROTOBUF_INCLUDE_DIRS}
|
||||
${GRPC_INCLUDE_DIR}
|
||||
${OPENSSL_INCLUDE_DIR})
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
||||
|
|
|
|||
|
|
@ -647,8 +647,8 @@ namespace etcd
|
|||
/**
|
||||
* Set a timeout value for grpc operations.
|
||||
*/
|
||||
template <typename Rep = std::micro>
|
||||
void set_grpc_timeout(std::chrono::duration<Rep> const &timeout) {
|
||||
template <typename Period = std::micro>
|
||||
void set_grpc_timeout(std::chrono::duration<std::chrono::microseconds::rep, Period> const &timeout) {
|
||||
this->client->set_grpc_timeout(timeout);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,19 @@ namespace etcd
|
|||
{
|
||||
typedef std::vector<std::string> Keys;
|
||||
|
||||
namespace detail {
|
||||
// Compute the duration between given start time point and now
|
||||
inline const std::chrono::microseconds duration_till_now(
|
||||
std::chrono::high_resolution_clock::time_point const & start_timepoint) {
|
||||
return std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::high_resolution_clock::now() - start_timepoint);
|
||||
}
|
||||
}
|
||||
|
||||
// forward declaration
|
||||
class KeepAlive;
|
||||
class Watcher;
|
||||
|
||||
/**
|
||||
* The Reponse object received for the requests of etcd::Client
|
||||
*/
|
||||
|
|
@ -33,10 +46,7 @@ namespace etcd
|
|||
{
|
||||
call->waitForResponse();
|
||||
auto v3resp = call->ParseResponse();
|
||||
|
||||
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::high_resolution_clock::now() - call->startTimepoint());
|
||||
return etcd::Response(v3resp, duration);
|
||||
return etcd::Response(v3resp, detail::duration_till_now(call->startTimepoint()));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
|
@ -44,10 +54,7 @@ namespace etcd
|
|||
{
|
||||
call->waitForResponse();
|
||||
auto v3resp = call->ParseResponse();
|
||||
|
||||
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::high_resolution_clock::now() - call->startTimepoint());
|
||||
return etcd::Response(v3resp, duration);
|
||||
return etcd::Response(v3resp, detail::duration_till_now(call->startTimepoint()));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
|
@ -56,10 +63,7 @@ namespace etcd
|
|||
{
|
||||
call->waitForResponse(callback);
|
||||
auto v3resp = call->ParseResponse();
|
||||
|
||||
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::high_resolution_clock::now() - call->startTimepoint());
|
||||
return etcd::Response(v3resp, duration);
|
||||
return etcd::Response(v3resp, detail::duration_till_now(call->startTimepoint()));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
|
@ -69,10 +73,7 @@ namespace etcd
|
|||
|
||||
call->waitForResponse();
|
||||
auto v3resp = call->ParseResponse();
|
||||
|
||||
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::high_resolution_clock::now() - call->startTimepoint());
|
||||
return etcd::Response(v3resp, duration);
|
||||
return etcd::Response(v3resp, detail::duration_till_now(call->startTimepoint()));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
|
@ -82,10 +83,7 @@ namespace etcd
|
|||
|
||||
call->waitForResponse();
|
||||
auto v3resp = call->ParseResponse();
|
||||
|
||||
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::high_resolution_clock::now() - call->startTimepoint());
|
||||
return etcd::Response(v3resp, duration);
|
||||
return etcd::Response(v3resp, detail::duration_till_now(call->startTimepoint()));
|
||||
}
|
||||
|
||||
Response();
|
||||
|
|
@ -233,6 +231,9 @@ namespace etcd
|
|||
|
||||
friend class Client;
|
||||
friend class SyncClient;
|
||||
friend class KeepAlive;
|
||||
friend class Watcher;
|
||||
|
||||
friend class etcdv3::AsyncWatchAction;
|
||||
friend class etcdv3::AsyncLeaseKeepAliveAction;
|
||||
friend class etcdv3::AsyncObserveAction;
|
||||
|
|
|
|||
|
|
@ -721,8 +721,8 @@ namespace etcd
|
|||
/**
|
||||
* Set a timeout value for grpc operations.
|
||||
*/
|
||||
template <typename Rep = std::micro>
|
||||
void set_grpc_timeout(std::chrono::duration<Rep> const &timeout) {
|
||||
template <typename Period = std::micro>
|
||||
void set_grpc_timeout(std::chrono::duration<std::chrono::microseconds::rep, Period> const &timeout) {
|
||||
grpc_timeout = std::chrono::duration_cast<std::chrono::milliseconds>(timeout);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@
|
|||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <cstddef>
|
||||
#include <ratio>
|
||||
|
||||
#include "etcd/Value.hpp"
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
|
@ -31,6 +33,8 @@
|
|||
|
||||
#include <grpc++/grpc++.h>
|
||||
#include <grpc++/security/credentials.h>
|
||||
#include <grpc++/support/status_code_enum.h>
|
||||
|
||||
#include "proto/rpc.grpc.pb.h"
|
||||
#include "proto/v3lock.grpc.pb.h"
|
||||
#include "proto/v3election.grpc.pb.h"
|
||||
|
|
@ -163,9 +167,8 @@ static std::string read_from_file(std::string const &filename) {
|
|||
return std::string{};
|
||||
}
|
||||
|
||||
static grpc::SslCredentialsOptions make_ssl_credentials(std::string const &ca,
|
||||
std::string const &cert,
|
||||
std::string const &key) {
|
||||
static grpc::SslCredentialsOptions make_ssl_credentials(
|
||||
std::string const &ca, std::string const &cert, std::string const &key) {
|
||||
grpc::SslCredentialsOptions options;
|
||||
options.pem_root_certs = read_from_file(ca);
|
||||
options.pem_cert_chain = read_from_file(cert);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "etcd/v3/AsyncLeaseAction.hpp"
|
||||
|
||||
#include "etcd/Response.hpp"
|
||||
#include "etcd/v3/action_constants.hpp"
|
||||
#include "etcd/v3/Transaction.hpp"
|
||||
|
||||
|
|
@ -101,8 +102,7 @@ etcd::Response etcdv3::AsyncLeaseKeepAliveAction::Refresh()
|
|||
auto start_timepoint = std::chrono::high_resolution_clock::now();
|
||||
if (isCancelled) {
|
||||
status = grpc::Status::CANCELLED;
|
||||
return etcd::Response(ParseResponse(), std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::high_resolution_clock::now() - start_timepoint));
|
||||
return etcd::Response(ParseResponse(), etcd::detail::duration_till_now(start_timepoint));
|
||||
}
|
||||
|
||||
LeaseKeepAliveRequest leasekeepalive_request;
|
||||
|
|
@ -130,8 +130,8 @@ etcd::Response etcdv3::AsyncLeaseKeepAliveAction::Refresh()
|
|||
}
|
||||
}
|
||||
if (!status.ok()) {
|
||||
return etcd::Response(ParseResponse(), std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::high_resolution_clock::now() - start_timepoint));
|
||||
this->CancelKeepAlive();
|
||||
return etcd::Response(ParseResponse(), etcd::detail::duration_till_now(start_timepoint));
|
||||
}
|
||||
|
||||
stream->Read(&reply, (void*)etcdv3::KEEPALIVE_READ);
|
||||
|
|
@ -152,8 +152,8 @@ etcd::Response etcdv3::AsyncLeaseKeepAliveAction::Refresh()
|
|||
break;
|
||||
}
|
||||
}
|
||||
return etcd::Response(ParseResponse(), std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::high_resolution_clock::now() - start_timepoint));
|
||||
this->CancelKeepAlive();
|
||||
return etcd::Response(ParseResponse(), etcd::detail::duration_till_now(start_timepoint));
|
||||
} else {
|
||||
stream->Write(leasekeepalive_request, (void *)etcdv3::KEEPALIVE_WRITE);
|
||||
// wait write finish
|
||||
|
|
@ -161,10 +161,10 @@ etcd::Response etcdv3::AsyncLeaseKeepAliveAction::Refresh()
|
|||
stream->Read(&reply, (void*)etcdv3::KEEPALIVE_READ);
|
||||
// wait read finish
|
||||
if (cq_.Next(&got_tag, &ok) && ok && got_tag == (void *)etcdv3::KEEPALIVE_READ) {
|
||||
return etcd::Response(ParseResponse(), std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::high_resolution_clock::now() - start_timepoint));
|
||||
return etcd::Response(ParseResponse(), etcd::detail::duration_till_now(start_timepoint));
|
||||
}
|
||||
}
|
||||
this->CancelKeepAlive();
|
||||
return etcd::Response(grpc::StatusCode::ABORTED, "Failed to create a lease keep-alive connection");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue