Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
ywqzzy committed Jul 26, 2022
1 parent 30ec688 commit a1bf38e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
38 changes: 19 additions & 19 deletions dbms/src/Flash/FlashService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ constexpr char tls_err_msg[] = "common name check is failed";

FlashService::FlashService(const TiFlashSecurityConfig & security_config_, Context & context_)
: security_config(security_config_)
, m_context(context_)
, context(context_)
, log(&Poco::Logger::get("FlashService"))
, manual_compact_manager(std::make_unique<Management::ManualCompactManager>(
m_context.getGlobalContext(),
m_context.getGlobalContext().getSettingsRef()))
context.getGlobalContext(),
context.getGlobalContext().getSettingsRef()))
{
auto settings = m_context.getSettingsRef();
auto settings = 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>(m_context);
context->setGlobalContext(m_context);
auto tmp_context = std::make_shared<Context>(context);
tmp_context->setGlobalContext(context);

/// Set a bunch of client information.
std::string user = getClientMetaVarWithDefault(grpc_context, "user", "default");
Expand All @@ -375,53 +375,53 @@ std::tuple<ContextPtr, grpc::Status> FlashService::createDBContext(const grpc::S
Int64 pos = peer.find(':');
if (pos == -1)
{
return std::make_tuple(context, ::grpc::Status(::grpc::StatusCode::INVALID_ARGUMENT, "Invalid peer address: " + peer));
return std::make_tuple(tmp_context, ::grpc::Status(::grpc::StatusCode::INVALID_ARGUMENT, "Invalid peer address: " + peer));
}
std::string client_ip = peer.substr(pos + 1);
Poco::Net::SocketAddress client_address(client_ip);

context->setUser(user, password, client_address, quota_key);
tmp_context->setUser(user, password, client_address, quota_key);

String query_id = getClientMetaVarWithDefault(grpc_context, "query_id", "");
context->setCurrentQueryId(query_id);
tmp_context->setCurrentQueryId(query_id);

ClientInfo & client_info = context->getClientInfo();
ClientInfo & client_info = tmp_context->getClientInfo();
client_info.query_kind = ClientInfo::QueryKind::INITIAL_QUERY;
client_info.interface = ClientInfo::Interface::GRPC;

/// Set DAG parameters.
std::string dag_records_per_chunk_str = getClientMetaVarWithDefault(grpc_context, "dag_records_per_chunk", "");
if (!dag_records_per_chunk_str.empty())
{
context->setSetting("dag_records_per_chunk", dag_records_per_chunk_str);
tmp_context->setSetting("dag_records_per_chunk", dag_records_per_chunk_str);
}

String max_threads = getClientMetaVarWithDefault(grpc_context, "tidb_max_tiflash_threads", "");
if (!max_threads.empty())
{
context->setSetting("max_threads", max_threads);
tmp_context->setSetting("max_threads", max_threads);
LOG_FMT_INFO(log, "set context setting max_threads to {}", max_threads);
}

context->setSetting("enable_async_server", is_async ? "true" : "false");
context->setSetting("enable_local_tunnel", enable_local_tunnel ? "true" : "false");
context->setSetting("enable_async_grpc_client", enable_async_grpc_client ? "true" : "false");
return std::make_tuple(context, grpc::Status::OK);
tmp_context->setSetting("enable_async_server", is_async ? "true" : "false");
tmp_context->setSetting("enable_local_tunnel", enable_local_tunnel ? "true" : "false");
tmp_context->setSetting("enable_async_grpc_client", enable_async_grpc_client ? "true" : "false");
return std::make_tuple(tmp_context, grpc::Status::OK);
}
catch (Exception & e)
{
LOG_FMT_ERROR(log, "DB Exception: {}", e.message());
return std::make_tuple(std::make_shared<Context>(m_context), grpc::Status(tiflashErrorCodeToGrpcStatusCode(e.code()), e.message()));
return std::make_tuple(std::make_shared<Context>(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>(m_context), grpc::Status(grpc::StatusCode::INTERNAL, e.what()));
return std::make_tuple(std::make_shared<Context>(context), grpc::Status(grpc::StatusCode::INTERNAL, e.what()));
}
catch (...)
{
LOG_FMT_ERROR(log, "other exception");
return std::make_tuple(std::make_shared<Context>(m_context), grpc::Status(grpc::StatusCode::INTERNAL, "other exception"));
return std::make_tuple(std::make_shared<Context>(context), grpc::Status(grpc::StatusCode::INTERNAL, "other exception"));
}
}

Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Flash/FlashService.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class FlashService : public tikvpb::Tikv::Service
std::tuple<ContextPtr, ::grpc::Status> createDBContext(const grpc::ServerContext * grpc_context) const;

const TiFlashSecurityConfig & security_config;
Context & m_context;
Context & context;
Poco::Logger * log;
bool is_async = false;
bool enable_local_tunnel = false;
Expand Down

0 comments on commit a1bf38e

Please sign in to comment.