From dd057ccc6bba0c655a85d851a451e921ba0b5ed7 Mon Sep 17 00:00:00 2001 From: CalvinNeo Date: Wed, 18 Aug 2021 10:33:00 +0800 Subject: [PATCH] read server_info from proxy through ffi(with test) --- contrib/tiflash-proxy | 2 +- dbms/src/Flash/DiagnosticsService.cpp | 25 ++++++++++++-- dbms/src/Server/Server.cpp | 2 +- dbms/src/Storages/Transaction/ProxyFFI.cpp | 7 ++++ dbms/src/Storages/Transaction/ProxyFFI.h | 2 ++ .../diagnostics/check_diagnostics.test | 34 +++++++++++++++++++ 6 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 tests/fullstack-test2/diagnostics/check_diagnostics.test diff --git a/contrib/tiflash-proxy b/contrib/tiflash-proxy index 7d4e73b43e8..fa27eb9bc20 160000 --- a/contrib/tiflash-proxy +++ b/contrib/tiflash-proxy @@ -1 +1 @@ -Subproject commit 7d4e73b43e8ddf47946378208b6db25df8d4e1e6 +Subproject commit fa27eb9bc2085050619813392b48754ef6fa0545 diff --git a/dbms/src/Flash/DiagnosticsService.cpp b/dbms/src/Flash/DiagnosticsService.cpp index 866ceb21a67..3dec7e6f23a 100644 --- a/dbms/src/Flash/DiagnosticsService.cpp +++ b/dbms/src/Flash/DiagnosticsService.cpp @@ -3,6 +3,9 @@ #include #include #include +#include +#include +#include #include #include @@ -363,7 +366,7 @@ struct CPUArchHelper const std::string & get() const { return arch_; } protected: - std::string execOrElse(const char * cmd [[ maybe_unused ]], const char * otherwise) + std::string execOrElse(const char * cmd [[maybe_unused]], const char * otherwise) { #if defined(__unix__) std::array buffer; @@ -942,6 +945,19 @@ try { (void)context; +#if true + //defined(__APPLE__) + const TiFlashRaftProxyHelper * helper = server.context().getTMTContext().getKVStore()->getProxyHelper(); + if (helper) + { + std::string req = request->SerializeAsString(); + helper->fn_server_info(helper->proxy_ptr, strIntoView(req), response); + } + else + { + LOG_ERROR(log, "TiFlashRaftProxyHelper is nullptr"); + } +#else auto tp = request->tp(); std::vector items; @@ -1006,7 +1022,7 @@ try added_pair->set_value(pair.value()); } } - +#endif return ::grpc::Status::OK; } catch (const Exception & e) @@ -1014,6 +1030,11 @@ catch (const Exception & e) LOG_ERROR(log, e.displayText()); return grpc::Status(grpc::StatusCode::INTERNAL, "internal error"); } +catch (const std::exception & e) +{ + LOG_ERROR(log, e.what()); + return grpc::Status(grpc::StatusCode::INTERNAL, "internal error"); +} ::grpc::Status DiagnosticsService::search_log(::grpc::ServerContext * grpc_context, const ::diagnosticspb::SearchLogRequest * request, ::grpc::ServerWriter<::diagnosticspb::SearchLogResponse> * stream) diff --git a/dbms/src/Server/Server.cpp b/dbms/src/Server/Server.cpp index 275242759a0..6aff4438d61 100644 --- a/dbms/src/Server/Server.cpp +++ b/dbms/src/Server/Server.cpp @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -874,6 +873,7 @@ int Server::main(const std::vector & /*args*/) .fn_gc_raw_cpp_ptr = GcRawCppPtr, .fn_gen_batch_read_index_res = GenBatchReadIndexRes, .fn_insert_batch_read_index_resp = InsertBatchReadIndexResp, + .fn_set_server_info_resp = SetSetverInfoResp, }; RaftStoreProxyRunner proxy_runner(RaftStoreProxyRunner::RunRaftStoreProxyParms{&helper, proxy_conf}, log); diff --git a/dbms/src/Storages/Transaction/ProxyFFI.cpp b/dbms/src/Storages/Transaction/ProxyFFI.cpp index b726e5d631b..dce83ab3eff 100644 --- a/dbms/src/Storages/Transaction/ProxyFFI.cpp +++ b/dbms/src/Storages/Transaction/ProxyFFI.cpp @@ -6,6 +6,7 @@ #include #include #include +#include namespace CurrentMetrics { @@ -370,4 +371,10 @@ void InsertBatchReadIndexResp(RawVoidPtr resp, BaseBuffView view, uint64_t regio RawCppPtr GenRawCppPtr(RawVoidPtr ptr_, RawCppPtrTypeImpl type_) { return RawCppPtr{ptr_, static_cast(type_)}; } +void SetSetverInfoResp(BaseBuffView view, RawVoidPtr ptr) +{ + using diagnosticspb::ServerInfoResponse; + reinterpret_cast(ptr)->ParseFromArray(view.data, view.len); +} + } // namespace DB diff --git a/dbms/src/Storages/Transaction/ProxyFFI.h b/dbms/src/Storages/Transaction/ProxyFFI.h index 022b67e9b1e..3e5322f6acc 100644 --- a/dbms/src/Storages/Transaction/ProxyFFI.h +++ b/dbms/src/Storages/Transaction/ProxyFFI.h @@ -75,5 +75,7 @@ uint8_t CheckHttpUriAvailable(BaseBuffView); void GcRawCppPtr(EngineStoreServerWrap *, void * ptr, RawCppPtrType type); RawVoidPtr GenBatchReadIndexRes(uint64_t cap); void InsertBatchReadIndexResp(RawVoidPtr, BaseBuffView, uint64_t); +void SetSetverInfoResp(BaseBuffView, RawVoidPtr); +BaseBuffView strIntoView(const std::string & view); } } // namespace DB diff --git a/tests/fullstack-test2/diagnostics/check_diagnostics.test b/tests/fullstack-test2/diagnostics/check_diagnostics.test new file mode 100644 index 00000000000..87bab2fa2a5 --- /dev/null +++ b/tests/fullstack-test2/diagnostics/check_diagnostics.test @@ -0,0 +1,34 @@ +mysql> select distinct(NAME) from INFORMATION_SCHEMA.CLUSTER_HARDWARE where TYPE='tiflash' order by NAME; ++--------------------+ +| NAME | ++--------------------+ +| capacity | +| cpu-arch | +| cpu-frequency | +| cpu-logical-cores | +| cpu-physical-cores | +| cpu-vendor-id | +| flag | +| free | +| free-percent | +| fstype | +| index | +| ip | +| is-broadcast | +| is-loopback | +| is-multicast | +| is-point-to-point | +| is-up | +| l1-cache-line-size | +| l1-cache-size | +| l2-cache-line-size | +| l2-cache-size | +| l3-cache-line-size | +| l3-cache-size | +| mac | +| path | +| total | +| type | +| used | +| used-percent | ++--------------------+