From 020380053aa9f1ca7979e8b7be868bcf85fb247b Mon Sep 17 00:00:00 2001 From: Michael Grupp Date: Mon, 17 Sep 2018 17:09:53 +0200 Subject: [PATCH 1/3] Apply .clang-format to all files. Formatting with git clang-format was not consistent with some existing code. Applied the `.clang-format` file to all C++ files with: `clang-format --style=file **/*.h **/*.cc -i` --- async_grpc/opencensus_span.cc | 3 ++- async_grpc/retry.cc | 12 ++++++------ async_grpc/retry.h | 8 ++++---- async_grpc/server.cc | 17 +++++++++-------- async_grpc/server.h | 2 +- 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/async_grpc/opencensus_span.cc b/async_grpc/opencensus_span.cc index 283e062..2cdec0c 100644 --- a/async_grpc/opencensus_span.cc +++ b/async_grpc/opencensus_span.cc @@ -37,7 +37,8 @@ void OpencensusSpan::End() { span_.End(); } OpencensusSpan::OpencensusSpan(const std::string& name, const OpencensusSpan* parent) - : span_(opencensus::trace::Span::StartSpan(name, parent ? &parent->span_: nullptr)) {} + : span_(opencensus::trace::Span::StartSpan( + name, parent ? &parent->span_ : nullptr)) {} } // namespace async_grpc diff --git a/async_grpc/retry.cc b/async_grpc/retry.cc index 6684b65..9c360e4 100644 --- a/async_grpc/retry.cc +++ b/async_grpc/retry.cc @@ -26,7 +26,7 @@ namespace async_grpc { RetryStrategy CreateRetryStrategy(RetryIndicator retry_indicator, RetryDelayCalculator retry_delay_calculator) { return [retry_indicator, retry_delay_calculator]( - int failed_attempts, const ::grpc::Status &status) { + int failed_attempts, const ::grpc::Status& status) { if (!retry_indicator(failed_attempts, status)) { return optional(); } @@ -35,19 +35,19 @@ RetryStrategy CreateRetryStrategy(RetryIndicator retry_indicator, } RetryIndicator CreateLimitedRetryIndicator(int max_attempts) { - return [max_attempts](int failed_attempts, const ::grpc::Status &status) { + return [max_attempts](int failed_attempts, const ::grpc::Status& status) { return failed_attempts < max_attempts; }; } RetryIndicator CreateUnlimitedRetryIndicator() { - return [](int failed_attempts, const ::grpc::Status &status) { return true; }; + return [](int failed_attempts, const ::grpc::Status& status) { return true; }; } RetryIndicator CreateUnlimitedRetryIndicator( - const std::set<::grpc::StatusCode> &unrecoverable_codes) { + const std::set<::grpc::StatusCode>& unrecoverable_codes) { return - [unrecoverable_codes](int failed_attempts, const ::grpc::Status &status) { + [unrecoverable_codes](int failed_attempts, const ::grpc::Status& status) { return unrecoverable_codes.count(status.error_code()) <= 0; }; } @@ -81,7 +81,7 @@ RetryStrategy CreateUnlimitedConstantDelayStrategy(Duration delay) { } RetryStrategy CreateUnlimitedConstantDelayStrategy( - Duration delay, const std::set<::grpc::StatusCode> &unrecoverable_codes) { + Duration delay, const std::set<::grpc::StatusCode>& unrecoverable_codes) { return CreateRetryStrategy(CreateUnlimitedRetryIndicator(unrecoverable_codes), CreateConstantDelayCalculator(delay)); } diff --git a/async_grpc/retry.h b/async_grpc/retry.h index 3be38be..302560a 100644 --- a/async_grpc/retry.h +++ b/async_grpc/retry.h @@ -29,9 +29,9 @@ using common::Duration; using common::optional; using RetryStrategy = std::function( - int /* failed_attempts */, const ::grpc::Status &)>; + int /* failed_attempts */, const ::grpc::Status&)>; using RetryIndicator = - std::function; + std::function; using RetryDelayCalculator = std::function; RetryStrategy CreateRetryStrategy(RetryIndicator retry_indicator, @@ -40,7 +40,7 @@ RetryStrategy CreateRetryStrategy(RetryIndicator retry_indicator, RetryIndicator CreateLimitedRetryIndicator(int max_attempts); RetryIndicator CreateUnlimitedRetryIndicator(); RetryIndicator CreateUnlimitedRetryIndicator( - const std::set<::grpc::StatusCode> &unrecoverable_codes); + const std::set<::grpc::StatusCode>& unrecoverable_codes); RetryDelayCalculator CreateBackoffDelayCalculator(Duration min_delay, float backoff_factor); RetryDelayCalculator CreateConstantDelayCalculator(Duration delay); @@ -49,7 +49,7 @@ RetryStrategy CreateLimitedBackoffStrategy(Duration min_delay, int max_attempts); RetryStrategy CreateUnlimitedConstantDelayStrategy(Duration delay); RetryStrategy CreateUnlimitedConstantDelayStrategy( - Duration delay, const std::set<::grpc::StatusCode> &unrecoverable_codes); + Duration delay, const std::set<::grpc::StatusCode>& unrecoverable_codes); bool RetryWithStrategy(RetryStrategy retry_strategy, std::function<::grpc::Status()> op, diff --git a/async_grpc/server.cc b/async_grpc/server.cc index 8b58d92..6ad0822 100644 --- a/async_grpc/server.cc +++ b/async_grpc/server.cc @@ -46,12 +46,14 @@ void Server::Builder::SetServerAddress(const std::string& server_address) { } void Server::Builder::SetMaxReceiveMessageSize(int max_receive_message_size) { - CHECK_GT(max_receive_message_size, 0) << "max_receive_message_size must be larger than 0."; + CHECK_GT(max_receive_message_size, 0) + << "max_receive_message_size must be larger than 0."; options_.max_receive_message_size = max_receive_message_size; } void Server::Builder::SetMaxSendMessageSize(int max_send_message_size) { - CHECK_GT(max_send_message_size, 0) << "max_send_message_size must be larger than 0."; + CHECK_GT(max_send_message_size, 0) + << "max_send_message_size must be larger than 0."; options_.max_send_message_size = max_send_message_size; } @@ -63,11 +65,10 @@ void Server::Builder::EnableTracing() { #endif } -void Server::Builder::DisableTracing() { - options_.enable_tracing = false; -} +void Server::Builder::DisableTracing() { options_.enable_tracing = false; } -void Server::Builder::SetTracingSamplerProbability(double tracing_sampler_probability) { +void Server::Builder::SetTracingSamplerProbability( + double tracing_sampler_probability) { options_.tracing_sampler_probability = tracing_sampler_probability; } @@ -75,7 +76,8 @@ void Server::Builder::SetTracingTaskName(const std::string& tracing_task_name) { options_.tracing_task_name = tracing_task_name; } -void Server::Builder::SetTracingGcpProjectId(const std::string& tracing_gcp_project_id) { +void Server::Builder::SetTracingGcpProjectId( + const std::string& tracing_gcp_project_id) { options_.tracing_gcp_project_id = tracing_gcp_project_id; } @@ -178,7 +180,6 @@ void Server::Start() { } #endif - // Start the gRPC server process. server_ = server_builder_.BuildAndStart(); diff --git a/async_grpc/server.h b/async_grpc/server.h index e396ed4..11cb24a 100644 --- a/async_grpc/server.h +++ b/async_grpc/server.h @@ -36,7 +36,7 @@ namespace async_grpc { namespace { -constexpr int kDefaultMaxMessageSize = 10 * 1024 * 1024; // 10 MB +constexpr int kDefaultMaxMessageSize = 10 * 1024 * 1024; // 10 MB constexpr double kDefaultTracingSamplerProbability = 0.01; // 1 Percent } // namespace From 43d0a794e8deb4c4c3b7d3ddb9dec22064a24de6 Mon Sep 17 00:00:00 2001 From: Michael Grupp Date: Tue, 25 Sep 2018 18:09:30 +0200 Subject: [PATCH 2/3] Flaky test? From 03c6b82343933e978e1a1d0548f829867f790cdc Mon Sep 17 00:00:00 2001 From: Andre Gaschler Date: Tue, 23 Jul 2019 17:29:14 +0200 Subject: [PATCH 3/3] Ran clang-format. --- async_grpc/client.h | 4 +--- async_grpc/completion_queue_pool.cc | 6 +++--- async_grpc/completion_queue_thread.h | 1 + async_grpc/retry.cc | 5 +++-- async_grpc/rpc.cc | 2 +- async_grpc/server.h | 1 - async_grpc/service.cc | 3 +-- 7 files changed, 10 insertions(+), 12 deletions(-) diff --git a/async_grpc/client.h b/async_grpc/client.h index c4ba45b..7cbca47 100644 --- a/async_grpc/client.h +++ b/async_grpc/client.h @@ -21,14 +21,12 @@ #include "async_grpc/retry.h" #include "async_grpc/rpc_handler_interface.h" #include "async_grpc/rpc_service_method_traits.h" - +#include "glog/logging.h" #include "grpc++/grpc++.h" #include "grpc++/impl/codegen/client_unary_call.h" #include "grpc++/impl/codegen/proto_utils.h" #include "grpc++/impl/codegen/sync_stream.h" -#include "glog/logging.h" - namespace async_grpc { // Wraps a method invocation for all rpc types, unary, client streaming, diff --git a/async_grpc/completion_queue_pool.cc b/async_grpc/completion_queue_pool.cc index a32d0c0..cd5ce04 100644 --- a/async_grpc/completion_queue_pool.cc +++ b/async_grpc/completion_queue_pool.cc @@ -14,10 +14,11 @@ * limitations under the License. */ +#include "async_grpc/completion_queue_pool.h" + #include #include "async_grpc/async_client.h" -#include "async_grpc/completion_queue_pool.h" #include "common/make_unique.h" #include "glog/logging.h" @@ -89,8 +90,7 @@ void CompletionQueuePool::Shutdown() { } CompletionQueuePool::CompletionQueuePool() - : number_completion_queues_(kDefaultNumberCompletionQueues) { -} + : number_completion_queues_(kDefaultNumberCompletionQueues) {} CompletionQueuePool::~CompletionQueuePool() { LOG(INFO) << "~CompletionQueuePool"; diff --git a/async_grpc/completion_queue_thread.h b/async_grpc/completion_queue_thread.h index 9c2c217..b132014 100644 --- a/async_grpc/completion_queue_thread.h +++ b/async_grpc/completion_queue_thread.h @@ -18,6 +18,7 @@ #define CPP_GRPC_COMMON_COMPLETION_QUEUE_THREAD_H_ #include + #include #include diff --git a/async_grpc/retry.cc b/async_grpc/retry.cc index 9c360e4..c5f487b 100644 --- a/async_grpc/retry.cc +++ b/async_grpc/retry.cc @@ -14,11 +14,12 @@ * limitations under the License. */ +#include "async_grpc/retry.h" + #include #include #include -#include "async_grpc/retry.h" #include "glog/logging.h" namespace async_grpc { @@ -26,7 +27,7 @@ namespace async_grpc { RetryStrategy CreateRetryStrategy(RetryIndicator retry_indicator, RetryDelayCalculator retry_delay_calculator) { return [retry_indicator, retry_delay_calculator]( - int failed_attempts, const ::grpc::Status& status) { + int failed_attempts, const ::grpc::Status& status) { if (!retry_indicator(failed_attempts, status)) { return optional(); } diff --git a/async_grpc/rpc.cc b/async_grpc/rpc.cc index f29e84b..7970413 100644 --- a/async_grpc/rpc.cc +++ b/async_grpc/rpc.cc @@ -15,9 +15,9 @@ */ #include "async_grpc/rpc.h" -#include "async_grpc/service.h" #include "async_grpc/common/make_unique.h" +#include "async_grpc/service.h" #include "glog/logging.h" namespace async_grpc { diff --git a/async_grpc/server.h b/async_grpc/server.h index 11cb24a..0f422fd 100644 --- a/async_grpc/server.h +++ b/async_grpc/server.h @@ -30,7 +30,6 @@ #include "async_grpc/rpc_handler.h" #include "async_grpc/rpc_service_method_traits.h" #include "async_grpc/service.h" - #include "grpc++/grpc++.h" namespace async_grpc { diff --git a/async_grpc/service.cc b/async_grpc/service.cc index d99529d..ae6aeb3 100644 --- a/async_grpc/service.cc +++ b/async_grpc/service.cc @@ -14,10 +14,9 @@ * limitations under the License. */ -#include "async_grpc/server.h" - #include +#include "async_grpc/server.h" #include "glog/logging.h" #include "grpc++/impl/codegen/proto_utils.h"