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

refine FlashService #5471

Merged
merged 7 commits into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
22 changes: 11 additions & 11 deletions dbms/src/Flash/FlashService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ extern const int NOT_IMPLEMENTED;

constexpr char tls_err_msg[] = "common name check is failed";

FlashService::FlashService(IServer & server_)
: server(server_)
, security_config(server_.securityConfig())
FlashService::FlashService(const TiFlashSecurityConfig & security_config_, Context & context_)
: security_config(security_config_)
, m_context(context_)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m_context is not recommended by ClickHouse's coding style.

, log(&Poco::Logger::get("FlashService"))
, manual_compact_manager(std::make_unique<Management::ManualCompactManager>(
server_.context().getGlobalContext(),
server_.context().getGlobalContext().getSettingsRef()))
m_context.getGlobalContext(),
m_context.getGlobalContext().getSettingsRef()))
{
auto settings = server_.context().getSettingsRef();
auto settings = m_context.getSettingsRef();
enable_local_tunnel = settings.enable_local_tunnel;
enable_async_grpc_client = settings.enable_async_grpc_client;
const size_t default_size = 2 * getNumberOfPhysicalCPUCores();
Expand Down Expand Up @@ -364,8 +364,8 @@ std::tuple<ContextPtr, grpc::Status> FlashService::createDBContext(const grpc::S
try
{
/// Create DB context.
auto context = std::make_shared<Context>(server.context());
context->setGlobalContext(server.context());
auto context = std::make_shared<Context>(m_context);
context->setGlobalContext(m_context);

/// Set a bunch of client information.
std::string user = getClientMetaVarWithDefault(grpc_context, "user", "default");
Expand Down Expand Up @@ -411,17 +411,17 @@ std::tuple<ContextPtr, grpc::Status> FlashService::createDBContext(const grpc::S
catch (Exception & e)
{
LOG_FMT_ERROR(log, "DB Exception: {}", e.message());
return std::make_tuple(std::make_shared<Context>(server.context()), grpc::Status(tiflashErrorCodeToGrpcStatusCode(e.code()), e.message()));
return std::make_tuple(std::make_shared<Context>(m_context), grpc::Status(tiflashErrorCodeToGrpcStatusCode(e.code()), e.message()));
}
catch (const std::exception & e)
{
LOG_FMT_ERROR(log, "std exception: {}", e.what());
return std::make_tuple(std::make_shared<Context>(server.context()), grpc::Status(grpc::StatusCode::INTERNAL, e.what()));
return std::make_tuple(std::make_shared<Context>(m_context), grpc::Status(grpc::StatusCode::INTERNAL, e.what()));
}
catch (...)
{
LOG_FMT_ERROR(log, "other exception");
return std::make_tuple(std::make_shared<Context>(server.context()), grpc::Status(grpc::StatusCode::INTERNAL, "other exception"));
return std::make_tuple(std::make_shared<Context>(m_context), grpc::Status(grpc::StatusCode::INTERNAL, "other exception"));
}
}

Expand Down
8 changes: 4 additions & 4 deletions dbms/src/Flash/FlashService.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class FlashService : public tikvpb::Tikv::Service
, private boost::noncopyable
{
public:
explicit FlashService(IServer & server_);
FlashService(const TiFlashSecurityConfig & security_config_, Context & context_);

~FlashService() override;

Expand Down Expand Up @@ -83,8 +83,8 @@ class FlashService : public tikvpb::Tikv::Service
protected:
std::tuple<ContextPtr, ::grpc::Status> createDBContext(const grpc::ServerContext * grpc_context) const;

IServer & server;
const TiFlashSecurityConfig & security_config;
Context & m_context;
Poco::Logger * log;
bool is_async = false;
bool enable_local_tunnel = false;
Expand All @@ -103,8 +103,8 @@ class AsyncFlashService final : public FlashService
// 48 is EstablishMPPConnection API ID of GRPC
// note: if the kvrpc protocal is updated, please keep consistent with the generated code.
static constexpr int EstablishMPPConnectionApiID = 48;
explicit AsyncFlashService(IServer & server)
: FlashService(server)
AsyncFlashService(const TiFlashSecurityConfig & security_config_, Context & context_)
: FlashService(security_config_, context_)
{
is_async = true;
::grpc::Service::MarkMethodAsync(EstablishMPPConnectionApiID);
Expand Down
4 changes: 2 additions & 2 deletions dbms/src/Server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,9 +598,9 @@ class Server::FlashGrpcServerHolder
/// Init and register flash service.
bool enable_async_server = server.context().getSettingsRef().enable_async_server;
if (enable_async_server)
flash_service = std::make_unique<AsyncFlashService>(server);
flash_service = std::make_unique<AsyncFlashService>(server.securityConfig(), server.context());
else
flash_service = std::make_unique<FlashService>(server);
flash_service = std::make_unique<FlashService>(server.securityConfig(), server.context());
diagnostics_service = std::make_unique<DiagnosticsService>(server);
builder.SetOption(grpc::MakeChannelArgumentOption(GRPC_ARG_HTTP2_MIN_RECV_PING_INTERVAL_WITHOUT_DATA_MS, 5 * 1000));
builder.SetOption(grpc::MakeChannelArgumentOption(GRPC_ARG_HTTP2_MIN_SENT_PING_INTERVAL_WITHOUT_DATA_MS, 10 * 1000));
Expand Down